Search
lxdream.org :: lxdream :: r854:130928a3cdcb
lxdream 0.9.1
released Jun 29
Download Now
changeset854:130928a3cdcb
parent853:9a0aa8217a31
child855:b937948d79d9
authornkeynes
dateTue Sep 09 00:51:43 2008 +0000 (11 years ago)
Add general gl_window_to_system_coords function to convert window system coordinates
back into something in the DC range of 640x480, update mouse events to use it
src/drivers/video_gl.c
src/drivers/video_gl.h
src/drivers/video_osx.c
src/gtkui/gtk_win.c
1.1 --- a/src/drivers/video_gl.c Tue Sep 09 00:50:15 2008 +0000
1.2 +++ b/src/drivers/video_gl.c Tue Sep 09 00:51:43 2008 +0000
1.3 @@ -51,6 +51,34 @@
1.4 gl_texture_window( buffer->width, buffer->height, buffer->buf_id, buffer->inverted );
1.5 }
1.6
1.7 +/**
1.8 + * Convert window coordinates to dreamcast device coords (640x480) using the
1.9 + * same viewable area as gl_texture_window.
1.10 + * If the coordinates are outside the viewable area, the result is -1,-1.
1.11 + */
1.12 +void gl_window_to_system_coords( int *x, int *y )
1.13 +{
1.14 + int x1=0,y1=0,x2=video_width,y2=video_height;
1.15 +
1.16 + int ah = video_width * 0.75;
1.17 +
1.18 + if( ah > video_height ) {
1.19 + int w = (video_height/0.75);
1.20 + x1 = (video_width - w)/2;
1.21 + x2 -= x1;
1.22 + } else if( ah < video_height ) {
1.23 + y1 = (video_height - ah)/2;
1.24 + y2 -= y1;
1.25 + }
1.26 + if( *x < x1 || *x >= x2 || *y < y1 || *y >= y2 ) {
1.27 + *x = -1;
1.28 + *y = -1;
1.29 + } else {
1.30 + *x = (*x - x1) * DISPLAY_WIDTH / (x2-x1);
1.31 + *y = (*y - y1) * DISPLAY_HEIGHT / (y2-y1);
1.32 + }
1.33 +}
1.34 +
1.35 void gl_texture_window( int width, int height, int tex_id, gboolean inverted )
1.36 {
1.37 float top, bottom;
2.1 --- a/src/drivers/video_gl.h Tue Sep 09 00:50:15 2008 +0000
2.2 +++ b/src/drivers/video_gl.h Tue Sep 09 00:51:43 2008 +0000
2.3 @@ -49,6 +49,13 @@
2.4 void gl_texture_window( int width, int height, int tex_id, gboolean inverted );
2.5
2.6 /**
2.7 + * Convert window coordinates to dreamcast device coords (640x480) using the
2.8 + * same viewable area as gl_texture_window.
2.9 + * If the coordinates are outside the viewable area, the result is -1,-1.
2.10 + */
2.11 +void gl_window_to_system_coords( int *x, int *y );
2.12 +
2.13 +/**
2.14 * Generic GL read_render_buffer. This function assumes that the caller
2.15 * has already set the appropriate glReadBuffer(); in other words, unless
2.16 * there's only one buffer this needs to be wrapped.
3.1 --- a/src/drivers/video_osx.c Tue Sep 09 00:50:15 2008 +0000
3.2 +++ b/src/drivers/video_osx.c Tue Sep 09 00:51:43 2008 +0000
3.3 @@ -159,8 +159,10 @@
3.4 input_event_mousedown( button, 0, 0, FALSE );
3.5 } else {
3.6 NSPoint pt = [event locationInWindow];
3.7 - input_event_mousedown( button, (int)(pt.x * DISPLAY_WIDTH) / video_width,
3.8 - DISPLAY_HEIGHT - ((int)(pt.y * DISPLAY_HEIGHT) / video_height), TRUE );
3.9 + int x = (int)pt.x;
3.10 + int y = video_height - (int)pt.y;
3.11 + gl_window_to_system_coords(&x,&y);
3.12 + input_event_mousedown( button, x, y, TRUE );
3.13 }
3.14 }
3.15 - (void)emitMouseUpEvent: (NSEvent *)event button: (int)button
3.16 @@ -169,8 +171,10 @@
3.17 input_event_mouseup( button, 0, 0, FALSE );
3.18 } else {
3.19 NSPoint pt = [event locationInWindow];
3.20 - input_event_mouseup( button, (int)(pt.x * DISPLAY_WIDTH) / video_width,
3.21 - DISPLAY_HEIGHT - ((int)(pt.y * DISPLAY_HEIGHT) / video_height), TRUE );
3.22 + int x = (int)pt.x;
3.23 + int y = video_height - (int)pt.y;
3.24 + gl_window_to_system_coords(&x,&y);
3.25 + input_event_mouseup( button, x, y, TRUE );
3.26 }
3.27 }
3.28 - (void)emitMouseMoveEvent: (NSEvent *)event
3.29 @@ -179,8 +183,10 @@
3.30 input_event_mousemove( [event deltaX] * MOUSE_X_SCALE, [event deltaY] * MOUSE_Y_SCALE, FALSE );
3.31 } else {
3.32 NSPoint pt = [event locationInWindow];
3.33 - input_event_mousemove( (int)(pt.x * DISPLAY_WIDTH) / video_width,
3.34 - DISPLAY_HEIGHT - ((int)(pt.y * DISPLAY_HEIGHT) / video_height), TRUE );
3.35 + int x = (int)pt.x;
3.36 + int y = video_height - (int)pt.y;
3.37 + gl_window_to_system_coords(&x,&y);
3.38 + input_event_mousemove( x, y, TRUE );
3.39 }
3.40 }
3.41 - (void)mouseExited: (NSEvent *)event
4.1 --- a/src/gtkui/gtk_win.c Tue Sep 09 00:50:15 2008 +0000
4.2 +++ b/src/gtkui/gtk_win.c Tue Sep 09 00:51:43 2008 +0000
4.3 @@ -128,16 +128,16 @@
4.4 gpointer user_data )
4.5 {
4.6 main_window_t win = (main_window_t)user_data;
4.7 - int32_t x = (int32_t)event->x;
4.8 - int32_t y = (int32_t)event->y;
4.9 + int x = (int)event->x;
4.10 + int y = (int)event->y;
4.11 if( win->is_grabbed &&
4.12 (x != win->mouse_x || y != win->mouse_y) ) {
4.13 input_event_mousemove( x - win->mouse_x, y - win->mouse_y, FALSE );
4.14 video_window_center_pointer(win);
4.15 } else {
4.16 int width, height;
4.17 - gdk_drawable_get_size(GDK_DRAWABLE(widget->window), &width, &height);
4.18 - input_event_mousemove( x * DISPLAY_WIDTH /width , y * DISPLAY_HEIGHT / height, TRUE );
4.19 + gl_window_to_system_coords( &x, &y );
4.20 + input_event_mousemove( x, y, TRUE );
4.21 }
4.22 return TRUE;
4.23 }
4.24 @@ -159,10 +159,10 @@
4.25 if( win->is_grabbed ) {
4.26 input_event_mousedown( event->button-1, 0, 0, FALSE );
4.27 } else {
4.28 - int width, height;
4.29 - gdk_drawable_get_size(GDK_DRAWABLE(widget->window), &width, &height);
4.30 - input_event_mousedown( event->button-1, (int32_t)event->x * DISPLAY_WIDTH / width,
4.31 - (int32_t)event->y * DISPLAY_HEIGHT / height, TRUE );
4.32 + int x = (int)event->x;
4.33 + int y = (int)event->y;
4.34 + gl_window_to_system_coords( &x, &y );
4.35 + input_event_mousedown( event->button-1, x, y, TRUE );
4.36 }
4.37 return TRUE;
4.38 }
4.39 @@ -176,10 +176,10 @@
4.40 } else if( win->use_grab) {
4.41 video_window_grab_display(win);
4.42 } else {
4.43 - int width, height;
4.44 - gdk_drawable_get_size(GDK_DRAWABLE(widget->window), &width, &height);
4.45 - input_event_mouseup( event->button-1, (int32_t)event->x * DISPLAY_WIDTH / width,
4.46 - (int32_t)event->y * DISPLAY_HEIGHT / height, TRUE );
4.47 + int x = (int)event->x;
4.48 + int y = (int)event->y;
4.49 + gl_window_to_system_coords( &x, &y );
4.50 + input_event_mouseup( event->button-1, x, y, TRUE );
4.51 }
4.52 return TRUE;
4.53 }
.