[gtk+/gtk-style-context: 37/191] GtkThemingEngine: Add vmethod to render frames.



commit b68e53b8be1cd77798ebd98e1008bdad68f6d154
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Mar 27 20:11:31 2010 +0100

    GtkThemingEngine: Add vmethod to render frames.

 gtk/gtkthemingengine.c |   96 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkthemingengine.h |    6 +++
 2 files changed, 102 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index ed9d29d..2356440 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -67,6 +67,12 @@ static void gtk_theming_engine_render_background (GtkThemingEngine *engine,
                                                   gdouble           y,
                                                   gdouble           width,
                                                   gdouble           height);
+static void gtk_theming_engine_render_frame  (GtkThemingEngine *engine,
+                                              cairo_t          *cr,
+                                              gdouble           x,
+                                              gdouble           y,
+                                              gdouble           width,
+                                              gdouble           height);
 
 G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
 
@@ -102,6 +108,7 @@ gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
   klass->render_option = gtk_theming_engine_render_option;
   klass->render_arrow = gtk_theming_engine_render_arrow;
   klass->render_background = gtk_theming_engine_render_background;
+  klass->render_frame = gtk_theming_engine_render_frame;
 
   g_type_class_add_private (object_class, sizeof (GtkThemingEnginePrivate));
 }
@@ -668,6 +675,16 @@ add_path_rounded_rectangle (cairo_t           *cr,
 }
 
 static void
+color_shade (const GdkColor *color,
+             gdouble         factor,
+             GdkColor       *color_return)
+{
+  color_return->red = CLAMP (color->red * factor, 0, 65535);
+  color_return->green = CLAMP (color->green * factor, 0, 65535);
+  color_return->blue = CLAMP (color->blue * factor, 0, 65535);
+}
+
+static void
 gtk_theming_engine_render_background (GtkThemingEngine *engine,
                                       cairo_t          *cr,
                                       gdouble           x,
@@ -704,5 +721,84 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
   cairo_restore (cr);
 }
 
+static void
+gtk_theming_engine_render_frame (GtkThemingEngine *engine,
+                                 cairo_t          *cr,
+                                 gdouble           x,
+                                 gdouble           y,
+                                 gdouble           width,
+                                 gdouble           height)
+{
+  GtkStateFlags flags;
+  GtkStateType state;
+  GdkColor *bg_color;
+  GdkColor lighter, darker;
+
+  cairo_save (cr);
+  flags = gtk_theming_engine_get_state (engine);
+
+  if (flags & GTK_STATE_FLAG_PRELIGHT)
+    state = GTK_STATE_PRELIGHT;
+  else if (flags & GTK_STATE_FLAG_INSENSITIVE)
+    state = GTK_STATE_INSENSITIVE;
+  else
+    state = GTK_STATE_NORMAL;
+
+  cairo_set_line_width (cr, 1);
+
+  gtk_theming_engine_get (engine, state,
+                          "background-color", &bg_color,
+                          NULL);
+  color_shade (bg_color, 0.7, &darker);
+  color_shade (bg_color, 1.3, &lighter);
+
+  if (flags & GTK_STATE_FLAG_ACTIVE)
+    {
+      add_path_rounded_rectangle (cr, 0,
+                                  SIDE_BOTTOM | SIDE_RIGHT,
+                                  x, y, width, height);
+
+      gdk_cairo_set_source_color (cr, &lighter);
+      cairo_stroke (cr);
+
+      add_path_rounded_rectangle (cr, 0,
+                                  SIDE_TOP | SIDE_LEFT,
+                                  x + 1, y + 1, width - 2, height - 2);
+      cairo_set_source_rgb (cr, 0, 0, 0);
+      cairo_stroke (cr);
+
+      add_path_rounded_rectangle (cr, 0,
+                                  SIDE_TOP | SIDE_LEFT,
+                                  x, y, width, height);
+      gdk_cairo_set_source_color (cr, &darker);
+      cairo_stroke (cr);
+    }
+  else
+    {
+      add_path_rounded_rectangle (cr, 0,
+                                  SIDE_BOTTOM | SIDE_RIGHT,
+                                  x, y, width, height);
+
+      cairo_set_source_rgb (cr, 0, 0, 0);
+      cairo_stroke (cr);
+
+      add_path_rounded_rectangle (cr, 0,
+                                  SIDE_BOTTOM | SIDE_RIGHT,
+                                  x, y, width - 1, height - 1);
+
+      gdk_cairo_set_source_color (cr, &darker);
+      cairo_stroke (cr);
+
+      add_path_rounded_rectangle (cr, 0,
+                                  SIDE_TOP | SIDE_LEFT,
+                                  x, y, width, height);
+
+      gdk_cairo_set_source_color (cr, &lighter);
+      cairo_stroke (cr);
+    }
+
+  cairo_restore (cr);
+}
+
 #define __GTK_THEMING_ENGINE_C__
 #include "gtkaliasdef.c"
diff --git a/gtk/gtkthemingengine.h b/gtk/gtkthemingengine.h
index a9dcff4..a2b167d 100644
--- a/gtk/gtkthemingengine.h
+++ b/gtk/gtkthemingengine.h
@@ -55,6 +55,12 @@ struct GtkThemingEngineClass
                               gdouble           y,
                               gdouble           width,
                               gdouble           height);
+  void (* render_frame) (GtkThemingEngine *engine,
+                         cairo_t          *cr,
+                         gdouble           x,
+                         gdouble           y,
+                         gdouble           width,
+                         gdouble           height);
   void (* render_check) (GtkThemingEngine *engine,
                          cairo_t          *cr,
                          gdouble           x,



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