[monet/monet-xml: 9/10] Use an XML format to describe what to draw



commit 7a7ee188dd4037ec20e622ed1cb5199055ad7108
Author: Thomas Wood <thos gnome org>
Date:   Mon May 3 10:36:27 2010 +0100

    Use an XML format to describe what to draw
    
    Add support for reading and parsing an XML document that describes what
    to draw for each widget.

 monet-gtk/Makefile.am |    2 +-
 monet-gtk/monet.xml   |   16 ++
 monet-gtk/monetrc     |   39 -----
 monet-gtk/style.c     |    6 +-
 monet/Makefile.am     |    2 +
 monet/mn-config.c     |  259 +++++++++++++++++++++++++++++
 monet/mn-config.h     |   83 +++++++++
 monet/mn-style.c      |  442 ++++++++++---------------------------------------
 8 files changed, 449 insertions(+), 400 deletions(-)
---
diff --git a/monet-gtk/Makefile.am b/monet-gtk/Makefile.am
index dd06447..49504de 100644
--- a/monet-gtk/Makefile.am
+++ b/monet-gtk/Makefile.am
@@ -17,6 +17,6 @@ libmonet_gtk_la_LDFLAGS = -avoid-version -module -no-undefined
 libmonet_gtk_la_LIBADD = $(GTK_LIBS) -lmonet
 
 theme_DATA = gtkrc \
-	     monetrc
+	     monet.xml
 
 -include $(top_srcdir)/git.mk
diff --git a/monet-gtk/monet.xml b/monet-gtk/monet.xml
new file mode 100644
index 0000000..f86e4e9
--- /dev/null
+++ b/monet-gtk/monet.xml
@@ -0,0 +1,16 @@
+<monet>
+<widget type="button">
+  <rect x="0.5" y="0.5" width="-1" height="-1" stroke-width="1" stroke="#aaa"></rect>
+  <rect x="1.5" y="1.5" width="-3" height="-3" stroke-width="1" stroke="#fff"></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"/>
+
+  <line x1="-0.5" y1="0.5" y2="-0.5" x1="-0.5" stroke="#fff" stroke-width="1"/>
+  <line x1="-0.5" y1="-0.5" y2="-0.5" x1="0.5" stroke="#fff" stroke-width="1"/>
+
+  <rect x="1.5" y="1.5" width="-3" height="-3" stroke="#ccc" stroke-width="1"/>
+</widget>
+
+</monet>
diff --git a/monet-gtk/style.c b/monet-gtk/style.c
index e5e7cee..5ba8660 100644
--- a/monet-gtk/style.c
+++ b/monet-gtk/style.c
@@ -228,7 +228,7 @@ monet_gtk_draw_shadow (GtkStyle      *style,
                             mn_state, mn_flags);
     }
   else
-    printf ("draw_shadow: %s\n", detail);
+    monet_gtk_style_parent_class->draw_shadow (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
 
   cairo_destroy (cr);
 }
@@ -305,7 +305,7 @@ monet_gtk_draw_box (GtkStyle      *style,
                                mn_state, mn_flags);
     }
   else
-    printf ("draw_box: %s\n", detail);
+    monet_gtk_style_parent_class->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
 
 
   cairo_destroy (cr);
@@ -593,7 +593,7 @@ monet_gtk_style_init (GObject *self)
 
   mn_gtk->mn_style = mn_style_new ();
 
-  mn_style_load_config (mn_gtk->mn_style, THEMEDIR"/monetrc", &err);
+  mn_style_load_config (mn_gtk->mn_style, THEMEDIR"/monet.xml", &err);
 
   if (err)
     {
diff --git a/monet/Makefile.am b/monet/Makefile.am
index 6e82675..0c533ef 100644
--- a/monet/Makefile.am
+++ b/monet/Makefile.am
@@ -16,12 +16,14 @@ source_h = \
 	mn-palette.h \
 	mn-style.h \
 	mn-types.h \
+	mn-config.h \
 	monet.h
 
 source_c = \
 	mn-color.c	 \
 	mn-style.c	 \
 	mn-palette.c	 \
+	mn-config.c	 \
 	monet.c
 
 source_h_priv = mn-private.h
diff --git a/monet/mn-config.c b/monet/mn-config.c
new file mode 100644
index 0000000..b241c03
--- /dev/null
+++ b/monet/mn-config.c
@@ -0,0 +1,259 @@
+/*
+ * Copyright 2010 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ *
+ * Author: Thomas Wood <thos gnome org>
+ */
+
+#include "mn-config.h"
+
+#include "mn-color.h"
+
+#include <string.h>
+
+static cairo_pattern_t*
+cairo_pattern_from_paint (const gchar *string)
+{
+  MnColor color;
+
+  if (!mn_color_from_string (&color, string))
+    {
+      g_warning ("Could not parse \"%s\" as a color.", string);
+      return NULL;
+    }
+
+  return cairo_pattern_create_rgba (color.red / 255.0, color.green / 255.0,
+                                    color.blue / 255.0, color.alpha / 255.0);
+
+}
+
+static void
+perror (GMarkupParseContext *context,
+       GError              *error,
+       gpointer             user_data)
+{
+  g_warning ("An error occured during parsing: %s", error->message);
+}
+
+
+static void
+widget_start_element (GMarkupParseContext  *context,
+                      const gchar          *element_name,
+                      const gchar         **attribute_names,
+                      const gchar         **attribute_values,
+                      gpointer              user_data,
+                      GError              **error)
+{
+  GSList **ops = (GSList **) user_data;
+  const gchar **attr_n;
+  int i;
+
+  if (!strcmp (element_name, "rect"))
+    {
+      MnRectangleOp *op = g_slice_new (MnRectangleOp);
+      ((MnDrawingOp*)op)->type = MN_RECT;
+
+      /* inspect the attributes */
+      for (attr_n = attribute_names, i = 0; *attr_n; attr_n++, i++)
+        {
+          if (!strcmp (*attr_n, "x"))
+            op->x = g_ascii_strtod (attribute_values[i], NULL);
+          else if (!strcmp (*attr_n, "y"))
+            op->y = g_ascii_strtod (attribute_values[i], NULL);
+          else if (!strcmp (*attr_n, "width"))
+            op->width = g_ascii_strtod (attribute_values[i], NULL);
+          else if (!strcmp (*attr_n, "height"))
+            op->height = g_ascii_strtod (attribute_values[i], NULL);
+          else if (!strcmp (*attr_n, "stroke"))
+            ((MnDrawingOp*) op)->stroke = cairo_pattern_from_paint (attribute_values[i]);
+          else if (!strcmp (*attr_n, "stroke-width"))
+            ((MnDrawingOp*) op)->stroke_width = g_ascii_strtod (attribute_values[i], NULL);
+          else if (!strcmp (*attr_n, "fill"))
+            op->fill = cairo_pattern_from_paint (attribute_values[i]);
+        }
+
+      *ops = g_slist_append (*ops, op);
+    }
+  else if (!strcmp (element_name, "line"))
+    {
+      MnLineOp *op = g_slice_new (MnLineOp);
+      ((MnDrawingOp*)op)->type = MN_LINE;
+
+      for (attr_n = attribute_names, i = 0; *attr_n; attr_n++, i++)
+        {
+          if (!strcmp (*attr_n, "x1"))
+            op->x1 = g_ascii_strtod (attribute_values[i], NULL);
+          else if (!strcmp (*attr_n, "y1"))
+            op->y1 = g_ascii_strtod (attribute_values[i], NULL);
+          else if (!strcmp (*attr_n, "x2"))
+            op->x2 = g_ascii_strtod (attribute_values[i], NULL);
+          else if (!strcmp (*attr_n, "y2"))
+            op->y2 = g_ascii_strtod (attribute_values[i], NULL);
+          else if (!strcmp (*attr_n, "stroke"))
+            ((MnDrawingOp *) op)->stroke = cairo_pattern_from_paint (attribute_values[i]);
+          else if (!strcmp (*attr_n, "stroke-width"))
+            ((MnDrawingOp *) op)->stroke_width = g_ascii_strtod (attribute_values[i], NULL);
+        }
+
+      *ops = g_slist_append (*ops, op);
+    }
+  else if (!strcmp (element_name, "circle"))
+    {
+      MnCircleOp *op = g_slice_new (MnCircleOp);
+      ((MnDrawingOp*)op)->type = MN_CIRCLE;
+
+      for (attr_n = attribute_names, i = 0; *attr_n; attr_n++, i++)
+        {
+          if (!strcmp (*attr_n, "cx"))
+            op->x = g_ascii_strtod (attribute_values[i], NULL);
+          else if (!strcmp (*attr_n, "cy"))
+            op->y = g_ascii_strtod (attribute_values[i], NULL);
+          else if (!strcmp (*attr_n, "r"))
+            op->radius = g_ascii_strtod (attribute_values[i], NULL);
+          else if (!strcmp (*attr_n, "stroke"))
+            ((MnDrawingOp*) op)->stroke = cairo_pattern_from_paint (attribute_values[i]);
+          else if (!strcmp (*attr_n, "stroke-width"))
+            ((MnDrawingOp *)op)->stroke_width = g_ascii_strtod (attribute_values[i], NULL);
+          else if (!strcmp (*attr_n, "fill"))
+            op->fill = cairo_pattern_from_paint (attribute_values[i]);
+        }
+
+      *ops = g_slist_append (*ops, op);
+    }
+}
+
+static GMarkupParser widget_parser = { widget_start_element, NULL, NULL,
+    NULL, perror };
+
+static void
+monet_start_element (GMarkupParseContext  *context,
+                     const gchar          *element_name,
+                     const gchar         **attribute_names,
+                     const gchar         **attribute_values,
+                     gpointer              user_data,
+                     GError              **error)
+{
+  GError *err = NULL;
+  const gchar **attr_n;
+  gint i;
+  MnConfig *config = (MnConfig *) user_data;
+
+  if (!strcmp (element_name, "monet"))
+    {
+      /* this is the root element */
+      return;
+    }
+
+  if (!strcmp (element_name, "widget"))
+    {
+      const gchar *type = NULL;
+      gpointer ops;
+
+      /* inspect the attributes */
+      for (attr_n = attribute_names, i = 0; *attr_n; attr_n++, i++)
+        {
+          if (!strcmp (*attr_n, "type"))
+            type = attribute_values[i];
+        }
+
+      if (!type)
+        {
+          err = g_error_new (G_MARKUP_ERROR, G_MARKUP_ERROR_MISSING_ATTRIBUTE,
+                             "Missing \"type\" attribute");
+          g_propagate_error (error, err);
+          return;
+        }
+
+      if (!strcmp (type, "button"))
+        ops = &config->button_ops;
+      else if (!strcmp (type, "entry"))
+        ops = &config->entry_ops;
+      else if (!strcmp (type, "check"))
+        ops = &config->check_ops;
+      else if (!strcmp (type, "radio"))
+        ops = &config->radio_ops;
+      else if (!strcmp (type, "menu"))
+        ops = &config->menu_ops;
+      else if (!strcmp (type, "menu-item"))
+        ops = &config->menu_item_ops;
+      else if (!strcmp (type, "menu-bar"))
+        ops = &config->menu_bar_ops;
+
+      g_markup_parse_context_push (context, &widget_parser, ops);
+    }
+}
+
+static void
+monet_end_element (GMarkupParseContext  *context,
+                   const gchar          *element_name,
+                   gpointer              user_data,
+                   GError              **error)
+{
+  if (!strcmp ("widget", element_name))
+    {
+      g_markup_parse_context_pop (context);
+    }
+}
+
+
+MnConfig*
+mn_config_load_from_file (const gchar  *filename,
+                          GError      **err)
+{
+  GMarkupParser parser = { monet_start_element, monet_end_element, NULL, NULL, perror };
+  GMarkupParseContext *context;
+  MnConfig *config;
+  GError *error = NULL;
+  gchar *markup;
+
+  g_file_get_contents (filename,
+                       &markup,
+                       NULL,
+                       &error);
+
+  if (error)
+    {
+      g_warning ("Could not load Monet configuration file \"%s\": %s", filename,
+                 error->message);
+      g_propagate_error (err, error);
+      return NULL;
+    }
+
+  config = g_new0 (MnConfig, 1);
+
+
+
+  context = g_markup_parse_context_new (&parser, 0, config, NULL);
+
+  g_markup_parse_context_parse (context, markup, strlen (markup), &error);
+
+  if (error)
+    {
+      g_warning ("Could not parse Monet configuration file \"%s\": %s",
+                 filename, error->message);
+      g_propagate_error (err, error);
+
+      g_free (markup);
+      g_free (config);
+      g_markup_parse_context_free (context);
+      return NULL;
+    }
+
+  g_free (markup);
+  g_markup_parse_context_free (context);
+  return config;
+}
diff --git a/monet/mn-config.h b/monet/mn-config.h
new file mode 100644
index 0000000..42b447c
--- /dev/null
+++ b/monet/mn-config.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2010 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ *
+ * Author: Thomas Wood <thos gnome org>
+ */
+
+#include <glib.h>
+#include <cairo/cairo.h>
+
+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;
+} MnConfig;
+
+
+typedef enum
+{
+  MN_RECT,
+  MN_CIRCLE,
+  MN_LINE
+} MnDrawingOpType;
+
+typedef struct
+{
+  MnDrawingOpType type;
+  cairo_pattern_t *stroke;
+  double stroke_width;
+} MnDrawingOp;
+
+typedef struct
+{
+  MnDrawingOp op;
+
+  cairo_pattern_t *fill;
+  double x;
+  double y;
+  double width;
+  double height;
+} MnRectangleOp;
+
+typedef struct
+{
+  MnDrawingOp op;
+
+  cairo_pattern_t *fill;
+  double x;
+  double y;
+  double radius;
+} MnCircleOp;
+
+typedef struct
+{
+  MnDrawingOp op;
+
+  double x1;
+  double y1;
+  double x2;
+  double y2;
+} MnLineOp;
+
+MnConfig* mn_config_load_from_file (const gchar  *file,
+                                    GError      **err);
diff --git a/monet/mn-style.c b/monet/mn-style.c
index dc231f1..877a368 100644
--- a/monet/mn-style.c
+++ b/monet/mn-style.c
@@ -21,6 +21,8 @@
 
 #include "mn-style.h"
 
+#include "mn-config.h"
+
 #include <math.h>
 #include <string.h>
 
@@ -32,6 +34,7 @@ G_DEFINE_TYPE (MnStyle, mn_style, G_TYPE_OBJECT)
 struct _MnStylePrivate
 {
   GHashTable *colors;
+  MnConfig *config;
 };
 
 
@@ -100,29 +103,7 @@ mn_style_init (MnStyle *self)
                                               g_str_equal,
                                               g_free,
                                               (GDestroyNotify) mn_palette_free);
-}
-
-static MnPalette*
-mn_style_find_colors (MnStyle     *style,
-                      const gchar *paint,
-                      MnPalette   *colors)
-{
-  /* if colors is NULL, find the colours for the paint function */
-  if (!colors)
-    {
-      colors = g_hash_table_lookup (style->priv->colors, paint);
-
-      if (!colors)
-        {
-          g_warning ("No colors specified for %ss", paint);
-
-          /* returns a new transparent palette! */
-
-          return mn_palette_new ();
-        }
-
-    }
-  return colors;
+  self->priv->config = g_new0 (MnConfig, 1);
 }
 
 MnStyle *
@@ -136,187 +117,83 @@ mn_style_load_config (MnStyle      *style,
                       const gchar  *filename,
                       GError      **error)
 {
-  MnStylePrivate *priv = style->priv;
-  GKeyFile *file;
-  GError *err = NULL;
-  gchar **groups, **g;
-  GHashTable *symbolic_colors;
+  style->priv->config = mn_config_load_from_file (filename, error);
 
-  file = g_key_file_new ();
-  g_key_file_load_from_file (file, filename, 0, &err);
-
-  if (err)
-    {
-      g_propagate_error (error, err);
-
-      return FALSE;
-    }
-
-  symbolic_colors = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
-                                           (GDestroyNotify) mn_color_free);
+  return (style->priv->config != NULL);
+}
 
-  groups = g_key_file_get_groups (file, NULL);
+static void
+mn_style_draw_ops (MnStyle   *style,
+                   GSList    *ops,
+                   cairo_t   *cr,
+                   gdouble    x,
+                   gdouble    y,
+                   gdouble    width,
+                   gdouble    height,
+                   MnPalette *colors,
+                   MnState    state,
+                   MnFlags    flags)
+{
+  GSList *o;
 
-  for (g = groups; *g; g++)
+  for (o = ops; o; o = g_slist_next (o))
     {
-      gchar **keys, **k;
-      MnPalette *palette;
-
-      /* load symbolic colors */
-      if (!strcmp (*g, "colors"))
+      MnDrawingOp *op = (MnDrawingOp *) o->data;
+      MnRectangleOp *rect;
+      MnCircleOp *circle;
+      MnLineOp *line;
+      gdouble w, h;
+      gdouble x_1, y_1, x_2, y_2;
+
+      /* set generic options */
+      cairo_set_line_width (cr, op->stroke_width);
+      if (op->stroke)
+        cairo_set_source (cr, op->stroke);
+
+      switch (op->type)
         {
-          keys = g_key_file_get_keys (file, *g, NULL, &err);
-
-          if (err)
-            {
-              g_propagate_error (error, err);
-
-              g_strfreev (groups);
-              g_hash_table_destroy (symbolic_colors);
-              return FALSE;
-            }
-
-          for (k = keys; *k; k++)
-           {
-             MnColor color;
-             gchar *value;
-
-             value = g_key_file_get_string (file, *g, *k, NULL);
-
-             if (!value || !mn_color_from_string (&color, value))
-               {
-                 g_warning ("Could not parse value of symbolic color \"%s\"",
-                            *k);
-                 continue;
-               }
-
-             g_hash_table_insert (symbolic_colors, *k, mn_color_copy (&color));
-           }
+        case MN_RECT:
+          rect = (MnRectangleOp *) o->data;
 
+          if (rect->width <= 0)
+            w = width + rect->width;
+          else
+            w = rect->width;
 
-          /* done loading symbolics colours, so go to the next group */
-          continue;
-        }
+          if (rect->height <= 0)
+            h = height + rect->height;
+          else
+            h = rect->height;
 
-      palette = g_hash_table_lookup (priv->colors, *g);
+          cairo_rectangle (cr, x + rect->x, y + rect->y, w, h);
+          cairo_stroke (cr);
+          break;
 
-      if (!palette)
-        {
-          g_debug ("Adding hash table for %s", *g);
+        case MN_CIRCLE:
+          circle = (MnCircleOp *) o->data;
 
-          palette = mn_palette_new ();
-          g_hash_table_insert (priv->colors, g_strdup (*g), palette);
-        }
+          x_1 = (circle->x < 0) ? width + circle->x : circle->x;
+          y_1 = (circle->y < 0) ? height + circle->y : circle->y;
 
-      keys = g_key_file_get_keys (file, *g, NULL, &err);
+          cairo_arc (cr, x_1, y_1, circle->radius, 0, M_PI * 360);
 
-      if (err)
-        {
-          g_propagate_error (error, err);
+          cairo_stroke (cr);
+          break;
 
-          g_strfreev (groups);
-          g_hash_table_destroy (symbolic_colors);
-          return FALSE;
-        }
+        case MN_LINE:
+          line = (MnLineOp *) o->data;
 
-      for (k = keys; *k; k++)
-        {
-          gchar **split, *value;
-          MnState state = MN_STATE_NORMAL;
-          MnPaletteIndex pindex;
-          MnColor color;
-
-
-          split = g_strsplit (*k, ":", 2);
-
-          /* find the colour name */
-          if (!strcmp (split[0], "bg"))
-            pindex = MN_COLOR_BG;
-          else if (!strcmp (split[0], "fg"))
-            pindex = MN_COLOR_FG;
-          else if (!strcmp (split[0], "highlight-fg"))
-            pindex = MN_COLOR_HIGHLIGHT_FG;
-          else if (!strcmp (split[0], "highlight-bg"))
-            pindex = MN_COLOR_HIGHLIGHT_BG;
-          else if (!strcmp (split[0], "border"))
-            pindex = MN_COLOR_BORDER;
-          else
-            {
-              g_warning ("Unknown colour \"%s\" for \"%s\"", *k, *g);
-              g_strfreev (split);
-              continue;
-            }
-
-          /* see if there is a state flag */
-          if (split[1] != NULL)
-            {
-              gchar *s = split[1];
-
-              switch (s[0])
-                {
-                case 'h': /* "hover" */
-                  state = MN_STATE_HOVER;
-                  break;
-                case 'a': /* "active" */
-                  state = MN_STATE_ACTIVE;
-                  break;
-                case 'd': /* "disabled" */
-                  state = MN_STATE_DISABLED;
-                  break;
-                }
-            }
-
-          g_strfreev (split);
-          split = NULL;
-
-          value = g_key_file_get_string (file, *g, *k, &err);
-          if (err)
-            {
-              g_propagate_error (error, err);
-
-              g_strfreev (groups);
-              g_strfreev (keys);
-              g_hash_table_destroy (symbolic_colors);
-
-              return FALSE;
-            }
-
-          if (value[0] == '@')
-            {
-              MnColor *c;
-
-              /* symbolic color */
-              c = g_hash_table_lookup (symbolic_colors, value + 1);
-              if (!c)
-                {
-                  g_warning ("Could not find symbolic color \"%s\"", value + 1);
-                  continue;
-                }
-              else
-                color = *c;
-            }
-          else if (!mn_color_from_string (&color, value))
-            {
-              g_warning ("Could not parse \"%s\" as a color", value);
-              continue;
-            }
-
-          mn_palette_set_color (palette, pindex, state, &color);
-
-          g_debug ("Added %s color (%s) for %s", *k,
-                   mn_color_to_string (&color), *g);
+          x_1 = (line->x1 < 0) ? width + line->x1 : line->x1;
+          y_1 = (line->y1 < 0) ? height + line->y1 : line->y1;
+          x_2 = (line->x2 < 0) ? width + line->x2 : line->x2;
+          y_2 = (line->y2 < 0) ? height + line->y2 : line->y2;
 
+          cairo_move_to (cr, x_1, y_1);
+          cairo_line_to (cr, x_2, y_2);
+          cairo_stroke (cr);
+          break;
         }
-
-      g_strfreev (keys);
-
     }
-
-  g_strfreev (groups);
-  g_hash_table_destroy (symbolic_colors);
-
-
-  return TRUE;
 }
 
 void
@@ -330,28 +207,11 @@ mn_style_paint_entry (MnStyle   *style,
                       MnState    state,
                       MnFlags    flags)
 {
-  gdouble line_width;
-
-  cairo_save (cr);
+  GSList *ops;
 
-  colors = mn_style_find_colors (style, "entry", colors);
+  ops = style->priv->config->entry_ops;
 
-  if (flags & MN_FLAGS_FOCUS)
-    line_width = 2;
-  else
-    line_width = 1;
-
-  cairo_translate (cr, line_width / 2.0, line_width / 2.0);
-  cairo_set_line_width (cr, line_width);
-  width -= line_width; height -= line_width;
-
-  cairo_rectangle (cr, x, y, width, height);
-
-  mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_BORDER, state);
-
-  cairo_stroke (cr);
-
-  cairo_restore (cr);
+  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
 }
 
 void
@@ -365,33 +225,11 @@ mn_style_paint_button (MnStyle   *style,
                        MnState    state,
                        MnFlags    flags)
 {
-  gdouble line_width;
-
-  cairo_save (cr);
+  GSList *ops;
 
-  if (flags & MN_FLAGS_FOCUS)
-    line_width = 3;
-  else
-    line_width = 1;
+  ops = style->priv->config->button_ops;
 
-  cairo_translate (cr, line_width / 2.0, line_width / 2.0);
-  cairo_set_line_width (cr, line_width);
-  width -= line_width; height -= line_width;
-
-  cairo_rectangle (cr, x, y, width, height);
-
-  colors = mn_style_find_colors (style, "button", colors);
-
-
-  mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_BG, state);
-
-  cairo_fill_preserve (cr);
-
-  mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_BORDER, state);
-
-  cairo_stroke (cr);
-
-  cairo_restore (cr);
+  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
 }
 
 void
@@ -405,41 +243,11 @@ mn_style_paint_check_box (MnStyle   *style,
                           MnState    state,
                           MnFlags    flags)
 {
-  gdouble line_width;
-
-  cairo_save (cr);
-
-  colors = mn_style_find_colors (style, "check-box", colors);
-
-  if (flags & MN_FLAGS_FOCUS)
-    line_width = 2;
-  else
-    line_width = 1;
-
-  cairo_translate (cr, line_width / 2.0, line_width / 2.0);
-  cairo_set_line_width (cr, line_width);
-  width -= line_width; height -= line_width;
+  GSList *ops;
 
-  cairo_rectangle (cr, x, y, width, height);
+  ops = style->priv->config->check_ops;
 
-  mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_BG, state);
-  cairo_fill_preserve (cr);
-
-  mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_BORDER, state);
-  cairo_stroke (cr);
-
-
-  if (flags & MN_FLAGS_CHECKED)
-    {
-      cairo_rectangle (cr, x + 2.5, y + 2.5, width - 5, height - 5);
-
-      mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_FG,
-                                        state);
-
-      cairo_fill (cr);
-    }
-
-  cairo_restore (cr);
+  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
 }
 
 void
@@ -453,61 +261,14 @@ mn_style_paint_radio_button (MnStyle   *style,
                              MnState    state,
                              MnFlags    flags)
 {
-  gdouble line_width;
-
-  cairo_save (cr);
-
-  colors = mn_style_find_colors (style, "radio-button", colors);
-
-
-  if (flags & MN_FLAGS_FOCUS)
-    line_width = 2;
-  else
-    line_width = 1;
+  GSList *ops;
 
-  cairo_translate (cr, line_width / 2.0, line_width / 2.0);
-  cairo_set_line_width (cr, line_width);
-  width -= line_width; height -= line_width;
+  ops = style->priv->config->radio_ops;
 
-  cairo_arc (cr, x + width / 2.0, y + width / 2.0, width / 2.0, 0, 2 * M_PI);
-
-  mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_BG, state);
-  cairo_fill_preserve (cr);
-
-  mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_BORDER, state);
-  cairo_stroke (cr);
-
-  if (flags & MN_FLAGS_CHECKED)
-    {
-      cairo_arc (cr,
-                 x + width / 2.0,
-                 y + width / 2.0,
-                 width / 2.0 - 2.5, 0, 2 * M_PI);
-
-      mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_FG,
-                                        state);
-
-      cairo_fill (cr);
-    }
-
-  cairo_restore (cr);
+  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
 }
 
 
-
-void
-mn_style_paint_scroll_bar (MnStyle   *style,
-                           cairo_t   *cr,
-                           gdouble    x,
-                           gdouble    y,
-                           gdouble    width,
-                           gdouble    height,
-                           MnPalette *colors,
-                           MnState    state,
-                           MnFlags    flags)
-{
-}
-
 void
 mn_style_paint_menu (MnStyle   *style,
                      cairo_t   *cr,
@@ -519,20 +280,11 @@ mn_style_paint_menu (MnStyle   *style,
                      MnState    state,
                      MnFlags    flags)
 {
-  cairo_save (cr);
-
-  colors = mn_style_find_colors (style, "menu", colors);
-
-  cairo_translate (cr, 0.5, 0.5);
-  width--; height--;
-  cairo_set_line_width (cr, 1.0);
+  GSList *ops;
 
-  cairo_rectangle (cr, x, y, width, height);
+  ops = style->priv->config->menu_ops;
 
-  mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_BORDER, state);
-  cairo_stroke (cr);
-
-  cairo_restore (cr);
+  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
 }
 
 void
@@ -546,23 +298,11 @@ mn_style_paint_menu_item (MnStyle   *style,
                           MnState    state,
                           MnFlags    flags)
 {
-  cairo_save (cr);
-
-  colors = mn_style_find_colors (style, "menu-item", colors);
-
-  cairo_translate (cr, 0.5, 0.5);
-  width--; height--;
-  cairo_set_line_width (cr, 1.0);
+  GSList *ops;
 
-  cairo_rectangle (cr, x, y, width, height);
+  ops = style->priv->config->menu_item_ops;
 
-  mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_BG, state);
-  cairo_fill_preserve (cr);
-
-  mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_BORDER, state);
-  cairo_stroke (cr);
-
-  cairo_restore (cr);
+  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
 }
 
 void
@@ -576,21 +316,9 @@ mn_style_paint_menu_bar (MnStyle   *style,
                          MnState    state,
                          MnFlags    flags)
 {
-  cairo_save (cr);
-
-  colors = mn_style_find_colors (style, "menu-bar", colors);
-
-  cairo_translate (cr, 0.5, 0.5);
-  width--; height--;
-  cairo_set_line_width (cr, 1.0);
-
-  cairo_rectangle (cr, x, y, width, height);
-
-  mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_BG, state);
-  cairo_fill_preserve (cr);
+  GSList *ops;
 
-  mn_cairo_set_source_from_palette (cr, colors, MN_COLOR_BORDER, state);
-  cairo_stroke (cr);
+  ops = style->priv->config->menu_bar_ops;
 
-  cairo_restore (cr);
+  mn_style_draw_ops (style, ops, cr, x, y, width, height, colors, state, flags);
 }



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