[gtk+/gtk-style-context: 459/490] Add the style example code used to generate illustrations



commit 8b3b45dcb439a76dbf6b14307aa0cc2c7c7da6d9
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Nov 23 11:30:17 2010 -0500

    Add the style example code used to generate illustrations

 tests/Makefile.am     |    7 ++-
 tests/styleexamples.c |  140 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 146 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a567c3a..c969e36 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -95,7 +95,8 @@ noinst_PROGRAMS =  $(TEST_PROGS)	\
 	testexpand			\
 	testexpander			\
 	testvolumebutton		\
-	testscrolledwindow
+	testscrolledwindow		\
+	styleexamples
 
 if USE_X11
 noinst_PROGRAMS += testerrors
@@ -184,6 +185,7 @@ testscrolledwindow_DEPENDENCIES = $(TEST_DEPS)
 testwindows_DEPENDENCIES = $(TEST_DEPS)
 testexpand_DEPENDENCIES = $(TEST_DEPS)
 testexpander_DEPENDENCIES = $(TEST_DEPS)
+styleexamples_DEPENDENCIES = $(TEST_DEPS)
 
 flicker_LDADD = $(LDADDS)
 simple_LDADD = $(LDADDS)
@@ -258,6 +260,7 @@ testscrolledwindow_LDADD = $(LDADDS)
 testwindows_LDADD = $(LDADDS)
 testexpand_LDADD = $(LDADDS)
 testexpander_LDADD = $(LDADDS)
+styleexamples_LDADD = $(LDADDS)
 
 testentrycompletion_SOURCES = 	\
 	prop-editor.c		\
@@ -382,6 +385,8 @@ testexpand_SOURCES = testexpand.c
 
 testexpander_SOURCES = testexpander.c
 
+styleexamples_SOURCES = styleexamples.c
+
 EXTRA_DIST += 			\
 	prop-editor.h		\
 	testgtk.1 		\
diff --git a/tests/styleexamples.c b/tests/styleexamples.c
new file mode 100644
index 0000000..13c57d8
--- /dev/null
+++ b/tests/styleexamples.c
@@ -0,0 +1,140 @@
+#include <string.h>
+#include <gtk/gtk.h>
+
+static gboolean
+draw_cb_checks (GtkWidget *widget, cairo_t *cr)
+{
+  GtkStyleContext *context;
+
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_style_context_save (context);
+
+  gtk_style_context_add_class (context, "check");
+  gtk_style_context_set_state (context, 0);
+  gtk_render_check (context, cr, 12, 12, 12, 12);
+  gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
+  gtk_render_check (context, cr, 36, 12, 12, 12);
+  gtk_style_context_set_state (context, GTK_STATE_FLAG_INCONSISTENT);
+  gtk_render_check (context, cr, 60, 12, 12, 12);
+  gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE);
+  gtk_render_check (context, cr, 84, 12, 12, 12);
+
+  gtk_style_context_restore (context);
+
+  return TRUE;
+}
+
+
+static gboolean
+draw_cb_options (GtkWidget *widget, cairo_t *cr)
+{
+  GtkStyleContext *context;
+
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_style_context_save (context);
+
+  gtk_style_context_add_class (context, "radio");
+  gtk_style_context_set_state (context, 0);
+  gtk_render_option (context, cr, 12, 12, 12, 12);
+  gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
+  gtk_render_option (context, cr, 36, 12, 12, 12);
+  gtk_style_context_set_state (context, GTK_STATE_FLAG_INCONSISTENT);
+  gtk_render_option (context, cr, 60, 12, 12, 12);
+  gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE);
+  gtk_render_option (context, cr, 84, 12, 12, 12);
+
+  gtk_style_context_restore (context);
+
+  return TRUE;
+}
+
+static gboolean
+draw_cb_arrows (GtkWidget *widget, cairo_t *cr)
+{
+  GtkStyleContext *context;
+
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_style_context_save (context);
+
+  gtk_style_context_set_state (context, 0);
+  gtk_render_arrow (context, cr, 0,        12, 12, 12);
+  gtk_render_arrow (context, cr, G_PI/2,   36, 12, 12);
+  gtk_render_arrow (context, cr, G_PI,     60, 12, 12);
+  gtk_render_arrow (context, cr, G_PI*3/2, 84, 12, 12);
+
+  gtk_style_context_restore (context);
+
+  return TRUE;
+}
+
+static gboolean
+draw_cb_expanders (GtkWidget *widget, cairo_t *cr)
+{
+  GtkStyleContext *context;
+
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_style_context_save (context);
+
+  gtk_style_context_add_class (context, "expander");
+  gtk_style_context_set_state (context, 0);
+  gtk_render_expander (context, cr, 12, 12, 12, 12);
+  gtk_style_context_set_state (context, GTK_STATE_FLAG_PRELIGHT);
+  gtk_render_expander (context, cr, 36, 12, 12, 12);
+  gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
+  gtk_render_expander (context, cr, 60, 12, 12, 12);
+  gtk_style_context_set_state (context, GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_ACTIVE);
+  gtk_render_expander (context, cr, 84, 12, 12, 12);
+
+  gtk_style_context_restore (context);
+
+  return TRUE;
+}
+
+static char *what;
+
+static gboolean
+draw_cb (GtkWidget *widget, cairo_t *cr)
+{
+  if (strcmp (what, "check") == 0)
+    return draw_cb_checks (widget, cr);
+  else if (strcmp (what, "option") == 0)
+    return draw_cb_options (widget, cr);
+  else if (strcmp (what, "arrow") == 0)
+    return draw_cb_arrows (widget, cr);
+  else if (strcmp (what, "expander") == 0)
+    return draw_cb_expanders (widget ,cr);
+
+  return FALSE;
+}
+
+int main (int argc, char *argv[])
+{
+  GtkWidget *window;
+  GtkWidget *ebox;
+
+  gtk_init (&argc, &argv);
+
+  if (argc > 1)
+    what = argv[1];
+  else
+    what = "check";
+
+  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  gtk_window_set_has_resize_grip (GTK_WINDOW (window), FALSE);
+  ebox = gtk_event_box_new ();
+  gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), TRUE);
+  gtk_container_add (GTK_CONTAINER (window), ebox);
+  gtk_widget_set_name (ebox, "ebox");
+  g_signal_connect_after (ebox, "draw", G_CALLBACK (draw_cb), NULL);
+
+  gtk_widget_show_all (window);
+
+  gtk_main ();
+
+  return 0;
+}
+



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