From e61b873f084e43b1bccff10a64e9392d240562b9 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 10 Nov 2018 20:11:42 +0100 Subject: Make furniture widgets work --- data/stylesheeteditor.ui | 27 ++++++++-- src/stylesheet_editor.c | 126 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 129 insertions(+), 24 deletions(-) diff --git a/data/stylesheeteditor.ui b/data/stylesheeteditor.ui index e02a8e8..626d3a5 100644 --- a/data/stylesheeteditor.ui +++ b/data/stylesheeteditor.ui @@ -53,7 +53,7 @@ 10 - 100 + 5000 1 10 @@ -63,17 +63,17 @@ 10 - 100 + 5000 1 10 - 100 + 5000 1 10 - 100 + 5000 1 10 @@ -1463,6 +1463,7 @@ True 0 adjustment19 + 1 @@ -1475,6 +1476,7 @@ True 0 adjustment20 + 1 @@ -1487,6 +1489,7 @@ True 0 adjustment21 + 4 @@ -1499,6 +1502,7 @@ True 0 adjustment22 + 4 @@ -1515,6 +1519,7 @@ % slide units + 5 @@ -1530,6 +1535,7 @@ % slide units + 2 @@ -1599,6 +1605,7 @@ True True True + False @@ -1640,6 +1647,7 @@ Horizontal gradient Vertical gradient + True @@ -1653,6 +1661,7 @@ True True True + False @@ -1666,6 +1675,7 @@ True True True + False @@ -1709,6 +1719,7 @@ Center Right + False @@ -1802,6 +1813,7 @@ True 0 adjustment23 + 1 @@ -1814,6 +1826,7 @@ True 0 adjustment24 + 1 @@ -1826,6 +1839,7 @@ True 0 adjustment25 + 3 @@ -1838,6 +1852,7 @@ True 0 adjustment26 + 3 @@ -1936,6 +1951,7 @@ True 0 adjustment27 + 1 @@ -1948,6 +1964,7 @@ True 0 adjustment28 + 1 @@ -1960,6 +1977,7 @@ True 0 adjustment29 + 3 @@ -1972,6 +1990,7 @@ True 0 adjustment30 + 3 diff --git a/src/stylesheet_editor.c b/src/stylesheet_editor.c index 0eb7fde..292bbf1 100644 --- a/src/stylesheet_editor.c +++ b/src/stylesheet_editor.c @@ -254,8 +254,6 @@ static void set_furniture(StylesheetEditor *se, const char *furniture) } - - static void set_values_from_presentation(StylesheetEditor *se) { Stylesheet *ss = se->priv->p->stylesheet; @@ -386,6 +384,46 @@ static void update_spacing(struct presentation *p, const char *style_name, } +static char units_id_to_char(const char *id) +{ + if ( strcmp(id, "units") == 0 ) return 'u'; + if ( strcmp(id, "percent") == 0 ) return 'f'; + return 'u'; +} + + +static void update_ss_dims(struct presentation *p, const char *style_name, + const char *key, GtkWidget *ww, GtkWidget *wh, + GtkWidget *wx, GtkWidget *wy, + GtkWidget *wwu, GtkWidget *whu) +{ + float w, h, x, y; + char w_units, h_units; + const gchar *uid; + char tmp[256]; + + w = gtk_spin_button_get_value(GTK_SPIN_BUTTON(ww)); + h = gtk_spin_button_get_value(GTK_SPIN_BUTTON(wh)); + x = gtk_spin_button_get_value(GTK_SPIN_BUTTON(wx)); + y = gtk_spin_button_get_value(GTK_SPIN_BUTTON(wy)); + uid = gtk_combo_box_get_active_id(GTK_COMBO_BOX(wwu)); + w_units = units_id_to_char(uid); + uid = gtk_combo_box_get_active_id(GTK_COMBO_BOX(whu)); + h_units = units_id_to_char(uid); + + if ( w_units == 'f' ) w /= 100.0; + if ( h_units == 'f' ) h /= 100.0; + + if ( snprintf(tmp, 256, "%.2f%cx%.2f%c+%.0f+%0.f", + w, w_units, h, h_units, x, y) >= 256 ) + { + fprintf(stderr, "Spacing too long\n"); + } else { + stylesheet_set(p->stylesheet, style_name, key, tmp); + } +} + + static void revert_sig(GtkButton *button, StylesheetEditor *se) { stylesheet_set_data(se->priv->p->stylesheet, @@ -402,7 +440,6 @@ 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"); } @@ -566,30 +603,79 @@ static void narrative_paraspace_sig(GtkSpinButton *widget, StylesheetEditor *se) } +static void furniture_selector_change_sig(GtkComboBoxText *widget, StylesheetEditor *se) +{ + 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 furniture_fgcol_sig(GtkColorButton *widget, StylesheetEditor *se) +{ + set_col(widget, se,se->priv->furniture, "fgcol"); +} + + +static void furniture_bg_sig(GtkColorButton *widget, StylesheetEditor *se) +{ + update_bg(se->priv->p, se->priv->furniture, se->furniture_bggrad, + se->furniture_bgcol, se->furniture_bgcol2); + set_values_from_presentation(se); + g_signal_emit_by_name(se, "changed"); +} + + static void furniture_paraspace_sig(GtkSpinButton *widget, StylesheetEditor *se) { + update_spacing(se->priv->p, se->priv->furniture, "pad", + se->furniture_padding_l, + se->furniture_padding_r, + se->furniture_padding_t, + se->furniture_padding_b); + set_values_from_presentation(se); + g_signal_emit_by_name(se, "changed"); } static void furniture_padding_sig(GtkSpinButton *widget, StylesheetEditor *se) { + update_spacing(se->priv->p, se->priv->furniture, "pad", + se->furniture_padding_l, + se->furniture_padding_r, + se->furniture_padding_t, + se->furniture_padding_b); + set_values_from_presentation(se); + g_signal_emit_by_name(se, "changed"); } -static void furniture_selector_change_sig(GtkComboBoxText *widget, StylesheetEditor *se) +static void furniture_alignment_sig(GtkComboBoxText *widget, StylesheetEditor *se) { - se->priv->furniture = gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget)); - set_furniture(se, se->priv->furniture); + const gchar *id = gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget)); + stylesheet_set(se->priv->p->stylesheet, se->priv->furniture, + "alignment", id); + set_values_from_presentation(se); + g_signal_emit_by_name(se, "changed"); } -static void furniture_font_sig(GtkFontButton *widget, StylesheetEditor *se) +static void furniture_dims_sig(GtkSpinButton *widget, StylesheetEditor *se) { - set_font(widget, se, se->priv->furniture); + update_ss_dims(se->priv->p, se->priv->furniture, "geometry", + se->furniture_w, se->furniture_h, + se->furniture_x, se->furniture_y, + se->furniture_w_units, se->furniture_h_units); + set_values_from_presentation(se); + g_signal_emit_by_name(se, "changed"); } - static void stylesheet_editor_finalize(GObject *obj) { StylesheetEditor *se = COLLOQUIUM_STYLESHEET_EDITOR(obj); @@ -671,17 +757,17 @@ void stylesheet_editor_class_init(StylesheetEditorClass *klass) 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); + SE_BIND_CHILD(furniture_fgcol, furniture_fgcol_sig); + SE_BIND_CHILD(furniture_bgcol, furniture_bg_sig); + SE_BIND_CHILD(furniture_bgcol2, furniture_bg_sig); + SE_BIND_CHILD(furniture_bggrad, furniture_bg_sig); + SE_BIND_CHILD(furniture_alignment, furniture_alignment_sig); + SE_BIND_CHILD(furniture_w, furniture_dims_sig); + SE_BIND_CHILD(furniture_h, furniture_dims_sig); + SE_BIND_CHILD(furniture_x, furniture_dims_sig); + SE_BIND_CHILD(furniture_y, furniture_dims_sig); + SE_BIND_CHILD(furniture_w_units, furniture_dims_sig); + SE_BIND_CHILD(furniture_h_units, furniture_dims_sig); gtk_widget_class_bind_template_callback(widget_class, revert_sig); -- cgit v1.2.3