feat(ui): add keybindings for color change

This commit is contained in:
Jeremy Attali 2019-12-27 16:21:13 -05:00
parent 562a9a6e92
commit c5ec285ee7
3 changed files with 31 additions and 5 deletions

View File

@ -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;
};

View File

@ -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>
@ -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>

View File

@ -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);
@ -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;
@ -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 =