[monet/monet-xml] Add support widget flags
- From: Thomas Wood <thos src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [monet/monet-xml] Add support widget flags
- Date: Sun, 25 Jul 2010 17:22:16 +0000 (UTC)
commit 814a2616d0854cf53923736bb6adaba1aafb3906
Author: Thomas Wood <thos gnome org>
Date: Sun Jul 25 18:01:45 2010 +0100
Add support widget flags
Add support for widget flags (such as "checked" or "focused") by creating
a list of flags and drawing operations for each state of a widget.
monet-gtk/monet.xml | 9 ++++++
monet/mn-config.c | 70 +++++++++++++++++++++++++++++++++++++++-----------
monet/mn-config.h | 18 +++++--------
monet/mn-style.c | 54 +++++++++++++++++++++++++++-----------
4 files changed, 108 insertions(+), 43 deletions(-)
---
diff --git a/monet-gtk/monet.xml b/monet-gtk/monet.xml
index f692b03..807d3eb 100644
--- a/monet-gtk/monet.xml
+++ b/monet-gtk/monet.xml
@@ -45,6 +45,15 @@
</rect>
</widget>
+<widget type="check" flags="checked">
+ <rect x="0" y="0" width="width-2" height="height-2" stroke="#000" stroke-width="1">
+ <gradient x1="0" y1="0" x2="0" y2="20">
+ <stop color="#fff" position="0"/>
+ <stop color="#000" position="1"/>
+ </gradient>
+ </rect>
+</widget>
+
<widget type="tool-bar">
<rect x="0" y="0" width="width-2" height="height-2" stroke="#000" stroke-width="1">
<stroke-gradient x1="0" y1="0" x2="0" y2="20">
diff --git a/monet/mn-config.c b/monet/mn-config.c
index c58a174..0f89c69 100644
--- a/monet/mn-config.c
+++ b/monet/mn-config.c
@@ -56,28 +56,30 @@ mn_config_free_drawing_op (MnDrawingOp *op)
}
static void
-mn_config_free_ops (GSList **ops)
+mn_config_free_drawing_ops (MnDrawingOps *ops)
{
- gint i;
+ g_slist_foreach (ops->ops, (GFunc) mn_config_free_drawing_op, NULL);
+ g_free (ops);
+}
- for (i = 0; i < 4; i++)
- {
- g_slist_foreach (ops[i], (GFunc) mn_config_free_drawing_op, NULL);
- g_slist_free (ops[i]);
- ops[i] = NULL;
- }
+static void
+mn_config_free_ops (GSList *ops)
+{
+ g_slist_foreach (ops, (GFunc) mn_config_free_drawing_ops, NULL);
+ g_slist_free (ops);
}
static void
mn_config_finalize (GObject *object)
{
MnConfig *config = MN_CONFIG (object);
- gint i;
+ gint widget, state;
- for (i = 0; i < MN_WIDGET_LAST;i++)
- {
- mn_config_free_ops (config->widget_ops[i]);
- }
+ for (widget = 0; widget < MN_WIDGET_LAST; widget++)
+ for (state = 0; state < 4; state++)
+ {
+ mn_config_free_ops (config->widget_ops[widget][state]);
+ }
G_OBJECT_CLASS (mn_config_parent_class)->finalize (object);
}
@@ -339,6 +341,29 @@ monet_state_from_string (const gchar *string)
}
}
+static MnFlags
+monet_flags_from_string (const gchar *string)
+{
+ MnFlags flags;
+ gchar **flag_list, **s;
+
+ flag_list = g_strsplit (string, ",", 0);
+
+ for (s = flag_list; *s; s++)
+ {
+ switch (**s)
+ {
+ case 'c': flags |= MN_FLAGS_CHECKED; break;
+ case 's': flags |= MN_FLAGS_SELECTED; break;
+ case 'f': flags |= MN_FLAGS_FOCUS; break;
+ }
+ }
+
+ g_strfreev (flag_list);
+
+ return flags;
+}
+
static void
monet_start_element (GMarkupParseContext *context,
const gchar *element_name,
@@ -361,18 +386,25 @@ monet_start_element (GMarkupParseContext *context,
if (!strcmp (element_name, "widget"))
{
const gchar *type = NULL;
- gpointer ops;
+ gpointer ops_list;
+ MnDrawingOps *ops;
MnState wstate;
+ MnFlags wflags;
wstate = MN_STATE_NORMAL;
+ wflags = 0;
/* 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]);
+
+ else if (!strcmp (*attr_n, "flags"))
+ wflags = monet_flags_from_string (attribute_values[i]);
}
if (!type)
@@ -400,9 +432,15 @@ monet_start_element (GMarkupParseContext *context,
else if (!strcmp (type, "tool-bar"))
widget = MN_TOOL_BAR;
- ops = &config->widget_ops[widget][wstate];
+ /* add the drawing operations for this widget and state */
+ ops = g_new0 (MnDrawingOps, 1);
+ ops->flags = wflags;
+
+ config->widget_ops[widget][wstate] = g_slist_prepend (config->widget_ops[widget][wstate], ops);
+
+ ops_list = &ops->ops;
- g_markup_parse_context_push (context, &widget_parser, ops);
+ g_markup_parse_context_push (context, &widget_parser, ops_list);
}
}
diff --git a/monet/mn-config.h b/monet/mn-config.h
index 27a8ce5..67a5536 100644
--- a/monet/mn-config.h
+++ b/monet/mn-config.h
@@ -25,6 +25,7 @@
#include <glib.h>
#include <glib-object.h>
#include <cairo/cairo.h>
+#include "mn-palette.h"
G_BEGIN_DECLS
@@ -54,7 +55,11 @@ typedef struct _MnConfig MnConfig;
typedef struct _MnConfigClass MnConfigClass;
typedef struct _MnConfigPrivate MnConfigPrivate;
-typedef GSList *MnDrawingOps[4];
+typedef struct
+{
+ MnFlags flags;
+ GSList *ops;
+} MnDrawingOps;
typedef enum
{
@@ -78,7 +83,7 @@ struct _MnConfig
MnConfigPrivate *priv;
/*< private >*/
- MnDrawingOps widget_ops[MN_WIDGET_LAST];
+ GSList *widget_ops[MN_WIDGET_LAST][4];
};
struct _MnConfigClass
@@ -86,15 +91,6 @@ struct _MnConfigClass
GObjectClass parent_class;
};
-
-typedef struct
-{
- GSList *normal;
- GSList *hover;
- GSList *active;
- GSList *disabled;
-} MnWidgetOps;
-
typedef enum
{
MN_RECT,
diff --git a/monet/mn-style.c b/monet/mn-style.c
index e48589e..9f9f77e 100644
--- a/monet/mn-style.c
+++ b/monet/mn-style.c
@@ -210,28 +210,17 @@ parse_expression (gchar *expression,
static void
mn_style_draw_ops (MnStyle *style,
- GSList **ops,
+ GSList *o,
cairo_t *cr,
gdouble x,
gdouble y,
gdouble width,
gdouble height,
- MnPalette *colors,
- MnState state,
- MnFlags flags)
+ MnPalette *colors)
{
- GSList *o;
-
/* translate to ensure pattern is in the correct position */
cairo_translate (cr, x, y);
- /* 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;
@@ -334,9 +323,42 @@ mn_style_paint_widget (MnStyle *style,
MnState state,
MnFlags flags)
{
- GSList **ops;
+ GSList *widget_ops;
+ GSList *l;
+ GSList *drawing_ops = NULL;
+ GSList *default_ops = NULL;
+
+ widget_ops = style->priv->config->widget_ops[widget][state];
- ops = style->priv->config->widget_ops[widget];
+ /* if no ops were found for the request state, try the default state */
+ if (!widget_ops)
+ widget_ops = style->priv->config->widget_ops[widget][MN_STATE_NORMAL];
+
+ /* find an ops withe the requested flags */
+ for (l = widget_ops; l; l = g_slist_next (l))
+ {
+ MnDrawingOps *ops = l->data;
+
+ if (ops->flags & flags)
+ {
+ /* found an exact match for flags */
+ drawing_ops = ops->ops;
+ break;
+ }
+ else if (ops->flags == 0)
+ {
+ /* store the drawing ops that have no flags for use if no exacty
+ * match can be found */
+ default_ops = ops->ops;
+ }
+ }
+
+ if (drawing_ops)
+ mn_style_draw_ops (style, drawing_ops, cr, x, y, width, height, colors);
+ else if (default_ops)
+ mn_style_draw_ops (style, default_ops, cr, x, y, width, height, colors);
+ else
+ g_warning ("No drawing could be found for widget type %d in state %d",
+ widget, state);
- 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]