From aff5da9d4eb4ce403e9fac70ea17cd8db0d5dddc Mon Sep 17 00:00:00 2001 From: Jeremy Attali Date: Tue, 17 Dec 2019 00:11:01 -0500 Subject: [PATCH] application: adding more painting shapes --- include/application.h | 5 ++-- include/swappy.h | 5 +++- res/swappy.ui | 60 +++++++++++++++++++++++++++++++++++++++++-- src/application.c | 51 +++++++++++++++++++++++++++--------- 4 files changed, 104 insertions(+), 17 deletions(-) diff --git a/include/application.h b/include/application.h index 76c2dc2..d8bc44a 100644 --- a/include/application.h +++ b/include/application.h @@ -8,5 +8,6 @@ void application_finish(struct swappy_state *state); void brush_clicked_handler(GtkWidget *widget, struct swappy_state *state); void text_clicked_handler(GtkWidget *widget, struct swappy_state *state); -void arrow_clicked_handler(GtkWidget *widget, struct swappy_state *state); -void shape_clicked_handler(GtkWidget *widget, struct swappy_state *state); \ No newline at end of file +void rectangle_clicked_handler(GtkWidget *widget, struct swappy_state *state); +void ellipse_clicked_handler(GtkWidget *widget, struct swappy_state *state); +void arrow_clicked_handler(GtkWidget *widget, struct swappy_state *state); \ No newline at end of file diff --git a/include/swappy.h b/include/swappy.h index f8c2c22..c6c01aa 100644 --- a/include/swappy.h +++ b/include/swappy.h @@ -24,8 +24,9 @@ enum swappy_brush_point_kind { enum swappy_paint_mode_type { SWAPPY_PAINT_MODE_BRUSH = 0, /* Brush mode to draw arbitrary shapes */ SWAPPY_PAINT_MODE_TEXT, /* Mode to draw texts */ - SWAPPY_PAINT_MODE_ARROW, /* Rectangle shapes */ SWAPPY_PAINT_MODE_RECTANGLE, /* Rectangle shapes */ + SWAPPY_PAINT_MODE_ELLIPSE, /* Ellipse shapes */ + SWAPPY_PAINT_MODE_ARROW, /* Arrow shapes */ }; struct swappy_brush_point { @@ -50,6 +51,8 @@ struct swappy_state_ui_popover { GtkRadioButton *brush; GtkRadioButton *text; GtkRadioButton *rectangle; + GtkRadioButton *ellipse; + GtkRadioButton *arrow; }; struct swappy_state { diff --git a/res/swappy.ui b/res/swappy.ui index d845391..0ae85a0 100644 --- a/res/swappy.ui +++ b/res/swappy.ui @@ -128,7 +128,7 @@ True False - R,O,A + R False @@ -136,6 +136,30 @@ 2 + + + True + False + O + + + False + True + 3 + + + + + True + False + A + + + False + True + 4 + + @@ -185,7 +209,7 @@ - + True True False @@ -199,6 +223,38 @@ 2 + + + + True + True + False + False + brush + + + + False + True + 3 + + + + + + True + True + False + False + brush + + + + False + True + 4 + + diff --git a/src/application.c b/src/application.c index d2ea1e5..084e5ec 100644 --- a/src/application.c +++ b/src/application.c @@ -28,28 +28,41 @@ static void switch_mode_to_text(struct swappy_state *state) { state->mode = SWAPPY_PAINT_MODE_TEXT; } +static void switch_mode_to_rectangle(struct swappy_state *state) { + g_debug("switching mode to rectangle"); + state->mode = SWAPPY_PAINT_MODE_RECTANGLE; +} + +static void switch_mode_to_ellipse(struct swappy_state *state) { + g_debug("switching mode to ellipse"); + state->mode = SWAPPY_PAINT_MODE_ELLIPSE; +} + static void switch_mode_to_arrow(struct swappy_state *state) { g_debug("switching mode to arrow"); state->mode = SWAPPY_PAINT_MODE_ARROW; } -static void switch_mode_to_rectangle(struct swappy_state *state) { - g_debug("switching mode to rectangle"); - state->mode = SWAPPY_PAINT_MODE_RECTANGLE; +void brush_clicked_handler(GtkWidget *widget, struct swappy_state *state) { + switch_mode_to_brush(state); } void text_clicked_handler(GtkWidget *widget, struct swappy_state *state) { switch_mode_to_text(state); } -void arrow_clicked_handler(GtkWidget *widget, struct swappy_state *state) { - switch_mode_to_arrow(state); -} - void rectangle_clicked_handler(GtkWidget *widget, struct swappy_state *state) { switch_mode_to_rectangle(state); } +void ellipse_clicked_handler(GtkWidget *widget, struct swappy_state *state) { + switch_mode_to_ellipse(state); +} + +void arrow_clicked_handler(GtkWidget *widget, struct swappy_state *state) { + switch_mode_to_arrow(state); +} + void application_finish(struct swappy_state *state) { g_debug("application is shutting down"); swappy_overlay_clear(state); @@ -62,10 +75,6 @@ void application_finish(struct swappy_state *state) { g_object_unref(state->app); } -void brush_clicked_handler(GtkWidget *widget, struct swappy_state *state) { - switch_mode_to_brush(state); -} - static gboolean draw_area_handler(GtkWidget *widget, cairo_t *cr, struct swappy_state *state) { cairo_set_source_surface(cr, state->cairo_surface, 0, 0); @@ -168,6 +177,18 @@ static void keypress_handler(GtkWidget *widget, GdkEventKey *event, } else if (event->keyval == GDK_KEY_T || event->keyval == GDK_KEY_t) { switch_mode_to_text(state); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->text), true); + } else if (event->keyval == GDK_KEY_R || event->keyval == GDK_KEY_r) { + switch_mode_to_rectangle(state); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->rectangle), + true); + } else if (event->keyval == GDK_KEY_O || event->keyval == GDK_KEY_o) { + switch_mode_to_ellipse(state); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->ellipse), + true); + } else if (event->keyval == GDK_KEY_A || event->keyval == GDK_KEY_a) { + switch_mode_to_arrow(state); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->arrow), + true); } } @@ -254,6 +275,8 @@ static bool load_layout(struct swappy_state *state) { GtkRadioButton *brush; GtkRadioButton *text; GtkRadioButton *rectangle; + GtkRadioButton *ellipse; + GtkRadioButton *arrow; GError *error = NULL; /* Construct a GtkBuilder instance and load our UI description */ @@ -276,7 +299,9 @@ static bool load_layout(struct swappy_state *state) { popover = GTK_POPOVER(gtk_builder_get_object(builder, "popover")); brush = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "brush")); text = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "text")); - rectangle = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "shape")); + rectangle = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "rectangle")); + ellipse = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "ellipse")); + arrow = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "arrow")); gtk_builder_connect_signals(builder, state); @@ -316,6 +341,8 @@ static bool load_layout(struct swappy_state *state) { state->popover->brush = brush; state->popover->text = text; state->popover->rectangle = rectangle; + state->popover->ellipse = ellipse; + state->popover->arrow = arrow; state->area = area; g_object_unref(G_OBJECT(builder));