[Xfce4-commits] <xfce4-panel:master> Fixed drawing code in panel-image and arrow-button

Nick Schermer noreply at xfce.org
Sat Nov 30 17:12:09 CET 2013


Updating branch refs/heads/master
         to 17fabdc1123be9e191b21375a302020608a8320b (commit)
       from a682ae47be0485d20b984fbe4e796b1450c226dc (commit)

commit 17fabdc1123be9e191b21375a302020608a8320b
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Sun Apr 14 01:08:01 2013 +0100

    Fixed drawing code in panel-image and arrow-button
    
    - top-left coordinate at 0,0, not alloc->x,alloc->y
    - use gdouble instead of gint in _draw
    - use GtkStyleContext
    - fix uninitialized alloc variable

 libxfce4panel/xfce-arrow-button.c |   38 ++++++++++++++++++++-----------------
 libxfce4panel/xfce-panel-image.c  |    4 ++--
 2 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/libxfce4panel/xfce-arrow-button.c b/libxfce4panel/xfce-arrow-button.c
index bbf2369..a9363de 100644
--- a/libxfce4panel/xfce-arrow-button.c
+++ b/libxfce4panel/xfce-arrow-button.c
@@ -265,10 +265,12 @@ xfce_arrow_button_draw (GtkWidget *widget,
 {
   XfceArrowButton *button = XFCE_ARROW_BUTTON (widget);
   GtkWidget       *child;
-  gint             x, y, width;
+  gdouble          x, y, width;
   GtkAllocation    alloc;
   gdouble          angle;
   GtkStyleContext *context;
+  GtkBorder        padding;
+  GdkRGBA          fg_rgba;
 
   /* draw the button */
   (*GTK_WIDGET_CLASS (xfce_arrow_button_parent_class)->draw) (widget, cr);
@@ -276,34 +278,36 @@ xfce_arrow_button_draw (GtkWidget *widget,
   if (button->priv->arrow_type != GTK_ARROW_NONE
       && gtk_widget_is_drawable (widget))
     {
+      gtk_widget_get_allocation (widget, &alloc);
       child = gtk_bin_get_child (GTK_BIN (widget));
+      context = gtk_widget_get_style_context (widget);
+      gtk_style_context_get_padding (context, gtk_widget_get_state_flags (widget), &padding);
+
       if (child != NULL
           && gtk_widget_get_visible (child))
         {
-          gtk_widget_get_allocation (widget, &alloc);
-          
           if (button->priv->arrow_type == GTK_ARROW_UP
               || button->priv->arrow_type == GTK_ARROW_DOWN)
             {
-              width = ARROW_WIDTH;
-              x = alloc.x + 1 /* widget->style->xthickness */;
-              y = alloc.y + (alloc.height - width) / 2;
+              width = (gdouble) ARROW_WIDTH;
+              x = (gdouble) padding.left;
+              y = (gdouble) (alloc.height - width) / 2.0;
             }
           else
             {
-              width = ARROW_WIDTH;
-              x = alloc.x + (alloc.width - width) / 2;
-              y = alloc.y + 1 /* widget->style->ythickness */;
+              width = (gdouble) ARROW_WIDTH;
+              x = (gdouble) (alloc.width - width) / 2.0;
+              y = (gdouble) padding.top;
             }
         }
       else
         {
-          width = MIN (alloc.height - 2 * 1 /* widget->style->ythickness */,
-                       alloc.width  - 2 * 1 /* widget->style->xthickness */);
-          width = CLAMP (width, 1, ARROW_WIDTH);
+          width = (gdouble) MIN (alloc.height - padding.top - padding.bottom,
+                                 alloc.width  - padding.left - padding.right);
+          width = (gdouble) CLAMP (width, 1.0, (gdouble) ARROW_WIDTH);
 
-          x = alloc.x + (alloc.width - width) / 2;
-          y = alloc.y + (alloc.height - width) / 2;
+          x = (gdouble) (alloc.width - width) / 2.0;
+          y = (gdouble) (alloc.height - width) / 2.0;
         }
 
       switch (button->priv->arrow_type)
@@ -311,10 +315,10 @@ xfce_arrow_button_draw (GtkWidget *widget,
         case GTK_ARROW_DOWN:  angle = G_PI;
         case GTK_ARROW_LEFT:  angle = G_PI / 2.0 + G_PI;
         case GTK_ARROW_RIGHT: angle = G_PI / 2.0;
-        default:              angle = 0;
+        default:              angle = 0.0;
         }
-
-      context = gtk_widget_get_style_context (widget);
+      gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget), &fg_rgba);
+      gdk_cairo_set_source_rgba (cr, &fg_rgba);
       gtk_render_arrow (context, cr, angle, x, y, ARROW_WIDTH);
     }
 
diff --git a/libxfce4panel/xfce-panel-image.c b/libxfce4panel/xfce-panel-image.c
index 2c5ba5b..1fd96d4 100644
--- a/libxfce4panel/xfce-panel-image.c
+++ b/libxfce4panel/xfce-panel-image.c
@@ -438,8 +438,8 @@ xfce_panel_image_draw (GtkWidget *widget,
 
       /* position */
       gtk_widget_get_allocation (widget, &alloc);
-      dest_x = alloc.x + (priv->width - source_width) / 2;
-      dest_y = alloc.y + (priv->height - source_height) / 2;
+      dest_x = (priv->width - source_width) / 2;
+      dest_y = (priv->height - source_height) / 2;
 
       context = gtk_widget_get_style_context (widget);
 


More information about the Xfce4-commits mailing list