Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » mouse won't appear

This thread is locked; no one can reply to it. rss feed Print
mouse won't appear
vlad417
Member #8,720
June 2007

so the mouse pointer will not appear, i dont know how to get it to show up inside the window. the program works just fine, i just want the mouse to appear (if possible could i get a crosshair mouse?) IDE:Code::Blocks Compiler: GNU GPP

1#include <allegro.h>
2using namespace std;
3 
4int x[2] = {-1,-1};
5int y[2] = {-1,-1};
6int count=1;
7int blue = makecol(0,0,255);
8 
9void reset(){
10 x[0] = -1;
11 x[1] = -1;
12 y[0] = -1;
13 y[1] = -1;
14}
15 
16void solidDraw(){
17 if(count == 1){
18 x[0]=mouse_x;
19 y[0]=mouse_y;
20 count++;
21 //break;
22 }
23 else if(count == 2){
24 x[1]=mouse_x;
25 y[1]=mouse_y;
26 count--;
27 //break;
28 }
29 if(x[0]!=-1 && x[1]!=-1 && y[0]!=-1 && y[1]!=-1){
30 line(screen,x[0],y[0],x[1],y[1],blue);
31 }
32}
33 
34void dotDraw(){
35 putpixel(screen,mouse_x,mouse_y, blue);
36}
37 
38int main(){
39 allegro_init();
40 install_keyboard();
41 install_timer();
42 install_mouse();
43 show_mouse(screen);
44 
45 
46 
47 set_color_depth(32);
48 set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,640,0,0);
49 clear_to_color(screen,makecol(255,255,255));
50 
51 do{
52 if(mouse_b & 1){solidDraw();}
53 }while(!key[KEY_ESC]);
54 
55 allegro_exit();
56}
57END_OF_MAIN();

Kris Asick
Member #1,424
July 2001

You have to call show_mouse() after you set the video mode, not before. This is because at the moment you currently call show_mouse() the screen pointer is NULL.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Rampage
Member #3,035
December 2002
avatar

[edit]

What he said.

Besides, you must hide the mouse pointer before doing any drawing. Use scare_mouse and unscare_mouse() to achieve this:

    install_mouse();

    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,640,0,0);
    clear_to_color(screen,makecol(255,255,255));
    show_mouse(screen);

    do{
        scare_mouse();
        if(mouse_b & 1){solidDraw();}
        unscare_mouse();
    }while(!key[KEY_ESC]);

    allegro_exit();

-R

vlad417
Member #8,720
June 2007

thx guys

Go to: