From 7faa9019fd6638846b0b65eec2f68da6f8159232 Mon Sep 17 00:00:00 2001 From: Jean-Yves Lamoureux Date: Sat, 25 Jun 2005 11:27:31 +0000 Subject: [PATCH] * OpenGL driver mouse support --- src/event.c | 19 +++++++++++++++---- src/graphics.c | 25 ++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/event.c b/src/event.c index 0a30148..5d24d59 100644 --- a/src/event.c +++ b/src/event.c @@ -64,7 +64,9 @@ extern float gl_font_width; extern float gl_font_height; extern int gl_new_width; extern int gl_new_height; - +extern unsigned char gl_mouse_changed, gl_mouse_clicked; +extern unsigned int gl_mouse_x, gl_mouse_y; +extern unsigned int gl_mouse_button, gl_mouse_state; #endif #include "caca.h" #include "caca_internals.h" @@ -746,14 +748,23 @@ static unsigned int _lowlevel_event(void) { if(!_caca_resize) { - - _caca_resize = 1; gl_resized=0; return CACA_EVENT_RESIZE; } } - + if(gl_mouse_changed) + { + if(gl_mouse_clicked) + { + event|= CACA_EVENT_MOUSE_PRESS | gl_mouse_button; + gl_mouse_clicked=0; + } + mouse_x = gl_mouse_x; + mouse_y = gl_mouse_y; + event |= CACA_EVENT_MOUSE_MOTION | (mouse_x << 12) | mouse_y; + gl_mouse_changed = 0; + } if(gl_key!=0) { event |= CACA_EVENT_KEY_PRESS; diff --git a/src/graphics.c b/src/graphics.c index 7008cb0..ad0dc38 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -265,6 +265,9 @@ float gl_font_width, gl_font_height; float gl_incx, gl_incy; int id[94]; unsigned char gl_resized=0, gl_bit=0; +unsigned char gl_mouse_changed=0, gl_mouse_clicked=0; +unsigned int gl_mouse_x, gl_mouse_y; +unsigned int gl_mouse_button=0, gl_mouse_state=0; #endif @@ -324,8 +327,23 @@ static void gl_handle_reshape (int w, int h) } else gl_bit=1; - } +static void gl_handle_mouse(int button, int state, int x, int y) +{ + gl_mouse_clicked = 1; + gl_mouse_button = button; + gl_mouse_state = state; + gl_mouse_x = x/gl_font_width; + gl_mouse_y = y/gl_font_height; + gl_mouse_changed = 1; +} +static void gl_handle_mouse_motion(int x, int y) +{ + gl_mouse_x = x/gl_font_width; + gl_mouse_y = y/gl_font_height; + gl_mouse_changed = 1; +} + #endif @@ -1008,6 +1026,11 @@ int _caca_init_graphics(void) glutSpecialFunc(gl_handle_special_key); glutReshapeFunc(gl_handle_reshape); + glutMouseFunc(gl_handle_mouse); + glutMotionFunc(gl_handle_mouse_motion); + glutPassiveMotionFunc(gl_handle_mouse_motion); + + glLoadIdentity(); glMatrixMode(GL_PROJECTION);