feat(blur): remove blur configuration

This commit is contained in:
Jeremy Attali 2020-06-13 13:40:55 -04:00
parent b9d685b7b2
commit 361be6aa80
9 changed files with 3 additions and 160 deletions

View File

@ -59,14 +59,12 @@ The following lines can be used as swappy's default:
```
[Default]
save_dir=$HOME/Desktop
blur_level=80
line_size=5
text_size=20
text_font=sans-serif
```
- `save_dir` is where swappshots will be saved, can contain env variables and must exist in your filesystem
- `blur_level` is the default blur level (must be between 1 and 500)
- `line_size` is the default line size (must be between 1 and 50)
- `text_size` is the default text size (must be between 10 and 50)
- `text_font` is the font used to render text, its format is pango friendly

View File

@ -27,10 +27,6 @@ void draw_area_button_release_handler(GtkWidget *widget, GdkEventButton *event,
void draw_area_motion_notify_handler(GtkWidget *widget, GdkEventMotion *event,
struct swappy_state *state);
void blur_level_decrease_handler(GtkWidget *widget, struct swappy_state *state);
void blur_level_increase_handler(GtkWidget *widget, struct swappy_state *state);
void blur_level_reset_handler(GtkWidget *widget, 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 rectangle_clicked_handler(GtkWidget *widget, struct swappy_state *state);

View File

@ -1,6 +1,5 @@
#include "swappy.h"
#define CONFIG_BLUR_LEVEL_DEFAULT 80
#define CONFIG_LINE_SIZE_DEFAULT 5
#define CONFIG_TEXT_FONT_DEFAULT "sans-serif"
#define CONFIG_TEXT_SIZE_DEFAULT 20

View File

@ -19,9 +19,6 @@
#define SWAPPY_LINE_SIZE_MIN 1
#define SWAPPY_LINE_SIZE_MAX 50
#define SWAPPY_BLUR_LEVEL_MIN 1
#define SWAPPY_BLUR_LEVEL_MAX 500
#define SWAPPY_TEXT_SIZE_MIN 10
#define SWAPPY_TEXT_SIZE_MAX 50
@ -79,7 +76,6 @@ struct swappy_paint_brush {
};
struct swappy_paint_blur {
double blur_level;
struct swappy_point from;
struct swappy_point to;
cairo_surface_t *surface;
@ -111,7 +107,6 @@ struct swappy_state_settings {
double a;
double w;
double t;
guint32 blur_level;
};
struct swappy_state_ui {
@ -137,7 +132,6 @@ struct swappy_state_ui {
GtkRadioButton *custom;
GtkColorButton *color;
GtkButton *blur_level;
GtkButton *line_size;
GtkButton *text_size;
};
@ -188,7 +182,6 @@ struct swappy_config {
char *save_dir;
guint32 line_size;
guint32 text_size;
guint32 blur_level;
char *text_font;
};

View File

@ -690,76 +690,6 @@
<property name="position">4</property>
</packing>
</child>
<child>
<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>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Blur Level</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="blur-minus-button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">True</property>
<property name="image">zoom-out2</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="blur_level_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="blur-radius-button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">True</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="blur_level_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="blur-plus-button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">True</property>
<property name="image">zoom-in2</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="blur_level_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">5</property>
</packing>
</child>
</object>
<packing>
<property name="resize">False</property>

View File

@ -30,13 +30,6 @@ static void update_ui_undo_redo(struct swappy_state *state) {
gtk_widget_set_sensitive(redo, redo_sensitive);
}
static void update_ui_blur_level_widget(struct swappy_state *state) {
GtkButton *button = GTK_BUTTON(state->ui->blur_level);
char label[255];
snprintf(label, 255, "%u", state->settings.blur_level);
gtk_button_set_label(button, label);
}
static void update_ui_stroke_size_widget(struct swappy_state *state) {
GtkButton *button = GTK_BUTTON(state->ui->line_size);
char label[255];
@ -130,33 +123,6 @@ static void switch_mode_to_blur(struct swappy_state *state) {
state->mode = SWAPPY_PAINT_MODE_BLUR;
}
static void action_blur_level_decrease(struct swappy_state *state) {
guint step = state->settings.blur_level <= 50 ? 5 : 10;
state->settings.blur_level -= step;
if (state->settings.blur_level < SWAPPY_BLUR_LEVEL_MIN) {
state->settings.blur_level = SWAPPY_BLUR_LEVEL_MIN;
}
update_ui_blur_level_widget(state);
}
static void action_blur_level_increase(struct swappy_state *state) {
guint step = state->settings.blur_level >= 50 ? 10 : 5;
state->settings.blur_level += step;
if (state->settings.blur_level > SWAPPY_BLUR_LEVEL_MAX) {
state->settings.blur_level = SWAPPY_BLUR_LEVEL_MAX;
}
update_ui_blur_level_widget(state);
}
static void action_blur_level_reset(struct swappy_state *state) {
state->settings.blur_level = state->config->blur_level;
update_ui_blur_level_widget(state);
}
static void action_stroke_size_decrease(struct swappy_state *state) {
guint step = state->settings.w <= 10 ? 1 : 5;
@ -510,19 +476,6 @@ void draw_area_button_release_handler(GtkWidget *widget, GdkEventButton *event,
}
}
void blur_level_decrease_handler(GtkWidget *widget,
struct swappy_state *state) {
action_blur_level_decrease(state);
}
void blur_level_increase_handler(GtkWidget *widget,
struct swappy_state *state) {
action_blur_level_increase(state);
}
void blur_level_reset_handler(GtkWidget *widget, struct swappy_state *state) {
action_blur_level_reset(state);
}
void color_red_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
action_update_color_state(state, 1, 0, 0, 1, false);
}
@ -671,8 +624,6 @@ static bool load_layout(struct swappy_state *state) {
state->ui->color =
GTK_COLOR_BUTTON(gtk_builder_get_object(builder, "custom-color-button"));
state->ui->blur_level =
GTK_BUTTON(gtk_builder_get_object(builder, "blur-radius-button"));
state->ui->line_size =
GTK_BUTTON(gtk_builder_get_object(builder, "stroke-size-button"));
state->ui->text_size =
@ -714,7 +665,6 @@ static bool init_gtk_window(struct swappy_state *state) {
return false;
}
update_ui_blur_level_widget(state);
update_ui_stroke_size_widget(state);
update_ui_text_size_widget(state);
update_ui_undo_redo(state);
@ -741,7 +691,6 @@ static void init_settings(struct swappy_state *state) {
state->settings.a = 1;
state->settings.w = state->config->line_size;
state->settings.t = state->config->text_size;
state->settings.blur_level = state->config->blur_level;
}
static gint command_line_handler(GtkApplication *app,

View File

@ -13,7 +13,6 @@ static void print_config(struct swappy_config *config) {
g_info("printing config:");
g_info("config_dir: %s", config->config_file);
g_info("save_dir: %s", config->save_dir);
g_info("blur_level: %d", config->blur_level);
g_info("line_size: %d", config->line_size);
g_info("text_font: %s", config->text_font);
g_info("text_size: %d", config->text_size);
@ -69,7 +68,7 @@ static void load_config_from_file(struct swappy_config *config,
const gchar *group = "Default";
gchar *save_dir = NULL;
gchar *save_dir_expanded = NULL;
guint64 line_size, text_size, blur_level;
guint64 line_size, text_size;
gchar *text_font = NULL;
GError *error = NULL;
@ -140,23 +139,6 @@ static void load_config_from_file(struct swappy_config *config,
error = NULL;
}
blur_level = g_key_file_get_uint64(gkf, group, "blur_level", &error);
if (error == NULL) {
if (blur_level >= SWAPPY_BLUR_LEVEL_MIN &&
blur_level <= SWAPPY_BLUR_LEVEL_MAX) {
config->blur_level = blur_level;
} else {
g_warning(
"blur_level is not a valid value: %ld - see man page for details",
blur_level);
}
} else {
g_info("blur_level is missing in %s (%s)", file, error->message);
g_error_free(error);
error = NULL;
}
text_font = g_key_file_get_string(gkf, group, "text_font", &error);
if (error == NULL) {
@ -177,7 +159,6 @@ static void load_default_config(struct swappy_config *config) {
}
config->save_dir = get_default_save_dir();
config->blur_level = CONFIG_BLUR_LEVEL_DEFAULT;
config->line_size = CONFIG_LINE_SIZE_DEFAULT;
config->text_font = g_strdup(CONFIG_TEXT_FONT_DEFAULT);
config->text_size = CONFIG_TEXT_SIZE_DEFAULT;

View File

@ -84,7 +84,6 @@ void paint_add_temporary(struct swappy_state *state, double x, double y,
case SWAPPY_PAINT_MODE_BLUR:
paint->can_draw = false;
paint->content.blur.blur_level = state->settings.blur_level;
paint->content.blur.from.x = x;
paint->content.blur.from.y = y;
paint->content.blur.surface = NULL;

View File

@ -15,8 +15,7 @@
* https://www.cairographics.org/cookbook/blur.c/
*/
static cairo_surface_t *blur_surface(cairo_surface_t *surface, double x,
double y, double width, double height,
gint blur_level) {
double y, double width, double height) {
cairo_surface_t *dest_surface, *tmp_surface;
cairo_t *cr;
int src_width, src_height;
@ -372,8 +371,7 @@ static void render_blur(cairo_t *cr, struct swappy_paint *paint) {
cairo_save(cr);
if (!paint->is_committed) {
cairo_surface_t *blurred =
blur_surface(target, x, y, w, h, blur.blur_level);
cairo_surface_t *blurred = blur_surface(target, x, y, w, h);
if (blurred && cairo_surface_status(blurred) == CAIRO_STATUS_SUCCESS) {
cairo_set_source_surface(cr, blurred, x, y);