[monet/vala] [theme] add abstract protect functions to draw individual widget types



commit 794fc016bd0e341377005edeecb1be384a058ecf
Author: Thomas Wood <thos gnome org>
Date:   Mon Jan 11 22:19:23 2010 +0000

    [theme] add abstract protect functions to draw individual widget types
    
    Theme implementations should override the paint functions for the available
    widget types in order to implement a complete theme.

 monet/mn-theme.vala   |   32 ++++++++++++++-
 tests/test-theme.vala |  107 +++++++++++++++++++++++++++++--------------------
 2 files changed, 95 insertions(+), 44 deletions(-)
---
diff --git a/monet/mn-theme.vala b/monet/mn-theme.vala
index 2961ab3..afd0b21 100644
--- a/monet/mn-theme.vala
+++ b/monet/mn-theme.vala
@@ -4,6 +4,36 @@ namespace Monet
 {
   public abstract class Theme
   {
-    public abstract bool paint_widget (Widget widget, Cairo.Context cr);
+    protected abstract void paint_button (Button button, Cairo.Context cr);
+    protected abstract void paint_check_box (CheckBox check, Cairo.Context cr);
+    protected abstract void paint_radio_button (RadioButton radio, Cairo.Context cr);
+    protected abstract void paint_entry (Entry entry, Cairo.Context cr);
+    protected abstract void paint_text_box (TextBox text_box, Cairo.Context cr);
+    protected abstract void paint_expander (Expander expander, Cairo.Context cr);
+    protected abstract void paint_tooltip (Tooltip tooltip, Cairo.Context cr);
+    protected abstract void paint_progress_bar (ProgressBar progress, Cairo.Context cr);
+    protected abstract void paint_resize_seperator (ResizeSeparator resize, Cairo.Context cr);
+
+    public void paint_widget (Widget widget, Cairo.Context cr)
+    {
+      if (widget is Button)
+        this.paint_button ((Button) widget, cr);
+      else if (widget is CheckBox)
+        this.paint_check_box ((CheckBox) widget, cr);
+      else if (widget is RadioButton)
+        this.paint_radio_button ((RadioButton) widget, cr);
+      else if (widget is Entry)
+        this.paint_entry ((Entry) widget, cr);
+      else if (widget is TextBox)
+        this.paint_text_box ((TextBox) widget, cr);
+      else if (widget is Expander)
+        this.paint_expander ((Expander) widget, cr);
+      else if (widget is Tooltip)
+        this.paint_tooltip ((Tooltip) widget, cr);
+      else if (widget is ProgressBar)
+        this.paint_progress_bar ((ProgressBar) widget, cr);
+      else if (widget is ResizeSeparator)
+        this.paint_resize_seperator ((ResizeSeparator) widget, cr);
+    }
   }
 }
diff --git a/tests/test-theme.vala b/tests/test-theme.vala
index 53348b4..0e0ec1f 100644
--- a/tests/test-theme.vala
+++ b/tests/test-theme.vala
@@ -21,56 +21,77 @@
 
 using Monet;
 using Cairo;
-using Gtk;
 
 namespace Test
 {
   /* sample theme engine */
   public class Theme : Monet.Theme
   {
-    public override bool paint_widget (Monet.Widget widget, Cairo.Context cr)
+    protected override void paint_button (Button button, Cairo.Context cr)
+    {
+      cr.rectangle (button.area.x, button.area.y, button.area.width,
+                    button.area.height);
+
+      cr.set_source_rgb (0.5, 0.5, 0.5);
+      cr.fill_preserve ();
+
+      cr.set_source_rgb (0.0, 0.0, 0.0);
+      cr.stroke ();
+
+      cr.set_source_rgb (1.0, 1.0, 1.0);
+      cr.move_to (button.area.x + 10, button.area.y + (button.area.height / 2));
+      cr.show_text (button.text);
+      cr.stroke ();
+    }
+
+    protected override void
+    paint_check_box (CheckBox check, Cairo.Context cr)
+    {
+    }
+
+    protected override void
+    paint_radio_button (RadioButton radio, Cairo.Context cr)
+    {
+    }
+
+    protected override void paint_entry (Entry entry, Cairo.Context cr)
+    {
+      cr.rectangle (entry.area.x, entry.area.y, entry.area.width,
+                    entry.area.height);
+
+      cr.set_source_rgb (1.0, 1.0, 1.0);
+      cr.fill_preserve ();
+
+      cr.set_source_rgb (0.0, 0.0, 0.0);
+      cr.stroke ();
+    }
+
+    protected override void
+    paint_text_box (TextBox text_box, Cairo.Context cr)
+    {
+    }
+
+    protected override void
+    paint_expander (Expander expander, Cairo.Context cr)
+    {
+    }
+
+    protected override void
+    paint_tooltip (Tooltip tooltip, Cairo.Context cr)
+    {
+    }
+
+    protected override void
+    paint_progress_bar (ProgressBar progress, Cairo.Context cr)
+    {
+    }
+
+
+
+    protected override void
+    paint_resize_seperator (ResizeSeparator resize, Cairo.Context cr)
     {
-      /* buttons */
-      if (widget is Monet.Button)
-      {
-        Monet.Button button = (Monet.Button) widget;
-
-        cr.rectangle (widget.area.x, widget.area.y, widget.area.width,
-            widget.area.height);
-
-        cr.set_source_rgb (0.5, 0.5, 0.5);
-        cr.fill_preserve ();
-
-        cr.set_source_rgb (0.0, 0.0, 0.0);
-        cr.stroke ();
-
-        cr.set_source_rgb (1.0, 1.0, 1.0);
-        cr.move_to (widget.area.x + 10,
-                    widget.area.y + (widget.area.height / 2));
-        cr.show_text (button.text);
-        cr.stroke ();
-
-        return true;
-      }
-      /* entry */
-      else if (widget is Monet.Entry)
-      {
-        cr.rectangle (widget.area.x, widget.area.y, widget.area.width,
-            widget.area.height);
-
-        cr.set_source_rgb (1.0, 1.0, 1.0);
-        cr.fill_preserve ();
-
-        cr.set_source_rgb (0.0, 0.0, 0.0);
-        cr.stroke ();
-
-        return true;
-      }
-      /* default */
-      else
-      {
-        return false;
-      }
     }
+
   }
 }



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