application: implement signal for brush button

This commit is contained in:
Jeremy Attali 2019-12-16 22:30:22 -05:00
parent b41c572f1e
commit 5a006cf1f6
4 changed files with 17 additions and 2 deletions

View File

@ -6,3 +6,4 @@ bool application_init(struct swappy_state *state);
int application_run(struct swappy_state *state);
void application_finish(struct swappy_state *state);
void brush_clicked_handler(GtkWidget *widget, struct swappy_state *state);

View File

@ -53,6 +53,7 @@ executable(
wayland_client,
wayland_cursor,
],
link_args: '-rdynamic',
include_directories: [swappy_inc],
install: true,
)

View File

@ -162,6 +162,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="brush_clicked_handler" swapped="no"/>
<style>
<class name="brush"/>
</style>

View File

@ -18,6 +18,11 @@ static void swappy_overlay_clear(struct swappy_state *state) {
}
}
static void switch_mode_to_brush(struct swappy_state *state) {
g_debug("switching mode to brush");
state->mode = SWAPPY_PAINT_MODE_BRUSH;
}
void application_finish(struct swappy_state *state) {
g_debug("application is shutting down");
swappy_overlay_clear(state);
@ -29,6 +34,10 @@ 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);
@ -119,12 +128,13 @@ static void tools_menu_button_copy_clicked_handler(GtkToggleButton *source,
}
static void keypress_handler(GtkWidget *widget, GdkEventKey *event,
gpointer data) {
struct swappy_state *state = data;
struct swappy_state *state) {
g_debug("keypress_handler key pressed: %d\n", event->keyval);
if (event->keyval == GDK_KEY_Escape) {
g_debug("keypress_handler: escape key pressed, ciao bye\n");
gtk_window_close(state->window);
} else if (event->keyval == GDK_KEY_B || event->keyval == GDK_KEY_b) {
switch_mode_to_brush(state);
}
}
@ -232,6 +242,8 @@ static bool load_layout(struct swappy_state *state) {
area = GTK_WIDGET(gtk_builder_get_object(builder, "paint_area"));
popover = GTK_POPOVER(gtk_builder_get_object(builder, "popover"));
gtk_builder_connect_signals(builder, state);
g_signal_connect(G_OBJECT(state->window), "key_press_event",
G_CALLBACK(keypress_handler), state);
g_signal_connect(brush, "toggled",