Fix GTK+ 3.0 changes that required GTK+ 2.24 for compatibility.

This commit is contained in:
Brandon Wright 2011-02-11 03:44:47 -06:00
parent 10c498e37b
commit f9b909b022
3 changed files with 47 additions and 41 deletions

View File

@ -30,7 +30,7 @@ S9xXVDisplayDriver::S9xXVDisplayDriver (Snes9xWindow *window,
this->config = config; this->config = config;
this->drawing_area = GTK_WIDGET (window->drawing_area); this->drawing_area = GTK_WIDGET (window->drawing_area);
display = display =
gdk_x11_display_get_xdisplay (gdk_window_get_display (gtk_widget_get_window (drawing_area))); gdk_x11_display_get_xdisplay (gtk_widget_get_display (drawing_area));
last_known_width = last_known_height = -1; last_known_width = last_known_height = -1;
return; return;
@ -273,7 +273,7 @@ S9xXVDisplayDriver::init (void)
/* Setup XV */ /* Setup XV */
gtk_widget_realize (drawing_area); gtk_widget_realize (drawing_area);
display = gdk_x11_display_get_xdisplay (gdk_window_get_display (gtk_widget_get_window (drawing_area))); display = gdk_x11_display_get_xdisplay (gtk_widget_get_display (drawing_area));
screen = gtk_widget_get_screen (drawing_area); screen = gtk_widget_get_screen (drawing_area);
root = gdk_screen_get_root_window (screen); root = gdk_screen_get_root_window (screen);

View File

@ -732,14 +732,13 @@ Snes9xWindow::expose (GdkEventExpose *event, cairo_t *cr)
config->window_height = get_height (); config->window_height = get_height ();
} }
#ifdef USE_GTK3 if (!cr)
draw_background (cr); draw_background (event->area.x,
#else event->area.y,
draw_background_clipped (event->area.x, event->area.width,
event->area.y, event->area.height);
event->area.width, else
event->area.height); draw_background (cr);
#endif
} }
else else
{ {
@ -1595,7 +1594,7 @@ Snes9xWindow::enter_fullscreen_mode (void)
} }
else else
{ {
GdkDisplay *gdk_display = gdk_window_get_display (gtk_widget_get_window (window)); GdkDisplay *gdk_display = gtk_widget_get_display (window);
Display *display = gdk_x11_display_get_xdisplay (gdk_display); Display *display = gdk_x11_display_get_xdisplay (gdk_display);
GdkScreen *screen = gtk_widget_get_screen (window); GdkScreen *screen = gtk_widget_get_screen (window);
GdkWindow *root = gdk_screen_get_root_window (screen); GdkWindow *root = gdk_screen_get_root_window (screen);
@ -1641,7 +1640,7 @@ Snes9xWindow::leave_fullscreen_mode (void)
{ {
gtk_widget_hide (window); gtk_widget_hide (window);
GdkDisplay *gdk_display = gdk_window_get_display (gtk_widget_get_window (window)); GdkDisplay *gdk_display = gtk_widget_get_display (window);
Display *display = gdk_x11_display_get_xdisplay (gdk_display); Display *display = gdk_x11_display_get_xdisplay (gdk_display);
GdkScreen *screen = gtk_widget_get_screen (window); GdkScreen *screen = gtk_widget_get_screen (window);
GdkWindow *root = gdk_screen_get_root_window (screen); GdkWindow *root = gdk_screen_get_root_window (screen);
@ -1682,14 +1681,11 @@ Snes9xWindow::draw_background (cairo_t *cr)
GtkWidget *widget = GTK_WIDGET (drawing_area); GtkWidget *widget = GTK_WIDGET (drawing_area);
GdkColor sel; GdkColor sel;
GtkAllocation allocation; GtkAllocation allocation;
int w, h;
cairo_pattern_t *pattern; cairo_pattern_t *pattern;
cairo_save (cr);
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_allocation (widget, &allocation);
w = allocation.width;
h = allocation.height; cairo_save (cr);
#ifdef USE_GTK3 #ifdef USE_GTK3
GdkRGBA rgba; GdkRGBA rgba;
@ -1704,7 +1700,7 @@ Snes9xWindow::draw_background (cairo_t *cr)
pattern = cairo_pattern_create_linear (0.0, pattern = cairo_pattern_create_linear (0.0,
0.0, 0.0,
0.0, 0.0,
(double) h); (double) allocation.height);
cairo_pattern_add_color_stop_rgb (pattern, cairo_pattern_add_color_stop_rgb (pattern,
0.0, 0.0,
@ -1725,12 +1721,12 @@ Snes9xWindow::draw_background (cairo_t *cr)
/* Put the Snes9x logo in the center */ /* Put the Snes9x logo in the center */
gdk_cairo_set_source_pixbuf (cr, splash, gdk_cairo_set_source_pixbuf (cr, splash,
(w - gdk_pixbuf_get_width (splash)) / 2, (allocation.width - gdk_pixbuf_get_width (splash)) / 2,
(h - gdk_pixbuf_get_height (splash)) / 2); (allocation.height - gdk_pixbuf_get_height (splash)) / 2);
cairo_rectangle (cr, cairo_rectangle (cr,
(w - gdk_pixbuf_get_width (splash)) / 2, (allocation.width - gdk_pixbuf_get_width (splash)) / 2,
(h - gdk_pixbuf_get_height (splash)) / 2, (allocation.height - gdk_pixbuf_get_height (splash)) / 2,
gdk_pixbuf_get_width (splash), gdk_pixbuf_get_width (splash),
gdk_pixbuf_get_height (splash)); gdk_pixbuf_get_height (splash));
cairo_fill (cr); cairo_fill (cr);
@ -1741,28 +1737,41 @@ Snes9xWindow::draw_background (cairo_t *cr)
} }
void void
Snes9xWindow::draw_background_clipped (int rect_x, Snes9xWindow::draw_background (int x, int y, int w, int h)
int rect_y,
int rect_w,
int rect_h)
{ {
GtkWidget *widget = GTK_WIDGET (drawing_area); cairo_t *cr = NULL;
cairo_t *cr; GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (drawing_area));
cr = gdk_cairo_create (gtk_widget_get_window (widget)); if (x >= 0)
if (rect_x >= 0)
{ {
GdkRectangle rect;
rect.x = x;
rect.y = y;
rect.width = w;
rect.height = h;
gdk_window_begin_paint_rect (gdk_window, &rect);
cr = gdk_cairo_create (gdk_window);
cairo_rectangle (cr, cairo_rectangle (cr,
(double) rect_x, (double) x,
(double) rect_y, (double) y,
(double) rect_w, (double) w,
(double) rect_h); (double) h);
cairo_clip (cr); cairo_clip (cr);
}
draw_background (cr); draw_background (cr);
gdk_window_end_paint (gdk_window);
}
else
{
cr = gdk_cairo_create (gdk_window);
draw_background (cr);
}
cairo_destroy (cr); cairo_destroy (cr);

View File

@ -53,10 +53,7 @@ class Snes9xWindow : public GtkBuilderWindow
void show (void); void show (void);
void show_status_message (const char *message); void show_status_message (const char *message);
void update_statusbar (void); void update_statusbar (void);
void draw_background_clipped (int rect_x = -1, void draw_background (int x = -1, int y = -1, int w = -1, int h = -1);
int rect_y = -1,
int rect_w = -1,
int rect_h = -1);
void draw_background (cairo_t *cr); void draw_background (cairo_t *cr);
void set_menu_item_selected (const char *name); void set_menu_item_selected (const char *name);
void set_mouseable_area (int x, int y, int width, int height); void set_mouseable_area (int x, int y, int width, int height);