From 361be6aa8085143d9fd721e4c315c6b9e6fbdfca Mon Sep 17 00:00:00 2001 From: Jeremy Attali Date: Sat, 13 Jun 2020 13:40:55 -0400 Subject: [PATCH] feat(blur): remove blur configuration --- README.md | 2 -- include/application.h | 4 --- include/config.h | 1 - include/swappy.h | 7 ----- res/swappy.ui | 70 ------------------------------------------- src/application.c | 51 ------------------------------- src/config.c | 21 +------------ src/paint.c | 1 - src/render.c | 6 ++-- 9 files changed, 3 insertions(+), 160 deletions(-) diff --git a/README.md b/README.md index 9eb462e..ebf757f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/include/application.h b/include/application.h index 4f63aa2..e7bc133 100644 --- a/include/application.h +++ b/include/application.h @@ -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); diff --git a/include/config.h b/include/config.h index 78e31b3..ad0f2ee 100644 --- a/include/config.h +++ b/include/config.h @@ -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 diff --git a/include/swappy.h b/include/swappy.h index b71008c..68206b7 100644 --- a/include/swappy.h +++ b/include/swappy.h @@ -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; }; diff --git a/res/swappy.ui b/res/swappy.ui index b115723..998978d 100644 --- a/res/swappy.ui +++ b/res/swappy.ui @@ -690,76 +690,6 @@ 4 - - - True - False - 10 - 2 - True - - - True - False - Blur Level - - - False - True - 0 - - - - - True - False - True - zoom-out2 - True - - - - False - False - 1 - - - - - True - False - True - True - - - - False - True - 2 - - - - - True - False - True - zoom-in2 - True - - - - False - False - 3 - - - - - False - True - 5 - - False diff --git a/src/application.c b/src/application.c index 7696b09..c8adcd9 100644 --- a/src/application.c +++ b/src/application.c @@ -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, diff --git a/src/config.c b/src/config.c index 3fdaea8..a1244a7 100644 --- a/src/config.c +++ b/src/config.c @@ -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; diff --git a/src/paint.c b/src/paint.c index f60047c..86caee7 100644 --- a/src/paint.c +++ b/src/paint.c @@ -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; diff --git a/src/render.c b/src/render.c index 9f0aa77..8904784 100644 --- a/src/render.c +++ b/src/render.c @@ -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);