mirror of
https://github.com/jtheoof/swappy.git
synced 2024-09-11 14:55:49 +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;
|
int32_t height;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct swappy_state_ui_popover {
|
||||||
|
GtkPopover *container;
|
||||||
|
GtkRadioButton *brush;
|
||||||
|
GtkRadioButton *text;
|
||||||
|
GtkRadioButton *rectangle;
|
||||||
|
};
|
||||||
|
|
||||||
struct swappy_state {
|
struct swappy_state {
|
||||||
GResource *resource;
|
GResource *resource;
|
||||||
GtkApplication *app;
|
GtkApplication *app;
|
||||||
|
|
||||||
GtkWindow *window;
|
GtkWindow *window;
|
||||||
GtkWidget *area;
|
GtkWidget *area;
|
||||||
GtkPopover *popover;
|
|
||||||
|
struct swappy_state_ui_popover *popover;
|
||||||
|
|
||||||
cairo_surface_t *cairo_surface;
|
cairo_surface_t *cairo_surface;
|
||||||
|
|
||||||
|
@ -14,63 +14,7 @@
|
|||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="homogeneous">True</property>
|
<property name="homogeneous">True</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="paint_box">
|
<placeholder/>
|
||||||
<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>
|
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="control_box">
|
<object class="GtkBox" id="control_box">
|
||||||
@ -157,15 +101,10 @@
|
|||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="homogeneous">True</property>
|
<property name="homogeneous">True</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkToggleButton" id="brus">
|
<object class="GtkLabel">
|
||||||
<property name="label" translatable="yes"></property>
|
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="label" translatable="yes">B</property>
|
||||||
<signal name="clicked" handler="brush_clicked_handler" swapped="no"/>
|
|
||||||
<style>
|
|
||||||
<class name="brush"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
@ -174,14 +113,10 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkToggleButton" id="tex">
|
<object class="GtkLabel">
|
||||||
<property name="label" translatable="yes"></property>
|
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="label" translatable="yes">T</property>
|
||||||
<style>
|
|
||||||
<class name="text"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
@ -190,14 +125,10 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkToggleButton" id="shapes">
|
<object class="GtkLabel">
|
||||||
<property name="label" translatable="yes"></property>
|
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="label" translatable="yes">R,O,A</property>
|
||||||
<style>
|
|
||||||
<class name="shapes"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
@ -219,15 +150,15 @@
|
|||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="homogeneous">True</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkRadioButton">
|
<object class="GtkRadioButton" id="brush">
|
||||||
<property name="label" translatable="yes"></property>
|
<property name="label" translatable="yes"></property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">False</property>
|
<property name="receives_default">False</property>
|
||||||
<property name="active">True</property>
|
<property name="active">True</property>
|
||||||
<property name="draw_indicator">False</property>
|
<property name="draw_indicator">False</property>
|
||||||
<property name="group">brush</property>
|
|
||||||
<signal name="clicked" handler="brush_clicked_handler" swapped="no"/>
|
<signal name="clicked" handler="brush_clicked_handler" swapped="no"/>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
@ -237,7 +168,7 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkRadioButton">
|
<object class="GtkRadioButton" id="text">
|
||||||
<property name="label" translatable="yes"></property>
|
<property name="label" translatable="yes"></property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
@ -253,7 +184,7 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkRadioButton">
|
<object class="GtkRadioButton" id="rectangle">
|
||||||
<property name="label" translatable="yes"></property>
|
<property name="label" translatable="yes"></property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">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;
|
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");
|
g_debug("switching mode to arrow");
|
||||||
state->mode = SWAPPY_PAINT_MODE_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) {
|
void arrow_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||||
g_debug("switching mode to arrow");
|
switch_mode_to_arrow(state);
|
||||||
state->mode = SWAPPY_PAINT_MODE_ARROW;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rectangle_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
void rectangle_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||||
g_debug("switching mode to rectangle");
|
switch_mode_to_rectangle(state);
|
||||||
state->mode = SWAPPY_PAINT_MODE_RECTANGLE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void application_finish(struct swappy_state *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_str);
|
||||||
g_free(state->geometry);
|
g_free(state->geometry);
|
||||||
g_resources_unregister(state->resource);
|
g_resources_unregister(state->resource);
|
||||||
|
g_free(state->popover);
|
||||||
g_object_unref(state->app);
|
g_object_unref(state->app);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,6 +163,11 @@ static void keypress_handler(GtkWidget *widget, GdkEventKey *event,
|
|||||||
gtk_window_close(state->window);
|
gtk_window_close(state->window);
|
||||||
} else if (event->keyval == GDK_KEY_B || event->keyval == GDK_KEY_b) {
|
} else if (event->keyval == GDK_KEY_B || event->keyval == GDK_KEY_b) {
|
||||||
switch_mode_to_brush(state);
|
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) {
|
struct swappy_state *state) {
|
||||||
g_debug("press event: state: %d, button: %d", event->state, event->button);
|
g_debug("press event: state: %d, button: %d", event->state, event->button);
|
||||||
if (event->button == 3) {
|
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) {
|
static void load_css(struct swappy_state *state) {
|
||||||
GtkCssProvider *provider = gtk_css_provider_new();
|
GtkCssProvider *provider = gtk_css_provider_new();
|
||||||
gtk_css_provider_load_from_resource(provider, "/swappy/style/popover.css");
|
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);
|
g_object_unref(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool load_layout(struct swappy_state *state) {
|
static bool load_layout(struct swappy_state *state) {
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
GObject *container;
|
GObject *container;
|
||||||
GObject *brush;
|
|
||||||
GObject *text;
|
|
||||||
GObject *shape;
|
|
||||||
GtkWidget *area;
|
GtkWidget *area;
|
||||||
GObject *copy;
|
GObject *copy;
|
||||||
GObject *save;
|
GObject *save;
|
||||||
GObject *clear;
|
GObject *clear;
|
||||||
GtkPopover *popover;
|
GtkPopover *popover;
|
||||||
|
GtkRadioButton *brush;
|
||||||
|
GtkRadioButton *text;
|
||||||
|
GtkRadioButton *rectangle;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* Construct a GtkBuilder instance and load our UI description */
|
/* 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. */
|
/* Connect signal handlers to the constructed widgets. */
|
||||||
container = gtk_builder_get_object(builder, "container");
|
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");
|
copy = gtk_builder_get_object(builder, "copy");
|
||||||
save = gtk_builder_get_object(builder, "save");
|
save = gtk_builder_get_object(builder, "save");
|
||||||
clear = gtk_builder_get_object(builder, "clear");
|
clear = gtk_builder_get_object(builder, "clear");
|
||||||
area = GTK_WIDGET(gtk_builder_get_object(builder, "paint_area"));
|
area = GTK_WIDGET(gtk_builder_get_object(builder, "paint_area"));
|
||||||
|
|
||||||
popover = GTK_POPOVER(gtk_builder_get_object(builder, "popover"));
|
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);
|
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_CALLBACK(tools_menu_button_brush_toggle_handler), state);
|
||||||
g_signal_connect(text, "toggled",
|
g_signal_connect(text, "toggled",
|
||||||
G_CALLBACK(tools_menu_button_text_toggle_handler), state);
|
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_CALLBACK(tools_menu_button_shape_toggle_handler), state);
|
||||||
g_signal_connect(copy, "clicked",
|
g_signal_connect(copy, "clicked",
|
||||||
G_CALLBACK(tools_menu_button_copy_clicked_handler), state);
|
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_container_add(GTK_CONTAINER(state->window), GTK_WIDGET(container));
|
||||||
gtk_popover_set_relative_to(popover, area);
|
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;
|
state->area = area;
|
||||||
|
|
||||||
g_object_unref(G_OBJECT(builder));
|
g_object_unref(G_OBJECT(builder));
|
||||||
@ -398,6 +422,8 @@ bool application_init(struct swappy_state *state) {
|
|||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state->popover = g_new(struct swappy_state_ui_popover, 1);
|
||||||
|
|
||||||
g_resources_register(state->resource);
|
g_resources_register(state->resource);
|
||||||
|
|
||||||
g_signal_connect(state->app, "command-line", G_CALLBACK(command_line_handler),
|
g_signal_connect(state->app, "command-line", G_CALLBACK(command_line_handler),
|
||||||
|
Loading…
Reference in New Issue
Block a user