mirror of
https://github.com/jtheoof/swappy.git
synced 2024-09-11 14:55:49 +03:00
application: adding more painting shapes
This commit is contained in:
parent
3728cc8456
commit
aff5da9d4e
@ -8,5 +8,6 @@ void application_finish(struct swappy_state *state);
|
||||
|
||||
void brush_clicked_handler(GtkWidget *widget, struct swappy_state *state);
|
||||
void text_clicked_handler(GtkWidget *widget, struct swappy_state *state);
|
||||
void arrow_clicked_handler(GtkWidget *widget, struct swappy_state *state);
|
||||
void shape_clicked_handler(GtkWidget *widget, struct swappy_state *state);
|
||||
void rectangle_clicked_handler(GtkWidget *widget, struct swappy_state *state);
|
||||
void ellipse_clicked_handler(GtkWidget *widget, struct swappy_state *state);
|
||||
void arrow_clicked_handler(GtkWidget *widget, struct swappy_state *state);
|
@ -24,8 +24,9 @@ enum swappy_brush_point_kind {
|
||||
enum swappy_paint_mode_type {
|
||||
SWAPPY_PAINT_MODE_BRUSH = 0, /* Brush mode to draw arbitrary shapes */
|
||||
SWAPPY_PAINT_MODE_TEXT, /* Mode to draw texts */
|
||||
SWAPPY_PAINT_MODE_ARROW, /* Rectangle shapes */
|
||||
SWAPPY_PAINT_MODE_RECTANGLE, /* Rectangle shapes */
|
||||
SWAPPY_PAINT_MODE_ELLIPSE, /* Ellipse shapes */
|
||||
SWAPPY_PAINT_MODE_ARROW, /* Arrow shapes */
|
||||
};
|
||||
|
||||
struct swappy_brush_point {
|
||||
@ -50,6 +51,8 @@ struct swappy_state_ui_popover {
|
||||
GtkRadioButton *brush;
|
||||
GtkRadioButton *text;
|
||||
GtkRadioButton *rectangle;
|
||||
GtkRadioButton *ellipse;
|
||||
GtkRadioButton *arrow;
|
||||
};
|
||||
|
||||
struct swappy_state {
|
||||
|
@ -128,7 +128,7 @@
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">R,O,A</property>
|
||||
<property name="label" translatable="yes">R</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
@ -136,6 +136,30 @@
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">O</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">A</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<style>
|
||||
<class name="drawing"/>
|
||||
</style>
|
||||
@ -185,7 +209,7 @@
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="rectangle">
|
||||
<property name="label" translatable="yes"></property>
|
||||
<property name="label" translatable="yes"></property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
@ -199,6 +223,38 @@
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="ellipse">
|
||||
<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="draw_indicator">False</property>
|
||||
<property name="group">brush</property>
|
||||
<signal name="clicked" handler="ellipse_clicked_handler" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="arrow">
|
||||
<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="draw_indicator">False</property>
|
||||
<property name="group">brush</property>
|
||||
<signal name="clicked" handler="arrow_clicked_handler" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<style>
|
||||
<class name="drawing"/>
|
||||
</style>
|
||||
|
@ -28,28 +28,41 @@ static void switch_mode_to_text(struct swappy_state *state) {
|
||||
state->mode = SWAPPY_PAINT_MODE_TEXT;
|
||||
}
|
||||
|
||||
static void switch_mode_to_rectangle(struct swappy_state *state) {
|
||||
g_debug("switching mode to rectangle");
|
||||
state->mode = SWAPPY_PAINT_MODE_RECTANGLE;
|
||||
}
|
||||
|
||||
static void switch_mode_to_ellipse(struct swappy_state *state) {
|
||||
g_debug("switching mode to ellipse");
|
||||
state->mode = SWAPPY_PAINT_MODE_ELLIPSE;
|
||||
}
|
||||
|
||||
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 brush_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
switch_mode_to_brush(state);
|
||||
}
|
||||
|
||||
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) {
|
||||
switch_mode_to_arrow(state);
|
||||
}
|
||||
|
||||
void rectangle_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
switch_mode_to_rectangle(state);
|
||||
}
|
||||
|
||||
void ellipse_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
switch_mode_to_ellipse(state);
|
||||
}
|
||||
|
||||
void arrow_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
switch_mode_to_arrow(state);
|
||||
}
|
||||
|
||||
void application_finish(struct swappy_state *state) {
|
||||
g_debug("application is shutting down");
|
||||
swappy_overlay_clear(state);
|
||||
@ -62,10 +75,6 @@ void application_finish(struct swappy_state *state) {
|
||||
g_object_unref(state->app);
|
||||
}
|
||||
|
||||
void brush_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
switch_mode_to_brush(state);
|
||||
}
|
||||
|
||||
static gboolean draw_area_handler(GtkWidget *widget, cairo_t *cr,
|
||||
struct swappy_state *state) {
|
||||
cairo_set_source_surface(cr, state->cairo_surface, 0, 0);
|
||||
@ -168,6 +177,18 @@ static void keypress_handler(GtkWidget *widget, GdkEventKey *event,
|
||||
} 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);
|
||||
} else if (event->keyval == GDK_KEY_R || event->keyval == GDK_KEY_r) {
|
||||
switch_mode_to_rectangle(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->rectangle),
|
||||
true);
|
||||
} else if (event->keyval == GDK_KEY_O || event->keyval == GDK_KEY_o) {
|
||||
switch_mode_to_ellipse(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->ellipse),
|
||||
true);
|
||||
} else if (event->keyval == GDK_KEY_A || event->keyval == GDK_KEY_a) {
|
||||
switch_mode_to_arrow(state);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->popover->arrow),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,6 +275,8 @@ static bool load_layout(struct swappy_state *state) {
|
||||
GtkRadioButton *brush;
|
||||
GtkRadioButton *text;
|
||||
GtkRadioButton *rectangle;
|
||||
GtkRadioButton *ellipse;
|
||||
GtkRadioButton *arrow;
|
||||
GError *error = NULL;
|
||||
|
||||
/* Construct a GtkBuilder instance and load our UI description */
|
||||
@ -276,7 +299,9 @@ static bool load_layout(struct swappy_state *state) {
|
||||
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"));
|
||||
rectangle = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "rectangle"));
|
||||
ellipse = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "ellipse"));
|
||||
arrow = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "arrow"));
|
||||
|
||||
gtk_builder_connect_signals(builder, state);
|
||||
|
||||
@ -316,6 +341,8 @@ static bool load_layout(struct swappy_state *state) {
|
||||
state->popover->brush = brush;
|
||||
state->popover->text = text;
|
||||
state->popover->rectangle = rectangle;
|
||||
state->popover->ellipse = ellipse;
|
||||
state->popover->arrow = arrow;
|
||||
state->area = area;
|
||||
|
||||
g_object_unref(G_OBJECT(builder));
|
||||
|
Loading…
Reference in New Issue
Block a user