hi,
i'm having lots of images like options or radio buttons,
what i want to do is i want to select the option on click on that position?
my code is
int onoffflg = 1;
int optionss()
{
int mx,my;
while(!key[KEY_ESC] || 0){
draw_sprite(screen,options, 115,130);
if(onoffflg==0)
{
draw_sprite(options, opton, 195,70);
draw_sprite(options, optoff, 360,70);
}
else
{
draw_sprite(options, optoff, 195,70);
draw_sprite(options, opton, 360,70);
}
if(mouse_b)
{
mx=mouse_x;
my=mouse_y;
play_sample(sound2, 300, 128, 1000, 0);
if(mx>=195 && mx<=223 && my>=70 && my<=91)
{
if(onoffflg==1)
onoffflg=0;
else
onoffflg=1;
}
}
i'm calling this function and it's working but what it does is when i click the images are changing but too quickly but once i click completely i.e a click and a release it is working properly but when the mouse is in click (only a pressdown) the images are changing,
what should i do here?
help me on this...
if(mouse_b&1)
hi ,
i tried that one but still happening in the same way..
i call that options inside a while loop
while(!key[KEY_ESC]){
if(key[KEY_R]){
garbagecollection();
loader();
}
options();
.
.
.
.
}
would this cause the probs?
this happens because the mouse button is not released fast enough
a cheap trick would be, after detecting the mouse click, wait until the mouse is released in order to proceed, like this: (took your source and modified it)
1 | if(mouse_b & 1) |
2 | { |
3 | |
4 | mx=mouse_x; |
5 | my=mouse_y; |
6 | play_sample(sound2, 300, 128, 1000, 0); |
7 | if(mx>=195 && mx<=223 && my>=70 && my<=91) |
8 | { |
9 | if(onoffflg==1) |
10 | onoffflg=0; |
11 | else |
12 | onoffflg=1; |
13 | } |
14 | |
15 | // here is my part to wait user for mouse button release |
16 | while (mouse_b & 1) ; |
17 | |
18 | } |
let me know if it works...
The proper way is to remember that the mouse button has been click and then look for the release. Sample code:
1 | bool button_is_being_pressed_down = false; |
2 | ... |
3 | while (!done) { |
4 | if (!button_is_being_pressed_down) { |
5 | // watch for a mouse down event |
6 | if (mouse_b&1) { |
7 | button_is_being_pressed_down = true; |
8 | } |
9 | } |
10 | else { |
11 | // watch for a mouse up event |
12 | if (!(mouse_b&1)) { |
13 | // here it is!!!!!!11 |
14 | button_is_being_pressed_down = false; |
15 | } |
16 | } |
17 | } |
http://www.allegro.cc/manual/api/mouse-routines/mouse_callback
You could have this callback keep track of how long it's been since the last click for doubleclick capability as well as signaling button press/release.