changeset 2859:312ba23cbb87

transform UiSkinnedButton into windowless widget
author Tomasz Mon <desowin@gmail.com>
date Sun, 03 Aug 2008 14:11:02 +0200
parents 528d19a2ea3d
children 2e081c64a529
files src/skins/plugin.c src/skins/ui_skin.c src/skins/ui_skin.h src/skins/ui_skinned_button.c
diffstat 4 files changed, 42 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/src/skins/plugin.c	Sat Aug 02 22:40:41 2008 +0300
+++ b/src/skins/plugin.c	Sun Aug 03 14:11:02 2008 +0200
@@ -107,6 +107,7 @@
 gboolean skins_cleanup(void) {
     if (plugin_is_active == TRUE) {
         skins_cfg_save();
+        cleanup_skins();
         skins_free_paths();
         ui_main_evlistener_dissociate();
         ui_playlist_evlistener_dissociate();
@@ -115,8 +116,6 @@
         gtk_widget_destroy(equalizerwin);
         gtk_widget_destroy(playlistwin);
         ui_manager_destroy();
-        skin_destroy(aud_active_skin);
-        aud_active_skin = NULL;
         mainwin = NULL;
         equalizerwin = NULL;
         playlistwin = NULL;
--- a/src/skins/ui_skin.c	Sat Aug 02 22:40:41 2008 +0300
+++ b/src/skins/ui_skin.c	Sun Aug 03 14:11:02 2008 +0200
@@ -1749,42 +1749,25 @@
                 gtk_widget_hide(widget);
                 return;
             }
-            gint x, y;
-            x = -1;
-            y = -1;
 
-            if (gtk_widget_get_parent(widget) == SKINNED_WINDOW(mainwin)->normal) {
-                GList *iter;
-                for (iter = GTK_FIXED (SKINNED_WINDOW(mainwin)->normal)->children; iter; iter = g_list_next (iter)) {
-                     GtkFixedChild *child_data = (GtkFixedChild *) iter->data;
-                     if (child_data->widget == widget) {
-                         x = child_data->x;
-                         y = child_data->y;
-                         break;
-                     }
-                }
+            /* Some skins include SKIN_VOLUME and/or SKIN_BALANCE without knobs */
+            if (pixmap_id == SKIN_VOLUME || pixmap_id == SKIN_BALANCE) {
+                if (ysrc+height > 421 && xsrc+width <= pixmap->width)
+                    return;
+            }
 
-                if (x != -1 && y != -1) {
-                    /* Some skins include SKIN_VOLUME and/or SKIN_BALANCE
-                       without knobs */
-                    if (pixmap_id == SKIN_VOLUME || pixmap_id == SKIN_BALANCE) {
-                        if (ysrc+height > 421 && xsrc+width <= pixmap->width)
-                            return;
-                    }
-                    /* let's copy what's under widget */
-                    gdk_pixbuf_copy_area(skin_get_pixmap(aud_active_skin, SKIN_MAIN)->pixbuf,
-                                         x, y, width, height, pix, xdest, ydest);
+            /* XMMS skins seems to have SKIN_MONOSTEREO with size 58x20 instead of 58x24 */
+            if (pixmap_id == SKIN_MONOSTEREO)
+                height = pixmap->height/2;
 
-                    /* XMMS skins seems to have SKIN_MONOSTEREO with size 58x20 instead of 58x24 */
-                    if (pixmap_id == SKIN_MONOSTEREO)
-                        height = pixmap->height/2;
-                }
-            } else if (gtk_widget_get_parent(widget) == SKINNED_WINDOW(equalizerwin)->normal) {
-                   if (!(pixmap_id == SKIN_EQMAIN && ysrc == 314)) /* equalizer preamp on equalizer graph */
-                         gtk_widget_hide(widget);
-            } else if (gtk_widget_get_parent(widget) == SKINNED_WINDOW(playlistwin)->normal) {
-                   /* I haven't seen any skin with substandard playlist */
-                   gtk_widget_hide(widget);
+            if (gtk_widget_get_parent(widget) == SKINNED_WINDOW(equalizerwin)->normal) {
+                if (!(pixmap_id == SKIN_EQMAIN && ysrc == 314)) /* equalizer preamp on equalizer graph */
+                    gtk_widget_hide(widget);
+            }
+
+            if (gtk_widget_get_parent(widget) == SKINNED_WINDOW(playlistwin)->normal) {
+                /* I haven't seen any skin with substandard playlist */
+                gtk_widget_hide(widget);
             }
         } else
             return;
@@ -2039,16 +2022,19 @@
     aud_active_skin_load(node->path);
 }
 
-
-void ui_skinned_widget_draw(GtkWidget *widget, GdkPixbuf *obj, gint width, gint height, gboolean scale) {
+void ui_skinned_widget_draw_with_coordinates(GtkWidget *widget, GdkPixbuf *obj, gint width, gint height, gint destx, gint desty, gboolean scale) {
     g_return_if_fail(widget != NULL);
     g_return_if_fail(obj != NULL);
 
     if (scale) {
         GdkPixbuf *image = gdk_pixbuf_scale_simple(obj, width * config.scale_factor, height* config.scale_factor, GDK_INTERP_NEAREST);
-        gdk_draw_pixbuf(widget->window, NULL, image, 0, 0, 0, 0, width * config.scale_factor , height * config.scale_factor, GDK_RGB_DITHER_NONE, 0, 0);
+        gdk_draw_pixbuf(widget->window, NULL, image, 0, 0, destx, desty, width * config.scale_factor , height * config.scale_factor, GDK_RGB_DITHER_NONE, 0, 0);
         g_object_unref(image);
     } else {
-        gdk_draw_pixbuf(widget->window, NULL, obj, 0, 0, 0, 0, width, height, GDK_RGB_DITHER_NONE, 0, 0);
+        gdk_draw_pixbuf(widget->window, NULL, obj, 0, 0, destx, desty, width, height, GDK_RGB_DITHER_NONE, 0, 0);
     }
 }
+
+void ui_skinned_widget_draw(GtkWidget *widget, GdkPixbuf *obj, gint width, gint height, gboolean scale) {
+    ui_skinned_widget_draw_with_coordinates(widget, obj, width, height, 0, 0, scale);
+}
--- a/src/skins/ui_skin.h	Sat Aug 02 22:40:41 2008 +0300
+++ b/src/skins/ui_skin.h	Sun Aug 03 14:11:02 2008 +0200
@@ -239,7 +239,7 @@
 
 void skin_set_random_skin(void);
 
-
+void ui_skinned_widget_draw_with_coordinates(GtkWidget *widget, GdkPixbuf *obj, gint width, gint height, gint destx, gint desty, gboolean scale);
 void ui_skinned_widget_draw(GtkWidget *widget, GdkPixbuf *obj, gint width, gint height, gboolean scale);
 
 #endif
--- a/src/skins/ui_skinned_button.c	Sat Aug 02 22:40:41 2008 +0300
+++ b/src/skins/ui_skinned_button.c	Sun Aug 03 14:11:02 2008 +0200
@@ -157,6 +157,8 @@
     priv->move_x = 0;
     priv->move_y = 0;
     button->event_window = NULL;
+
+    GTK_WIDGET_SET_FLAGS (button, GTK_NO_WINDOW);
 }
 
 static void ui_skinned_button_destroy (GtkObject *object) {
@@ -174,38 +176,27 @@
 static void ui_skinned_button_realize (GtkWidget *widget) {
     g_return_if_fail (widget != NULL);
     g_return_if_fail (UI_SKINNED_IS_BUTTON(widget));
+
+    if (GTK_WIDGET_CLASS (parent_class)->realize)
+        (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
+
     UiSkinnedButton *button = UI_SKINNED_BUTTON (widget);
     GdkWindowAttr attributes;
     gint attributes_mask;
 
-    GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
-
     attributes.x = widget->allocation.x;
     attributes.y = widget->allocation.y;
     attributes.width = widget->allocation.width;
     attributes.height = widget->allocation.height;
-    attributes.window_type = GDK_WINDOW_CHILD;
+    attributes.window_type = GDK_INPUT_ONLY;
     attributes.event_mask = gtk_widget_get_events(widget);
     attributes.event_mask |= GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK;
 
-    if (button->type == TYPE_SMALL || button->type == TYPE_NOT_SET) {
-        widget->window = gtk_widget_get_parent_window (widget);
-        g_object_ref (widget->window);
-        attributes.wclass = GDK_INPUT_ONLY;
-        attributes_mask = GDK_WA_X | GDK_WA_Y;
-        button->event_window = gdk_window_new (widget->window, &attributes, attributes_mask);
-        GTK_WIDGET_SET_FLAGS (widget, GTK_NO_WINDOW);
-        gdk_window_set_user_data(button->event_window, widget);
-    } else {
-        attributes.visual = gtk_widget_get_visual(widget);
-        attributes.colormap = gtk_widget_get_colormap(widget);
-        attributes.wclass = GDK_INPUT_OUTPUT;
-        attributes.event_mask |= GDK_EXPOSURE_MASK;
-        attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-        widget->window = gdk_window_new(widget->parent->window, &attributes, attributes_mask);
-        GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_WINDOW);
-        gdk_window_set_user_data(widget->window, widget);
-    }
+    attributes.wclass = GDK_INPUT_ONLY;
+    attributes_mask = GDK_WA_X | GDK_WA_Y;
+    button->event_window = gdk_window_new (widget->window, &attributes, attributes_mask);
+
+    gdk_window_set_user_data(button->event_window, widget);
 
     widget->style = gtk_style_attach(widget->style, widget->window);
 }
@@ -289,12 +280,9 @@
     if (button->type == TYPE_SMALL || button->type == TYPE_NOT_SET)
         return FALSE;
 
-    /* paranoia */
-    if (button->event_window != NULL)
-        return FALSE;
-
     GdkPixbuf *obj;
     obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, priv->w, priv->h);
+    gdk_pixbuf_fill(obj, 0x00000000); /* fill with alpha */
 
     switch (button->type) {
         case TYPE_PUSH:
@@ -322,7 +310,10 @@
             break;
     }
 
-    ui_skinned_widget_draw(widget, obj, priv->w, priv->h, priv->scaled);
+    ui_skinned_widget_draw_with_coordinates(widget, obj, priv->w, priv->h,
+                                            widget->allocation.x,
+                                            widget->allocation.y,
+                                            priv->scaled);
     g_object_unref(obj);
 
     return FALSE;