aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2019-02-25 21:29:20 +0100
committerThomas White <taw@bitwiz.me.uk>2019-02-25 21:29:20 +0100
commit572d0f24e4923cac794e7b2da8632951cd807852 (patch)
treea4a67af89408e4849e281d258d23bbd0bf6f6c71
parenta779b9a9095cfceaa4a0a8da5b4faaaa98287078 (diff)
Render background
-rw-r--r--libstorycode/slide_render_cairo.c33
-rw-r--r--libstorycode/storycode.y3
-rw-r--r--libstorycode/stylesheet.c28
-rw-r--r--libstorycode/stylesheet.h5
4 files changed, 62 insertions, 7 deletions
diff --git a/libstorycode/slide_render_cairo.c b/libstorycode/slide_render_cairo.c
index 05039d9..7e1cc91 100644
--- a/libstorycode/slide_render_cairo.c
+++ b/libstorycode/slide_render_cairo.c
@@ -159,11 +159,38 @@ static void render_image(struct slide_item *item, cairo_t *cr,
int slide_render_cairo(Slide *s, cairo_t *cr, ImageStore *is, Stylesheet *stylesheet,
int slide_number, PangoLanguage *lang, PangoContext *pc)
{
- int i;
+ int i, r;
+ enum gradient bg;
+ double bgcol[4];
+ double bgcol2[4];
+ cairo_pattern_t *patt = NULL;
+
+ r = stylesheet_get_background(stylesheet, STYEL_SLIDE, &bg, bgcol, bgcol2);
+ if ( r ) return 1;
- /* Overall default background */
+ /* Overall background */
cairo_rectangle(cr, 0.0, 0.0, s->logical_w, s->logical_h);
- cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
+ switch ( bg ) {
+
+ case GRAD_NONE:
+ cairo_set_source_rgb(cr, bgcol[0], bgcol[1], bgcol[2]);
+ break;
+
+ case GRAD_VERT:
+ patt = cairo_pattern_create_linear(0.0, 0.0, 0.0, s->logical_h);
+ cairo_pattern_add_color_stop_rgb(patt, 0.0, bgcol[0], bgcol[1], bgcol[2]);
+ cairo_pattern_add_color_stop_rgb(patt, 1.0, bgcol2[0], bgcol2[1], bgcol2[2]);
+ cairo_set_source(cr, patt);
+ break;
+
+ case GRAD_HORIZ:
+ patt = cairo_pattern_create_linear(0.0, 0.0, s->logical_w, 0.0);
+ cairo_pattern_add_color_stop_rgb(patt, 0.0, bgcol[0], bgcol[1], bgcol[2]);
+ cairo_pattern_add_color_stop_rgb(patt, 1.0, bgcol2[0], bgcol2[1], bgcol2[2]);
+ cairo_set_source(cr, patt);
+ break;
+
+ }
cairo_fill(cr);
for ( i=0; i<s->n_items; i++ ) {
diff --git a/libstorycode/storycode.y b/libstorycode/storycode.y
index 38a0750..66e69a1 100644
--- a/libstorycode/storycode.y
+++ b/libstorycode/storycode.y
@@ -165,7 +165,8 @@ void set_style(struct scpctx *ctx, enum style_element element)
if ( ctx->mask & STYMASK_PADDING ) stylesheet_set_padding(ctx->ss, element, ctx->padding);
if ( ctx->mask & STYMASK_PARASPACE ) stylesheet_set_paraspace(ctx->ss, element, ctx->paraspace);
if ( ctx->mask & STYMASK_FGCOL ) stylesheet_set_fgcol(ctx->ss, element, ctx->fgcol);
- if ( ctx->mask & STYMASK_BGCOL ) stylesheet_set_bgcol(ctx->ss, element, ctx->bgcol);
+ if ( ctx->mask & STYMASK_BGCOL ) stylesheet_set_background(ctx->ss, element, ctx->bggrad,
+ ctx->bgcol, ctx->bgcol2);
ctx->mask = 0;
}
diff --git a/libstorycode/stylesheet.c b/libstorycode/stylesheet.c
index 094edf7..451f3f0 100644
--- a/libstorycode/stylesheet.c
+++ b/libstorycode/stylesheet.c
@@ -35,6 +35,7 @@ struct style
struct frame_geom geom;
char *font;
double fgcol[4]; /* r g b a */
+ enum gradient bggrad;
double bgcol[4]; /* r g b a */
double bgcol2[4]; /* r g b a, if gradient */
struct length paraspace[4]; /* l r t b */
@@ -49,6 +50,7 @@ struct _stylesheet
double default_slide_w;
double default_slide_h;
+ struct style slide;
struct style slide_text;
struct style slide_prestitle;
struct style slide_slidetitle;
@@ -73,6 +75,8 @@ static void default_style(struct style *s)
s->fgcol[2] = 0.0;
s->fgcol[3] = 1.0;
+ s->bggrad = GRAD_NONE;
+
s->bgcol[0] = 1.0;
s->bgcol[1] = 1.0;
s->bgcol[2] = 1.0;
@@ -129,6 +133,7 @@ static struct style *get_style(Stylesheet *s, enum style_element el)
if ( s == NULL ) return NULL;
switch ( el ) {
case STYEL_NARRATIVE : return &s->narrative;
+ case STYEL_SLIDE : return &s->slide;
case STYEL_SLIDE_TEXT : return &s->slide_text;
case STYEL_SLIDE_PRESTITLE : return &s->slide_prestitle;
case STYEL_SLIDE_SLIDETITLE : return &s->slide_slidetitle;
@@ -203,13 +208,16 @@ int stylesheet_set_fgcol(Stylesheet *s, enum style_element el, double rgba[4])
}
-int stylesheet_set_bgcol(Stylesheet *s, enum style_element el, double rgba[4])
+int stylesheet_set_background(Stylesheet *s, enum style_element el, enum gradient grad,
+ double bgcol[4], double bgcol2[4])
{
int i;
struct style *sty = get_style(s, el);
if ( sty == NULL ) return 1;
+ sty->bggrad = grad;
for ( i=0; i<4; i++ ) {
- sty->bgcol[i] = rgba[i];
+ sty->bgcol[i] = bgcol[i];
+ sty->bgcol2[i] = bgcol2[i];
}
return 0;
}
@@ -229,3 +237,19 @@ const char *stylesheet_get_slide_text_font(Stylesheet *s)
if ( s == NULL ) return NULL;
return s->slide_text.font;
}
+
+
+int stylesheet_get_background(Stylesheet *s, enum style_element el,
+ enum gradient *grad, double *bgcol, double *bgcol2)
+{
+ int i;
+ struct style *sty = get_style(s, el);
+ if ( sty == NULL ) return 1;
+
+ for ( i=0; i<4; i++ ) {
+ bgcol[i] = sty->bgcol[i];
+ bgcol2[i] = sty->bgcol2[i];
+ }
+ *grad = sty->bggrad;
+ return 0;
+}
diff --git a/libstorycode/stylesheet.h b/libstorycode/stylesheet.h
index b4d3f00..5c33928 100644
--- a/libstorycode/stylesheet.h
+++ b/libstorycode/stylesheet.h
@@ -89,9 +89,12 @@ extern int stylesheet_set_alignment(Stylesheet *s, enum style_element el, enum a
extern int stylesheet_set_padding(Stylesheet *s, enum style_element el, struct length padding[4]);
extern int stylesheet_set_paraspace(Stylesheet *s, enum style_element el, struct length paraspace[4]);
extern int stylesheet_set_fgcol(Stylesheet *s, enum style_element el, double rgba[4]);
-extern int stylesheet_set_bgcol(Stylesheet *s, enum style_element el, double rgba[4]);
+extern int stylesheet_set_background(Stylesheet *s, enum style_element el, enum gradient grad,
+ double bgcol[4], double bgcol2[4]);
extern const char *stylesheet_get_slide_text_font(Stylesheet *s);
+extern int stylesheet_get_background(Stylesheet *s, enum style_element el,
+ enum gradient *grad, double *bgcol, double *bgcol2);
#endif /* STYLESHEET_H */