From d5f7ae9d6a28781051d7649a656dd2f93b6ea96d Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 25 Oct 2018 23:28:33 +0200 Subject: Set values in stylesheet editor --- src/stylesheet_editor.c | 238 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 237 insertions(+), 1 deletion(-) (limited to 'src/stylesheet_editor.c') diff --git a/src/stylesheet_editor.c b/src/stylesheet_editor.c index 2b9d21e..03eac36 100644 --- a/src/stylesheet_editor.c +++ b/src/stylesheet_editor.c @@ -33,6 +33,8 @@ #include "stylesheet_editor.h" #include "presentation.h" #include "sc_interp.h" +#include "stylesheet.h" +#include "utils.h" G_DEFINE_TYPE_WITH_CODE(StylesheetEditor, stylesheet_editor, @@ -45,9 +47,200 @@ struct _sspriv }; +static int colour_duo_parse(const char *a, GdkRGBA *col1, GdkRGBA *col2) +{ + char *acopy; + char *n2; + + acopy = strdup(a); + if ( acopy == NULL ) return 1; + + n2 = strchr(acopy, ','); + if ( n2 == NULL ) { + fprintf(stderr, _("Invalid bg gradient spec '%s'\n"), a); + return 1; + } + + n2[0] = '\0'; + + if ( gdk_rgba_parse(col1, acopy) != TRUE ) { + fprintf(stderr, _("Failed to parse colour: %s\n"), acopy); + } + if ( gdk_rgba_parse(col2, &n2[1]) != TRUE ) { + fprintf(stderr, _("Failed to parse colour: %s\n"), &n2[1]); + } + + free(acopy); + return 0; +} + + +static void set_font_from_ss(Stylesheet *ss, const char *path, GtkWidget *w) +{ + char *result = stylesheet_lookup(ss, path); + if ( result != NULL ) { + gtk_font_button_set_font_name(GTK_FONT_BUTTON(w), result); + } +} + + +static void set_col_from_ss(Stylesheet *ss, const char *path, GtkWidget *w) +{ + char *result = stylesheet_lookup(ss, path); + if ( result != NULL ) { + GdkRGBA rgba; + if ( gdk_rgba_parse(&rgba, result) == TRUE ) { + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(w), &rgba); + } + } +} + + +static void set_vals_from_ss(Stylesheet *ss, const char *path, + GtkWidget *wl, GtkWidget *wr, + GtkWidget *wt, GtkWidget *wb) +{ + char *result = stylesheet_lookup(ss, path); + if ( result != NULL ) { + float v[4]; + if ( parse_tuple(result, v) == 0 ) { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(wl), v[0]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(wr), v[1]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(wt), v[2]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(wb), v[3]); + } else { + fprintf(stderr, _("Failed to parse quad: %s\n"), result); + } + } else { + printf("Not found %s\n", path); + } +} + + +static void set_size_from_ss(Stylesheet *ss, const char *path, + GtkWidget *ww, GtkWidget *wh) +{ + char *result = stylesheet_lookup(ss, path); + if ( result != NULL ) { + float v[2]; + if ( parse_double(result, v) == 0 ) { + gtk_spin_button_set_value(GTK_SPIN_BUTTON(ww), v[0]); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(wh), v[1]); + } else { + fprintf(stderr, _("Failed to parse double: %s\n"), result); + } + } else { + printf("Not found %s\n", path); + } +} + +static void set_bg_from_ss(Stylesheet *ss, const char *path, GtkWidget *wcol, + GtkWidget *wcol2, GtkWidget *wgrad) +{ + char *result; + char fullpath[256]; + int found = 0; + + strcpy(fullpath, path); + strcat(fullpath, ".bgcol"); + result = stylesheet_lookup(ss, fullpath); + if ( result != NULL ) { + 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); + } + } else { + fprintf(stderr, _("Failed to parse colour: %s\n"), result); + } + } + + strcpy(fullpath, path); + strcat(fullpath, ".bggradv"); + result = stylesheet_lookup(ss, fullpath); + if ( result != NULL ) { + GdkRGBA rgba1, rgba2; + found = 1; + if ( colour_duo_parse(result, &rgba1, &rgba2) == 0 ) { + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(wcol), &rgba1); + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(wcol2), &rgba2); + gtk_combo_box_set_active_id(GTK_COMBO_BOX(wgrad), "vert"); + gtk_widget_set_sensitive(wcol, TRUE); + gtk_widget_set_sensitive(wcol2, TRUE); + } + } + + strcpy(fullpath, path); + strcat(fullpath, ".bggradh"); + result = stylesheet_lookup(ss, fullpath); + if ( result != NULL ) { + GdkRGBA rgba1, rgba2; + found = 1; + if ( colour_duo_parse(result, &rgba1, &rgba2) == 0 ) { + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(wcol), &rgba1); + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(wcol2), &rgba2); + gtk_combo_box_set_active_id(GTK_COMBO_BOX(wgrad), "horiz"); + gtk_widget_set_sensitive(wcol, TRUE); + gtk_widget_set_sensitive(wcol2, TRUE); + } + } + + if ( !found ) { + gtk_combo_box_set_active_id(GTK_COMBO_BOX(wgrad), "none"); + gtk_widget_set_sensitive(wcol, FALSE); + gtk_widget_set_sensitive(wcol2, FALSE); + } +} + + static void set_values_from_presentation(StylesheetEditor *se) { - /* FIXME: From JSON */ + Stylesheet *ss = se->priv->p->stylesheet; + + /* Narrative */ + set_font_from_ss(ss, "$.narrative.font", se->narrative_style_font); + set_col_from_ss(ss, "$.narrative.fgcol", se->narrative_style_fgcol); + set_bg_from_ss(ss, "$.narrative", se->narrative_style_bgcol, + se->narrative_style_bgcol2, + se->narrative_style_bggrad); + set_vals_from_ss(ss, "$.narrative.pad", se->narrative_style_padding_l, + se->narrative_style_padding_r, + se->narrative_style_padding_t, + se->narrative_style_padding_b); + set_vals_from_ss(ss, "$.narrative.paraspace", se->narrative_style_paraspace_l, + se->narrative_style_paraspace_r, + se->narrative_style_paraspace_t, + se->narrative_style_paraspace_b); + + /* Slides */ + set_size_from_ss(ss, "$.slide.size", se->slide_size_w, se->slide_size_h); + set_bg_from_ss(ss, "$.slide", se->slide_style_bgcol, + se->slide_style_bgcol2, + se->slide_style_bggrad); + + + /* Frames */ + set_font_from_ss(ss, "$.slide.frame.font", se->frame_style_font); + set_col_from_ss(ss, "$.slide.frame.fgcol", se->frame_style_fgcol); + set_bg_from_ss(ss, "$.slide.frame", se->frame_style_bgcol, + se->frame_style_bgcol2, + se->frame_style_bggrad); + set_vals_from_ss(ss, "$.slide.frame.pad", se->frame_style_padding_l, + se->frame_style_padding_r, + se->frame_style_padding_t, + se->frame_style_padding_b); + set_vals_from_ss(ss, "$.slide.frame.paraspace", se->frame_style_paraspace_l, + se->frame_style_paraspace_r, + se->frame_style_paraspace_t, + se->frame_style_paraspace_b); } @@ -149,6 +342,11 @@ static void narrative_bggrad_sig(GtkComboBox *widget, StylesheetEditor *se) } +static void slide_size_sig(GtkSpinButton *widget, StylesheetEditor *se) +{ +} + + static void slide_bgcol_sig(GtkColorButton *widget, StylesheetEditor *se) { gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), @@ -236,6 +434,26 @@ static void frame_bggrad_sig(GtkComboBox *widget, StylesheetEditor *se) } +static void frame_padding_sig(GtkSpinButton *widget, StylesheetEditor *se) +{ +} + + +static void frame_paraspace_sig(GtkSpinButton *widget, StylesheetEditor *se) +{ +} + + +static void narrative_padding_sig(GtkSpinButton *widget, StylesheetEditor *se) +{ +} + + +static void narrative_paraspace_sig(GtkSpinButton *widget, StylesheetEditor *se) +{ +} + + static void stylesheet_editor_init(StylesheetEditor *se) { se->priv = G_TYPE_INSTANCE_GET_PRIVATE(se, COLLOQUIUM_TYPE_STYLESHEET_EDITOR, @@ -265,8 +483,18 @@ void stylesheet_editor_class_init(StylesheetEditorClass *klass) SE_BIND_CHILD(narrative_style_bgcol, narrative_bgcol_sig); SE_BIND_CHILD(narrative_style_bgcol2, narrative_bgcol2_sig); SE_BIND_CHILD(narrative_style_bggrad, narrative_bggrad_sig); + SE_BIND_CHILD(narrative_style_paraspace_l, narrative_paraspace_sig); + SE_BIND_CHILD(narrative_style_paraspace_r, narrative_paraspace_sig); + SE_BIND_CHILD(narrative_style_paraspace_t, narrative_paraspace_sig); + SE_BIND_CHILD(narrative_style_paraspace_b, narrative_paraspace_sig); + SE_BIND_CHILD(narrative_style_padding_l, narrative_padding_sig); + SE_BIND_CHILD(narrative_style_padding_r, narrative_padding_sig); + SE_BIND_CHILD(narrative_style_padding_t, narrative_padding_sig); + SE_BIND_CHILD(narrative_style_padding_b, narrative_padding_sig); /* Slide style */ + SE_BIND_CHILD(slide_size_w, slide_size_sig); + SE_BIND_CHILD(slide_size_h, slide_size_sig); SE_BIND_CHILD(slide_style_bgcol, slide_bgcol_sig); SE_BIND_CHILD(slide_style_bgcol2, slide_bgcol2_sig); SE_BIND_CHILD(slide_style_bggrad, slide_bggrad_sig); @@ -277,6 +505,14 @@ void stylesheet_editor_class_init(StylesheetEditorClass *klass) SE_BIND_CHILD(frame_style_bgcol, frame_bgcol_sig); SE_BIND_CHILD(frame_style_bgcol2, frame_bgcol2_sig); SE_BIND_CHILD(frame_style_bggrad, frame_bggrad_sig); + SE_BIND_CHILD(frame_style_paraspace_l, frame_paraspace_sig); + SE_BIND_CHILD(frame_style_paraspace_r, frame_paraspace_sig); + SE_BIND_CHILD(frame_style_paraspace_t, frame_paraspace_sig); + SE_BIND_CHILD(frame_style_paraspace_b, frame_paraspace_sig); + SE_BIND_CHILD(frame_style_padding_l, frame_padding_sig); + SE_BIND_CHILD(frame_style_padding_r, frame_padding_sig); + SE_BIND_CHILD(frame_style_padding_t, frame_padding_sig); + SE_BIND_CHILD(frame_style_padding_b, frame_padding_sig); gtk_widget_class_bind_template_callback(widget_class, revert_sig); -- cgit v1.2.3