diff options
| author | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2011-02-16 03:38:02 +0000 |
|---|---|---|
| committer | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2011-02-16 03:38:02 +0000 |
| commit | 394f7a2b4a604dc40cf29f23a7121deb19eed79c (patch) | |
| tree | ff56e3a9568726042924c1594116e455c29d0a44 /gui | |
| parent | af73c2069339f0315d53e85fd5c45c7c89d6638a (diff) | |
| download | pcsxr-394f7a2b4a604dc40cf29f23a7121deb19eed79c.tar.gz | |
-(YarTour)Clean deprecated GTK+ symbols, preliminary GTK+-3.0 compatibility (Issue #8084, Patch #8353).
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@63426 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/DebugMemory.c | 4 | ||||
| -rw-r--r-- | gui/MemcardDlg.c | 41 | ||||
| -rw-r--r-- | gui/gdk-compat.h | 155 |
3 files changed, 198 insertions, 2 deletions
diff --git a/gui/DebugMemory.c b/gui/DebugMemory.c index 239aeed0..289c9b9a 100644 --- a/gui/DebugMemory.c +++ b/gui/DebugMemory.c @@ -290,7 +290,11 @@ void RunDebugMemoryDialog() { pfd = pango_font_description_from_string("Bitstream Vera Sans Mono, " "DejaVu Sans Mono, Liberation Mono, FreeMono, Sans Mono 9"); +#if GTK_CHECK_VERSION(3, 0, 0) + gtk_widget_override_font(widget, pfd); +#else gtk_widget_modify_font(widget, pfd); +#endif pango_font_description_free(pfd); UpdateMemViewDlg(); diff --git a/gui/MemcardDlg.c b/gui/MemcardDlg.c index aa7538f7..bfe96125 100644 --- a/gui/MemcardDlg.c +++ b/gui/MemcardDlg.c @@ -29,6 +29,10 @@ #include "Linux.h" #include "../libpcsxcore/sio.h" +#if GTK_CHECK_VERSION(2, 20, 0) && !GTK_CHECK_VERSION(3, 0, 0) +#include "gdk-compat.h" +#endif + #define MAX_MEMCARD_BLOCKS 15 static gboolean quit; @@ -82,6 +86,38 @@ static void AddColumns(GtkTreeView *treeview) { gtk_tree_view_append_column(treeview, column); } +#if GTK_CHECK_VERSION(2, 20, 0) +static GdkPixbuf *SetIcon(GtkWidget *dialog, short *icon, int scale) { + GdkPixbuf *pixbuf; + cairo_surface_t *s; + cairo_t *cr; + int x, y, c, i, r, g, b; + int size = 16 * scale; + s = cairo_image_surface_create(CAIRO_FORMAT_RGB24, size, size); + cr = cairo_create(s); + cairo_scale(cr, scale, scale); + for (i=0; i< 256; i++) { + x = (i % 16); + y = (i / 16); + c = icon[i]; + r = (c & 0x001f) << 3; + g = ((c & 0x03e0) >> 5) << 3; + b = ((c & 0x7c00) >> 10) << 3; + cairo_rectangle(cr, x, y, 1, 1); + cairo_set_source_rgb(cr, r/255.0, g/255.0, b/255.0); + cairo_fill(cr); + } + cairo_destroy(cr); +#if GTK_CHECK_VERSION(3, 0, 0) + pixbuf = gdk_pixbuf_get_from_surface(s, 0, 0, size, size); +#else + pixbuf = compat_gdk_pixbuf_get_from_surface(s, 0, 0, size, size); +#endif + cairo_surface_destroy(s); + return pixbuf; +} + +#else static GdkPixbuf *SetIcon(GtkWidget *dialog, short *icon, int i) { GdkPixmap *pixmap; GdkImage *image; @@ -122,6 +158,7 @@ static GdkPixbuf *SetIcon(GtkWidget *dialog, short *icon, int i) { return pixbuf; } +#endif static void LoadListItems(int mcd, GtkWidget *widget) { int i; @@ -160,7 +197,7 @@ static void LoadListItems(int mcd, GtkWidget *widget) { else state = _("Free"); - pixbuf = SetIcon(dialog, Info->Icon, i + 1); + pixbuf = SetIcon(dialog, Info->Icon, 2); gtk_list_store_append(store, &iter); @@ -271,7 +308,7 @@ static void UpdateListItems(int mcd, GtkWidget *widget) { pIcon = Info->Icon; } - pixbuf = SetIcon(dialog, pIcon, i + 1); + pixbuf = SetIcon(dialog, pIcon, 2); title = g_convert(Info->sTitle, strlen(Info->sTitle), "UTF-8", "Shift-JIS", NULL, NULL, NULL); diff --git a/gui/gdk-compat.h b/gui/gdk-compat.h new file mode 100644 index 00000000..8be02787 --- /dev/null +++ b/gui/gdk-compat.h @@ -0,0 +1,155 @@ +static cairo_format_t
+compat_gdk_cairo_format_for_content (cairo_content_t content)
+{
+ switch (content)
+ {
+ case CAIRO_CONTENT_COLOR:
+ return CAIRO_FORMAT_RGB24;
+ case CAIRO_CONTENT_ALPHA:
+ return CAIRO_FORMAT_A8;
+ case CAIRO_CONTENT_COLOR_ALPHA:
+ default:
+ return CAIRO_FORMAT_ARGB32;
+ }
+}
+
+static cairo_surface_t *
+compat_gdk_cairo_surface_coerce_to_image (cairo_surface_t *surface,
+ cairo_content_t content,
+ int src_x,
+ int src_y,
+ int width,
+ int height)
+{
+ cairo_surface_t *copy;
+ cairo_t *cr;
+
+ copy = cairo_image_surface_create (compat_gdk_cairo_format_for_content (content),
+ width,
+ height);
+
+ cr = cairo_create (copy);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_surface (cr, surface, -src_x, -src_y);
+ cairo_paint (cr);
+ cairo_destroy (cr);
+
+ return copy;
+}
+
+static void
+compat_convert_alpha (guchar *dest_data,
+ int dest_stride,
+ guchar *src_data,
+ int src_stride,
+ int src_x,
+ int src_y,
+ int width,
+ int height)
+{
+ int x, y;
+
+ src_data += src_stride * src_y + src_x * 4;
+
+ for (y = 0; y < height; y++) {
+ guint32 *src = (guint32 *) src_data;
+
+ for (x = 0; x < width; x++) {
+ guint alpha = src[x] >> 24;
+
+ if (alpha == 0)
+ {
+ dest_data[x * 4 + 0] = 0;
+ dest_data[x * 4 + 1] = 0;
+ dest_data[x * 4 + 2] = 0;
+ }
+ else
+ {
+ dest_data[x * 4 + 0] = (((src[x] & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
+ dest_data[x * 4 + 1] = (((src[x] & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
+ dest_data[x * 4 + 2] = (((src[x] & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
+ }
+ dest_data[x * 4 + 3] = alpha;
+ }
+
+ src_data += src_stride;
+ dest_data += dest_stride;
+ }
+}
+
+static void
+compat_convert_no_alpha (guchar *dest_data,
+ int dest_stride,
+ guchar *src_data,
+ int src_stride,
+ int src_x,
+ int src_y,
+ int width,
+ int height)
+{
+ int x, y;
+
+ src_data += src_stride * src_y + src_x * 4;
+
+ for (y = 0; y < height; y++) {
+ guint32 *src = (guint32 *) src_data;
+
+ for (x = 0; x < width; x++) {
+ dest_data[x * 3 + 0] = src[x] >> 16;
+ dest_data[x * 3 + 1] = src[x] >> 8;
+ dest_data[x * 3 + 2] = src[x];
+ }
+
+ src_data += src_stride;
+ dest_data += dest_stride;
+ }
+}
+
+GdkPixbuf *
+compat_gdk_pixbuf_get_from_surface (cairo_surface_t *surface,
+ gint src_x,
+ gint src_y,
+ gint width,
+ gint height)
+{
+ cairo_content_t content;
+ GdkPixbuf *dest;
+
+ /* General sanity checks */
+ g_return_val_if_fail (surface != NULL, NULL);
+ g_return_val_if_fail (width > 0 && height > 0, NULL);
+
+ content = cairo_surface_get_content (surface) | CAIRO_CONTENT_COLOR;
+ dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
+ !!(content & CAIRO_CONTENT_ALPHA),
+ 8,
+ width, height);
+
+ surface = compat_gdk_cairo_surface_coerce_to_image (surface, content,
+ src_x, src_y,
+ width, height);
+ cairo_surface_flush (surface);
+ if (cairo_surface_status (surface) || dest == NULL)
+ {
+ cairo_surface_destroy (surface);
+ return NULL;
+ }
+
+ if (gdk_pixbuf_get_has_alpha (dest))
+ compat_convert_alpha (gdk_pixbuf_get_pixels (dest),
+ gdk_pixbuf_get_rowstride (dest),
+ cairo_image_surface_get_data (surface),
+ cairo_image_surface_get_stride (surface),
+ 0, 0,
+ width, height);
+ else
+ compat_convert_no_alpha (gdk_pixbuf_get_pixels (dest),
+ gdk_pixbuf_get_rowstride (dest),
+ cairo_image_surface_get_data (surface),
+ cairo_image_surface_get_stride (surface),
+ 0, 0,
+ width, height);
+
+ cairo_surface_destroy (surface);
+ return dest;
+}
|
