[monet/vala] [tests] add a sample theme and drawing test



commit 8aef8c0edf96440c715a618c45b2b4fc6622ead1
Author: Thomas Wood <thos gnome org>
Date:   Sun Jan 3 00:09:54 2010 +0000

    [tests] add a sample theme and drawing test
    
    Add a sample theme class that implements Monet.Theme and add a sample
    application that uses the Monet API to draw widgets.

 tests/Makefile.am       |    8 +++--
 tests/test-drawing.vala |   84 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/test-theme.vala   |   76 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 165 insertions(+), 3 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 03875d4..d381e37 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,8 @@
-AM_CFLAGS = $(MONET_CFLAGS)
-INCLUDES = -I$(top_srcdir)
-LDADD = $(MONET_LIBS) $(top_builddir)/monet/libmonet.la
+AM_CFLAGS = $(MONET_CFLAGS) $(MONET_MAINTAINER_CFLAGS) $(GTK_CFLAGS) -I$(top_srcdir)/monet
+AM_LDFLAGS = $(MONET_LIBS) $(GTK_LIBS) $(top_srcdir)/monet/libmonet.la
 
+VALAFLAGS=--pkg cairo --pkg gtk+-2.0 --pkg monet --vapidir=$(top_srcdir)/monet
+bin_PROGRAMS = test-theme
+test_theme_SOURCES = test-theme.vala test-drawing.vala
 
 -include $(top_srcdir)/git.mk
diff --git a/tests/test-drawing.vala b/tests/test-drawing.vala
new file mode 100644
index 0000000..965d592
--- /dev/null
+++ b/tests/test-drawing.vala
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2009 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ *
+ * Author: Thomas Wood <thos gnome org>
+ */
+
+using Gtk;
+using Monet;
+
+namespace Test
+{
+  public class Window : Gtk.Window
+  {
+    private Theme theme;
+
+    public Window ()
+    {
+      this.theme = new Theme ();
+      this.expose_event.connect (this.expose_event_cb);
+      this.delete_event.connect (this.quit);
+    }
+
+    private bool expose_event_cb (Gdk.EventExpose event)
+    {
+      Cairo.Context cr;
+      Monet.Button button;
+      Monet.Entry entry;
+
+      button = new Monet.Button ();
+
+      cr = Gdk.cairo_create (this.window);
+
+      /* draw a button */
+      button.area = { 10, 10, 100, 32 };
+      button.text = "My Button";
+      theme.paint_widget (button, cr);
+
+      /* draw an entry */
+      entry = new Monet.Entry ();
+      entry.area = { 10, 50, 150, 32 };
+      theme.paint_widget (entry, cr);
+
+      return true;
+    }
+
+    private bool quit (Gdk.Event event)
+    {
+      Gtk.main_quit ();
+      return false;
+    }
+
+  }
+}
+
+
+public static int main (string[] args)
+{
+  Test.Window window;
+
+  Gtk.init (ref args);
+
+  window = new Test.Window ();
+  window.app_paintable = true;
+  window.show_all ();
+
+  Gtk.main ();
+
+  return 0;
+}
diff --git a/tests/test-theme.vala b/tests/test-theme.vala
new file mode 100644
index 0000000..53348b4
--- /dev/null
+++ b/tests/test-theme.vala
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2009 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ *
+ * Author: Thomas Wood <thos gnome org>
+ */
+
+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)
+    {
+      /* 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]