nice scaling (only for those having GTKGLEXT -- hardware accel.)

This commit is contained in:
damdoum 2007-02-07 19:39:55 +00:00
parent 9badd2dd42
commit 252cc00ac8
5 changed files with 207 additions and 40 deletions

View File

@ -47,7 +47,7 @@ void enable_rom_features() {
void MAINWINDOW_RESIZE() {
GtkWidget * spacer1 = glade_xml_get_widget(xml, "misc_sep3");
GtkWidget * spacer2 = glade_xml_get_widget(xml, "misc_sep4");
int dim = 66 * ScreenCoeff_Size;
int dim = 66 * ScreenCoeff_Size[0];
/* sees whether we want a gap */
if (!ScreenGap) dim = -1;
@ -195,22 +195,23 @@ void on_fs9_activate (GtkMenuItem *menuitem,gpointer user_data) { Frameskip =
/* SUBMENU SIZE ***** ***** ***** ***** */
int H=192, W=256;
void resize (int Size) {
void resize (float Size1, float Size2) {
// not ready yet to handle different zoom factors
Size2 = Size1;
/* we want to scale drawing areas by a factor (1x,2x or 3x) */
gtk_drawing_area_size(GTK_DRAWING_AREA(pDrawingArea), W * Size, H * Size);
gtk_widget_set_usize (pDrawingArea, W * Size, H * Size);
gtk_drawing_area_size(GTK_DRAWING_AREA(pDrawingArea2), W * Size, H * Size);
gtk_widget_set_usize (pDrawingArea2, W * Size, H * Size);
ScreenCoeff_Size = Size;
gtk_widget_set_size_request (pDrawingArea, W * Size1, H * Size1);
gtk_widget_set_size_request (pDrawingArea2, W * Size2, H * Size2);
ScreenCoeff_Size[0] = Size1;
ScreenCoeff_Size[1] = Size2;
/* remove artifacts */
black_screen();
/* pack the window */
MAINWINDOW_RESIZE();
}
void on_size1x_activate (GtkMenuItem *menuitem, gpointer user_data) { resize(1); }
void on_size2x_activate (GtkMenuItem *menuitem, gpointer user_data) { resize(2); }
void on_size3x_activate (GtkMenuItem *menuitem, gpointer user_data) { resize(3); }
void on_size1x_activate (GtkMenuItem *menuitem, gpointer user_data) { resize(1.0,1.0); }
void on_size2x_activate (GtkMenuItem *menuitem, gpointer user_data) { resize(2.0,2.0); }
void on_size3x_activate (GtkMenuItem *menuitem, gpointer user_data) { resize(3.0,3.0); }
/* MENU CONFIG ***** ***** ***** ***** */
@ -303,7 +304,7 @@ void on_menu_rotatescreen_activate (GtkMenuItem *menuitem, gpointer user_data)
} else {
W=256; H=192;
}
resize(ScreenCoeff_Size);
resize(ScreenCoeff_Size[0],ScreenCoeff_Size[1]);
}
/* MENU TOOLS ***** ***** ***** ***** */

View File

@ -23,8 +23,7 @@
#include "callbacks_IO.h"
static u16 Cur_Keypad = 0;
int ScreenCoeff_Size=1;
float fScreenCoeff_Size=1.0;
float ScreenCoeff_Size[2]={1.0,1.0};
gboolean ScreenRotate=FALSE;
gboolean Boost=FALSE;
int BoostFS=20;
@ -84,7 +83,8 @@ void init_pix_col_map() {
u32 on_screen_image32[RAW_W*RAW_H*2*MAX_SIZE*MAX_SIZE];
int inline screen_size() {
return RAW_W*RAW_H*2*ScreenCoeff_Size*ScreenCoeff_Size*sizeof(u32);
int sz = ScreenCoeff_Size[0];
return RAW_W*RAW_H*2*sz*sz*sizeof(u32);
}
int inline offset_pixels_lower_screen() {
return screen_size()/2;
@ -111,17 +111,17 @@ void decode_screen () {
}
}
#define LOOP(a,b,c,d,e,f) \
L=W*ScreenCoeff_Size; \
L=W*ScreenCoeff_Size[0]; \
BL=L*sizeof(u32); \
for (a; b; c) { \
for (d; e; f) { \
pix = image[y][x]; \
for (m=0; m<ScreenCoeff_Size; m++) { \
for (m=0; m<ScreenCoeff_Size[0]; m++) { \
*rgb32 = pix; rgb32++; \
} \
} \
/* lines duplicated for scaling height */ \
for (m=1; m<ScreenCoeff_Size; m++) { \
for (m=1; m<ScreenCoeff_Size[0]; m++) { \
memmove(rgb32, rgb32-L, BL); \
rgb32 += L; \
} \
@ -156,12 +156,12 @@ gboolean screen (GtkWidget * widget, int off) {
} else {
H=RAW_H; W=RAW_W;
}
L=W*ScreenCoeff_Size*sizeof(u32);
L=W*ScreenCoeff_Size[0]*sizeof(u32);
off*= offset_pixels_lower_screen();
gdk_draw_rgb_32_image (widget->window,
widget->style->fg_gc[widget->state],0,0,
W*ScreenCoeff_Size, H*ScreenCoeff_Size,
W*ScreenCoeff_Size[0], H*ScreenCoeff_Size[0],
GDK_RGB_DITHER_NONE,((guchar*)on_screen_image32)+off,L);
return TRUE;
}
@ -204,8 +204,8 @@ gboolean on_wDraw_Sub_configure_event(GtkWidget *widget, GdkEventConfigure *eve
void set_touch_pos (int x, int y) {
s32 EmuX, EmuY;
x /= ScreenCoeff_Size;
y /= ScreenCoeff_Size;
x /= ScreenCoeff_Size[1];
y /= ScreenCoeff_Size[1];
EmuX = x; EmuY = y;
if (ScreenRotate) { EmuX = 256-y; EmuY = x; }
if(EmuX<0) EmuX = 0; else if(EmuX>255) EmuX = 255;
@ -213,18 +213,39 @@ void set_touch_pos (int x, int y) {
NDS_setTouchPos(EmuX, EmuY);
}
gboolean on_wDraw_Main_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data) {
switch (event->button) {
case 1: break;
case 3: break;
case 2: ScreenCoeff_Size[0]=1.0;
resize(ScreenCoeff_Size[0],ScreenCoeff_Size[1]); break;
}
return TRUE;
}
gboolean on_wDraw_Main_button_release_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data) {
return TRUE;
}
gboolean on_wDraw_Sub_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data) {
GdkModifierType state;
gint x,y;
if(desmume_running())
if(event->button == 1)
{
switch (event->button) {
case 1:
if(desmume_running()) {
click = TRUE;
gdk_window_get_pointer(widget->window, &x, &y, &state);
if (state & GDK_BUTTON1_MASK)
set_touch_pos(x,y);
}
break;
case 3: break;
case 2:
ScreenCoeff_Size[0]=1.0;
//ScreenCoeff_Size[1]=1.0; // separate zoom factors
resize(ScreenCoeff_Size[0],ScreenCoeff_Size[1]); break;
}
return TRUE;
}
@ -234,6 +255,35 @@ gboolean on_wDraw_Sub_button_release_event (GtkWidget *widget, GdkEventButton
return TRUE;
}
static void resize_incremental(int i, GdkEventScroll *event) {
#ifdef HAVE_LIBGDKGLEXT_X11_1_0
float zoom_inc=.125, zoom_min=0.25, zoom_max=5.0;
#else
float zoom_inc=1.0, zoom_min=1.0, zoom_max=3.0;
#endif
switch (event->direction) {
case GDK_SCROLL_UP:
ScreenCoeff_Size[i]=MIN(ScreenCoeff_Size[i]+zoom_inc,zoom_max); break;
case GDK_SCROLL_DOWN:
ScreenCoeff_Size[i]=MAX(ScreenCoeff_Size[i]-zoom_inc,zoom_min); break;
case GDK_SCROLL_LEFT:
case GDK_SCROLL_RIGHT:
return;
}
resize(ScreenCoeff_Size[0],ScreenCoeff_Size[1]);
}
gboolean on_wDraw_Main_scroll_event (GtkWidget *widget, GdkEvent *event, gpointer user_data) {
resize_incremental(0,event);
}
gboolean on_wDraw_Sub_scroll_event (GtkWidget *widget, GdkEvent *event, gpointer user_data) {
// using separate zoom factors is bad for now
resize_incremental(0,event);
// resize_incremental(1,event);
}
gboolean on_wDraw_Sub_motion_notify_event (GtkWidget *widget, GdkEventMotion *event, gpointer user_data) {
GdkModifierType state;
gint x,y;

View File

@ -31,16 +31,20 @@ G_MODULE_EXPORT void on_wDraw_Main_realize (GtkWidget *widget, gpoint
G_MODULE_EXPORT gboolean on_wDraw_Main_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data);
G_MODULE_EXPORT gboolean on_wDraw_Main_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data);
/* OUTPUT LOWER SCREEN */
G_MODULE_EXPORT void on_wDraw_Sub_realize (GtkWidget *widget, gpointer user_data);
G_MODULE_EXPORT gboolean on_wDraw_Sub_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data);
G_MODULE_EXPORT gboolean on_wDraw_Sub_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data);
/* INPUT STYLUS / MOUSE */
G_MODULE_EXPORT gboolean on_wDraw_Sub_motion_notify_event (GtkWidget *widget, GdkEventMotion *event, gpointer user_data);
G_MODULE_EXPORT gboolean on_wDraw_Main_button_release_event(GtkWidget *widget, GdkEventButton *event, gpointer user_data);
G_MODULE_EXPORT gboolean on_wDraw_Main_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data);
G_MODULE_EXPORT gboolean on_wDraw_Sub_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data);
G_MODULE_EXPORT gboolean on_wDraw_Sub_button_release_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data);
G_MODULE_EXPORT gboolean on_wDraw_Sub_motion_notify_event (GtkWidget *widget, GdkEventMotion *event, gpointer user_data);
G_MODULE_EXPORT gboolean on_wDraw_Main_scroll_event (GtkWidget *widget, GdkEvent *event, gpointer user_data);
G_MODULE_EXPORT gboolean on_wDraw_Sub_scroll_event (GtkWidget *widget, GdkEvent *event, gpointer user_data);

View File

@ -329,6 +329,7 @@
<signal name="activate" handler="on_savetype1_activate" last_modification_time="Thu, 01 Feb 2007 11:41:11 GMT"/>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="savetype2">
<property name="visible">True</property>
@ -339,6 +340,7 @@
<signal name="activate" handler="on_savetype2_activate" last_modification_time="Thu, 01 Feb 2007 11:41:11 GMT"/>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="savetype3">
<property name="visible">True</property>
@ -349,6 +351,7 @@
<signal name="activate" handler="on_savetype3_activate" last_modification_time="Thu, 01 Feb 2007 11:41:11 GMT"/>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="savetype4">
<property name="visible">True</property>
@ -359,28 +362,28 @@
<signal name="activate" handler="on_savetype4_activate" last_modification_time="Thu, 01 Feb 2007 11:41:11 GMT"/>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="savetype5">
<property name="visible">True</property>
<property name="label" translatable="yes">TYPE: FLASH (256KB)</property>
<property name="use_underline">True</property>
<property name="group">savetype1</property>
<property name="active">False</property>
<property name="group">savetype1</property>
<signal name="activate" handler="on_savetype5_activate" last_modification_time="Thu, 01 Feb 2007 11:41:11 GMT"/>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="savetype6">
<property name="visible">True</property>
<property name="label" translatable="yes">TYPE: FRAM (2MB)</property>
<property name="use_underline">True</property>
<property name="group">savetype1</property>
<property name="active">False</property>
<property name="group">savetype1</property>
<signal name="activate" handler="on_savetype6_activate" last_modification_time="Thu, 01 Feb 2007 11:41:11 GMT"/>
</widget>
</child>
</widget>
</child>
</widget>
@ -587,6 +590,7 @@
<signal name="activate" handler="on_size1x_activate" last_modification_time="Mon, 01 Jan 2007 20:14:20 GMT"/>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="size2x">
<property name="visible">True</property>
@ -597,6 +601,7 @@
<signal name="activate" handler="on_size2x_activate" last_modification_time="Mon, 01 Jan 2007 20:14:20 GMT"/>
</widget>
</child>
<child>
<widget class="GtkRadioMenuItem" id="size3x">
<property name="visible">True</property>
@ -818,7 +823,6 @@
<child>
<widget class="GtkToolbar" id="wgToolBar">
<property name="visible">True</property>
<property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
<property name="toolbar_style">GTK_TOOLBAR_BOTH</property>
<property name="tooltips">True</property>
@ -1051,10 +1055,12 @@
<widget class="GtkDrawingArea" id="wDraw_Main">
<property name="width_request">256</property>
<property name="height_request">192</property>
<property name="visible">False</property>
<property name="events">GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK</property>
<property name="events">GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK</property>
<signal name="configure_event" handler="on_wDraw_Main_configure_event" last_modification_time="Mon, 05 Feb 2007 00:49:24 GMT"/>
<signal name="expose_event" handler="on_wDraw_Main_expose_event" last_modification_time="Tue, 02 Jan 2007 10:27:18 GMT"/>
<signal name="button_release_event" handler="on_wDraw_Main_button_release_event" last_modification_time="Wed, 07 Feb 2007 17:32:00 GMT"/>
<signal name="button_press_event" handler="on_wDraw_Main_button_press_event" last_modification_time="Wed, 07 Feb 2007 17:32:57 GMT"/>
<signal name="scroll_event" handler="on_wDraw_Main_scroll_event" last_modification_time="Wed, 07 Feb 2007 19:18:23 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
@ -1215,13 +1221,13 @@
<widget class="GtkDrawingArea" id="wDraw_Sub">
<property name="width_request">256</property>
<property name="height_request">192</property>
<property name="visible">False</property>
<property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK</property>
<signal name="configure_event" handler="on_wDraw_Sub_configure_event" last_modification_time="Mon, 05 Feb 2007 00:49:24 GMT"/>
<signal name="expose_event" handler="on_wDraw_Sub_expose_event" last_modification_time="Tue, 02 Jan 2007 10:27:52 GMT"/>
<signal name="button_press_event" handler="on_wDraw_Sub_button_press_event" last_modification_time="Tue, 02 Jan 2007 10:28:11 GMT"/>
<signal name="button_release_event" handler="on_wDraw_Sub_button_release_event" last_modification_time="Tue, 02 Jan 2007 10:28:18 GMT"/>
<signal name="motion_notify_event" handler="on_wDraw_Sub_motion_notify_event" last_modification_time="Tue, 02 Jan 2007 10:28:32 GMT"/>
<signal name="scroll_event" handler="on_wDraw_Sub_scroll_event" last_modification_time="Wed, 07 Feb 2007 19:18:37 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
@ -2175,4 +2181,109 @@
</child>
</widget>
<widget class="GtkMenu" id="wPopMenu">
<child>
<widget class="GtkImageMenuItem" id="pop_pause">
<property name="visible">True</property>
<property name="label">gtk-media-pause</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_pop_pause_activate" last_modification_time="Wed, 07 Feb 2007 17:29:36 GMT"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="pop_rightscreen">
<property name="visible">True</property>
<property name="label" translatable="yes">Right Screen</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_pop_rightscreen_activate" last_modification_time="Wed, 07 Feb 2007 17:35:26 GMT"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="pop_true_gap">
<property name="visible">True</property>
<property name="label" translatable="yes">True Gap</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_pop_true_gap_activate" last_modification_time="Wed, 07 Feb 2007 17:35:26 GMT"/>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="séparateur2">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="pop_rotate0">
<property name="visible">True</property>
<property name="label" translatable="yes">Rotate 0</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_pop_rotate0_activate" last_modification_time="Wed, 07 Feb 2007 17:29:36 GMT"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="pop_rotate1">
<property name="visible">True</property>
<property name="label" translatable="yes">Rotate 90</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_pop_rotate1_activate" last_modification_time="Wed, 07 Feb 2007 17:29:36 GMT"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="pop_rotate2">
<property name="visible">True</property>
<property name="label" translatable="yes">Rotate 180</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_pop_rotate2_activate" last_modification_time="Wed, 07 Feb 2007 17:29:36 GMT"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="pop_rotate3">
<property name="visible">True</property>
<property name="label" translatable="yes">Rotate 270</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_pop_rotate3_activate" last_modification_time="Wed, 07 Feb 2007 17:29:36 GMT"/>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="séparateur3">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="pop_zoom100">
<property name="visible">True</property>
<property name="label">gtk-zoom-100</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_pop_zoom100_activate" last_modification_time="Wed, 07 Feb 2007 17:29:36 GMT"/>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="pop_zoom_in">
<property name="visible">True</property>
<property name="label">gtk-zoom-in</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_pop_zoom_in_activate" last_modification_time="Wed, 07 Feb 2007 17:29:36 GMT"/>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="pop_zoom_out">
<property name="visible">True</property>
<property name="label">gtk-zoom-out</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_pop_zoom_out_activate" last_modification_time="Wed, 07 Feb 2007 17:29:36 GMT"/>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -85,9 +85,10 @@ void unregister_Tool(VoidFunPtr fun);
/* callbacks.c */
void enable_rom_features();
void resize (float Size1, float Size2);
/* callbacks_IO.c */
int ScreenCoeff_Size;
float ScreenCoeff_Size[2];
gboolean ScreenRotate;
gboolean ScreenRight;
gboolean ScreenGap;