mirror of
https://github.com/jtheoof/swappy.git
synced 2024-08-16 18:20:45 +03:00
application: moved popover element logic
This commit is contained in:
parent
65d4e516ca
commit
3728cc8456
@ -45,13 +45,21 @@ struct swappy_box {
|
||||
int32_t height;
|
||||
};
|
||||
|
||||
struct swappy_state_ui_popover {
|
||||
GtkPopover *container;
|
||||
GtkRadioButton *brush;
|
||||
GtkRadioButton *text;
|
||||
GtkRadioButton *rectangle;
|
||||
};
|
||||
|
||||
struct swappy_state {
|
||||
GResource *resource;
|
||||
GtkApplication *app;
|
||||
|
||||
GtkWindow *window;
|
||||
GtkWidget *area;
|
||||
GtkPopover *popover;
|
||||
|
||||
struct swappy_state_ui_popover *popover;
|
||||
|
||||
cairo_surface_t *cairo_surface;
|
||||
|
||||
|
@ -14,63 +14,7 @@
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="paint_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="brush">
|
||||
<property name="label" translatable="yes">Brush</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="group">text</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="text">
|
||||
<property name="label" translatable="yes">Text</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="group">brush</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="shape">
|
||||
<property name="label" translatable="yes">Shape</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="group">brush</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="control_box">
|
||||
@ -157,15 +101,10 @@
|
||||
<property name="can_focus">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="brus">
|
||||
<property name="label" translatable="yes"></property>
|
||||
<object class="GtkLabel">
|
||||
<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>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">B</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@ -174,14 +113,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="tex">
|
||||
<property name="label" translatable="yes"></property>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<style>
|
||||
<class name="text"/>
|
||||
</style>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">T</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@ -190,14 +125,10 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="shapes">
|
||||
<property name="label" translatable="yes"></property>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<style>
|
||||
<class name="shapes"/>
|
||||
</style>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">R,O,A</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@ -219,15 +150,15 @@
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkRadioButton">
|
||||
<object class="GtkRadioButton" id="brush">
|
||||
<property name="label" translatable="yes"></property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">False</property>
|
||||
<property name="group">brush</property>
|
||||
<signal name="clicked" handler="brush_clicked_handler" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
@ -237,7 +168,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton">
|
||||
<object class="GtkRadioButton" id="text">
|
||||
<property name="label" translatable="yes"></property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
@ -253,7 +184,7 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton">
|
||||
<object class="GtkRadioButton" id="rectangle">
|
||||
<property name="label" translatable="yes"></property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
|
@ -23,19 +23,31 @@ static void switch_mode_to_brush(struct swappy_state *state) {
|
||||
state->mode = SWAPPY_PAINT_MODE_BRUSH;
|
||||
}
|
||||
|
||||
void text_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
static void switch_mode_to_text(struct swappy_state *state) {
|
||||
g_debug("switching mode to arrow");
|
||||
state->mode = SWAPPY_PAINT_MODE_TEXT;
|
||||
}
|
||||
|
||||
static void switch_mode_to_arrow(struct swappy_state *state) {
|
||||
g_debug("switching mode to arrow");
|
||||
state->mode = SWAPPY_PAINT_MODE_ARROW;
|
||||
}
|
||||
|
||||
static void switch_mode_to_rectangle(struct swappy_state *state) {
|
||||
g_debug("switching mode to rectangle");
|
||||
state->mode = SWAPPY_PAINT_MODE_RECTANGLE;
|
||||
}
|
||||
|
||||
void text_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
switch_mode_to_text(state);
|
||||
}
|
||||
|
||||
void arrow_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
g_debug("switching mode to arrow");
|
||||
state->mode = SWAPPY_PAINT_MODE_ARROW;
|
||||
switch_mode_to_arrow(state);
|
||||
}
|
||||
|
||||
void rectangle_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
g_debug("switching mode to rectangle");
|
||||
state->mode = SWAPPY_PAINT_MODE_RECTANGLE;
|
||||
switch_mode_to_rectangle(state);
|
||||
}
|
||||
|
||||
void application_finish(struct swappy_state *state) {
|
||||
@ -46,6 +58,7 @@ void application_finish(struct swappy_state *state) {
|
||||
g_free(state->geometry_str);
|
||||
g_free(state->geometry);
|
||||
g_resources_unregister(state->resource);
|
||||
g_free(state->popover);
|
||||
g_object_unref(state->app);
|
||||
}
|
||||
|
||||
@ -150,6 +163,11 @@ static void keypress_handler(GtkWidget *widget, GdkEventKey *event,
|
||||
gtk_window_close(state->window);
|
||||
} else if (event->keyval == GDK_KEY_B || event->keyval == GDK_KEY_b) {
|
||||
switch_mode_to_brush(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->brush),
|
||||
true);
|
||||
} else if (event->keyval == GDK_KEY_T || event->keyval == GDK_KEY_t) {
|
||||
switch_mode_to_text(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->text), true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,7 +190,7 @@ static void draw_area_button_press_handler(GtkWidget *widget,
|
||||
struct swappy_state *state) {
|
||||
g_debug("press event: state: %d, button: %d", event->state, event->button);
|
||||
if (event->button == 3) {
|
||||
gtk_popover_popup(state->popover);
|
||||
gtk_popover_popup(state->popover->container);
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,21 +238,22 @@ static void apply_css(GtkWidget *widget, GtkStyleProvider *provider) {
|
||||
static void load_css(struct swappy_state *state) {
|
||||
GtkCssProvider *provider = gtk_css_provider_new();
|
||||
gtk_css_provider_load_from_resource(provider, "/swappy/style/popover.css");
|
||||
apply_css(GTK_WIDGET(state->popover), GTK_STYLE_PROVIDER(provider));
|
||||
apply_css(GTK_WIDGET(state->popover->container),
|
||||
GTK_STYLE_PROVIDER(provider));
|
||||
g_object_unref(provider);
|
||||
}
|
||||
|
||||
static bool load_layout(struct swappy_state *state) {
|
||||
GtkBuilder *builder;
|
||||
GObject *container;
|
||||
GObject *brush;
|
||||
GObject *text;
|
||||
GObject *shape;
|
||||
GtkWidget *area;
|
||||
GObject *copy;
|
||||
GObject *save;
|
||||
GObject *clear;
|
||||
GtkPopover *popover;
|
||||
GtkRadioButton *brush;
|
||||
GtkRadioButton *text;
|
||||
GtkRadioButton *rectangle;
|
||||
GError *error = NULL;
|
||||
|
||||
/* Construct a GtkBuilder instance and load our UI description */
|
||||
@ -248,14 +267,16 @@ static bool load_layout(struct swappy_state *state) {
|
||||
|
||||
/* Connect signal handlers to the constructed widgets. */
|
||||
container = gtk_builder_get_object(builder, "container");
|
||||
brush = gtk_builder_get_object(builder, "brush");
|
||||
text = gtk_builder_get_object(builder, "text");
|
||||
shape = gtk_builder_get_object(builder, "shape");
|
||||
|
||||
copy = gtk_builder_get_object(builder, "copy");
|
||||
save = gtk_builder_get_object(builder, "save");
|
||||
clear = gtk_builder_get_object(builder, "clear");
|
||||
area = GTK_WIDGET(gtk_builder_get_object(builder, "paint_area"));
|
||||
|
||||
popover = GTK_POPOVER(gtk_builder_get_object(builder, "popover"));
|
||||
brush = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "brush"));
|
||||
text = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "text"));
|
||||
rectangle = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "shape"));
|
||||
|
||||
gtk_builder_connect_signals(builder, state);
|
||||
|
||||
@ -265,7 +286,7 @@ static bool load_layout(struct swappy_state *state) {
|
||||
G_CALLBACK(tools_menu_button_brush_toggle_handler), state);
|
||||
g_signal_connect(text, "toggled",
|
||||
G_CALLBACK(tools_menu_button_text_toggle_handler), state);
|
||||
g_signal_connect(shape, "toggled",
|
||||
g_signal_connect(rectangle, "toggled",
|
||||
G_CALLBACK(tools_menu_button_shape_toggle_handler), state);
|
||||
g_signal_connect(copy, "clicked",
|
||||
G_CALLBACK(tools_menu_button_copy_clicked_handler), state);
|
||||
@ -291,7 +312,10 @@ static bool load_layout(struct swappy_state *state) {
|
||||
gtk_container_add(GTK_CONTAINER(state->window), GTK_WIDGET(container));
|
||||
gtk_popover_set_relative_to(popover, area);
|
||||
|
||||
state->popover = popover;
|
||||
state->popover->container = popover;
|
||||
state->popover->brush = brush;
|
||||
state->popover->text = text;
|
||||
state->popover->rectangle = rectangle;
|
||||
state->area = area;
|
||||
|
||||
g_object_unref(G_OBJECT(builder));
|
||||
@ -398,6 +422,8 @@ bool application_init(struct swappy_state *state) {
|
||||
g_error_free(error);
|
||||
}
|
||||
|
||||
state->popover = g_new(struct swappy_state_ui_popover, 1);
|
||||
|
||||
g_resources_register(state->resource);
|
||||
|
||||
g_signal_connect(state->app, "command-line", G_CALLBACK(command_line_handler),
|
||||
|
Loading…
Reference in New Issue
Block a user