Allow alpha values for stylesheet colours
authorThomas White <taw@bitwiz.me.uk>
Sat, 27 Oct 2018 21:29:14 +0000 (23:29 +0200)
committerThomas White <taw@bitwiz.me.uk>
Sat, 27 Oct 2018 21:29:14 +0000 (23:29 +0200)
Get rid of GRAD_NOBG, because it's now handled by transparency

data/stylesheeteditor.ui
src/frame.h
src/render.c
src/sc_interp.c
src/stylesheet_editor.c

index 3e64d3d..19723bb 100644 (file)
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">True</property>
+                        <property name="use_alpha">True</property>
                         <signal name="color-set" handler="narrative_fgcol_sig" swapped="no"/>
                       </object>
                       <packing>
                           <item id="flat" translatable="yes">Flat colour</item>
                           <item id="horiz" translatable="yes">Horizontal gradient</item>
                           <item id="vert" translatable="yes">Vertical gradient</item>
-                          <item id="none" translatable="yes">None</item>
                         </items>
                         <signal name="changed" handler="narrative_bg_sig" swapped="no"/>
                       </object>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">True</property>
+                        <property name="use_alpha">True</property>
                         <signal name="color-set" handler="narrative_bg_sig" swapped="no"/>
                       </object>
                       <packing>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">True</property>
+                        <property name="use_alpha">True</property>
                         <signal name="color-set" handler="narrative_bg_sig" swapped="no"/>
                       </object>
                       <packing>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">True</property>
+                        <property name="use_alpha">True</property>
                         <signal name="color-set" handler="slide_bg_sig" swapped="no"/>
                       </object>
                       <packing>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">True</property>
+                        <property name="use_alpha">True</property>
                         <signal name="color-set" handler="slide_bg_sig" swapped="no"/>
                       </object>
                       <packing>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">True</property>
+                        <property name="use_alpha">True</property>
                         <signal name="color-set" handler="frame_fgcol_sig" swapped="no"/>
                       </object>
                       <packing>
                           <item id="flat" translatable="yes">Flat colour</item>
                           <item id="horiz" translatable="yes">Horizontal gradient</item>
                           <item id="vert" translatable="yes">Vertical gradient</item>
-                          <item id="none" translatable="yes">None</item>
                         </items>
                         <signal name="changed" handler="frame_bg_sig" swapped="no"/>
                       </object>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">True</property>
+                        <property name="use_alpha">True</property>
                         <signal name="color-set" handler="frame_bg_sig" swapped="no"/>
                       </object>
                       <packing>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">True</property>
+                        <property name="use_alpha">True</property>
                         <signal name="color-set" handler="frame_bg_sig" swapped="no"/>
                       </object>
                       <packing>
index b786065..f52c6e6 100644 (file)
@@ -42,8 +42,7 @@ typedef enum
 {
        GRAD_NONE,
        GRAD_HORIZ,
-       GRAD_VERT,
-       GRAD_NOBG
+       GRAD_VERT
 } GradientType;
 
 enum para_type
index 8aa7dbe..f9f4cca 100644 (file)
@@ -48,8 +48,6 @@ static void do_background(cairo_t *cr, struct frame *fr)
 {
        cairo_pattern_t *patt = NULL;
 
-       if ( fr->grad == GRAD_NOBG ) return;  /* Should not end up here */
-
        cairo_new_path(cr);
        cairo_rectangle(cr, 0.0, 0.0, fr->w, fr->h);
 
@@ -86,9 +84,6 @@ static void do_background(cairo_t *cr, struct frame *fr)
                cairo_set_source(cr, patt);
                break;
 
-               case GRAD_NOBG:
-               break;
-
        }
 
        cairo_fill(cr);
index 91775f5..7bbfeeb 100644 (file)
@@ -584,7 +584,7 @@ SCInterpreter *sc_interp_new(PangoContext *pc, PangoLanguage *lang,
        st->bgcol2[1] = 1.0;
        st->bgcol2[2] = 1.0;
        st->bgcol2[3] = 1.0;
-       st->bggrad = GRAD_NOBG;
+       st->bggrad = GRAD_NONE;
        scin->lang = lang;
 
        /* The "ultimate" default font */
index bab784a..753918a 100644 (file)
@@ -117,16 +117,10 @@ static void set_bg_from_ss(Stylesheet *ss, const char *path, GtkWidget *wcol,
                GdkRGBA rgba;
                found = 1;
                if ( gdk_rgba_parse(&rgba, result) == TRUE ) {
-                       if ( rgba.alpha == 0.0 ) {
-                               gtk_combo_box_set_active_id(GTK_COMBO_BOX(wgrad), "none");
-                               gtk_widget_set_sensitive(wcol, FALSE);
-                               gtk_widget_set_sensitive(wcol2, FALSE);
-                       } else {
-                               gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(wcol), &rgba);
-                               gtk_combo_box_set_active_id(GTK_COMBO_BOX(wgrad), "flat");
-                               gtk_widget_set_sensitive(wcol, TRUE);
-                               gtk_widget_set_sensitive(wcol2, FALSE);
-                       }
+                       gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(wcol), &rgba);
+                       gtk_combo_box_set_active_id(GTK_COMBO_BOX(wgrad), "flat");
+                       gtk_widget_set_sensitive(wcol, TRUE);
+                       gtk_widget_set_sensitive(wcol2, FALSE);
                } else {
                        fprintf(stderr, _("Failed to parse colour: %s\n"), result);
                }
@@ -159,8 +153,14 @@ static void set_bg_from_ss(Stylesheet *ss, const char *path, GtkWidget *wcol,
        }
 
        if ( !found ) {
-               gtk_combo_box_set_active_id(GTK_COMBO_BOX(wgrad), "none");
-               gtk_widget_set_sensitive(wcol, FALSE);
+               GdkRGBA rgba;
+               rgba.red = 1.0;
+               rgba.green = 1.0;
+               rgba.blue = 1.0;
+               rgba.alpha = 0.0;
+               gtk_combo_box_set_active_id(GTK_COMBO_BOX(wgrad), "flat");
+               gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(wcol), &rgba);
+               gtk_widget_set_sensitive(wcol, TRUE);
                gtk_widget_set_sensitive(wcol2, FALSE);
        }
 }
@@ -215,7 +215,6 @@ static GradientType id_to_gradtype(const gchar *id)
        if ( strcmp(id, "flat") == 0 ) return GRAD_NONE;
        if ( strcmp(id, "horiz") == 0 ) return GRAD_HORIZ;
        if ( strcmp(id, "vert") == 0 ) return GRAD_VERT;
-       if ( strcmp(id, "none") == 0 ) return GRAD_NOBG;
        return GRAD_NONE;
 }
 
@@ -234,7 +233,9 @@ static void update_bg(struct presentation *p, const char *style_name,
        g = id_to_gradtype(id);
 
        gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(col1w), &rgba);
+       if ( rgba.alpha < 0.000001 ) rgba.alpha = 0.0;
        col1 = gdk_rgba_to_string(&rgba);
+       printf("got colour %s\n", col1);
 
        gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(col2w), &rgba);
        col2 = gdk_rgba_to_string(&rgba);
@@ -243,13 +244,6 @@ static void update_bg(struct presentation *p, const char *style_name,
 
        switch ( g ) {
 
-               case GRAD_NOBG :
-               stylesheet_set(p->stylesheet, style_name, "bgcol",
-                              "rgba(0,0,0,0)");
-               stylesheet_delete(p->stylesheet, style_name, "bggradv");
-               stylesheet_delete(p->stylesheet, style_name, "bggradh");
-               break;
-
                case GRAD_NONE :
                stylesheet_set(p->stylesheet, style_name, "bgcol",
                               col1);