diff options
author | Robert Staudinger <robsta@gnome.org> | 2009-08-05 15:39:13 +0200 |
---|---|---|
committer | Robert Staudinger <robsta@gnome.org> | 2009-08-05 15:39:13 +0200 |
commit | a4a678e38cdb995b9fcc00a9586f4bb2368ace2a (patch) | |
tree | 754b8d5e44f5a61db9fe721e7fc32a606df6ad1f /examples | |
parent | 3c26429f902a3adfd89533f350ff67529eaa7f30 (diff) |
[cairo] Implement pluggable appearance renderers.
A ccss-cairo consumer can install an appearance rendering module
into the plugin directory and refer to the drawing functions
from the CSS.
For the CSS statement
box {
appearance: custom_box example-8;
}
the module "libexample-8.so" is loaded, and the symbol "custom_box()"
is invoked for rendering.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Makefile.am | 16 | ||||
-rw-r--r-- | examples/example-8.c | 113 |
2 files changed, 129 insertions, 0 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am index 2baa97c..93f21b1 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -5,6 +5,7 @@ AM_CPPFLAGS = \ -I$(top_builddir) \ -I$(top_srcdir) \ $(CCSS_EXAMPLES_CFLAGS) \ + -DCCSS_CAIRO_APPEARANCE_MODULE_INTERFACE_VERSION=\"$(CCSS_CAIRO_APPEARANCE_MODULE_INTERFACE_VERSION)\" \ $(NULL) AM_LDFLAGS = \ @@ -22,8 +23,14 @@ noinst_PROGRAMS = \ example-4-2 \ example-6 \ example-7 \ + example-8 \ $(NULL) +noinst_LTLIBRARIES = libexample-8-noinst.la + +pkglibdir = $(CCSS_CAIRO_APPEARANCE_MODULE_PATH) +pkglib_LTLIBRARIES = libexample-8.la + if CCSS_WITH_SOUP noinst_PROGRAMS += example-5 endif @@ -46,6 +53,15 @@ example_6_SOURCES = example-6.c example_7_SOURCES = example-7.c +libexample_8_noinst_la_LDFLAGS = -module -no-undefined +libexample_8_noinst_la_SOURCES = example-8.c + +example_8_SOURCES = +example_8_LDADD = libexample-8-noinst.la + +libexample_8_la_LDFLAGS = -avoid-version -export-dynamic -module -no-undefined +libexample_8_la_SOURCES = example-8.c + EXTRA_DIST = \ example-3.png \ example-5.svg \ diff --git a/examples/example-8.c b/examples/example-8.c new file mode 100644 index 0000000..cb098f0 --- /dev/null +++ b/examples/example-8.c @@ -0,0 +1,113 @@ +/* vim: set ts=8 sw=8 noexpandtab: */ + +#include <stdlib.h> +#include <cairo.h> +#include <ccss-cairo/ccss-cairo.h> +#include <gtk/gtk.h> +#include "config.h" + +/* + * ccss-cairo appearance module interface. + */ + +G_MODULE_EXPORT char const * +ccss_appearance_module_get_interface_version (void); + +G_MODULE_EXPORT void +custom_box (ccss_style_t const *self, + cairo_t *cr, + int x, + int y, + int width, + int height); + +G_MODULE_EXPORT char const * +ccss_appearance_module_get_interface_version (void) +{ + return CCSS_CAIRO_APPEARANCE_MODULE_INTERFACE_VERSION; +} + +G_MODULE_EXPORT void +custom_box (ccss_style_t const *self, + cairo_t *cr, + int x, + int y, + int width, + int height) +{ + cairo_rectangle (cr, x, y, width, height); + cairo_set_line_width (cr, 3); + cairo_set_line_cap (cr, CAIRO_LINE_JOIN_MITER); + cairo_stroke (cr); +} + +/* + * Example binary. + */ + +static gboolean +expose_cb (GtkWidget *widget, + GdkEventExpose *event, + ccss_style_t const *style) +{ + cairo_t *cr; + + cr = gdk_cairo_create (widget->window); + + ccss_cairo_style_draw_rectangle (style, cr, + widget->allocation.x + 10, + widget->allocation.y + 10, + widget->allocation.width - 20, + widget->allocation.height - 20); + + cairo_destroy (cr); + + return FALSE; +} + +static char const _css[] = " \ + box { \ + appearance: custom_box example-8; \ + } \ +"; + +int +main (int argc, + char **argv) +{ + ccss_grammar_t *grammar; + ccss_stylesheet_t *stylesheet; + ccss_style_t *style; + GtkWidget *window; + + gtk_init (&argc, &argv); + + grammar = ccss_cairo_grammar_create (); + stylesheet = ccss_grammar_create_stylesheet_from_buffer (grammar, + _css, sizeof (_css), + NULL); + + style = ccss_stylesheet_query_type (stylesheet, "box"); + g_assert (style); + +#ifdef CCSS_DEBUG + ccss_style_dump (style); +#endif + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_default_size (GTK_WINDOW (window), 160, 90); + gtk_widget_set_app_paintable (window, TRUE); + g_signal_connect (G_OBJECT (window), "delete-event", + G_CALLBACK (gtk_main_quit), NULL); + g_signal_connect (G_OBJECT (window), "expose-event", + G_CALLBACK (expose_cb), style); + + gtk_widget_show_all (window); + gtk_main (); + + ccss_style_destroy (style); + ccss_stylesheet_destroy (stylesheet); + ccss_grammar_destroy (grammar); + + return EXIT_SUCCESS; +} + |