gtk-css-engine r45 - in branches/bzr: . libccd/ccd libccd/doc/tmpl src themes/gtk-css-test/gtk-2.0



Author: robsta
Date: Fri Sep  5 11:32:58 2008
New Revision: 45
URL: http://svn.gnome.org/viewvc/gtk-css-engine?rev=45&view=rev

Log:
Basic background-image support.

Added:
   branches/bzr/libccd/ccd/ccd-function.c
   branches/bzr/libccd/ccd/ccd-function.h
   branches/bzr/src/gce-functions.c
   branches/bzr/src/gce-functions.h
   branches/bzr/themes/gtk-css-test/gtk-2.0/arrow-down.png
   branches/bzr/themes/gtk-css-test/gtk-2.0/arrow-left.png
   branches/bzr/themes/gtk-css-test/gtk-2.0/arrow-right.png
   branches/bzr/themes/gtk-css-test/gtk-2.0/arrow-up.png
Modified:
   branches/bzr/   (props changed)
   branches/bzr/TODO
   branches/bzr/libccd/ccd/Makefile.am
   branches/bzr/libccd/ccd/ccd-background.c
   branches/bzr/libccd/ccd/ccd-background.h
   branches/bzr/libccd/ccd/ccd-image.c
   branches/bzr/libccd/ccd/ccd-selector.c
   branches/bzr/libccd/ccd/ccd.c
   branches/bzr/libccd/ccd/ccd.h
   branches/bzr/libccd/doc/tmpl/ccd.sgml
   branches/bzr/libccd/doc/tmpl/node.sgml
   branches/bzr/src/Makefile.am
   branches/bzr/src/gce-theme.c
   branches/bzr/themes/gtk-css-test/gtk-2.0/styles.css

Modified: branches/bzr/TODO
==============================================================================
--- branches/bzr/TODO	(original)
+++ branches/bzr/TODO	Fri Sep  5 11:32:58 2008
@@ -5,7 +5,7 @@
 0.1 "Infrastructure"
 --------------------
 
-* Matching.
+* Matching (descendant and child).
 * Background color.
 * Basic border styles.
 * Single background image, repeating, tiling.

Modified: branches/bzr/libccd/ccd/Makefile.am
==============================================================================
--- branches/bzr/libccd/ccd/Makefile.am	(original)
+++ branches/bzr/libccd/ccd/Makefile.am	Fri Sep  5 11:32:58 2008
@@ -16,6 +16,8 @@
 	ccd-color.c \
 	ccd-color.h \
 	ccd-features.h \
+	ccd-function.c \
+	ccd-function.h \
 	ccd.c \
 	ccd.h \
 	ccd-image.c \

Modified: branches/bzr/libccd/ccd/ccd-background.c
==============================================================================
--- branches/bzr/libccd/ccd/ccd-background.c	(original)
+++ branches/bzr/libccd/ccd/ccd-background.c	Fri Sep  5 11:32:58 2008
@@ -63,13 +63,34 @@
 		     int32_t			 width,
 		     int32_t			 height)
 {
+	double dx;
+	double dy;
+
 	g_assert (self);
 
+	cairo_save (cr);
+
 	if (self->color_spec != CCD_PROPERTY_SPEC_UNKNOWN) {
-		cairo_rectangle (cr, x, y, width, height);
+
 		cairo_set_source_rgb (cr, self->color.red, self->color.green, self->color.blue);
+		cairo_rectangle (cr, x, y, width, height);
 		cairo_fill (cr);
 	}
+
+	if (self->image_spec != CCD_PROPERTY_SPEC_UNKNOWN) {
+printf ("%s()\n", __FUNCTION__);
+		dx = (double) width / 
+		     cairo_image_surface_get_width (self->image.surface);
+		dy = (double) height /
+		     cairo_image_surface_get_height (self->image.surface);
+		cairo_scale (cr, dx, dy);
+
+		cairo_set_source_surface (cr, self->image.surface, x / dx, y / dy);
+		cairo_rectangle (cr, x / dx, y / dy, width / dx, height / dy);
+		cairo_fill (cr);
+	}
+
+	cairo_restore (cr);
 }
 
 void

Modified: branches/bzr/libccd/ccd/ccd-background.h
==============================================================================
--- branches/bzr/libccd/ccd/ccd-background.h	(original)
+++ branches/bzr/libccd/ccd/ccd-background.h	Fri Sep  5 11:32:58 2008
@@ -24,6 +24,7 @@
 #include <stdint.h>
 #include <cairo.h>
 #include <glib.h>
+#include <libcroco/libcroco.h>
 #include <ccd/ccd-features.h>
 #include <ccd/ccd-color.h>
 #include <ccd/ccd-image.h>

Added: branches/bzr/libccd/ccd/ccd-function.c
==============================================================================
--- (empty file)
+++ branches/bzr/libccd/ccd/ccd-function.c	Fri Sep  5 11:32:58 2008
@@ -0,0 +1,139 @@
+/* The Cairo CSS Drawing Library.
+ * Copyright (C) 2008 Robert Staudinger
+ *
+ * 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 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <string.h>
+#include "ccd-function.h"
+
+static ccd_function_t *_vtable = NULL;
+
+void
+ccd_function_set_vtable (ccd_function_t	const *vtable)
+{
+	ccd_function_t const	*iter;
+	unsigned int		 i;
+
+	if (_vtable) {
+		g_free (_vtable);
+		_vtable = NULL;
+	}
+
+	if (vtable) {
+
+		iter = vtable;
+		for (i = 0; iter->name; iter++, i++)
+			;
+
+		/* also copy NULL-terminator */
+		i++;
+
+		_vtable = g_new0 (ccd_function_t, i);
+		memcpy (_vtable, vtable, sizeof (*vtable) * i);
+	}
+}
+
+char *
+ccd_function_invoke (char const		*name,
+		     CRTerm const	*values)
+{
+	ccd_function_f	 function;
+	GSList		*args;
+	GSList		*iter;
+	char		*val;
+	char const	*unit;
+	char		*ret;
+
+	g_return_val_if_fail (_vtable && name, NULL);
+
+	function = NULL;
+	for (unsigned int i = 0; _vtable[i].name; i++) {
+		if (0 == strcmp (name, _vtable[i].name)) {
+			function = _vtable[i].function;
+		}
+	}
+
+	if (!function) {
+		g_warning ("Function `%s' could not be resolved", name);
+		return NULL;
+	}
+
+	/* parse args */
+	args = NULL;
+	iter = NULL;
+	while (values) {
+		val = NULL;
+		switch (values->type) {
+		case TERM_NUMBER:
+			switch (values->content.num->type) {
+			case NUM_GENERIC:
+				unit = "";
+				break;
+			case NUM_LENGTH_PX:
+				unit = "px";
+				break;
+			case NUM_PERCENTAGE:
+				unit = "%";
+				break;
+			default:
+				g_assert_not_reached ();
+				unit = "";
+			}
+			val = g_strdup_printf ("%f%s", values->content.num->val, unit);
+			break;
+		case TERM_STRING:
+		case TERM_IDENT:
+		case TERM_URI:
+			val = g_strdup_printf ("%s", cr_string_peek_raw_str (values->content.str));			
+			break;
+		case TERM_HASH:
+			val = g_strdup_printf ("#%s", cr_string_peek_raw_str (values->content.str));			
+			break;
+		case TERM_NO_TYPE:
+		case TERM_FUNCTION:
+		case TERM_RGB:
+		case TERM_UNICODERANGE:
+		default:
+			g_assert_not_reached ();
+			values = values->next;
+			continue;
+		}
+
+		if (args == NULL) {
+			args = g_slist_append (NULL, val);
+			iter = args;
+		} else {
+			iter->next = g_slist_append (NULL, val);
+		}
+
+		values = values->next;
+	}
+
+	/* dispatch */
+	ret = function (args);
+
+	/* free args */
+	iter = args;
+	while (iter) {
+		val = (char *) iter->data;
+		iter = g_slist_remove (iter, val);
+		g_free (val);
+	}
+
+	return ret;
+}
+

Added: branches/bzr/libccd/ccd/ccd-function.h
==============================================================================
--- (empty file)
+++ branches/bzr/libccd/ccd/ccd-function.h	Fri Sep  5 11:32:58 2008
@@ -0,0 +1,42 @@
+/* The Cairo CSS Drawing Library.
+ * Copyright (C) 2008 Robert Staudinger
+ *
+ * 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 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef CCD_FUNCTION_H
+#define CCD_FUNCTION_H
+
+#include <glib.h>
+#include <libcroco/libcroco.h>
+
+G_BEGIN_DECLS
+
+typedef char * (*ccd_function_f) (GSList const *args);
+
+typedef struct {
+	char const	*name;
+	ccd_function_f	 function;
+} ccd_function_t;
+
+void ccd_function_set_vtable (ccd_function_t const *vtable);
+
+char * ccd_function_invoke (char const *name, CRTerm const *args);
+
+G_END_DECLS
+
+#endif /* CCD_FUNCTION_H */
+

Modified: branches/bzr/libccd/ccd/ccd-image.c
==============================================================================
--- branches/bzr/libccd/ccd/ccd-image.c	(original)
+++ branches/bzr/libccd/ccd/ccd-image.c	Fri Sep  5 11:32:58 2008
@@ -22,6 +22,7 @@
 
 #include <stdbool.h>
 #include <string.h>
+#include "ccd-function.h"
 #include "ccd-image.h"
 
 void
@@ -39,13 +40,11 @@
 }
 
 static bool
-load_image (ccd_image_t	*self, 
-	    char const	*uri)
+load_image (ccd_image_t	*self)
 {
-	// TODO continue here.
-// cairo_surface_t*    cairo_image_surface_create_from_png (const char *filename);
+	self->surface = cairo_image_surface_create_from_png (self->uri);
 
-	return true;
+	return (bool) self->surface;
 }
 
 ccd_property_spec_t
@@ -69,8 +68,8 @@
 		}
 		break;
 	case TERM_URI:
-		self->uri = g_strdup (cr_string_peek_raw_str (value->content.str));
-		ret = load_image (self, self->uri);
+		self->uri = ccd_function_invoke ("url", value);
+		ret = load_image (self);
 		if (ret)
 			return CCD_PROPERTY_SPEC_SET;
 		else

Modified: branches/bzr/libccd/ccd/ccd-selector.c
==============================================================================
--- branches/bzr/libccd/ccd/ccd-selector.c	(original)
+++ branches/bzr/libccd/ccd/ccd-selector.c	Fri Sep  5 11:32:58 2008
@@ -825,6 +825,9 @@
 {
 	g_return_val_if_fail (self && self->block && style, false);
 
+	/* TODO: probably need to split up background-color and -image
+	 * so they can be merged separately from different selectors. */
+
 	switch (self->block->background.color_spec) {
 	case CCD_PROPERTY_SPEC_UNKNOWN:
 		/* do nothing */
@@ -843,6 +846,24 @@
 		break;
 	}
 
+	switch (self->block->background.image_spec) {
+	case CCD_PROPERTY_SPEC_UNKNOWN:
+		/* do nothing */
+		break;
+	case CCD_PROPERTY_SPEC_NONE:
+		/* reset */
+		style->background = NULL;
+		break;
+	case CCD_PROPERTY_SPEC_INHERIT:
+		/* not implemented */
+		g_assert_not_reached ();
+		break;
+	case CCD_PROPERTY_SPEC_SET:
+		/* use */
+		style->background = &self->block->background;
+		break;
+	}
+
 	if (self->block->border.left.flags)
 		style->left = &self->block->border.left;
 	if (self->block->border.top.flags)

Modified: branches/bzr/libccd/ccd/ccd.c
==============================================================================
--- branches/bzr/libccd/ccd/ccd.c	(original)
+++ branches/bzr/libccd/ccd/ccd.c	Fri Sep  5 11:32:58 2008
@@ -21,16 +21,20 @@
 
 /**
  * ccd_init:
- * @node_class: dispatch table as described at #ccd_node_class_t.
+ * @node_class: 	dispatch table as described at #ccd_node_class_t.
+ * @functions:		table of functions that can be used in CSS.
+ * @n_functions:	size of the function table.
  * 
  * Initialize the CCD library before making any calls to it.
  **/
 void
-ccd_init (ccd_node_class_t const *node_class)
+ccd_init (ccd_node_class_t const	*node_class,
+	  ccd_function_t const		*vtable)
 {
 	g_assert (node_class);
 
 	ccd_node_set_class (node_class);
+	ccd_function_set_vtable (vtable);
 }
 
 /**

Modified: branches/bzr/libccd/ccd/ccd.h
==============================================================================
--- branches/bzr/libccd/ccd/ccd.h	(original)
+++ branches/bzr/libccd/ccd/ccd.h	Fri Sep  5 11:32:58 2008
@@ -25,6 +25,7 @@
 G_BEGIN_DECLS
 
 #include <ccd/ccd-features.h>
+#include <ccd/ccd-function.h>
 #include <ccd/ccd-node.h>
 #include <ccd/ccd-style.h>
 #include <ccd/ccd-stylesheet.h>
@@ -38,7 +39,8 @@
 #define XV(n_) (n_ + 0.5)
 #define YV(n_) (n_)
 
-void 		ccd_init	(ccd_node_class_t const *node_class);
+void 		ccd_init	(ccd_node_class_t const *node_class, 
+				 ccd_function_t const *vtable);
 void 		ccd_shutdown	(void);
 
 G_END_DECLS

Modified: branches/bzr/libccd/doc/tmpl/ccd.sgml
==============================================================================
--- branches/bzr/libccd/doc/tmpl/ccd.sgml	(original)
+++ branches/bzr/libccd/doc/tmpl/ccd.sgml	Fri Sep  5 11:32:58 2008
@@ -23,6 +23,7 @@
 </para>
 
 @node_class: 
+ vtable: 
 
 
 <!-- ##### FUNCTION ccd_shutdown ##### -->

Modified: branches/bzr/libccd/doc/tmpl/node.sgml
==============================================================================
--- branches/bzr/libccd/doc/tmpl/node.sgml	(original)
+++ branches/bzr/libccd/doc/tmpl/node.sgml	Fri Sep  5 11:32:58 2008
@@ -23,6 +23,7 @@
 </para>
 
 @node_class: 
+ vtable: 
 
 
 <!-- ##### FUNCTION ccd_shutdown ##### -->

Modified: branches/bzr/src/Makefile.am
==============================================================================
--- branches/bzr/src/Makefile.am	(original)
+++ branches/bzr/src/Makefile.am	Fri Sep  5 11:32:58 2008
@@ -15,6 +15,8 @@
 	./../libccd/ccd/libccd.la
 
 libcss_la_SOURCES = \
+	gce-functions.c \
+	gce-functions.h \
 	gce-maps.c \
 	gce-maps.h \
 	gce-rc-style.c \

Added: branches/bzr/src/gce-functions.c
==============================================================================
--- (empty file)
+++ branches/bzr/src/gce-functions.c	Fri Sep  5 11:32:58 2008
@@ -0,0 +1,44 @@
+/* Gtk CSS Engine
+ * Copyright (C) 2008 Robert Staudinger
+ *
+ * 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 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "gce-functions.h"
+
+static char *
+url (GSList const *args)
+{
+	char const *uri;
+
+	g_return_val_if_fail (args, NULL);
+
+	uri = (char const *) args->data;
+	gtk_rc_find_pixmap_in_path (gtk_settings_get_default (), NULL, uri);
+}
+
+static ccd_function_t const _functions[] = 
+{
+	{ "url", url },
+	{ NULL }
+};
+
+ccd_function_t const *
+gce_functions_get_vtable (void)
+{
+	return _functions;
+}
+

Added: branches/bzr/src/gce-functions.h
==============================================================================
--- (empty file)
+++ branches/bzr/src/gce-functions.h	Fri Sep  5 11:32:58 2008
@@ -0,0 +1,33 @@
+/* Gtk CSS Engine
+ * Copyright (C) 2008 Robert Staudinger
+ *
+ * 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 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GCE_FUNCTIONS_H
+#define GCE_FUNCTIONS_H
+
+#include <ccd/ccd.h>
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+ccd_function_t const * gce_functions_get_vtable (void);
+
+G_END_DECLS
+
+#endif /* GCE_FUNCTIONS_H */
+

Modified: branches/bzr/src/gce-theme.c
==============================================================================
--- branches/bzr/src/gce-theme.c	(original)
+++ branches/bzr/src/gce-theme.c	Fri Sep  5 11:32:58 2008
@@ -21,6 +21,7 @@
 #include <gmodule.h>
 #include <gtk/gtk.h>
 
+#include "gce-functions.h"
 #include "gce-style.h"
 #include "gce-rc-style.h"
 
@@ -33,10 +34,15 @@
 G_MODULE_EXPORT void 
 theme_init (GTypeModule *module)
 {
+	ccd_node_class_t const	*node_class;
+	ccd_function_t const	*vtable;
+
 	gce_rc_style_register_type (module);
 	gce_style_register_type (module);
 
-	ccd_init (gce_style_get_ccd_node_class ());
+	node_class = gce_style_get_ccd_node_class ();
+	vtable = gce_functions_get_vtable ();
+	ccd_init (node_class, vtable);
 }
 
 G_MODULE_EXPORT void 

Added: branches/bzr/themes/gtk-css-test/gtk-2.0/arrow-down.png
==============================================================================
Binary files (empty file) and branches/bzr/themes/gtk-css-test/gtk-2.0/arrow-down.png	Fri Sep  5 11:32:58 2008 differ

Added: branches/bzr/themes/gtk-css-test/gtk-2.0/arrow-left.png
==============================================================================
Binary files (empty file) and branches/bzr/themes/gtk-css-test/gtk-2.0/arrow-left.png	Fri Sep  5 11:32:58 2008 differ

Added: branches/bzr/themes/gtk-css-test/gtk-2.0/arrow-right.png
==============================================================================
Binary files (empty file) and branches/bzr/themes/gtk-css-test/gtk-2.0/arrow-right.png	Fri Sep  5 11:32:58 2008 differ

Added: branches/bzr/themes/gtk-css-test/gtk-2.0/arrow-up.png
==============================================================================
Binary files (empty file) and branches/bzr/themes/gtk-css-test/gtk-2.0/arrow-up.png	Fri Sep  5 11:32:58 2008 differ

Modified: branches/bzr/themes/gtk-css-test/gtk-2.0/styles.css
==============================================================================
--- branches/bzr/themes/gtk-css-test/gtk-2.0/styles.css	(original)
+++ branches/bzr/themes/gtk-css-test/gtk-2.0/styles.css	Fri Sep  5 11:32:58 2008
@@ -53,11 +53,18 @@
 	background-color: white;
 }
 */
-
-arrow {
-	background-color: black;
+arrow[orientation=up] {
+	background-image: url(arrow-up.png);
+}
+arrow[orientation=down] {
+	background-image: url(arrow-down.png);
+}
+arrow[orientation=left] {
+	background-image: url(arrow-left.png);
+}
+arrow[orientation=right] {
+	background-image: url(arrow-right.png);
 }
-
 tab {
 	background-color: blue;
 }
@@ -69,12 +76,10 @@
 check {
 	background-color: green;
 }
-
 box {
 	background-color: darkkhaki;
 	border: 1px solid black;
 }
-
 flatbox {
 	background-color: darkkhaki;
 	border: 1px solid black;



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