in windowed mode i can spy on the WM_LBUTTONDOWN mesages and log when they occur, this gives me suffecient timing information to detect double clicks.
but in fullscreen mode, WM_LBUTTONDOWN messages dont appear to be sent.
how can i detect double clicks ? accurately.
(polling the mouse_b) can not be done accurately.
i'll consider solutions that involve hacking allegro too.. as i think that is the only way its going to happen.
| 1 | //Mouse.h |
| 2 | #include "Button.h" |
| 3 | |
| 4 | class Mouse: public MenuObject |
| 5 | { |
| 6 | private: |
| 7 | |
| 8 | public: |
| 9 | Mouse(); |
| 10 | |
| 11 | |
| 12 | bool is_doubleclick(); |
| 13 | |
| 14 | void draw(BITMAP *bmp); |
| 15 | }; |
| 16 | Mouse::Mouse() |
| 17 | { |
| 18 | Set_x(mouse_x); |
| 19 | Set_y(mouse_y); |
| 20 | Set_w(10); |
| 21 | Set_h(10); |
| 22 | } |
| 23 | void Mouse::draw(BITMAP *bmp) |
| 24 | { |
| 25 | show_mouse(bmp); |
| 26 | Set_x( mouse_x); |
| 27 | Set_y( mouse_y); |
| 28 | drawRectangle(bmp,Get_x(), Get_y(), Get_w(), Get_h(), Get_color(), 0, Get_color()); |
| 29 | scare_mouse(); |
| 30 | |
| 31 | } |
| 32 | |
| 33 | bool Mouse::is_doubleclick()//we can even put the sleep valus as ints in the fuction header for more flex |
| 34 | { |
| 35 | if (mouse_b & 1) |
| 36 | { |
| 37 | Sleep(75); |
| 38 | if (!(mouse_b & 1)) |
| 39 | { |
| 40 | Sleep(50); |
| 41 | if (mouse_b & 1) |
| 42 | { |
| 43 | |
| 44 | return true; |
| 45 | |
| 46 | } |
| 47 | return false; |
| 48 | } |
| 49 | return false; |
| 50 | } |
| 51 | return false; |
| 52 | } |
| 1 | |
| 2 | #include "Menu.h" |
| 3 | Menu login; |
| 4 | |
| 5 | int draw_login(BITMAP* bmp) |
| 6 | { |
| 7 | |
| 8 | login.buttons[0].Set_lable( " Logon"); |
| 9 | login.buttons[0].Set_x(login.Get_x()+50); |
| 10 | login.buttons[0].Set_y(login.Get_y()+40); |
| 11 | login.buttons[0].Set_w(100); |
| 12 | login.buttons[0].Set_h(25); |
| 13 | login.buttons[1].Set_lable( "Make New"); |
| 14 | login.buttons[1].Set_x(login.Get_x()+100); |
| 15 | login.buttons[1].Set_y(login.Get_y()+110); |
| 16 | login.buttons[1].Set_w(100); |
| 17 | login.buttons[1].Set_h(25); |
| 18 | |
| 19 | login.buttons[2].Set_lable( " Exit"); |
| 20 | login.buttons[2].Set_x(login.Get_x()+100); |
| 21 | login.buttons[2].Set_y(login.Get_y()+150); |
| 22 | login.buttons[2].Set_w(100); |
| 23 | login.buttons[2].Set_h(25); |
| 24 | |
| 25 | login.textboxs[0].Set_lable( "Enter Uesrname"); |
| 26 | login.textboxs[0].Set_x(login.Get_x()+160); |
| 27 | login.textboxs[0].Set_y(login.Get_y()+20); |
| 28 | login.textboxs[0].Set_w(100); |
| 29 | login.textboxs[0].Set_h(25); |
| 30 | |
| 31 | login.textboxs[1].Set_lable( "Enter PassWord"); |
| 32 | login.textboxs[1].Set_x(login.Get_x()+160); |
| 33 | login.textboxs[1].Set_y(login.Get_y()+60); |
| 34 | login.textboxs[1].Set_w(100); |
| 35 | login.textboxs[1].Set_h(25); |
| 36 | |
| 37 | login.draw(bmp); |
| 38 | |
| 39 | login.buttons[0].draw(bmp); |
| 40 | login.buttons[1].draw(bmp); |
| 41 | login.buttons[2].draw(bmp); |
| 42 | |
| 43 | username = login.textboxs[0].draw(bmp); //returns username |
| 44 | password = login.textboxs[1].draw(bmp); //returns password |
| 45 | |
| 46 | if (!(mouse_b & 1)) |
| 47 | { |
| 48 | login.mx = mouse_x; |
| 49 | login.my = mouse_y; |
| 50 | } |
| 51 | login.mouse[0].draw(bmp); |
| 52 | //if (mouse_b & 1) |
| 53 | if (login.mouse[0].is_doubleclick()) |
| 54 | { |
| 55 | if(login.is_collision( login.mouse[0])) |
| 56 | { |
| 57 | if(!login.buttons[0].is_collision( login.mouse[0])) |
| 58 | { |
| 59 | if(!login.buttons[1].is_collision( login.mouse[0])) |
| 60 | { |
| 61 | if(!login.textboxs[0].is_collision( login.mouse[0])) |
| 62 | { |
| 63 | if(!login.textboxs[1].is_collision( login.mouse[0])) |
| 64 | { |
| 65 | |
| 66 | //login.Set_x( mouse_x ); |
| 67 | //login.Set_y( mouse_y ); |
| 68 | login.mov=mouse_x -login.mx; |
| 69 | login.mov2=mouse_y - login.my; |
| 70 | login.mx = mouse_x; |
| 71 | login.my = mouse_y; |
| 72 | |
| 73 | login.Set_x( login.Get_x()+login.mov); |
| 74 | login.Set_y( login.Get_y()+login.mov2); |
| 75 | |
| 76 | login.mov = 0; |
| 77 | login.mov2 = 0; |
| 78 | //mouse_x = login.mov + login.Get_x(); |
| 79 | //mouse_y = login.mov2 + login.Get_y(); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if(login.buttons[0].is_collision( login.mouse[0])) |
| 87 | { |
| 88 | login.buttons[0].Set_state(1); |
| 89 | //do this buttons stuff login |
| 90 | //sub menu get username and password |
| 91 | //need to give chances to enter that mean we need sever conection here |
| 92 | //contiual on to game |
| 93 | |
| 94 | return 1; |
| 95 | } |
| 96 | else |
| 97 | { |
| 98 | login.buttons[0].Set_state(0); |
| 99 | } |
| 100 | if(login.buttons[1].is_collision( login.mouse[0])) |
| 101 | { |
| 102 | login.buttons[1].Set_state(1); |
| 103 | //do this buttons stuff new acount |
| 104 | |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | login.buttons[1].Set_state(0); |
| 109 | |
| 110 | } |
| 111 | |
| 112 | if(login.buttons[2].is_collision( login.mouse[0])) |
| 113 | { |
| 114 | login.buttons[2].Set_state(1); |
| 115 | //do this buttons stuff exit |
| 116 | return -1;//are you done drawing |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | login.buttons[2].Set_state(0); |
| 121 | } |
| 122 | |
| 123 | if(login.textboxs[0].is_collision( login.mouse[0])) |
| 124 | { |
| 125 | login.textboxs[0].Set_selceted(true); |
| 126 | login.textboxs[1].Set_selceted(false); |
| 127 | //username text box has keybord |
| 128 | |
| 129 | } |
| 130 | if(login.textboxs[1].is_collision( login.mouse[0])) |
| 131 | { |
| 132 | login.textboxs[1].Set_selceted(true); |
| 133 | login.textboxs[0].Set_selceted(false); |
| 134 | //passWord text box has keybord |
| 135 | |
| 136 | } |
| 137 | |
| 138 | } |
| 139 | return 0; //are you done drawing |
| 140 | } |
That isn't very elegant... sleeping multiple times in the poll function.
Also, why use show_mouse? Just draw_sprite() mouse_sprite to the x/y.
That isn't very elegant... sleeping multiple times in the poll function.
there were 2 other way i thought up but they involve variables . this the best metod out of the tree. plus this can be class independent.
Also, why use show_mouse? Just draw_sprite() mouse_sprite to the x/y.
i am using the defalt mouse sprite. i did not load my own yet. check out my game and write a review if you can please
picollo, you've missed the point, how can i detect the mouse_b is im busy doing other stuff
how can i detect the mouse_b is im busy doing other stuff
héhé use pthread my bad !
is_doubleclick(); put that any where you want to check.
This is a windows prog? Check out WM_LBUTTONDBLCLK message.
What? That was the problem... it wasn't working for him full screen.
in windowed mode, i can see the WM_LBUTTON message, but in fullscreen mode i dont.
gezzz thouse sleeps are in Milli seconds I'm using 50 50, and it only activates when the mouse is pressed.
A bit offtopic: how do you make a window fullscreen? I think that doesn't mean it's maximized.
Maybe that's in some way related to why you're not getting those messages (I suppose you still get WM_CHAR and friends).
Marco.. i use set_gfx_mode(AUTO_DETECT_FULLSCREEN,
piccolo, it can't sleep, its busy doing other work, like rendering graphics.
You'll have to took at allegro source code why messages are not forwarded to you app. My wild guess is that it creates another window to handle input.
I'm not familiar with WM_LBUTTONDOWN, but couldn't you use Allegro's interrupt routines?
http://www.allegro.cc/manual/api/mouse-routines/mouse_callback
You'll need to keep track of the number of MOUSE_FLAG_LEFT_DOWNs you got, with a timer to see if they were sufficiently close together.