mouse_b problem
bendenote

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

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

miran

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

bendenote

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

bendenote

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

bendenote: please use the code tags

bendenote

sorry :(

GullRaDriel

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.

:-)

Sirocco

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

Richard Phipps

I think that counts as a middle button click?

Sirocco

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

Evert

What the blue monster said.

Dale M.A. Johnson
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

Thomas Fjellstrom
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.

Thread #587972. Printed from Allegro.cc