Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » mouse_b problem

This thread is locked; no one can reply to it. rss feed Print
mouse_b problem
bendenote
Member #7,842
October 2006

Hi;
I was reading allegro-manual-4.2.0.I found mouse click variable. When I try to this variable, program do nothing about mouse. Mouse display on the screen and move everywhere on the screen but click variables don't work.

I am using so:

at the top of program;

install_mouse();
show_mouse(screen);

and after

if(mouse_b&0)
printf("Left side is pressed\n");
if(mouse_b&1)
printf("Right side is pressed\n");

when program run, i don't see anything in console.

Richard Phipps
Member #1,632
November 2001
avatar

Try the mouse example and see if that works for you first.

miran
Member #2,407
June 2002

Did you set gfx mode or not?

EDIT: Also you got the logic wrong. mouse_b&0 doesn't make sense. It's mouse_b&1 for left and mouse_b&2 for the right button (middle button is mouse_b&4).

--
sig used to be here

bendenote
Member #7,842
October 2006

All of my code

#include <allegro.h>
#include <stdio.h>

int get_mouse(void){
int x,y;
if( (mouse_x<100) || (mouse_x>550) || (mouse_y<100) || (mouse_y>550))
return -1;
else{
x=(mouse_x-100)/50;
y=(mouse_y-100)/50;
return x+y*9;
}
}

int main(int argc, char *argv[]){


allegro_init();

BITMAP *resmim=NULL,*top=NULL;
int light_wood_1 = makecol(195, 135, 55);
set_color_depth(32);
install_keyboard();
install_mouse();
install_timer();

if (set_gfx_mode(GFX_AUTODETECT, 600, 600, 0, 0) != 0) {
if (set_gfx_mode(GFX_SAFE, 600, 600, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
return 1;
}
}


set_palette(desktop_palette);
clear_to_color(screen,light_wood_1);
show_mouse(screen);
resmim=load_bitmap("bg81.bmp",desktop_palette);
top=load_bitmap("brown00.bmp",desktop_palette);
draw_sprite(resmim,top,0,0);

blit(resmim,screen,0,0,100,100,450,450);

while(mouse_b & 1){/*This loop doesn't work. What can I do?*/
if ( get_mouse()>0)
printf("%d\n",fare_deger_al());
}


readkey();
destroy_bitmap(resmim);
destroy_bitmap(top);
return 0;
}

miran
Member #2,407
June 2002

Quote:

What can I do?

You can start by using code tags.

EDIT: What do you expect your code to do? It makes no sense.

Here's some sample code that does work:

1#include <allegro.h>
2#include <stdio.h>
3 
4int main() {
5 allegro_init();
6 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640,480,0,0);
7 install_mouse();
8 install_keyboard();
9 
10 while (!key[KEY_ESC]) {
11 if(mouse_b&1)
12 printf("Left side is pressed\n");
13 if(mouse_b&2)
14 printf("Right side is pressed\n");
15 rest(10);
16 }
17 
18 return 0;
19}
20END_OF_MAIN()

--
sig used to be here

bendenote
Member #7,842
October 2006

Thanks miran I try your code. Mouse works. Default variable was "left side is pressed". So it couldn't display screen. when I correct so while loop it works:

while(!key[KEY_ESC]){
if(mouse_b&1){if ( fare_deger_al()>0)
printf("%d\n",fare_deger_al());
}
printf("Left side is pressed\n");
if(mouse_b&2)
printf("Right side is pressed\n");
rest(10);
}

GullRaDriel
Member #3,861
September 2003
avatar

bendenote: please use the code tags

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

bendenote
Member #7,842
October 2006

sorry :(

GullRaDriel
Member #3,861
September 2003
avatar

You can edit your thread you know, and just add the right tag around your piece of code will make them looking as nice as the one you can see in Miran's post.

The edit button is the second one following "Posted on 10-10-2006 14:31" in each of your posts.

Don't be that sorry. I was doing the same when I was just coming here.

In fact, the code-tags also have a nice utility: each function who is in the allegro manual is shown in blue and is in fact a link into the function documentation in the manual.

It is also better because of syntax coloration, and it will not "eat" your indentation. Looking at it will be better for us.

:-)

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Sirocco
Member #88
April 2000
avatar

Out of curiosity, does Allegro pick up scroll wheel clicks as well (i.e. depressing the scroll wheel instead of rolling it)?

-->
Graphic file formats used to fascinate me, but now I find them rather satanic.

Richard Phipps
Member #1,632
November 2001
avatar

I think that counts as a middle button click?

Sirocco
Member #88
April 2000
avatar

Hmm... I'll have to try that out later and see. I've got a few situations where that could come in handy.

-->
Graphic file formats used to fascinate me, but now I find them rather satanic.

Evert
Member #794
November 2000
avatar

What the blue monster said.

Dale M.A. Johnson
Member #1,103
March 2001
avatar

Quote:

Out of curiosity, does Allegro pick up scroll wheel clicks as well (i.e. depressing the scroll wheel instead of rolling it)?

As in pressing the scroll wheel as a button? Yes, it does. Unless I'm mistaken, just use mouse_b & 4

------> SIG TIME!

"You know, I could be working on that battle engine... But NOOOO~, I'm too busy tweaking the title page." -Me

Thomas Fjellstrom
Member #476
June 2000
avatar

while(!key[KEY_ESC]){

   if(mouse_b&1){
      if ( fare_deger_al()>0)
         printf("%d\n",fare_deger_al());
   }

   printf("Left side is pressed\n");

   if(mouse_b&2)
      printf("Right side is pressed\n");
   rest(10);
}

First off, tell me what you think may be wrong with that?

...

Yup, its that printf in the middle there, which will be printed every single loop, as you forgot to put it inside the {}s for mouse_b&1.

Indentation and proper formatting really, really helps.

--
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

Go to: