diff options
author | Thomas White <taw@bitwiz.org.uk> | 2012-08-12 17:40:20 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2012-08-12 17:40:20 +0200 |
commit | 2fd37a95bd5fe109a62917eca483b36a18a74777 (patch) | |
tree | 0864a76938670d7b2740eaa9b8da281670ecd0d8 /src | |
parent | 6d0e78aadcf111cfd82cc8762ebd43c10c7923ae (diff) |
The style mechanism
Diffstat (limited to 'src')
-rw-r--r-- | src/layout.c | 23 | ||||
-rw-r--r-- | src/presentation.h | 23 | ||||
-rw-r--r-- | src/render.c | 88 | ||||
-rw-r--r-- | src/stylesheet.h | 48 |
4 files changed, 57 insertions, 125 deletions
diff --git a/src/layout.c b/src/layout.c index c111e18..a257112 100644 --- a/src/layout.c +++ b/src/layout.c @@ -27,11 +27,22 @@ #include <assert.h> #include <stdlib.h> +#include <string.h> #include "presentation.h" #include "layout.h" +#include "stylesheet.h" -void layout_frame(struct frame *fr, double w, double h) + +static void copy_lop_from_style(struct frame *fr, struct style *style) +{ + if ( style == NULL ) return; /* Not dictated by style sheet */ + + memcpy(&fr->lop, &style->lop, sizeof(struct layout_parameters)); +} + + +static void layout_subframe(struct frame *fr, double w, double h) { int i; @@ -47,6 +58,8 @@ void layout_frame(struct frame *fr, double w, double h) if ( child == fr ) continue; + copy_lop_from_style(child, child->style); + child->offs_x = child->lop.margin_l + fr->lop.pad_l; child->offs_y = child->lop.margin_t + fr->lop.pad_r; child_w = w - (child->lop.margin_l + child->lop.margin_r); @@ -54,8 +67,14 @@ void layout_frame(struct frame *fr, double w, double h) child_w -= (fr->lop.pad_l + fr->lop.pad_r); child_h -= (fr->lop.pad_t + fr->lop.pad_b); - layout_frame(child, child_w, child_h); + layout_subframe(child, child_w, child_h); } } + +void layout_frame(struct frame *fr, double w, double h) +{ + copy_lop_from_style(fr, fr->style); + layout_subframe(fr, w, h); +} diff --git a/src/presentation.h b/src/presentation.h index bda955a..64e6d79 100644 --- a/src/presentation.h +++ b/src/presentation.h @@ -53,23 +53,24 @@ struct slide struct frame { - //struct frame_class *cl; - PangoContext *pc; + PangoContext *pc; /* FIXME: Doesn't belong here */ - struct frame **rendering_order; - int num_ro; + struct frame **rendering_order; + int num_ro; - char *sc; /* Storycode */ + char *sc; /* Storycode */ - struct layout_parameters lop; + struct layout_parameters lop; + struct style *style; /* Non-NULL if 'lop' came from SS */ /* Location relative to parent, calculated from alignment parameters */ - double offs_x; - double offs_y; - double w; - double h; + double offs_x; + double offs_y; + double w; + double h; - int empty; + /* True if this frame should be deleted on the next mouse click */ + int empty; }; diff --git a/src/render.c b/src/render.c index 28365e8..e1915bf 100644 --- a/src/render.c +++ b/src/render.c @@ -30,77 +30,13 @@ #include <pango/pangocairo.h> #include <assert.h> #include <gdk/gdk.h> +#include <string.h> #include "storycode.h" #include "stylesheet.h" #include "presentation.h" -static void render_bgblock(cairo_t *cr, struct bgblock *b) -{ - GdkColor col1; - GdkColor col2; - cairo_pattern_t *patt = NULL; - double cx, cy, r, r1, r2; - - 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_CIRCULAR : - cx = b->min_x + (b->max_x-b->min_x)/2.0; - cy = b->min_y + (b->max_y-b->min_y)/2.0; - r1 = (b->max_x-b->min_x)/2.0; - r2 = (b->max_y-b->min_y)/2.0; - r = r1 > r2 ? r1 : r2; - patt = cairo_pattern_create_radial(cx, cy, r, cx, cy, 0.0); - /* Fall-through */ - - case BGBLOCK_GRADIENT_X : - if ( patt == NULL ) { - patt = cairo_pattern_create_linear(b->min_x, 0.0, - b->max_y, 0.0); - } - /* Fall-through */ - - case BGBLOCK_GRADIENT_Y : - if ( patt == NULL ) { - 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_rgba(patt, 0.0, col1.red/65535.0, - col1.green/65535.0, - col1.blue/65535.0, - b->alpha1); - cairo_pattern_add_color_stop_rgba(patt, 1.0, col2.red/65535.0, - col2.green/65535.0, - col2.blue/65535.0, - b->alpha2); - cairo_set_source(cr, patt); - cairo_fill(cr); - cairo_pattern_destroy(patt); - break; - - case BGBLOCK_IMAGE : - cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); - cairo_fill(cr); - - } -} - - /* Render Level 1 Storycode */ int render_sc(const char *sc, cairo_t *cr, double w, double h, PangoContext *pc) { @@ -139,6 +75,7 @@ int render_sc(const char *sc, cairo_t *cr, double w, double h, PangoContext *pc) int render_frame(struct frame *fr, cairo_t *cr, PangoContext *pc) { int i; + int d = 0; /* The rendering order is a list of children, but it also contains the * current frame. In this way, it contains information about which @@ -153,6 +90,15 @@ int render_frame(struct frame *fr, cairo_t *cr, PangoContext *pc) /* Draw the frame itself (rectangle) */ cairo_rectangle(cr, 0.0, 0.0, fr->w, fr->h); cairo_set_line_width(cr, 1.0); + + if ( (fr->style != NULL) + && (strcmp(fr->style->name, "Default") == 0) ) + { + cairo_set_source_rgb(cr, 0.0, 0.0, 1.0); + } else { + cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); + } + cairo_fill_preserve(cr); cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); cairo_stroke(cr); @@ -162,6 +108,8 @@ int render_frame(struct frame *fr, cairo_t *cr, PangoContext *pc) h = fr->h - (fr->lop.pad_t + fr->lop.pad_b); render_sc(fr->sc, cr, w, h, pc); + d = 1; + continue; } @@ -174,6 +122,11 @@ int render_frame(struct frame *fr, cairo_t *cr, PangoContext *pc) } + if ( !d ) { + fprintf(stderr, "WARNING: Frame didn't appear on its own " + "rendering list?\n"); + } + return 0; } @@ -183,7 +136,6 @@ cairo_surface_t *render_slide(struct slide *s, int w, int h) cairo_surface_t *surf; cairo_t *cr; cairo_font_options_t *fopts; - int i; surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); @@ -196,10 +148,6 @@ cairo_surface_t *render_slide(struct slide *s, int w, int h) cairo_font_options_set_antialias(fopts, CAIRO_ANTIALIAS_SUBPIXEL); cairo_set_font_options(cr, fopts); - for ( i=0; i<s->st->n_bgblocks; i++ ) { - render_bgblock(cr, s->st->bgblocks[i]); - } - render_frame(s->top, cr, NULL); /* FIXME: pc */ cairo_font_options_destroy(fopts); diff --git a/src/stylesheet.h b/src/stylesheet.h index b4dbf9f..f2f72b2 100644 --- a/src/stylesheet.h +++ b/src/stylesheet.h @@ -28,21 +28,15 @@ #endif -struct frame_class +struct frame; +#include "layout.h" + + +struct style { char *name; - /* Margins of this frame from the parent */ - double margin_l; - double margin_r; - double margin_t; - double margin_b; - - /* Padding between this frame and any children */ - double pad_l; - double pad_r; - double pad_t; - double pad_b; + struct layout_parameters lop; /* Storycode prologue (run through the interpreter before the * main storycode for the frame */ @@ -50,36 +44,6 @@ struct frame_class }; -enum bgblocktype -{ - BGBLOCK_SOLID, - BGBLOCK_GRADIENT_X, - BGBLOCK_GRADIENT_Y, - BGBLOCK_GRADIENT_CIRCULAR, - 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 slide_template { char *name; |