From c03f628de793e170d9f62c5b786fe18891bb6fa3 Mon Sep 17 00:00:00 2001 From: Jeremy Attali Date: Sun, 5 Jan 2020 16:17:19 -0500 Subject: [PATCH] feat(text): add controls in toggle panel --- include/application.h | 4 +++ include/swappy.h | 10 ++++-- res/swappy.ui | 82 ++++++++++++++++++++++++++++++++++++++++++- src/application.c | 45 ++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 4 deletions(-) diff --git a/include/application.h b/include/application.h index 04fd777..5d33a66 100644 --- a/include/application.h +++ b/include/application.h @@ -51,3 +51,7 @@ void stroke_size_decrease_handler(GtkWidget *widget, void stroke_size_reset_handler(GtkWidget *widget, struct swappy_state *state); void stroke_size_increase_handler(GtkWidget *widget, struct swappy_state *state); + +void text_size_decrease_handler(GtkWidget *widget, struct swappy_state *state); +void text_size_reset_handler(GtkWidget *widget, struct swappy_state *state); +void text_size_increase_handler(GtkWidget *widget, struct swappy_state *state); \ No newline at end of file diff --git a/include/swappy.h b/include/swappy.h index 1ba025c..6bd10ca 100644 --- a/include/swappy.h +++ b/include/swappy.h @@ -17,12 +17,15 @@ #define GEOMETRY_PATTERN "xx,yy wwxhh" -#define SWAPPY_STROKE_SIZE_MIN 1 #define SWAPPY_STROKE_SIZE_DEFAULT 5 -#define SWAPPY_TEXT_FONT_DEFAULT "serif" -#define SWAPPY_TEXT_SIZE_DEFAULT 21 +#define SWAPPY_STROKE_SIZE_MIN 1 #define SWAPPY_STROKE_SIZE_MAX 50 +#define SWAPPY_TEXT_FONT_DEFAULT "serif" +#define SWAPPY_TEXT_SIZE_DEFAULT 20 +#define SWAPPY_TEXT_SIZE_MIN 10 +#define SWAPPY_TEXT_SIZE_MAX 50 + enum swappy_paint_type { SWAPPY_PAINT_MODE_BRUSH = 0, /* Brush mode to draw arbitrary shapes */ SWAPPY_PAINT_MODE_TEXT, /* Mode to draw texts */ @@ -123,6 +126,7 @@ struct swappy_state_ui { GtkColorButton *color; GtkButton *stroke_size; + GtkButton *text_size; }; struct swappy_buffer { diff --git a/res/swappy.ui b/res/swappy.ui index ed73b74..65f61aa 100644 --- a/res/swappy.ui +++ b/res/swappy.ui @@ -17,6 +17,11 @@ False zoom-in + + True + False + zoom-in + True False @@ -67,8 +72,8 @@ edit-redo True - + True @@ -506,6 +511,7 @@ True False + 10 2 True @@ -571,6 +577,75 @@ 3 + + + True + False + 2 + True + + + True + False + Text Size + + + False + True + 0 + + + + + True + True + True + zoom-out1 + True + + + + False + False + 1 + + + + + True + True + True + True + + + + False + True + 2 + + + + + True + True + True + zoom-in1 + True + + + + False + False + 3 + + + + + False + True + 4 + + False @@ -613,4 +688,9 @@ + + True + False + zoom-out + diff --git a/src/application.c b/src/application.c index 10a439a..178f533 100644 --- a/src/application.c +++ b/src/application.c @@ -28,6 +28,13 @@ static void update_ui_stroke_size_widget(struct swappy_state *state) { gtk_button_set_label(button, label); } +static void update_ui_text_size_widget(struct swappy_state *state) { + GtkButton *button = GTK_BUTTON(state->ui->text_size); + char label[255]; + snprintf(label, 255, "%.0lf", state->settings.t); + gtk_button_set_label(button, label); +} + static void action_undo(struct swappy_state *state) { GList *first = state->paints; @@ -132,6 +139,31 @@ static void action_stroke_size_increase(struct swappy_state *state) { update_ui_stroke_size_widget(state); } +static void action_text_size_decrease(struct swappy_state *state) { + guint step = state->settings.t <= 20 ? 1 : 5; + state->settings.t -= step; + + if (state->settings.t < SWAPPY_TEXT_SIZE_MIN) { + state->settings.t = SWAPPY_TEXT_SIZE_MIN; + } + + update_ui_text_size_widget(state); +} +static void action_text_size_reset(struct swappy_state *state) { + state->settings.t = SWAPPY_TEXT_SIZE_DEFAULT; + update_ui_text_size_widget(state); +} +static void action_text_size_increase(struct swappy_state *state) { + guint step = state->settings.t >= 20 ? 5 : 1; + state->settings.t += step; + + if (state->settings.t > SWAPPY_TEXT_SIZE_MAX) { + state->settings.t = SWAPPY_TEXT_SIZE_MAX; + } + + update_ui_text_size_widget(state); +} + void brush_clicked_handler(GtkWidget *widget, struct swappy_state *state) { switch_mode_to_brush(state); } @@ -452,6 +484,16 @@ void stroke_size_increase_handler(GtkWidget *widget, action_stroke_size_increase(state); } +void text_size_decrease_handler(GtkWidget *widget, struct swappy_state *state) { + action_text_size_decrease(state); +} +void text_size_reset_handler(GtkWidget *widget, struct swappy_state *state) { + action_text_size_reset(state); +} +void text_size_increase_handler(GtkWidget *widget, struct swappy_state *state) { + action_text_size_increase(state); +} + static void apply_css(GtkWidget *widget, GtkStyleProvider *provider) { gtk_style_context_add_provider(gtk_widget_get_style_context(widget), provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); @@ -520,6 +562,8 @@ static bool load_layout(struct swappy_state *state) { state->ui->stroke_size = GTK_BUTTON(gtk_builder_get_object(builder, "stroke-size-button")); + state->ui->text_size = + GTK_BUTTON(gtk_builder_get_object(builder, "text-size-button")); gtk_widget_set_size_request(area, geometry->width, geometry->height); @@ -553,6 +597,7 @@ static bool init_gtk_window(struct swappy_state *state) { } update_ui_stroke_size_widget(state); + update_ui_text_size_widget(state); update_ui_undo_redo(state); return true;