From d669499b143316318f12c091173196c85e57527f Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 9 Nov 2018 20:46:31 +0100 Subject: Set furniture values in SS editor --- data/stylesheeteditor.ui | 164 +++++++++++++++++++++++++++++++++++++---------- src/frame.h | 7 -- src/sc_interp.c | 56 ++-------------- src/stylesheet.c | 10 ++- src/stylesheet_editor.c | 119 ++++++++++++++++++++++++++++++++-- src/stylesheet_editor.h | 20 ++++++ src/utils.c | 54 ++++++++++++++++ src/utils.h | 8 +++ 8 files changed, 342 insertions(+), 96 deletions(-) diff --git a/data/stylesheeteditor.ui b/data/stylesheeteditor.ui index 05aa5ae..e02a8e8 100644 --- a/data/stylesheeteditor.ui +++ b/data/stylesheeteditor.ui @@ -52,16 +52,76 @@ 1 10 + + 100 + 1 + 10 + 2000 1 10 + + 100 + 1 + 10 + + + 100 + 1 + 10 + + + 100 + 1 + 10 + + + 100 + 1 + 10 + + + 100 + 1 + 10 + + + 100 + 1 + 10 + + + 100 + 1 + 10 + + + 100 + 1 + 10 + + + 100 + 1 + 10 + + + 100 + 1 + 10 + 2000 1 10 + + 100 + 1 + 10 + 2000 1 @@ -1310,13 +1370,13 @@ True False 0 - slidetitle + $.slide.slidetitle - Presentation title - Presentation author - Slide title - Slide footer - Slide credit + Presentation title + Presentation author + Slide title + Slide footer + Slide credit @@ -1359,7 +1419,7 @@ - + True False Height: @@ -1367,12 +1427,12 @@ 1 - 2 + 3 0 - + True False Corner x: @@ -1385,7 +1445,7 @@ - + True False Corner y: @@ -1393,7 +1453,7 @@ 1 - 2 + 3 1 @@ -1402,7 +1462,7 @@ True True 0 - adjustment13 + adjustment19 1 @@ -1410,11 +1470,11 @@ - + True True 0 - adjustment14 + adjustment20 1 @@ -1422,29 +1482,66 @@ - + True True 0 - adjustment15 + adjustment21 - 3 + 4 0 - + True True 0 - adjustment16 + adjustment22 - 3 + 4 1 + + + True + False + 8 + 0 + + % slide + units + + + + 5 + 0 + + + + + True + False + 0 + + % slide + units + + + + 2 + 0 + + + + + + + + @@ -1482,12 +1579,13 @@ - + True True True Sans 12 Preview text + True @@ -1496,7 +1594,7 @@ - + True True True @@ -1534,7 +1632,7 @@ - + True False @@ -1550,7 +1648,7 @@ - + True True True @@ -1563,7 +1661,7 @@ - + True True True @@ -1703,7 +1801,7 @@ True True 0 - adjustment13 + adjustment23 1 @@ -1715,7 +1813,7 @@ True True 0 - adjustment14 + adjustment24 1 @@ -1727,7 +1825,7 @@ True True 0 - adjustment15 + adjustment25 3 @@ -1739,7 +1837,7 @@ True True 0 - adjustment16 + adjustment26 3 @@ -1837,7 +1935,7 @@ True True 0 - adjustment1 + adjustment27 1 @@ -1849,7 +1947,7 @@ True True 0 - adjustment2 + adjustment28 1 @@ -1861,7 +1959,7 @@ True True 0 - adjustment3 + adjustment29 3 @@ -1873,7 +1971,7 @@ True True 0 - adjustment4 + adjustment30 3 diff --git a/src/frame.h b/src/frame.h index 2a15209..d0525f8 100644 --- a/src/frame.h +++ b/src/frame.h @@ -31,13 +31,6 @@ #include -typedef enum -{ - UNITS_SLIDE, - UNITS_FRAC -} LengthUnits; - - typedef enum { GRAD_NONE, diff --git a/src/sc_interp.c b/src/sc_interp.c index 73135af..86084b0 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -676,44 +676,15 @@ void update_geom(struct frame *fr) } -static LengthUnits get_units(const char *t) +static int calculate_dims(const char *opt, struct frame *parent, + double *wp, double *hp, double *xp, double *yp) { - size_t len = strlen(t); - - if ( t[len-1] == 'f' ) return UNITS_FRAC; - if ( t[len-1] == 'u' ) return UNITS_SLIDE; - - fprintf(stderr, _("Invalid units in '%s'\n"), t); - return UNITS_SLIDE; -} - - -static int parse_dims(const char *opt, struct frame *parent, - double *wp, double *hp, double *xp, double *yp) -{ - char *w; - char *h; - char *x; - char *y; - char *check; LengthUnits h_units, w_units; - /* Looks like a dimension/position thing */ - w = strdup(opt); - h = index(w, 'x'); - h[0] = '\0'; h++; - - x = index(h, '+'); - if ( x == NULL ) goto invalid; - x[0] = '\0'; x++; - - y = index(x, '+'); - if ( x == NULL ) goto invalid; - y[0] = '\0'; y++; + if ( parse_dims(opt, wp, hp, &w_units, &h_units, xp, yp) ) { + return 1; + } - *wp = strtod(w, &check); - if ( check == w ) goto invalid; - w_units = get_units(w); if ( w_units == UNITS_FRAC ) { if ( parent != NULL ) { double pw = parent->w; @@ -725,10 +696,6 @@ static int parse_dims(const char *opt, struct frame *parent, } } - - *hp = strtod(h, &check); - if ( check == h ) goto invalid; - h_units = get_units(h); if ( h_units == UNITS_FRAC ) { if ( parent != NULL ) { double ph = parent->h; @@ -740,16 +707,7 @@ static int parse_dims(const char *opt, struct frame *parent, } } - *xp= strtod(x, &check); - if ( check == x ) goto invalid; - *yp = strtod(y, &check); - if ( check == y ) goto invalid; - return 0; - -invalid: - fprintf(stderr, _("Invalid dimensions '%s'\n"), opt); - return 1; } @@ -758,7 +716,7 @@ static int parse_frame_option(const char *opt, struct frame *fr, { if ( (index(opt, 'x') != NULL) && (index(opt, '+') != NULL) && (index(opt, '+') != rindex(opt, '+')) ) { - return parse_dims(opt, parent, &fr->w, &fr->h, &fr->x, &fr->y); + return calculate_dims(opt, parent, &fr->w, &fr->h, &fr->x, &fr->y); } fprintf(stderr, _("Unrecognised frame option '%s'\n"), opt); @@ -811,7 +769,7 @@ static int parse_image_option(const char *opt, struct frame *parent, if ( (index(opt, 'x') != NULL) && (index(opt, '+') != NULL) && (index(opt, '+') != rindex(opt, '+')) ) { double dum; - return parse_dims(opt, NULL, wp, hp, &dum, &dum); + return calculate_dims(opt, NULL, wp, hp, &dum, &dum); } if ( strncmp(opt, "filename=\"", 10) == 0 ) { diff --git a/src/stylesheet.c b/src/stylesheet.c index 52bc4ff..51e8bd4 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -133,7 +133,12 @@ static JsonObject *find_stylesheet_object(Stylesheet *ss, const char *path, node = json_path_query(path, ss->root, &err); array = json_node_get_array(node); - if ( json_array_get_length(array) != 1 ) { + if ( json_array_get_length(array) == 0 ) { + json_node_unref(node); + return NULL; + } + + if ( json_array_get_length(array) > 1 ) { json_node_unref(node); fprintf(stderr, "More than one result in SS lookup (%s)!\n", path); return NULL; @@ -158,11 +163,12 @@ char *stylesheet_lookup(Stylesheet *ss, const char *path, const char *key) JsonNode *node = NULL; if ( ss == NULL ) { - fprintf(stderr, _("No stylesheet!\n")); + fprintf(stderr, "No stylesheet!\n"); return NULL; } obj = find_stylesheet_object(ss, path, &node); + if ( obj == NULL ) return NULL; if ( json_object_has_member(obj, key) ) { diff --git a/src/stylesheet_editor.c b/src/stylesheet_editor.c index 1d899c7..0eb7fde 100644 --- a/src/stylesheet_editor.c +++ b/src/stylesheet_editor.c @@ -44,6 +44,7 @@ G_DEFINE_TYPE_WITH_CODE(StylesheetEditor, stylesheet_editor, struct _sspriv { struct presentation *p; + const gchar *furniture; char *ssdata; }; @@ -85,11 +86,45 @@ static void set_vals_from_ss(Stylesheet *ss, const char *path, const char *key, fprintf(stderr, _("Failed to parse quad: %s\n"), result); } } else { - printf("Not found %s\n", path); + printf("Not found %s.%s\n", path, key); } } +static void set_geom_from_ss(Stylesheet *ss, const char *path, const char *key, + GtkWidget *ww, GtkWidget *wh, + GtkWidget *wx, GtkWidget *wy, + GtkWidget *wwu, GtkWidget *whu) +{ + char *result = stylesheet_lookup(ss, path, key); + if ( result != NULL ) { + double x, y, w, h; + LengthUnits wu, hu; + if ( parse_dims(result, &w, &h, &wu, &hu, &x, &y) == 0 ) { + if ( wu == UNITS_FRAC ) { + w *= 100; + gtk_combo_box_set_active_id(GTK_COMBO_BOX(wwu), "percent"); + } else { + gtk_combo_box_set_active_id(GTK_COMBO_BOX(wwu), "units"); + } + if ( hu == UNITS_FRAC ) { + h *= 100; + gtk_combo_box_set_active_id(GTK_COMBO_BOX(whu), "percent"); + } else { + gtk_combo_box_set_active_id(GTK_COMBO_BOX(whu), "units"); + } + gtk_spin_button_set_value(GTK_SPIN_BUTTON(ww), w); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(wh), h); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(wx), x); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(wy), y); + } else { + fprintf(stderr, _("Failed to parse dims: %s\n"), result); + } + } else { + printf("Not found %s.%s\n", path, key); + } +} + static void set_size_from_ss(Stylesheet *ss, const char *path, GtkWidget *ww, GtkWidget *wh) { @@ -103,7 +138,7 @@ static void set_size_from_ss(Stylesheet *ss, const char *path, fprintf(stderr, _("Failed to parse double: %s\n"), result); } } else { - printf("Not found %s\n", path); + printf("Not found %s.size\n", path); } } @@ -188,6 +223,39 @@ static void set_bg_from_ss(Stylesheet *ss, const char *path, GtkWidget *wcol, } +static void set_furniture(StylesheetEditor *se, const char *furniture) +{ + set_geom_from_ss(se->priv->p->stylesheet, furniture, "geometry", + se->furniture_w, + se->furniture_h, + se->furniture_x, + se->furniture_y, + se->furniture_w_units, + se->furniture_h_units); + + set_vals_from_ss(se->priv->p->stylesheet, furniture, "pad", + se->furniture_padding_l, + se->furniture_padding_r, + se->furniture_padding_t, + se->furniture_padding_b); + + set_vals_from_ss(se->priv->p->stylesheet, furniture, "paraspace", + se->furniture_paraspace_l, + se->furniture_paraspace_r, + se->furniture_paraspace_t, + se->furniture_paraspace_b); + + set_font_from_ss(se->priv->p->stylesheet, furniture, se->furniture_font); + set_col_from_ss(se->priv->p->stylesheet, furniture, se->furniture_fgcol); + set_alignment_from_ss(se->priv->p->stylesheet, furniture, + se->furniture_alignment); + set_bg_from_ss(se->priv->p->stylesheet, furniture, se->furniture_bgcol, + se->furniture_bgcol2, se->furniture_bggrad); +} + + + + static void set_values_from_presentation(StylesheetEditor *se) { Stylesheet *ss = se->priv->p->stylesheet; @@ -230,6 +298,8 @@ static void set_values_from_presentation(StylesheetEditor *se) se->frame_style_paraspace_r, se->frame_style_paraspace_t, se->frame_style_paraspace_b); + + set_furniture(se, se->priv->furniture); } @@ -309,7 +379,7 @@ static void update_spacing(struct presentation *p, const char *style_name, v[3] = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(wb)); if ( snprintf(tmp, 256, "%i,%i,%i,%i", v[0], v[1], v[2], v[3]) >= 256 ) { - fprintf(stderr, _("Spacing too long\n")); + fprintf(stderr, "Spacing too long\n"); } else { stylesheet_set(p->stylesheet, style_name, key, tmp); } @@ -332,6 +402,7 @@ static void set_font(GtkFontButton *widget, StylesheetEditor *se, font = gtk_font_button_get_font_name(GTK_FONT_BUTTON(widget)); stylesheet_set(se->priv->p->stylesheet, style_name, "font", font); + printf("setting %s . %s to %s\n", style_name, "font", font); set_values_from_presentation(se); g_signal_emit_by_name(se, "changed"); } @@ -495,13 +566,30 @@ static void narrative_paraspace_sig(GtkSpinButton *widget, StylesheetEditor *se) } +static void furniture_paraspace_sig(GtkSpinButton *widget, StylesheetEditor *se) +{ +} + + +static void furniture_padding_sig(GtkSpinButton *widget, StylesheetEditor *se) +{ +} + + static void furniture_selector_change_sig(GtkComboBoxText *widget, StylesheetEditor *se) { - const gchar *id = gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget)); - printf("furniture %s\n", id); + se->priv->furniture = gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget)); + set_furniture(se, se->priv->furniture); +} + + +static void furniture_font_sig(GtkFontButton *widget, StylesheetEditor *se) +{ + set_font(widget, se, se->priv->furniture); } + static void stylesheet_editor_finalize(GObject *obj) { StylesheetEditor *se = COLLOQUIUM_STYLESHEET_EDITOR(obj); @@ -574,6 +662,26 @@ void stylesheet_editor_class_init(StylesheetEditorClass *klass) /* Furniture */ SE_BIND_CHILD(furniture_selector, furniture_selector_change_sig); + SE_BIND_CHILD(furniture_paraspace_l, furniture_paraspace_sig); + SE_BIND_CHILD(furniture_paraspace_r, furniture_paraspace_sig); + SE_BIND_CHILD(furniture_paraspace_t, furniture_paraspace_sig); + SE_BIND_CHILD(furniture_paraspace_b, furniture_paraspace_sig); + SE_BIND_CHILD(furniture_padding_l, furniture_padding_sig); + SE_BIND_CHILD(furniture_padding_r, furniture_padding_sig); + SE_BIND_CHILD(furniture_padding_t, furniture_padding_sig); + SE_BIND_CHILD(furniture_padding_b, furniture_padding_sig); + SE_BIND_CHILD(furniture_font, furniture_font_sig); + SE_BIND_CHILD(furniture_fgcol, NULL); + SE_BIND_CHILD(furniture_bgcol, NULL); + SE_BIND_CHILD(furniture_bgcol2, NULL); + SE_BIND_CHILD(furniture_bggrad, NULL); + SE_BIND_CHILD(furniture_alignment, NULL); + SE_BIND_CHILD(furniture_w, NULL); + SE_BIND_CHILD(furniture_h, NULL); + SE_BIND_CHILD(furniture_x, NULL); + SE_BIND_CHILD(furniture_y, NULL); + SE_BIND_CHILD(furniture_w_units, NULL); + SE_BIND_CHILD(furniture_h_units, NULL); gtk_widget_class_bind_template_callback(widget_class, revert_sig); @@ -590,6 +698,7 @@ StylesheetEditor *stylesheet_editor_new(struct presentation *p) if ( se == NULL ) return NULL; se->priv->p = p; + se->priv->furniture = gtk_combo_box_get_active_id(GTK_COMBO_BOX(se->furniture_selector)); set_values_from_presentation(se); se->priv->ssdata = stylesheet_data(p->stylesheet); diff --git a/src/stylesheet_editor.h b/src/stylesheet_editor.h index f9e5f65..a7c77b6 100644 --- a/src/stylesheet_editor.h +++ b/src/stylesheet_editor.h @@ -92,6 +92,26 @@ struct _stylesheeteditor GtkWidget *frame_style_padding_b; GtkWidget *frame_style_alignment; GtkWidget *furniture_selector; + GtkWidget *furniture_paraspace_l; + GtkWidget *furniture_paraspace_r; + GtkWidget *furniture_paraspace_t; + GtkWidget *furniture_paraspace_b; + GtkWidget *furniture_padding_l; + GtkWidget *furniture_padding_r; + GtkWidget *furniture_padding_t; + GtkWidget *furniture_padding_b; + GtkWidget *furniture_font; + GtkWidget *furniture_fgcol; + GtkWidget *furniture_bgcol; + GtkWidget *furniture_bgcol2; + GtkWidget *furniture_bggrad; + GtkWidget *furniture_alignment; + GtkWidget *furniture_w; + GtkWidget *furniture_h; + GtkWidget *furniture_x; + GtkWidget *furniture_y; + GtkWidget *furniture_w_units; + GtkWidget *furniture_h_units; StylesheetEditorPrivate *priv; }; diff --git a/src/utils.c b/src/utils.c index 277b3f1..b41f344 100644 --- a/src/utils.c +++ b/src/utils.c @@ -81,3 +81,57 @@ int parse_tuple(const char *a, float v[4]) return 0; } + +static LengthUnits get_units(const char *t) +{ + size_t len = strlen(t); + + if ( t[len-1] == 'f' ) return UNITS_FRAC; + if ( t[len-1] == 'u' ) return UNITS_SLIDE; + + fprintf(stderr, _("Invalid units in '%s'\n"), t); + return UNITS_SLIDE; +} + + +int parse_dims(const char *opt, double *wp, double *hp, + LengthUnits *wup, LengthUnits *hup, + double *xp, double *yp) +{ + char *w; + char *h; + char *x; + char *y; + char *check; + + w = strdup(opt); + h = index(w, 'x'); + h[0] = '\0'; h++; + + x = index(h, '+'); + if ( x == NULL ) goto invalid; + x[0] = '\0'; x++; + + y = index(x, '+'); + if ( x == NULL ) goto invalid; + y[0] = '\0'; y++; + + *wp = strtod(w, &check); + if ( check == w ) goto invalid; + *wup = get_units(w); + + *hp = strtod(h, &check); + if ( check == h ) goto invalid; + *hup = get_units(h); + + *xp= strtod(x, &check); + if ( check == x ) goto invalid; + *yp = strtod(y, &check); + if ( check == y ) goto invalid; + + return 0; + +invalid: + fprintf(stderr, _("Invalid dimensions '%s'\n"), opt); + return 1; +} diff --git a/src/utils.h b/src/utils.h index fc843c3..af3c7b8 100644 --- a/src/utils.h +++ b/src/utils.h @@ -27,11 +27,19 @@ #include #endif +typedef enum +{ + UNITS_SLIDE, + UNITS_FRAC +} LengthUnits; extern void chomp(char *s); extern int safe_strcmp(const char *a, const char *b); extern int parse_double(const char *a, float v[2]); extern int parse_tuple(const char *a, float v[4]); +extern int parse_dims(const char *opt, double *wp, double *hp, + LengthUnits *wup, LengthUnits *hup, + double *xp, double *yp); #include #define _(x) gettext(x) -- cgit v1.2.3