Basic background object rendering
authorThomas White <taw@bitwiz.org.uk>
Thu, 10 Nov 2011 19:59:48 +0000 (20:59 +0100)
committerThomas White <taw@bitwiz.org.uk>
Thu, 10 Nov 2011 19:59:48 +0000 (20:59 +0100)
src/slide_render.c
src/stylesheet.c
src/stylesheet.h

index 0eb6098..c3e5ee2 100644 (file)
 #include "stylesheet.h"
 
 
+static void render_bgblock(cairo_t *cr, struct bgblock *b)
+{
+       GdkColor col1;
+       GdkColor col2;
+       cairo_pattern_t *patt;
+
+       cairo_rectangle(cr, b->min_x, b->min_y,
+                           b->max_x - b->min_x,
+                           b->max_y - b->min_y);
+
+       switch ( b->type ) {
+
+               case BGBLOCK_SOLID :
+               gdk_color_parse(b->colour1, &col1);
+               gdk_cairo_set_source_color(cr, &col1);
+               /* FIXME: Honour alpha as well */
+               cairo_fill(cr);
+               break;
+
+               case BGBLOCK_GRADIENT_Y :
+               patt = cairo_pattern_create_linear(0.0, b->min_y,
+                                                  0.0, b->max_y);
+               gdk_color_parse(b->colour1, &col1);
+               gdk_color_parse(b->colour2, &col2);
+               cairo_pattern_add_color_stop_rgb(patt, 0.0, col1.red/65535.0,
+                                                           col1.green/65535.0,
+                                                           col1.blue/65535.0);
+               cairo_pattern_add_color_stop_rgb(patt, 1.0, col2.red/65535.0,
+                                                           col2.green/65535.0,
+                                                           col2.blue/65535.0);
+               cairo_set_source(cr, patt);
+               cairo_fill(cr);
+               cairo_pattern_destroy(patt);
+               break;
+
+       }
+}
+
+
 static cairo_surface_t *render_slide(struct slide *s, int w, int h)
 {
        cairo_surface_t *surf;
@@ -44,13 +83,12 @@ static cairo_surface_t *render_slide(struct slide *s, int w, int h)
        surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
 
        cr = cairo_create(surf);
-
-       cairo_rectangle(cr, 0.0, 0.0, w, h);
-       cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
-       cairo_fill(cr);
-
        cairo_scale(cr, w/s->parent->slide_width, h/s->parent->slide_height);
 
+       for ( i=0; i<s->parent->ss->n_bgblocks; i++ ) {
+               render_bgblock(cr, &s->parent->ss->bgblocks[i]);
+       }
+
        for ( i=0; i<s->num_objects; i++ ) {
 
                struct object *o = s->objects[i];
index 323b3a4..a164029 100644 (file)
@@ -570,6 +570,19 @@ void default_stylesheet(StyleSheet *ss)
        sty->valign = V_CENTER;
        sty->offset_x = +200.0;
        sty->offset_y = -300.0;
+
+       ss->bgblocks = malloc(sizeof(struct bgblock));
+       ss->n_bgblocks = 1;
+       ss->bgblocks[0].type = BGBLOCK_GRADIENT_Y;
+       ss->bgblocks[0].min_x = 0.0;
+       ss->bgblocks[0].max_x = 1024.0;
+       ss->bgblocks[0].min_y = 0.0;
+       ss->bgblocks[0].max_y = 768.0;
+       ss->bgblocks[0].colour1 = strdup("#000000000000");
+       ss->bgblocks[0].alpha1 = 1.0;
+       ss->bgblocks[0].colour2 = strdup("#ffffffffffff");
+       ss->bgblocks[0].alpha2 = 1.0;
+
 }
 
 
index cde0bcc..bdbf97e 100644 (file)
@@ -70,10 +70,42 @@ struct style
 };
 
 
+enum bgblocktype
+{
+       BGBLOCK_SOLID,
+       BGBLOCK_GRADIENT_X,
+       BGBLOCK_GRADIENT_Y,
+       BGBLOCK_IMAGE,
+};
+
+
+struct bgblock
+{
+       enum bgblocktype type;
+       double           min_x;
+       double           max_x;
+       double           min_y;
+       double           max_y;
+
+       char            *colour1;
+       double           alpha1;
+       char            *colour2;
+       double           alpha2;
+
+       struct image    *image;
+       GdkPixbuf       *scaled_pb;
+       int              scaled_w;
+       int              scaled_h;
+};
+
+
 struct _stylesheet
 {
-       struct style **styles;
-       int            n_styles;
+       struct style  **styles;
+       int             n_styles;
+
+       struct bgblock *bgblocks;
+       int             n_bgblocks;
 
        /* Background stuff */
 };