Skip to content

Commit

Permalink
feat(ui): add keybindings for color change
Browse files Browse the repository at this point in the history
  • Loading branch information
jtheoof committed Dec 27, 2019
1 parent 562a9a6 commit c5ec285
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
5 changes: 4 additions & 1 deletion include/swappy.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ struct swappy_state_ui {
GtkRadioButton *arrow;

GtkRadioButton *red;
GtkColorButton *custom;
GtkRadioButton *green;
GtkRadioButton *blue;
GtkRadioButton *custom;
GtkColorButton *color;

GtkButton *stroke_size;
};
Expand Down
4 changes: 2 additions & 2 deletions res/swappy.ui
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
<property name="image">edit-redo</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="redo_clicked_handler" swapped="no"/>
<accelerator key="z" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
<accelerator key="y" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
<accelerator key="z" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
</object>
<packing>
<property name="expand">True</property>
Expand Down Expand Up @@ -440,7 +440,7 @@
<property name="margin_left">12</property>
<property name="spacing">5</property>
<child>
<object class="GtkRadioButton" id="color-button-custom">
<object class="GtkRadioButton" id="color-custom-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
Expand Down
27 changes: 25 additions & 2 deletions src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ static void action_update_color_state(struct swappy_state *state, double r,
state->painting.b = b;
state->painting.a = a;

gtk_widget_set_sensitive(GTK_WIDGET(state->ui->custom), custom);
gtk_widget_set_sensitive(GTK_WIDGET(state->ui->color), custom);
}

static void action_set_color_from_custom(struct swappy_state *state) {
GdkRGBA color;
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(state->ui->custom), &color);
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(state->ui->color), &color);

action_update_color_state(state, color.red, color.green, color.blue,
color.alpha, true);
Expand Down Expand Up @@ -272,6 +272,23 @@ void window_keypress_handler(GtkWidget *widget, GdkEventKey *event,
case GDK_KEY_k:
action_clear(state);
break;
case GDK_KEY_R:
action_update_color_state(state, 1, 0, 0, 1, false);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->red), true);
break;
case GDK_KEY_G:
action_update_color_state(state, 0, 1, 0, 1, false);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->green), true);
break;
case GDK_KEY_B:
action_update_color_state(state, 0, 0, 1, 1, false);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->blue), true);
break;
case GDK_KEY_C:
action_set_color_from_custom(state);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->custom),
true);
break;
case GDK_KEY_minus:
action_stroke_size_decrease(state);
break;
Expand Down Expand Up @@ -474,7 +491,13 @@ static bool load_layout(struct swappy_state *state) {

state->ui->red =
GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "color-red-button"));
state->ui->green =
GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "color-green-button"));
state->ui->blue =
GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "color-blue-button"));
state->ui->custom =
GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "color-custom-button"));
state->ui->color =
GTK_COLOR_BUTTON(gtk_builder_get_object(builder, "custom-color-button"));

state->ui->stroke_size =
Expand Down

0 comments on commit c5ec285

Please sign in to comment.