gtk-css-engine r117 - in trunk: . libccd/ccd



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

Log:
* TODO: what todo regarding internals for the next release.
* libccd/ccd/ccd-background.c:
* libccd/ccd/ccd-background.h:
More work on tile creation. Not hooked up yet.
* libccd/ccd/ccd-gtk-style.c:
* libccd/ccd/ccd-selector.c:
* libccd/ccd/ccd-style.c:
* libccd/ccd/ccd-style.h:
Propagate background properties thru the selector chain.


Modified:
   trunk/   (props changed)
   trunk/ChangeLog
   trunk/TODO
   trunk/libccd/ccd/ccd-background.c
   trunk/libccd/ccd/ccd-background.h
   trunk/libccd/ccd/ccd-gtk-style.c
   trunk/libccd/ccd/ccd-selector.c
   trunk/libccd/ccd/ccd-style.c
   trunk/libccd/ccd/ccd-style.h

Modified: trunk/TODO
==============================================================================
--- trunk/TODO	(original)
+++ trunk/TODO	Fri Sep 19 11:28:32 2008
@@ -5,6 +5,7 @@
 0.2 "Correctness"
 -----------------
 
+Features:
 * Background image: repeating, tiling, position.
 * Border images, c.f. http://ejohn.org/blog/border-image-in-firefox/
 * Unit tests.
@@ -14,11 +15,17 @@
 * Bugzilla module.
 * Border radius.
 
-Code review:
-  + Check all list iterators for const-ness.
-  + Make all string comparisons case insensitive?
-  + Get rid of the _match() functions all toghether?
-  + Check 80 column code width.
+Internals:
+* Embed `property' struct in all properties, implement ccd_selector_apply()
+  in a generic manner.
+* Create `color' property and use it for bg- and fg-color (in block, style, ...).
+* Have an internal instance of `block' with default values, ccd_style_init() 
+  initialises the style to those. Then drawing functions don't have to check
+  for NULL pointers any more, or, at least not handle them functionally.
+* Check all list iterators for const-ness.
+* Make all string comparisons case insensitive?
+* Get rid of the _match() functions all toghether?
+* Check 80 column code width.
 
 0.3 "Features"
 --------------

Modified: trunk/libccd/ccd/ccd-background.c
==============================================================================
--- trunk/libccd/ccd/ccd-background.c	(original)
+++ trunk/libccd/ccd/ccd-background.c	Fri Sep 19 11:28:32 2008
@@ -298,55 +298,6 @@
 	return false;
 }
 
-#if 0
-/*
- * x, y are relative to the previous tile.
- */
-static void
-draw_tile (cairo_t	*cr,
-	   double	 x,
-	   double	 y)
-{
-	cairo_translate (cr, x, y);
-	cairo_fill (cr);
-}
-
-/*
- * y translation must already be set up when calling this.
- */
-static void
-repeat_x (cairo_t	*cr,
-	  double	 x,
-	  double	 width,
-	  double	 tile_width)
-{
-	cairo_translate (cr, x - tile_width, 0);
-	for (double xoff = 0; xoff < width; xoff += tile_width) {
-		draw_tile (cr, tile_width, 0);
-	}
-}
-/*
- * x translation must already be set up when calling this.
- */
-static void
-repeat_y (cairo_t	*cr,
-	  double	 y,
-	  double	 height,
-	  double	 tile_height)
-{
-	cairo_translate (cr, 0, y - tile_height);
-	for (double yoff = 0; yoff < height; yoff += tile_height) {
-		draw_tile (cr, 0, tile_height);
-	}
-}
-#endif
-
-#if 0
-
-/*
- * TODO: find out whether liberal use of cairo_create()/cairo_destroy()
- * causes performance problems.
- */
 static cairo_pattern_t *
 create_pattern (ccd_background_image_t const	*bg_image,
 		ccd_background_size_t const	*bg_size,
@@ -354,57 +305,46 @@
 		double				 height)
 {
 	cairo_t		*cr;
-	cairo_pattern_t *tile;
 	cairo_surface_t	*surface;
-	double		 intrinsic_width;
-	double		 intrinsic_height;
+	cairo_status_t	 status;
 	double		 tile_width;
 	double		 tile_height;
 	double		 dx;
 	double		 dy;
 	cairo_pattern_t *pattern;
 
-	/* Create a single tile of appropriate size. */
-	intrinsic_width = cairo_image_surface_get_width (bg_image->image.surface);
-	intrinsic_height = cairo_image_surface_get_height (bg_image->image.surface);
-	tile_width = ccd_position_get_horizontal (&bg_size->width, 
-						  width, height,
-						  intrinsic_width,
-						  intrinsic_height);
-	tile_height = ccd_position_get_horizontal (&bg_size->height,
-						   width, height,
-						   intrinsic_width,
-						   intrinsic_height);
-	surface = cairo_surface_create_similar (bg_image->image.surface,
+	/* Setup. */
+	surface = NULL;
+	status = cairo_pattern_get_surface (bg_image->image.pattern, &surface);
+	if (status != CAIRO_STATUS_SUCCESS) {
+		g_warning (cairo_status_to_string (status));
+		return NULL;
+	}
+
+	surface = cairo_surface_create_similar (surface,
 						CAIRO_CONTENT_COLOR_ALPHA,
-						tile_width, tile_height);
+						width, height);
 	cr = cairo_create (surface);
 	cairo_surface_destroy (surface), surface = NULL;
 
-	dx = tile_width / intrinsic_width;
-	dy = tile_height / intrinsic_height;
+	/* Drawing. */
+	tile_width = ccd_position_get_horizontal (&bg_size->width, 
+						  width, height,
+						  bg_image->image.width,
+						  bg_image->image.height);
+	tile_height = ccd_position_get_horizontal (&bg_size->height,
+						   width, height,
+						   bg_image->image.width,
+						   bg_image->image.height);
+	dx = tile_width / bg_image->image.width;
+	dy = tile_height / bg_image->image.height;
 	cairo_scale (cr, dx, dy);
-	cairo_set_source_surface (cr, bg_image->image.surface, 0, 0);
-	tile = cairo_get_source (cr);
-	cairo_pattern_set_extend (tile, CAIRO_EXTEND_PAD);
-	cairo_paint (cr);
-	cairo_pattern_reference (tile);
-	cairo_destroy (cr), cr = NULL;
 
-	/* Shortcut if we only want a single tile anyways. */
-	if (tile_width >= width && tile_height >= height)
-		return tile;
+	cairo_pattern_set_extend (bg_image->image.pattern, CAIRO_EXTEND_REPEAT);
+	cairo_set_source (cr, bg_image->image.pattern);
+	cairo_paint (cr);
 
-	/* Create pattern. */
-	surface = cairo_surface_create_similar (bg_image->image.surface,
-						CAIRO_CONTENT_COLOR_ALPHA,
-						width, height);
-	cr = cairo_create (surface);
-	cairo_surface_destroy (surface), surface = NULL;
-	cairo_pattern_set_extend (tile, CAIRO_EXTEND_REPEAT);
-	cairo_set_source (cr, tile);
-	cairo_pattern_destroy (tile), tile = NULL;
-	cairo_paint (cr);	
+	/* Cleanup. */
 	pattern = cairo_get_source (cr);
 	cairo_pattern_reference (pattern);
 	cairo_destroy (cr), cr = NULL;
@@ -412,7 +352,41 @@
 	return pattern;
 }
 
-#endif
+static void
+repeat (ccd_background_image_t const	*bg_image,
+	ccd_background_size_t const	*bg_size,
+	cairo_t				*cr,
+	int32_t				 x,
+	int32_t				 y, 
+	int32_t				 width,
+	int32_t				 height)
+{
+
+}
+
+static void
+repeat_x (ccd_background_image_t const	*bg_image,
+	  ccd_background_size_t const	*bg_size,
+	  cairo_t			*cr,
+	  int32_t			 x,
+	  int32_t			 y, 
+	  int32_t			 width,
+	  int32_t			 height)
+{
+
+}
+
+static void
+repeat_y (ccd_background_image_t const	*bg_image,
+	  ccd_background_size_t const	*bg_size,
+	  cairo_t			*cr,
+	  int32_t			 x,
+	  int32_t			 y, 
+	  int32_t			 width,
+	  int32_t			 height)
+{
+
+}
 
 /**
  * ccd_background_fill:
@@ -421,8 +395,12 @@
  * the background. The path is not modified.
  **/
 void
-ccd_background_fill (ccd_background_color_t const	*bg_color, 
+ccd_background_fill (ccd_background_attachment_t const	*bg_attachment, 
+		     ccd_background_color_t const	*bg_color,
 		     ccd_background_image_t const	*bg_image,
+		     ccd_background_position_t const	*bg_position,
+		     ccd_background_repeat_t const	*bg_repeat,
+		     ccd_background_size_t const	*bg_size,
 		     cairo_t				*cr,
 		     int32_t				 x,
 		     int32_t				 y, 
@@ -446,6 +424,26 @@
 	if (bg_image && bg_image->spec != CCD_PROPERTY_SPEC_UNSET) {
 
 		cairo_translate (cr, x, y);
+#if 0
+		switch (bg_repeat->repeat) {
+		case CCD_BACKGROUND_REPEAT:
+			repeat (bg_image, bg_size, cr, x, y, width, height);
+			break;
+		case CCD_BACKGROUND_REPEAT_X:
+			repeat_x (bg_image, bg_size, cr, x, y, width, height);
+			break;
+		case CCD_BACKGROUND_REPEAT_Y:
+			repeat_y (bg_image, bg_size, cr, x, y, width, height);
+			break;
+		case CCD_BACKGROUND_NO_REPEAT:
+			/* TODO */
+			break;
+		default:
+			g_assert_not_reached ();
+			/* Need some code here when building w/o assertions. */
+			break;
+		}
+#endif
 		dx = (double) width / bg_image->image.width;
 		dy = (double) height / bg_image->image.height;
 		cairo_scale (cr, dx, dy);

Modified: trunk/libccd/ccd/ccd-background.h
==============================================================================
--- trunk/libccd/ccd/ccd-background.h	(original)
+++ trunk/libccd/ccd/ccd-background.h	Fri Sep 19 11:28:32 2008
@@ -88,8 +88,12 @@
 bool ccd_background_parse (ccd_background_t *self, char const *property, 
 			   CRTerm const *values);
 
-void ccd_background_fill (ccd_background_color_t const *bg_color, 
+void ccd_background_fill (ccd_background_attachment_t const *bg_attachment, 
+			  ccd_background_color_t const *bg_color,
 			  ccd_background_image_t const *bg_image,
+			  ccd_background_position_t const *bg_position,
+			  ccd_background_repeat_t const *bg_repeat,
+			  ccd_background_size_t const *bg_size,
 			  cairo_t *cr, int32_t x, int32_t y, 
 			  int32_t width, int32_t height);
 

Modified: trunk/libccd/ccd/ccd-gtk-style.c
==============================================================================
--- trunk/libccd/ccd/ccd-gtk-style.c	(original)
+++ trunk/libccd/ccd/ccd-gtk-style.c	Fri Sep 19 11:28:32 2008
@@ -101,8 +101,9 @@
 			 &self->bottom, &bottom_left,
 			 cr, x, y, width, height);
 
-	ccd_background_fill (self->bg_color, self->bg_image,
-			     cr, x, y, width, height);
+	ccd_background_fill (self->bg_attachment, self->bg_color,
+			     self->bg_image, self->bg_position, self->bg_repeat,
+			     self->bg_size, cr, x, y, width, height);
 
 	cairo_new_path (cr);
 

Modified: trunk/libccd/ccd/ccd-selector.c
==============================================================================
--- trunk/libccd/ccd/ccd-selector.c	(original)
+++ trunk/libccd/ccd/ccd-selector.c	Fri Sep 19 11:28:32 2008
@@ -889,6 +889,24 @@
 
 	/* apply */
 
+	switch (self->block->background.bg_attachment.spec) {
+	case CCD_PROPERTY_SPEC_UNSET:
+		/* do nothing */
+		break;
+	case CCD_PROPERTY_SPEC_NONE:
+		/* reset */
+		style->bg_color = NULL;
+		break;
+	case CCD_PROPERTY_SPEC_INHERIT:
+		/* not implemented */
+		g_assert_not_reached ();
+		break;
+	case CCD_PROPERTY_SPEC_SET:
+		/* use */
+		style->bg_attachment = &self->block->background.bg_attachment;
+		break;
+	}
+
 	switch (self->block->background.bg_color.spec) {
 	case CCD_PROPERTY_SPEC_UNSET:
 		/* do nothing */
@@ -925,6 +943,60 @@
 		break;
 	}
 
+	switch (self->block->background.bg_position.spec) {
+	case CCD_PROPERTY_SPEC_UNSET:
+		/* do nothing */
+		break;
+	case CCD_PROPERTY_SPEC_NONE:
+		/* reset */
+		style->bg_position = NULL;
+		break;
+	case CCD_PROPERTY_SPEC_INHERIT:
+		/* not implemented */
+		g_assert_not_reached ();
+		break;
+	case CCD_PROPERTY_SPEC_SET:
+		/* use */
+		style->bg_position = &self->block->background.bg_position;
+		break;
+	}
+
+	switch (self->block->background.bg_repeat.spec) {
+	case CCD_PROPERTY_SPEC_UNSET:
+		/* do nothing */
+		break;
+	case CCD_PROPERTY_SPEC_NONE:
+		/* reset */
+		style->bg_position = NULL;
+		break;
+	case CCD_PROPERTY_SPEC_INHERIT:
+		/* not implemented */
+		g_assert_not_reached ();
+		break;
+	case CCD_PROPERTY_SPEC_SET:
+		/* use */
+		style->bg_repeat = &self->block->background.bg_repeat;
+		break;
+	}
+
+	switch (self->block->background.bg_size.spec) {
+	case CCD_PROPERTY_SPEC_UNSET:
+		/* do nothing */
+		break;
+	case CCD_PROPERTY_SPEC_NONE:
+		/* reset */
+		style->bg_position = NULL;
+		break;
+	case CCD_PROPERTY_SPEC_INHERIT:
+		/* not implemented */
+		g_assert_not_reached ();
+		break;
+	case CCD_PROPERTY_SPEC_SET:
+		/* use */
+		style->bg_size = &self->block->background.bg_size;
+		break;
+	}
+
 	if (CCD_BORDER_STROKE_IS_SET (self->block->border.left))
 		CCD_BORDER_STROKE_ASSIGN (style->left, self->block->border.left);
 	if (CCD_BORDER_JOIN_IS_SET (self->block->border.left_top))

Modified: trunk/libccd/ccd/ccd-style.c
==============================================================================
--- trunk/libccd/ccd/ccd-style.c	(original)
+++ trunk/libccd/ccd/ccd-style.c	Fri Sep 19 11:28:32 2008
@@ -139,8 +139,9 @@
 			 &self->bottom, &self->bottom_left,
 			 cr, x, y, width, height);
 
-	ccd_background_fill (self->bg_color, self->bg_image,
-			     cr, x, y, width, height);
+	ccd_background_fill (self->bg_attachment, self->bg_color,
+			     self->bg_image, self->bg_position, self->bg_repeat,
+			     self->bg_size, cr, x, y, width, height);
 
 	cairo_new_path (cr);
 

Modified: trunk/libccd/ccd/ccd-style.h
==============================================================================
--- trunk/libccd/ccd/ccd-style.h	(original)
+++ trunk/libccd/ccd/ccd-style.h	Fri Sep 19 11:28:32 2008
@@ -41,18 +41,22 @@
  **/
 typedef struct {
 	/*< private >*/
-	ccd_background_color_t const	*bg_color;
-	ccd_background_image_t const	*bg_image;
-	ccd_border_stroke_t		 left;
-	ccd_border_join_t		 left_top;
-	ccd_border_stroke_t		 top;
-	ccd_border_join_t		 top_right;
-	ccd_border_stroke_t		 right;
-	ccd_border_join_t		 right_bottom;
-	ccd_border_stroke_t		 bottom;
-	ccd_border_join_t		 bottom_left;
-	ccd_color_t const		*color;
-	ccd_property_spec_t		 color_spec;
+	ccd_background_attachment_t const	*bg_attachment;
+	ccd_background_color_t const		*bg_color;
+	ccd_background_image_t const		*bg_image;
+	ccd_background_position_t const		*bg_position;
+	ccd_background_repeat_t const		*bg_repeat;
+	ccd_background_size_t const		*bg_size;
+	ccd_border_stroke_t			 left;
+	ccd_border_join_t			 left_top;
+	ccd_border_stroke_t			 top;
+	ccd_border_join_t			 top_right;
+	ccd_border_stroke_t			 right;
+	ccd_border_join_t			 right_bottom;
+	ccd_border_stroke_t			 bottom;
+	ccd_border_join_t			 bottom_left;
+	ccd_color_t const			*color;
+	ccd_property_spec_t			 color_spec;
 } ccd_style_t;
 
 void ccd_style_init (ccd_style_t *self);



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