Skip to content

Commit

Permalink
feat(ui): add binding to toggle panel
Browse files Browse the repository at this point in the history
  • Loading branch information
jtheoof committed Dec 26, 2019
1 parent bcc1314 commit e8d2f12
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/swappy.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct swappy_state_ui {
GtkButton *redo;

// Painting Area
GtkBox *painting_box;
GtkRadioButton *brush;
GtkRadioButton *text;
GtkRadioButton *rectangle;
Expand Down
5 changes: 2 additions & 3 deletions res/swappy.ui
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,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="y" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
<accelerator key="z" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
<accelerator key="y" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
</object>
<packing>
<property name="expand">True</property>
Expand Down Expand Up @@ -162,8 +162,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<object class="GtkBox" id="painting-box">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
Expand Down
13 changes: 13 additions & 0 deletions src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ static void action_redo(struct swappy_state *state) {
}
}

static void action_toggle_painting_pane(struct swappy_state *state) {
GtkWidget *painting_box = GTK_WIDGET(state->ui->painting_box);
gboolean is_visible = gtk_widget_get_visible(painting_box);
gtk_widget_set_visible(painting_box, !is_visible);
}

static void switch_mode_to_brush(struct swappy_state *state) {
g_debug("switching mode to brush");
state->mode = SWAPPY_PAINT_MODE_BRUSH;
Expand Down Expand Up @@ -193,6 +199,9 @@ void keypress_handler(GtkWidget *widget, GdkEventKey *event,
case GDK_KEY_s:
action_save_area_to_file(state);
break;
case GDK_KEY_b:
action_toggle_painting_pane(state);
break;
default:
break;
}
Expand Down Expand Up @@ -221,6 +230,7 @@ gboolean draw_area_handler(GtkWidget *widget, cairo_t *cr,

return FALSE;
}

gboolean draw_area_configure_handler(GtkWidget *widget,
GdkEventConfigure *event,
struct swappy_state *state) {
Expand All @@ -236,6 +246,7 @@ gboolean draw_area_configure_handler(GtkWidget *widget,

return TRUE;
}

void draw_area_button_press_handler(GtkWidget *widget, GdkEventButton *event,
struct swappy_state *state) {
g_debug("press event: state: %d, button: %d", event->state, event->button);
Expand Down Expand Up @@ -339,6 +350,8 @@ static bool load_layout(struct swappy_state *state) {

GtkWidget *area = GTK_WIDGET(gtk_builder_get_object(builder, "paint_area"));

state->ui->painting_box =
GTK_BOX(gtk_builder_get_object(builder, "painting-box"));
GtkRadioButton *brush =
GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "brush"));
GtkRadioButton *text =
Expand Down

0 comments on commit e8d2f12

Please sign in to comment.