[cairo-commit] cairo-gtk-engine/src caligula-rc-style.c, 1.1, 1.2 caligula-rc-style.h, 1.1, 1.2 caligula-style.c, 1.2, 1.3 caligula.h, 1.1, 1.2

Carl Worth commit at pdx.freedesktop.org
Thu Feb 10 12:44:36 PST 2005


Committed by: cworth

Update of /cvs/cairo/cairo-gtk-engine/src
In directory gabe:/tmp/cvs-serv453/src

Modified Files:
	caligula-rc-style.c caligula-rc-style.h caligula-style.c 
	caligula.h 
Log Message:

        * theme/caligula-grassy/gtkrc:
        * theme/caligula-sketchy/gtkrc:
        * theme/caligula-swirly/gtkrc: Add three separate themes for
        selecting each of the available button styles.

        * src/caligula-style.c (caligula_draw_box): Use parsed
        drawing-style rather than randomly styled buttons.

        * src/caligula-rc-style.c (caligula_rc_style_parse_drawing_style)
        (caligula_rc_style_parse, caligula_rc_style_merge): Add parsing
        code, (just a single drawing-style parameter so far).


Index: caligula-rc-style.c
===================================================================
RCS file: /cvs/cairo/cairo-gtk-engine/src/caligula-rc-style.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- caligula-rc-style.c	10 Feb 2005 16:54:53 -0000	1.1
+++ caligula-rc-style.c	10 Feb 2005 20:44:33 -0000	1.2
@@ -22,15 +22,32 @@
 #include "caligula-style.h"
 #include "caligula-rc-style.h"
 
+#include <gtk/gtk.h>
+#include <string.h>
+
 static void
 caligula_rc_style_init (CaligulaRcStyle *style);
 
 static void
 caligula_rc_style_class_init (CaligulaRcStyleClass *klass);
 
+static void
+caligula_rc_style_finalize (GObject *object);
+
 static GtkStyle *
 caligula_rc_style_create_style (GtkRcStyle *style);
 
+static guint
+caligula_rc_style_parse (GtkRcStyle *rc_style,
+			 GtkSettings  *settings,
+			 GScanner   *scanner);
+
+static void
+caligula_rc_style_merge (GtkRcStyle *dest,
+			 GtkRcStyle *src);
+
+static GtkRcStyleClass *parent_class;
+
 GType caligula_type_rc_style = 0;
 
 void
@@ -55,20 +72,37 @@
 }
 
 static void
-caligula_rc_style_init (CaligulaRcStyle *style)
+caligula_rc_style_init (CaligulaRcStyle *rc_style)
 {
+    rc_style->drawing_style = CALIGULA_DRAWING_STYLE_GRASSY;
 }
 
 static void
 caligula_rc_style_class_init (CaligulaRcStyleClass *klass)
 {
-    GtkRcStyleClass *style_class = GTK_RC_STYLE_CLASS (klass);
+    GtkRcStyleClass *rc_style_class = GTK_RC_STYLE_CLASS (klass);
+    GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+    parent_class = g_type_class_peek_parent (klass);
 
-/*
     rc_style_class->parse = caligula_rc_style_parse;
     rc_style_class->merge = caligula_rc_style_merge;
-*/
-    style_class->create_style = caligula_rc_style_create_style;
+    rc_style_class->create_style = caligula_rc_style_create_style;
+
+    object_class->finalize = caligula_rc_style_finalize;
+}
+
+static void
+caligula_rc_style_finalize (GObject *object)
+{
+    CaligulaRcStyle *rc_style = CALIGULA_RC_STYLE (object);
+
+    /* We would free anything necessary in rc_style here. */
+
+    /* For now, just keep the compiler quiet about unused variables */
+    rc_style->drawing_style = rc_style->drawing_style;
+  
+    G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static GtkStyle *
@@ -76,3 +110,128 @@
 {
     return g_object_new (CALIGULA_TYPE_STYLE, NULL);
 }
+
+enum
+{
+    TOKEN_DRAWING_STYLE = G_TOKEN_LAST + 1
+};
+
+static struct
+{
+    gchar *name;
+    guint token;
+}
+theme_symbols[] =
+{
+    { "drawing-style",	TOKEN_DRAWING_STYLE }
+};
+
+static GTokenType
+caligula_rc_style_parse_drawing_style (CaligulaRcStyle	*rc_style,
+				       GtkSettings	*settings,
+				       GScanner		*scanner)
+{
+    GTokenType token;
+    GTokenValue value;
+
+    token = g_scanner_get_next_token (scanner);
+    if (token != TOKEN_DRAWING_STYLE)
+	return TOKEN_DRAWING_STYLE;
+
+    token = g_scanner_get_next_token (scanner);
+    if (token != G_TOKEN_EQUAL_SIGN)
+	return G_TOKEN_EQUAL_SIGN;
+
+    token = g_scanner_get_next_token (scanner);
+    if (token != G_TOKEN_IDENTIFIER)
+	return G_TOKEN_IDENTIFIER;
+
+    value = g_scanner_cur_value (scanner);
+
+    if (strcmp (value.v_identifier, "grassy") == 0)
+	rc_style->drawing_style = CALIGULA_DRAWING_STYLE_GRASSY;
+    else if (strcmp (value.v_identifier, "sketchy") == 0)
+	rc_style->drawing_style = CALIGULA_DRAWING_STYLE_SKETCHY;
+    else if (strcmp (value.v_identifier, "swirly") == 0)
+	rc_style->drawing_style = CALIGULA_DRAWING_STYLE_SWIRLY;
+    else
+	g_warning ("%s: Ignoring unknown drawing-style value: %s\n",
+		   __FILE__, value.v_identifier);
+
+    return G_TOKEN_NONE;
+}
+
+static GTokenType
+caligula_rc_style_parse (GtkRcStyle  *rc_style,
+			 GtkSettings *settings,
+			 GScanner    *scanner)
+{
+  static GQuark scope_id = 0;
+  CaligulaRcStyle *caligula_style = CALIGULA_RC_STYLE (rc_style);
+
+  guint old_scope;
+  GTokenType token, expected;
+  gint i;
+
+  /* Set up a new scope in this scanner. */
+  if (!scope_id)
+      scope_id = g_quark_from_string ("caligula_theme_engine");
+
+  old_scope = g_scanner_set_scope (scanner, scope_id);
+
+  /* Add symbols for this scope, (if not present already) */
+  if (!g_scanner_lookup_symbol(scanner, theme_symbols[0].name)) {
+      for (i = 0; i < G_N_ELEMENTS (theme_symbols); i++)
+	  g_scanner_scope_add_symbol(scanner, scope_id,
+				     theme_symbols[i].name,
+				     GINT_TO_POINTER(theme_symbols[i].token));
+  }
+
+  /* Begin parsing top-level. Apparently a left curly brace has
+   * already been consumed for use, but we're expected to consume the
+   * final right closing brace. Weird. */
+  while (1) {
+      token = g_scanner_peek_next_token(scanner);
+      if (token == G_TOKEN_RIGHT_CURLY) {
+	  g_scanner_get_next_token (scanner);
+	  expected = G_TOKEN_NONE;
+	  break;
+      }
+
+      switch (token)
+      {
+      case TOKEN_DRAWING_STYLE:
+	  expected = caligula_rc_style_parse_drawing_style (caligula_style, settings, scanner);
+	  break;
+      default:
+	  g_scanner_get_next_token (scanner);
+	  expected = G_TOKEN_RIGHT_CURLY;
+	  break;
+      }
+
+      if (expected != G_TOKEN_NONE)
+	  break;
+  }
+
+  /* On success, restore the previous scope. (For errors, we need the
+   * current scope to format a proper error message.) */
+  if (expected == G_TOKEN_NONE)
+      g_scanner_set_scope(scanner, old_scope);
+
+  return expected;
+}
+
+static void
+caligula_rc_style_merge (GtkRcStyle *dest,
+			 GtkRcStyle *src)
+{
+    if (CALIGULA_IS_RC_STYLE (src)) {
+
+      CaligulaRcStyle *caligula_dest = CALIGULA_RC_STYLE (dest);
+      CaligulaRcStyle *caligula_src = CALIGULA_RC_STYLE (src);
+
+      caligula_dest->drawing_style = caligula_src->drawing_style;
+    }
+
+    parent_class->merge (dest, src);
+}

Index: caligula-rc-style.h
===================================================================
RCS file: /cvs/cairo/cairo-gtk-engine/src/caligula-rc-style.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- caligula-rc-style.h	10 Feb 2005 16:54:53 -0000	1.1
+++ caligula-rc-style.h	10 Feb 2005 20:44:33 -0000	1.2
@@ -22,6 +22,8 @@
 #ifndef CALIGULA_RC_STYLE_H
 #define CALIGULA_RC_STYLE_H
 
+#include "caligula.h"
+
 #include <gtk/gtkrc.h>
 
 extern GType caligula_type_rc_style;
@@ -34,11 +36,13 @@
 #define CALIGULA_RC_STYLE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), CALIGULA_TYPE_RC_STYLE, CaligulaRcStyleClass))
 
 typedef struct _CaligulaRcStyle {
-  GtkRcStyle parent_instance;
+    GtkRcStyle parent_instance;
+
+    CaligulaDrawingStyle drawing_style;
 } CaligulaRcStyle;
 
 typedef struct _CaligulaRcStyleClass {
-  GtkRcStyleClass parent_class;
+    GtkRcStyleClass parent_class;
 } CaligulaRcStyleClass;;
 
 void

Index: caligula-style.c
===================================================================
RCS file: /cvs/cairo/cairo-gtk-engine/src/caligula-style.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- caligula-style.c	10 Feb 2005 20:23:18 -0000	1.2
+++ caligula-style.c	10 Feb 2005 20:44:33 -0000	1.3
@@ -25,8 +25,10 @@
 #include <cairo-xlib.h>
 #include <gdk/gdkx.h>
 
+#include "caligula.h"
 #include "caligula-rand.h"
 #include "caligula-style.h"
+#include "caligula-rc-style.h"
 #include "caligula-draw-sketchy.h"
 #include "caligula-draw-swirly.h"
 #include "caligula-draw-grassy.h"
@@ -76,20 +78,20 @@
 { 
     cairo_t *cr;
     gint x_offset, y_offset;
-    gint box;
+    CaligulaRcStyle *rc_style = CALIGULA_RC_STYLE (style->rc_style);
 
     caligula_srand ((unsigned)widget);
 
     cr = caligula_begin_paint (window, &x_offset, &y_offset);
 
-    box = caligula_rand_within (0, 3);
-    switch (box) {
-    case 0:
+    switch (rc_style->drawing_style) {
+    case CALIGULA_DRAWING_STYLE_SKETCHY:
 	caligula_draw_sketchy_box (cr, x, y, width, height);
 	break;
-    case 1:
+    case CALIGULA_DRAWING_STYLE_SWIRLY:
 	caligula_draw_swirly_box (cr, x, y, width, height);
 	break;
+    case CALIGULA_DRAWING_STYLE_GRASSY:
     default:
 	caligula_draw_grassy_box (cr, x, y, width, height);
 	break;

Index: caligula.h
===================================================================
RCS file: /cvs/cairo/cairo-gtk-engine/src/caligula.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- caligula.h	10 Feb 2005 16:54:53 -0000	1.1
+++ caligula.h	10 Feb 2005 20:44:33 -0000	1.2
@@ -33,4 +33,10 @@
 G_MODULE_EXPORT GtkRcStyle *
 theme_create_rc_style (void);
 
+typedef enum {
+    CALIGULA_DRAWING_STYLE_GRASSY,
+    CALIGULA_DRAWING_STYLE_SWIRLY,
+    CALIGULA_DRAWING_STYLE_SKETCHY
+} CaligulaDrawingStyle;
+
 #endif




More information about the cairo-commit mailing list