[gtk+/gtk-style-context: 31/206] GtkThemingEngine: Add vmethod to render radio buttons.



commit 71f1e8a398d35f66905f1c10cc49a7f2128b3b2b
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Mar 20 17:37:34 2010 +0100

    GtkThemingEngine: Add vmethod to render radio buttons.

 gtk/gtkthemingengine.c |   83 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkthemingengine.h |    6 +++
 2 files changed, 89 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index 82613ff..2962f52 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -42,6 +42,12 @@ static void gtk_theming_engine_render_check (GtkThemingEngine *engine,
                                              gdouble           y,
                                              gdouble           width,
                                              gdouble           height);
+static void gtk_theming_engine_render_option (GtkThemingEngine *engine,
+                                              cairo_t          *cr,
+                                              gdouble           x,
+                                              gdouble           y,
+                                              gdouble           width,
+                                              gdouble           height);
 
 G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
 
@@ -74,6 +80,7 @@ gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
   klass->render_check = gtk_theming_engine_render_check;
+  klass->render_option = gtk_theming_engine_render_option;
 
   g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate));
 }
@@ -378,5 +385,81 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
   gdk_color_free (text_color);
 }
 
+static void
+gtk_theming_engine_render_option (GtkThemingEngine *engine,
+                                  cairo_t          *cr,
+                                  gdouble           x,
+                                  gdouble           y,
+                                  gdouble           width,
+                                  gdouble           height)
+{
+  GtkStateFlags flags;
+  GdkColor *base_color, *fg_color, *text_color;
+  const GtkWidgetPath *path;
+  GtkStateType state;
+  gdouble radius;
+
+  flags = gtk_theming_engine_get_state (engine);
+  path = gtk_theming_engine_get_path (engine);
+  radius = MIN (width, height) / 2 - 0.5;
+
+  cairo_save (cr);
+  cairo_set_line_width (cr, 1);
+
+  if (flags & GTK_STATE_FLAG_PRELIGHT)
+    state = GTK_STATE_PRELIGHT;
+  else
+    state = GTK_STATE_NORMAL;
+
+  gtk_theming_engine_get (engine, state,
+                          "foreground-color", &fg_color,
+                          "base-color", &base_color,
+                          "text-color", &text_color,
+                          NULL);
+
+  if (!gtk_widget_path_has_parent (path, GTK_TYPE_MENU))
+    {
+      cairo_arc (cr,
+                 x + (width / 2),
+                 y + (height / 2),
+                 radius,
+                 0, 2 * G_PI);
+
+      gdk_cairo_set_source_color (cr, base_color);
+      cairo_fill_preserve (cr);
+
+      if (gtk_widget_path_has_parent (path, GTK_TYPE_TREE_VIEW))
+        gdk_cairo_set_source_color (cr, text_color);
+      else
+        gdk_cairo_set_source_color (cr, fg_color);
+
+      cairo_stroke (cr);
+    }
+
+  if (gtk_widget_path_has_parent (path, GTK_TYPE_MENU))
+    gdk_cairo_set_source_color (cr, fg_color);
+  else
+    gdk_cairo_set_source_color (cr, text_color);
+
+  if (gtk_theming_engine_is_state_set (engine, GTK_STATE_INCONSISTENT))
+    {
+      cairo_move_to (cr, x + (width * 0.2), y + (height / 2));
+      cairo_line_to (cr, x + (width * 0.8), y + (height / 2));
+      cairo_stroke (cr);
+    }
+  if (gtk_theming_engine_is_state_set (engine, GTK_STATE_ACTIVE))
+    {
+      cairo_arc (cr,
+                 x + (width / 2),
+                 y + (height / 2),
+                 radius / 2,
+                 0, 2 * G_PI);
+
+      cairo_fill (cr);
+    }
+
+  cairo_restore (cr);
+}
+
 #define __GTK_THEMING_ENGINE_C__
 #include "gtkaliasdef.c"
diff --git a/gtk/gtkthemingengine.h b/gtk/gtkthemingengine.h
index 7bba3fb..f322e73 100644
--- a/gtk/gtkthemingengine.h
+++ b/gtk/gtkthemingengine.h
@@ -55,6 +55,12 @@ struct GtkThemingEngineClass
                          gdouble           y,
                          gdouble           width,
                          gdouble           height);
+  void (* render_option) (GtkThemingEngine *engine,
+                          cairo_t          *cr,
+                          gdouble           x,
+                          gdouble           y,
+                          gdouble           width,
+                          gdouble           height);
 };
 
 GType gtk_theming_engine_get_type (void) G_GNUC_CONST;



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