mirror of
https://github.com/jtheoof/swappy.git
synced 2024-08-16 18:20:45 +03:00
feat(text): add controls in toggle panel
This commit is contained in:
parent
f9e231fba5
commit
c03f628de7
@ -51,3 +51,7 @@ void stroke_size_decrease_handler(GtkWidget *widget,
|
||||
void stroke_size_reset_handler(GtkWidget *widget, struct swappy_state *state);
|
||||
void stroke_size_increase_handler(GtkWidget *widget,
|
||||
struct swappy_state *state);
|
||||
|
||||
void text_size_decrease_handler(GtkWidget *widget, struct swappy_state *state);
|
||||
void text_size_reset_handler(GtkWidget *widget, struct swappy_state *state);
|
||||
void text_size_increase_handler(GtkWidget *widget, struct swappy_state *state);
|
@ -17,12 +17,15 @@
|
||||
|
||||
#define GEOMETRY_PATTERN "xx,yy wwxhh"
|
||||
|
||||
#define SWAPPY_STROKE_SIZE_MIN 1
|
||||
#define SWAPPY_STROKE_SIZE_DEFAULT 5
|
||||
#define SWAPPY_TEXT_FONT_DEFAULT "serif"
|
||||
#define SWAPPY_TEXT_SIZE_DEFAULT 21
|
||||
#define SWAPPY_STROKE_SIZE_MIN 1
|
||||
#define SWAPPY_STROKE_SIZE_MAX 50
|
||||
|
||||
#define SWAPPY_TEXT_FONT_DEFAULT "serif"
|
||||
#define SWAPPY_TEXT_SIZE_DEFAULT 20
|
||||
#define SWAPPY_TEXT_SIZE_MIN 10
|
||||
#define SWAPPY_TEXT_SIZE_MAX 50
|
||||
|
||||
enum swappy_paint_type {
|
||||
SWAPPY_PAINT_MODE_BRUSH = 0, /* Brush mode to draw arbitrary shapes */
|
||||
SWAPPY_PAINT_MODE_TEXT, /* Mode to draw texts */
|
||||
@ -123,6 +126,7 @@ struct swappy_state_ui {
|
||||
GtkColorButton *color;
|
||||
|
||||
GtkButton *stroke_size;
|
||||
GtkButton *text_size;
|
||||
};
|
||||
|
||||
struct swappy_buffer {
|
||||
|
@ -17,6 +17,11 @@
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">zoom-in</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="zoom-in1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">zoom-in</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="zoom-out">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
@ -67,8 +72,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="z" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
|
||||
<accelerator key="y" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||
<accelerator key="z" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
@ -506,6 +511,7 @@
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_bottom">10</property>
|
||||
<property name="spacing">2</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
@ -571,6 +577,75 @@
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">2</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Text Size</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="text-minus-button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="image">zoom-out1</property>
|
||||
<property name="always_show_image">True</property>
|
||||
<signal name="clicked" handler="text_size_decrease_handler" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="text-size-button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="always_show_image">True</property>
|
||||
<signal name="clicked" handler="text_size_reset_handler" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="text-plus-button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="image">zoom-in1</property>
|
||||
<property name="always_show_image">True</property>
|
||||
<signal name="clicked" handler="text_size_increase_handler" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="resize">False</property>
|
||||
@ -613,4 +688,9 @@
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkImage" id="zoom-out1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">zoom-out</property>
|
||||
</object>
|
||||
</interface>
|
||||
|
@ -28,6 +28,13 @@ static void update_ui_stroke_size_widget(struct swappy_state *state) {
|
||||
gtk_button_set_label(button, label);
|
||||
}
|
||||
|
||||
static void update_ui_text_size_widget(struct swappy_state *state) {
|
||||
GtkButton *button = GTK_BUTTON(state->ui->text_size);
|
||||
char label[255];
|
||||
snprintf(label, 255, "%.0lf", state->settings.t);
|
||||
gtk_button_set_label(button, label);
|
||||
}
|
||||
|
||||
static void action_undo(struct swappy_state *state) {
|
||||
GList *first = state->paints;
|
||||
|
||||
@ -132,6 +139,31 @@ static void action_stroke_size_increase(struct swappy_state *state) {
|
||||
update_ui_stroke_size_widget(state);
|
||||
}
|
||||
|
||||
static void action_text_size_decrease(struct swappy_state *state) {
|
||||
guint step = state->settings.t <= 20 ? 1 : 5;
|
||||
state->settings.t -= step;
|
||||
|
||||
if (state->settings.t < SWAPPY_TEXT_SIZE_MIN) {
|
||||
state->settings.t = SWAPPY_TEXT_SIZE_MIN;
|
||||
}
|
||||
|
||||
update_ui_text_size_widget(state);
|
||||
}
|
||||
static void action_text_size_reset(struct swappy_state *state) {
|
||||
state->settings.t = SWAPPY_TEXT_SIZE_DEFAULT;
|
||||
update_ui_text_size_widget(state);
|
||||
}
|
||||
static void action_text_size_increase(struct swappy_state *state) {
|
||||
guint step = state->settings.t >= 20 ? 5 : 1;
|
||||
state->settings.t += step;
|
||||
|
||||
if (state->settings.t > SWAPPY_TEXT_SIZE_MAX) {
|
||||
state->settings.t = SWAPPY_TEXT_SIZE_MAX;
|
||||
}
|
||||
|
||||
update_ui_text_size_widget(state);
|
||||
}
|
||||
|
||||
void brush_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
switch_mode_to_brush(state);
|
||||
}
|
||||
@ -452,6 +484,16 @@ void stroke_size_increase_handler(GtkWidget *widget,
|
||||
action_stroke_size_increase(state);
|
||||
}
|
||||
|
||||
void text_size_decrease_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
action_text_size_decrease(state);
|
||||
}
|
||||
void text_size_reset_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
action_text_size_reset(state);
|
||||
}
|
||||
void text_size_increase_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
action_text_size_increase(state);
|
||||
}
|
||||
|
||||
static void apply_css(GtkWidget *widget, GtkStyleProvider *provider) {
|
||||
gtk_style_context_add_provider(gtk_widget_get_style_context(widget), provider,
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
@ -520,6 +562,8 @@ static bool load_layout(struct swappy_state *state) {
|
||||
|
||||
state->ui->stroke_size =
|
||||
GTK_BUTTON(gtk_builder_get_object(builder, "stroke-size-button"));
|
||||
state->ui->text_size =
|
||||
GTK_BUTTON(gtk_builder_get_object(builder, "text-size-button"));
|
||||
|
||||
gtk_widget_set_size_request(area, geometry->width, geometry->height);
|
||||
|
||||
@ -553,6 +597,7 @@ static bool init_gtk_window(struct swappy_state *state) {
|
||||
}
|
||||
|
||||
update_ui_stroke_size_widget(state);
|
||||
update_ui_text_size_widget(state);
|
||||
update_ui_undo_redo(state);
|
||||
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user