Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5] Mouse cursor changig when holding down mouse button problem

This thread is locked; no one can reply to it. rss feed Print
[A5] Mouse cursor changig when holding down mouse button problem
mickwa
Member #13,928
January 2012

Hi,

I want to change mouse cursor on press and release mouse button events. When I press and hold mouse button, ALLEGRO_EVENT_MOUSE_BUTTON_DOWN event occurres, I get "grab cursor set" message in console, but cursor remains unchanged until I release the button. I don't know why it works like that, I expected that the cursor will change when I press and hold button. Am I missing something? Thank for help.

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_image.h> 3#include <allegro5/allegro_primitives.h> 4#include <iostream> 5using std::cout; 6using std::endl; 7 8int main(int argc, char **argv) 9{ 10 if(!al_init()) { 11 return -1; 12 } 13 al_init_image_addon(); 14 al_init_primitives_addon(); 15 16 ALLEGRO_DISPLAY *display = NULL; 17 18 display = al_create_display(555,567); 19 al_install_mouse(); 20 21 ALLEGRO_MOUSE_CURSOR *freeCursor = NULL; 22 ALLEGRO_MOUSE_CURSOR *grabCursor = NULL; 23 24 ALLEGRO_BITMAP *freeBmp = al_load_bitmap("handCursor.bmp"); 25 ALLEGRO_BITMAP *grabBmp = al_load_bitmap("handCursorGrab.bmp"); 26 27 freeCursor = al_create_mouse_cursor(freeBmp,5,5); 28 grabCursor = al_create_mouse_cursor(grabBmp,5,5); 29 30 ALLEGRO_EVENT_QUEUE *mouseEvents = NULL; 31 mouseEvents = al_create_event_queue(); 32 al_register_event_source(mouseEvents, al_get_mouse_event_source()); 33 ALLEGRO_EVENT button; 34 bool cursorChange1= false,cursorChange2=false; 35 al_show_mouse_cursor(display); 36 cout<<"start"<<endl; 37 38 while(1) 39 { 40 al_wait_for_event(mouseEvents,&button); 41 42 switch (button.type) 43 { 44 case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN : 45 { 46 cursorChange2 = al_set_mouse_cursor(display,grabCursor); 47 if (cursorChange2) 48 cout<<"grabCursor set"<<endl; 49 else 50 cout<<"failed to set grabCursor"<<endl; 51 52 al_rest(3); // for testing 53 break; 54 } 55 56 case ALLEGRO_EVENT_MOUSE_BUTTON_UP : 57 { 58 cursorChange1 = al_set_mouse_cursor(display,freeCursor); 59 if (cursorChange1) 60 cout<<"freeCursor set"<<endl; 61 else 62 cout<<"failed to set freeCursor"<<endl; 63 break; 64 } 65 } 66 } 67 return 0; 68}

Peter Wang
Member #23
April 2000

What operating system? I believe in Windows the cursor wouldn't change until you moved the mouse following the al_set_mouse_cursor call.

mickwa
Member #13,928
January 2012

It is Windows 7 32bit. Moving mouse does not solve the problem. When I add hiding and showing cursor like this it works fine.

#SelectExpand
1cursorChange2 = al_set_mouse_cursor(display,grabCursor); 2al_hide_mouse_cursor(display); 3al_show_mouse_cursor(display);

But I still don't understand why this code in my first post does not change cursor.

Peter Wang
Member #23
April 2000

Could well be a bug in Allegro.

mickwa
Member #13,928
January 2012

Maybe it is a bug. Can this post be moved to Allegro Development? I would be very thankful if someone could reply.

Thomas Fjellstrom
Member #476
June 2000
avatar

mickwa said:

Maybe it is a bug. Can this post be moved to Allegro Development? I would be very thankful if someone could reply.

Someone did ;) Peter is our defacto "Dear" leader.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

mickwa
Member #13,928
January 2012

Hi Peter, hi Thomas
Thanks for Your support.
I have tested this code on Ubuntu and it works different. On Ubuntu I don't have to release mouse button to change cursor.

Go to: