Skip to content

Commit

Permalink
feat(ui): life is full of colors and joy
Browse files Browse the repository at this point in the history
  • Loading branch information
jtheoof committed Dec 26, 2019
1 parent a8c8be3 commit 606cd34
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
29 changes: 21 additions & 8 deletions res/swappy.ui
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
Expand Down Expand Up @@ -412,13 +411,28 @@
<property name="position">2</property>
</packing>
</child>
<style>
<class name="color-box"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">50</property>
<property name="spacing">5</property>
<child>
<object class="GtkRadioButton" id="color-button-custom">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="valign">center</property>
<property name="margin_left">20</property>
<property name="draw_indicator">False</property>
<property name="group">color-red-button</property>
<signal name="clicked" handler="color_custom_clicked_handler" swapped="no"/>
Expand All @@ -433,7 +447,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
<property name="position">0</property>
</packing>
</child>
<child>
Expand All @@ -443,22 +457,21 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="valign">center</property>
<property name="title" translatable="yes"/>
<property name="rgba">rgb(193,125,17)</property>
<signal name="color-set" handler="color_custom_color_set_handler" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
<property name="position">1</property>
</packing>
</child>
<style>
<class name="color-box"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
</object>
Expand Down
19 changes: 12 additions & 7 deletions src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ static void action_toggle_painting_pane(struct swappy_state *state) {
gtk_widget_set_visible(painting_box, !is_visible);
}

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

state->painting.r = color.red;
state->painting.g = color.green;
state->painting.b = color.blue;
state->painting.a = color.alpha;
}

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 @@ -345,6 +355,7 @@ void color_blue_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
void color_custom_clicked_handler(GtkWidget *widget,
struct swappy_state *state) {
gtk_widget_set_sensitive(GTK_WIDGET(state->ui->custom), true);
action_set_color_from_custom(state);
}

void color_group_set_inactive(gpointer data, gpointer user_data) {
Expand All @@ -355,13 +366,7 @@ void color_group_set_inactive(gpointer data, gpointer user_data) {

void color_custom_color_set_handler(GtkWidget *widget,
struct swappy_state *state) {
GdkRGBA color;
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), &color);

state->painting.r = color.red;
state->painting.g = color.green;
state->painting.b = color.blue;
state->painting.a = color.alpha;
action_set_color_from_custom(state);
}

static void apply_css(GtkWidget *widget, GtkStyleProvider *provider) {
Expand Down

0 comments on commit 606cd34

Please sign in to comment.