From 1a7a88400dd4ade345cb895aaca7547174d0243c Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 8 Apr 2019 22:56:26 +0200 Subject: Fix colour types --- libstorycode/narrative_render_cairo.c | 30 +++++++++++++++++------------- libstorycode/slide_render_cairo.c | 27 ++++++++++++++++----------- 2 files changed, 33 insertions(+), 24 deletions(-) (limited to 'libstorycode') diff --git a/libstorycode/narrative_render_cairo.c b/libstorycode/narrative_render_cairo.c index 6da1db1..581cdae 100644 --- a/libstorycode/narrative_render_cairo.c +++ b/libstorycode/narrative_render_cairo.c @@ -79,10 +79,10 @@ static void wrap_text(struct narrative_item *item, PangoContext *pc, double wrap_w; PangoAttrList *attrs; PangoAttribute *attr; - double fgcol[4]; + struct colour fgcol; guint16 r, g, b; - font = stylesheet_get_font(ss, el, fgcol, &align); + font = stylesheet_get_font(ss, el, &fgcol, &align); if ( font == NULL ) return; fontdesc = pango_font_description_from_string(font); @@ -105,9 +105,9 @@ static void wrap_text(struct narrative_item *item, PangoContext *pc, /* Set foreground colour */ attrs = pango_attr_list_new(); - r = fgcol[0] * 65535; - g = fgcol[1] * 65535; - b = fgcol[2] * 65535; + r = fgcol.rgba[0] * 65535; + g = fgcol.rgba[1] * 65535; + b = fgcol.rgba[2] * 65535; attr = pango_attr_foreground_new(r, g, b); pango_attr_list_insert(attrs, attr); @@ -394,11 +394,11 @@ int narrative_render_cairo(Narrative *n, cairo_t *cr, Stylesheet *stylesheet) { int i, r; enum gradient bg; - double bgcol[4]; - double bgcol2[4]; + struct colour bgcol; + struct colour bgcol2; cairo_pattern_t *patt = NULL; - r = stylesheet_get_background(stylesheet, STYEL_NARRATIVE, &bg, bgcol, bgcol2); + r = stylesheet_get_background(stylesheet, STYEL_NARRATIVE, &bg, &bgcol, &bgcol2); if ( r ) return 1; /* Overall background */ @@ -406,20 +406,24 @@ int narrative_render_cairo(Narrative *n, cairo_t *cr, Stylesheet *stylesheet) switch ( bg ) { case GRAD_NONE: - cairo_set_source_rgb(cr, bgcol[0], bgcol[1], bgcol[2]); + cairo_set_source_rgb(cr, bgcol.rgba[0], bgcol.rgba[1], bgcol.rgba[2]); break; case GRAD_VERT: patt = cairo_pattern_create_linear(0.0, 0.0, 0.0, narrative_get_height(n)); - 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_pattern_add_color_stop_rgb(patt, 0.0, + bgcol.rgba[0], bgcol.rgba[1], bgcol.rgba[2]); + cairo_pattern_add_color_stop_rgb(patt, 1.0, + bgcol2.rgba[0], bgcol2.rgba[1], bgcol2.rgba[2]); cairo_set_source(cr, patt); break; case GRAD_HORIZ: patt = cairo_pattern_create_linear(0.0, 0.0, n->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_pattern_add_color_stop_rgb(patt, 0.0, + bgcol.rgba[0], bgcol.rgba[1], bgcol.rgba[2]); + cairo_pattern_add_color_stop_rgb(patt, 1.0, + bgcol2.rgba[0], bgcol2.rgba[1], bgcol2.rgba[2]); cairo_set_source(cr, patt); break; diff --git a/libstorycode/slide_render_cairo.c b/libstorycode/slide_render_cairo.c index 03df9c6..a812bd8 100644 --- a/libstorycode/slide_render_cairo.c +++ b/libstorycode/slide_render_cairo.c @@ -97,7 +97,7 @@ static void render_text(SlideItem *item, cairo_t *cr, PangoContext *pc, struct length pad[4]; const char *font; enum alignment align; - double fgcol[4]; + struct colour fgcol; PangoRectangle rect; PangoFontDescription *fontdesc; PangoAlignment palignment; @@ -112,7 +112,7 @@ static void render_text(SlideItem *item, cairo_t *cr, PangoContext *pc, pad_r = lcalc(pad[1], parent_w); pad_t = lcalc(pad[2], parent_h); - font = stylesheet_get_font(ss, el, fgcol, &align); + font = stylesheet_get_font(ss, el, &fgcol, &align); if ( font == NULL ) return; fontdesc = pango_font_description_from_string(font); @@ -191,7 +191,8 @@ static void render_text(SlideItem *item, cairo_t *cr, PangoContext *pc, /* FIXME: Clip to w,h */ - cairo_set_source_rgba(cr, fgcol[0], fgcol[1], fgcol[2], fgcol[3]); + cairo_set_source_rgba(cr, fgcol.rgba[0], fgcol.rgba[1], fgcol.rgba[2], + fgcol.rgba[3]); cairo_move_to(cr, 0.0, 0.0); pango_cairo_update_layout(cr, item->paras[i].layout); pango_cairo_show_layout(cr, item->paras[i].layout); @@ -266,12 +267,12 @@ int slide_render_cairo(Slide *s, cairo_t *cr, ImageStore *is, Stylesheet *styles { int i, r; enum gradient bg; - double bgcol[4]; - double bgcol2[4]; + struct colour bgcol; + struct colour bgcol2; cairo_pattern_t *patt = NULL; double w, h; - r = stylesheet_get_background(stylesheet, STYEL_SLIDE, &bg, bgcol, bgcol2); + r = stylesheet_get_background(stylesheet, STYEL_SLIDE, &bg, &bgcol, &bgcol2); if ( r ) return 1; slide_get_logical_size(s, stylesheet, &w, &h); @@ -282,20 +283,24 @@ int slide_render_cairo(Slide *s, cairo_t *cr, ImageStore *is, Stylesheet *styles switch ( bg ) { case GRAD_NONE: - cairo_set_source_rgb(cr, bgcol[0], bgcol[1], bgcol[2]); + cairo_set_source_rgb(cr, bgcol.rgba[0], bgcol.rgba[1], bgcol.rgba[2]); break; case GRAD_VERT: patt = cairo_pattern_create_linear(0.0, 0.0, 0.0, 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_pattern_add_color_stop_rgb(patt, 0.0, + bgcol.rgba[0], bgcol.rgba[1], bgcol.rgba[2]); + cairo_pattern_add_color_stop_rgb(patt, 1.0, + bgcol2.rgba[0], bgcol2.rgba[1], bgcol2.rgba[2]); cairo_set_source(cr, patt); break; case GRAD_HORIZ: patt = cairo_pattern_create_linear(0.0, 0.0, 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_pattern_add_color_stop_rgb(patt, 0.0, + bgcol.rgba[0], bgcol.rgba[1], bgcol.rgba[2]); + cairo_pattern_add_color_stop_rgb(patt, 1.0, + bgcol2.rgba[0], bgcol2.rgba[1], bgcol2.rgba[2]); cairo_set_source(cr, patt); break; -- cgit v1.2.3