[gnome-shell] [StThemeNode] Add basic background-position support



commit 9f9067e29b5c1826eecd88f3d0977cd69fdd679e
Author: Adel Gadllah <adel gadllah gmail com>
Date:   Wed Sep 1 18:13:43 2010 +0200

    [StThemeNode] Add basic background-position support
    
    Add basic support for background-position, which only supports absolute
    values.
    
    Also don't require an unit to be specified for 0 (because the unit does not
    really matter here 0 is 0 regardless of the unit).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=624375

 src/st/st-theme-node-drawing.c |   19 ++++++++++++++-----
 src/st/st-theme-node-private.h |    4 ++++
 src/st/st-theme-node.c         |   38 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 54 insertions(+), 7 deletions(-)
---
diff --git a/src/st/st-theme-node-drawing.c b/src/st/st-theme-node-drawing.c
index 0e23caa..ff7ea0c 100644
--- a/src/st/st-theme-node-drawing.c
+++ b/src/st/st-theme-node-drawing.c
@@ -466,8 +466,8 @@ get_background_position (StThemeNode             *self,
   w = cogl_texture_get_width (self->background_texture);
   h = cogl_texture_get_height (self->background_texture);
 
-  /* scale the background into the allocated bounds */
-  if (w > result->x2 || h > result->y2)
+  /* scale the background into the allocated bounds, when not being absolutely positioned */
+  if ((w > result->x2 || h > result->y2) && !self->background_position_set)
     {
       gint new_h, new_w, offset;
       gint box_w, box_h;
@@ -500,9 +500,18 @@ get_background_position (StThemeNode             *self,
     }
   else
     {
-      /* center the background on the widget */
-      result->x1 = (int)(((allocation->x2 - allocation->x1) / 2) - (w / 2));
-      result->y1 = (int)(((allocation->y2 - allocation->y1) / 2) - (h / 2));
+      /* honor the specified position if any */
+      if (self->background_position_set)
+        {
+          result->x1 = self->background_position_x;
+          result->y1 = self->background_position_y;
+        }
+      else
+        {
+          /* center the background on the widget */
+          result->x1 = (int)(((allocation->x2 - allocation->x1) / 2) - (w / 2));
+          result->y1 = (int)(((allocation->y2 - allocation->y1) / 2) - (h / 2));
+        }
       result->x2 = result->x1 + w;
       result->y2 = result->y1 + h;
     }
diff --git a/src/st/st-theme-node-private.h b/src/st/st-theme-node-private.h
index 4641df3..92d68be 100644
--- a/src/st/st-theme-node-private.h
+++ b/src/st/st-theme-node-private.h
@@ -22,6 +22,10 @@ struct _StThemeNode {
   StGradientType background_gradient_type;
   ClutterColor background_gradient_end;
 
+  int background_position_x;
+  int background_position_y;
+  gboolean background_position_set : 1;
+
   ClutterColor foreground_color;
   ClutterColor border_color[4];
   ClutterColor outline_color;
diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c
index 90b156a..b6000ea 100644
--- a/src/st/st-theme-node.c
+++ b/src/st/st-theme-node.c
@@ -679,8 +679,19 @@ get_length_from_term (StThemeNode *node,
       return VALUE_NOT_FOUND;
 
     case NUM_GENERIC:
-      g_warning ("length values must specify a unit");
-      return VALUE_NOT_FOUND;
+      {
+        if (num->val != 0)
+          {
+            g_warning ("length values must specify a unit");
+            return VALUE_NOT_FOUND;
+          }
+        else
+          {
+            type = ABSOLUTE;
+            multiplier = 0;
+          }
+        break;
+      }
 
     case NUM_PERCENTAGE:
       g_warning ("percentage lengths not currently supported");
@@ -1424,6 +1435,7 @@ _st_theme_node_ensure_background (StThemeNode *node)
   node->background_computed = TRUE;
   node->background_color = TRANSPARENT_COLOR;
   node->background_gradient_type = ST_GRADIENT_NONE;
+  node->background_position_set = FALSE;
 
   ensure_properties (node);
 
@@ -1450,6 +1462,7 @@ _st_theme_node_ensure_background (StThemeNode *node)
           node->background_color = TRANSPARENT_COLOR;
           g_free (node->background_image);
           node->background_image = NULL;
+          node->background_position_set = FALSE;
 
           for (term = decl->value; term; term = term->next)
             {
@@ -1478,6 +1491,27 @@ _st_theme_node_ensure_background (StThemeNode *node)
                 }
             }
         }
+      else if (strcmp (property_name, "-position") == 0)
+        {
+          GetFromTermResult result = get_length_from_term_int (node, decl->value, FALSE, &node->background_position_x);
+          if (result == VALUE_NOT_FOUND)
+            {
+              node->background_position_set = FALSE;
+              continue;
+            }
+          else
+            node->background_position_set = TRUE;
+            
+           result = get_length_from_term_int (node, decl->value->next, FALSE, &node->background_position_y);
+
+          if (result == VALUE_NOT_FOUND)
+            {
+              node->background_position_set = FALSE;
+              continue;
+            }
+          else
+            node->background_position_set = TRUE;
+        }
       else if (strcmp (property_name, "-color") == 0)
         {
           GetFromTermResult result;



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