[gtk+/wip/baedert/drawing: 2/8] range: Fix slider allocation



commit 8c81be582fe7de21a96928733045f06fbba99751
Author: Timm Bäder <mail baedert org>
Date:   Fri Jun 16 18:16:27 2017 +0200

    range: Fix slider allocation

 gtk/gtkrange.c |   41 +++++++++++++++++++----------------------
 gtk/gtkscale.c |   28 +++++++++++++---------------
 2 files changed, 32 insertions(+), 37 deletions(-)
---
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index e51d067..e85c9cd 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -909,7 +909,7 @@ gtk_range_get_slider_size_fixed (GtkRange *range)
  * @range_rect: (out): return location for the range rectangle
  *
  * This function returns the area that contains the range’s trough,
- * in widget->window coordinates.
+ * in coordinates relative to @range's origin.
  *
  * This function is useful mainly for #GtkRange subclasses.
  *
@@ -922,7 +922,7 @@ gtk_range_get_range_rect (GtkRange     *range,
   g_return_if_fail (GTK_IS_RANGE (range));
   g_return_if_fail (range_rect != NULL);
 
-  gtk_widget_get_margin_allocation (GTK_WIDGET (range->priv->trough_widget), range_rect);
+  gtk_widget_get_own_allocation (range->priv->trough_widget, range_rect);
 }
 
 /**
@@ -1627,8 +1627,8 @@ gtk_range_size_allocate (GtkWidget     *widget,
   else
     clamp_dimensions (allocation, &box_min_width, &box_min_height, &border, FALSE);
 
-  box_alloc.x = border.left + allocation->x;
-  box_alloc.y = border.top + allocation->y;
+  box_alloc.x = border.left;
+  box_alloc.y = border.top;
   box_alloc.width = box_min_width;
   box_alloc.height = box_min_height;
 
@@ -2695,15 +2695,6 @@ gtk_range_move_slider (GtkRange     *range,
     gtk_widget_error_bell (GTK_WIDGET (range));
 }
 
-static gboolean
-rectangle_contains_point (GdkRectangle *rect,
-                          gint          x,
-                          gint          y)
-{
-  return (x >= rect->x) && (x < rect->x + rect->width) &&
-         (y >= rect->y) && (y < rect->y + rect->height);
-}
-
 /* Update mouse location, return TRUE if it changes */
 static void
 gtk_range_update_mouse_location (GtkRange *range)
@@ -2720,18 +2711,22 @@ gtk_range_update_mouse_location (GtkRange *range)
   x = priv->mouse_x;
   y = priv->mouse_y;
 
-  gtk_widget_get_allocation (widget, &range_alloc);
+  gtk_widget_get_own_allocation (widget, &range_alloc);
   gtk_widget_get_border_allocation (priv->trough_widget, &trough_alloc);
-  gtk_widget_get_border_allocation (priv->slider_widget, &slider_alloc);
+
+  gtk_widget_get_outer_allocation (priv->slider_widget, &slider_alloc);
+  gtk_widget_translate_coordinates (priv->trough_widget, widget,
+                                    slider_alloc.x, slider_alloc.y, &slider_alloc.x, &slider_alloc.y);
+
   gdk_rectangle_union (&slider_alloc, &trough_alloc, &slider_trace);
 
   if (priv->grab_location != NULL)
     priv->mouse_location = priv->grab_location;
-  else if (rectangle_contains_point (&slider_alloc, range_alloc.x + x, range_alloc.y + y))
+  else if (gdk_rectangle_contains_point (&slider_alloc, x, y))
     priv->mouse_location = priv->slider_widget;
-  else if (rectangle_contains_point (&slider_trace, range_alloc.x + x, range_alloc.y + y))
+  else if (gdk_rectangle_contains_point (&slider_trace, x, y))
     priv->mouse_location = priv->trough_widget;
-  else if (rectangle_contains_point (&range_alloc, range_alloc.x + x, range_alloc.y + y))
+  else if (gdk_rectangle_contains_point (&range_alloc, x, y))
     priv->mouse_location = widget;
   else
     priv->mouse_location = NULL;
@@ -2784,13 +2779,13 @@ gtk_range_compute_slider_position (GtkRange     *range,
       /* Slider fits into the trough, with stepper_spacing on either side,
        * and the size/position based on the adjustment or fixed, depending.
        */
-      slider_rect->x = trough_content_alloc.x + (int) floor ((trough_content_alloc.width - slider_width) / 
2);
+      slider_rect->x = (int) floor ((trough_content_alloc.width - slider_width) / 2);
       slider_rect->width = slider_width;
 
       min_slider_size = slider_height;
 
       /* Compute slider position/length */
-      top = trough_content_alloc.y;
+      top = 0;
       bottom = top + trough_content_alloc.height;
 
       /* Scale slider half extends over the trough edge */
@@ -2837,13 +2832,13 @@ gtk_range_compute_slider_position (GtkRange     *range,
       /* Slider fits into the trough, with stepper_spacing on either side,
        * and the size/position based on the adjustment or fixed, depending.
        */
-      slider_rect->y = trough_content_alloc.y + (int) floor ((trough_content_alloc.height - slider_height) / 
2);
+      slider_rect->y = (int) floor ((trough_content_alloc.height - slider_height) / 2);
       slider_rect->height = slider_height;
 
       min_slider_size = slider_width;
 
       /* Compute slider position/length */
-      left = trough_content_alloc.x;
+      left = 0;
       right = left + trough_content_alloc.width;
 
       /* Scale slider half extends over the trough edge */
@@ -2915,6 +2910,8 @@ gtk_range_calc_marks (GtkRange *range)
   for (i = 0; i < priv->n_marks; i++)
     {
       gtk_range_compute_slider_position (range, priv->marks[i], &slider);
+      gtk_widget_translate_coordinates (priv->slider_widget, GTK_WIDGET (range),
+                                        slider.x, slider.y, &slider.x, &slider.y);
 
       if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
         priv->mark_pos[i] = slider.x + slider.width / 2;
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c
index 002e9d4..8b5442b 100644
--- a/gtk/gtkscale.c
+++ b/gtk/gtkscale.c
@@ -329,7 +329,7 @@ gtk_scale_allocate_value (GtkScale      *scale,
   GtkWidget *slider_widget;
   GtkAllocation range_alloc, slider_alloc, value_alloc;
 
-  gtk_widget_get_margin_allocation (widget, &range_alloc);
+  gtk_widget_get_content_allocation (widget, &range_alloc);
 
   slider_widget = gtk_range_get_slider_widget (range);
   gtk_widget_get_border_allocation (slider_widget, &slider_alloc);
@@ -348,25 +348,25 @@ gtk_scale_allocate_value (GtkScale      *scale,
       switch (priv->value_pos)
         {
         case GTK_POS_LEFT:
-          value_alloc.x = range_alloc.x;
-          value_alloc.y = range_alloc.y + (range_alloc.height - value_alloc.height) / 2;
+          value_alloc.x = 0;
+          value_alloc.y = (range_alloc.height - value_alloc.height) / 2;
           break;
 
         case GTK_POS_RIGHT:
-          value_alloc.x = range_alloc.x + range_alloc.width - value_alloc.width;
-          value_alloc.y = range_alloc.y + (range_alloc.height - value_alloc.height) / 2;
+          value_alloc.x = range_alloc.width - value_alloc.width;
+          value_alloc.y = (range_alloc.height - value_alloc.height) / 2;
           break;
 
         case GTK_POS_TOP:
           value_alloc.x = slider_alloc.x + (slider_alloc.width - value_alloc.width) / 2;
           value_alloc.x = CLAMP (value_alloc.x, range_alloc.x, range_alloc.x + range_alloc.width - 
value_alloc.width);
-          value_alloc.y = range_alloc.y;
+          value_alloc.y = 0;
           break;
 
         case GTK_POS_BOTTOM:
           value_alloc.x = slider_alloc.x + (slider_alloc.width - value_alloc.width) / 2;
           value_alloc.x = CLAMP (value_alloc.x, range_alloc.x, range_alloc.x + range_alloc.width - 
value_alloc.width);
-          value_alloc.y = range_alloc.y + range_alloc.height - value_alloc.height;
+          value_alloc.y = range_alloc.height - value_alloc.height;
           break;
 
         default:
@@ -379,25 +379,23 @@ gtk_scale_allocate_value (GtkScale      *scale,
       switch (priv->value_pos)
         {
         case GTK_POS_LEFT:
-          value_alloc.x = range_alloc.x;
-          value_alloc.y = slider_alloc.y + (slider_alloc.height - value_alloc.height) / 2;
+          value_alloc.x = 0;
           value_alloc.y = CLAMP (value_alloc.y, range_alloc.y, range_alloc.y + range_alloc.height - 
value_alloc.height);
           break;
 
         case GTK_POS_RIGHT:
-          value_alloc.x = range_alloc.x + range_alloc.width - value_alloc.width;
-          value_alloc.y = slider_alloc.y + (slider_alloc.height - value_alloc.height) / 2;
+          value_alloc.x = range_alloc.width - value_alloc.width;
           value_alloc.y = CLAMP (value_alloc.y, range_alloc.y, range_alloc.y + range_alloc.height - 
value_alloc.height);
           break;
 
         case GTK_POS_TOP:
-          value_alloc.x = range_alloc.x + (range_alloc.width - value_alloc.width) / 2;
-          value_alloc.y = range_alloc.y;
+          value_alloc.x = (range_alloc.width - value_alloc.width) / 2;
+          value_alloc.y = 0;
           break;
 
         case GTK_POS_BOTTOM:
-          value_alloc.x = range_alloc.x + (range_alloc.width - value_alloc.width) / 2;
-          value_alloc.y = range_alloc.y + range_alloc.height - value_alloc.height;
+          value_alloc.x = (range_alloc.width - value_alloc.width) / 2;
+          value_alloc.y = range_alloc.height - value_alloc.height;
           break;
 
         default:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]