[monet/monet-xml] Implement loading multiple states from MnConfig and XML files



commit 38b0c179efa40f9088e9c21a0584cb1a21d2fe92
Author: Thomas Wood <thos gnome org>
Date:   Sun May 9 21:15:36 2010 +0100

    Implement loading multiple states from MnConfig and XML files
    
    Add support for multiple states for each widget in MnConfig and load the
    states from the XML configuration file. If a set of drawing operations is
    not specified for a partical state, then Monet will use the "normal" state
    as the default.

 monet-gtk/monet.xml |   10 ++++++++++
 monet/mn-config.c   |   34 ++++++++++++++++++++++++++--------
 monet/mn-config.h   |   22 +++++++++++++++-------
 monet/mn-style.c    |   25 ++++++++++++++++---------
 4 files changed, 67 insertions(+), 24 deletions(-)
---
diff --git a/monet-gtk/monet.xml b/monet-gtk/monet.xml
index 0b0eceb..2f57df9 100644
--- a/monet-gtk/monet.xml
+++ b/monet-gtk/monet.xml
@@ -9,6 +9,16 @@
   <rect x="1.5" y="1.5" width="-3" height="-3" stroke-width="1" stroke="#fff" corner-radius="3"></rect>
 </widget>
 
+<widget type="button" state="active">
+  <rect x="0.5" y="0.5" width="-1" height="-1" stroke-width="1" stroke="#988c7c" corner-radius="4">
+    <gradient x1="0" y1="0" x2="0" y1="50">
+      <stop color="#fcfbfa" position="0"/>
+      <stop color="#e7e2da" position="1"/>
+    </gradient>
+  </rect>
+  <rect x="1.5" y="1.5" width="-3" height="-3" stroke-width="1" stroke="#fff" corner-radius="3"></rect>
+</widget>
+
 <widget type="entry">
   <line x1="0.5" y1="0.5" y2="-0.5" x1="0.5" stroke="#999" stroke-width="1"/>
   <line x1="0.5" y1="0.5" y2="0.5" x1="-0.5" stroke="#999" stroke-width="1"/>
diff --git a/monet/mn-config.c b/monet/mn-config.c
index 12ab5ea..a70aad7 100644
--- a/monet/mn-config.c
+++ b/monet/mn-config.c
@@ -20,7 +20,7 @@
  */
 
 #include "mn-config.h"
-
+#include "mn-types.h"
 #include "mn-color.h"
 
 #include <string.h>
@@ -239,6 +239,19 @@ widget_end_element (GMarkupParseContext  *context,
 static GMarkupParser widget_parser = { widget_start_element, widget_end_element, NULL,
     NULL, perror };
 
+static MnState
+monet_state_from_string (const gchar *string)
+{
+  switch (string[0])
+    {
+      case 'n': return MN_STATE_NORMAL;
+      case 'h': return MN_STATE_HOVER;
+      case 'd': return MN_STATE_DISABLED;
+      case 'a': return MN_STATE_ACTIVE;
+      default: return MN_STATE_NORMAL;
+    }
+}
+
 static void
 monet_start_element (GMarkupParseContext  *context,
                      const gchar          *element_name,
@@ -262,12 +275,17 @@ monet_start_element (GMarkupParseContext  *context,
     {
       const gchar *type = NULL;
       gpointer ops;
+      MnState wstate;
+
+      wstate = MN_STATE_NORMAL;
 
       /* inspect the attributes */
       for (attr_n = attribute_names, i = 0; *attr_n; attr_n++, i++)
         {
           if (!strcmp (*attr_n, "type"))
             type = attribute_values[i];
+          else if (!strcmp (*attr_n, "state"))
+            wstate = monet_state_from_string (attribute_values[i]);
         }
 
       if (!type)
@@ -279,19 +297,19 @@ monet_start_element (GMarkupParseContext  *context,
         }
 
       if (!strcmp (type, "button"))
-        ops = &config->button_ops;
+        ops = &config->button_ops[wstate];
       else if (!strcmp (type, "entry"))
-        ops = &config->entry_ops;
+        ops = &config->entry_ops[wstate];
       else if (!strcmp (type, "check"))
-        ops = &config->check_ops;
+        ops = &config->check_ops[wstate];
       else if (!strcmp (type, "radio"))
-        ops = &config->radio_ops;
+        ops = &config->radio_ops[wstate];
       else if (!strcmp (type, "menu"))
-        ops = &config->menu_ops;
+        ops = &config->menu_ops[wstate];
       else if (!strcmp (type, "menu-item"))
-        ops = &config->menu_item_ops;
+        ops = &config->menu_item_ops[wstate];
       else if (!strcmp (type, "menu-bar"))
-        ops = &config->menu_bar_ops;
+        ops = &config->menu_bar_ops[wstate];
 
       g_markup_parse_context_push (context, &widget_parser, ops);
     }
diff --git a/monet/mn-config.h b/monet/mn-config.h
index 1f606b1..10e0e85 100644
--- a/monet/mn-config.h
+++ b/monet/mn-config.h
@@ -24,13 +24,21 @@
 
 typedef struct
 {
-  GSList *button_ops;
-  GSList *entry_ops;
-  GSList *check_ops;
-  GSList *radio_ops;
-  GSList *menu_ops;
-  GSList *menu_item_ops;
-  GSList *menu_bar_ops;
+  GSList *normal;
+  GSList *hover;
+  GSList *active;
+  GSList *disabled;
+} MnWidgetOps;
+
+typedef struct
+{
+  GSList *button_ops[4];
+  GSList *entry_ops[4];
+  GSList *check_ops[4];
+  GSList *radio_ops[4];
+  GSList *menu_ops[4];
+  GSList *menu_item_ops[4];
+  GSList *menu_bar_ops[4];
 } MnConfig;
 
 
diff --git a/monet/mn-style.c b/monet/mn-style.c
index 40e0182..b335d92 100644
--- a/monet/mn-style.c
+++ b/monet/mn-style.c
@@ -124,7 +124,7 @@ mn_style_load_config (MnStyle      *style,
 
 static void
 mn_style_draw_ops (MnStyle   *style,
-                   GSList    *ops,
+                   GSList   **ops,
                    cairo_t   *cr,
                    gdouble    x,
                    gdouble    y,
@@ -139,7 +139,14 @@ mn_style_draw_ops (MnStyle   *style,
   /* translate to ensure pattern is in the correct position */
   cairo_translate (cr, x, y);
 
-  for (o = ops; o; o = g_slist_next (o))
+  /* pick the correct drawing operations, but fall back to "normal" state
+   * drawing operations if none are available for the given state */
+  if (ops[state])
+    o = ops[state];
+  else
+    o = ops[MN_STATE_NORMAL];
+
+  for (; o; o = g_slist_next (o))
     {
       MnDrawingOp *op = (MnDrawingOp *) o->data;
       MnRectangleOp *rect;
@@ -233,7 +240,7 @@ mn_style_paint_entry (MnStyle   *style,
                       MnState    state,
                       MnFlags    flags)
 {
-  GSList *ops;
+  GSList **ops;
 
   ops = style->priv->config->entry_ops;
 
@@ -251,7 +258,7 @@ mn_style_paint_button (MnStyle   *style,
                        MnState    state,
                        MnFlags    flags)
 {
-  GSList *ops;
+  GSList **ops;
 
   ops = style->priv->config->button_ops;
 
@@ -269,7 +276,7 @@ mn_style_paint_check_box (MnStyle   *style,
                           MnState    state,
                           MnFlags    flags)
 {
-  GSList *ops;
+  GSList **ops;
 
   ops = style->priv->config->check_ops;
 
@@ -287,7 +294,7 @@ mn_style_paint_radio_button (MnStyle   *style,
                              MnState    state,
                              MnFlags    flags)
 {
-  GSList *ops;
+  GSList **ops;
 
   ops = style->priv->config->radio_ops;
 
@@ -306,7 +313,7 @@ mn_style_paint_menu (MnStyle   *style,
                      MnState    state,
                      MnFlags    flags)
 {
-  GSList *ops;
+  GSList **ops;
 
   ops = style->priv->config->menu_ops;
 
@@ -324,7 +331,7 @@ mn_style_paint_menu_item (MnStyle   *style,
                           MnState    state,
                           MnFlags    flags)
 {
-  GSList *ops;
+  GSList **ops;
 
   ops = style->priv->config->menu_item_ops;
 
@@ -342,7 +349,7 @@ mn_style_paint_menu_bar (MnStyle   *style,
                          MnState    state,
                          MnFlags    flags)
 {
-  GSList *ops;
+  GSList **ops;
 
   ops = style->priv->config->menu_bar_ops;
 



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