Skip to content

Commit

Permalink
feat(tool): introduce blurring capability
Browse files Browse the repository at this point in the history
The blur algorithm is largely inspired from Kristian Høgsberg & Chris
Wilson in [this file](https://www.cairographics.org/cookbook/blur.c/)

Closes #17
  • Loading branch information
jtheoof committed Jun 1, 2020
1 parent 2eb4ebb commit fae0aea
Show file tree
Hide file tree
Showing 12 changed files with 434 additions and 17 deletions.
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@
}
]
},
{
"name": "swappy - file (small blue)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/swappy",
"args": ["-f", "test/images/small-blue.png"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "G_MESSAGES_DEBUG",
"value": "all"
}
],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "swappy - file (large)",
"type": "cppdbg",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ The following lines can be used as swappy's default:
- `r`: Switch to Rectangle
- `o`: Switch to Ellipse
- `a`: Switch to Arrow
- `d`: Switch to Blur (`d` stands for droplet)

<hr>

Expand Down
7 changes: 7 additions & 0 deletions include/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ 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_radius_decrease_handler(GtkWidget *widget,
struct swappy_state *state);
void blur_radius_increase_handler(GtkWidget *widget,
struct swappy_state *state);
void blur_radius_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);
void ellipse_clicked_handler(GtkWidget *widget, struct swappy_state *state);
void arrow_clicked_handler(GtkWidget *widget, struct swappy_state *state);
void blur_clicked_handler(GtkWidget *widget, struct swappy_state *state);

void copy_clicked_handler(GtkWidget *widget, struct swappy_state *state);
void save_clicked_handler(GtkWidget *widget, struct swappy_state *state);
Expand Down
1 change: 1 addition & 0 deletions include/config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "swappy.h"

#define CONFIG_BLUR_RADIUS_DEFAULT 15
#define CONFIG_LINE_SIZE_DEFAULT 5
#define CONFIG_TEXT_FONT_DEFAULT "sans-serif"
#define CONFIG_TEXT_SIZE_DEFAULT 20
Expand Down
14 changes: 14 additions & 0 deletions include/swappy.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#define SWAPPY_LINE_SIZE_MIN 1
#define SWAPPY_LINE_SIZE_MAX 50

#define SWAPPY_BLUR_RADIUS_MIN 1
#define SWAPPY_BLUR_RADIUS_MAX 50

#define SWAPPY_TEXT_SIZE_MIN 10
#define SWAPPY_TEXT_SIZE_MAX 50

Expand All @@ -28,6 +31,7 @@ enum swappy_paint_type {
SWAPPY_PAINT_MODE_RECTANGLE, /* Rectangle shapes */
SWAPPY_PAINT_MODE_ELLIPSE, /* Ellipse shapes */
SWAPPY_PAINT_MODE_ARROW, /* Arrow shapes */
SWAPPY_PAINT_MODE_BLUR, /* Blur mode */
};

enum swappy_text_mode {
Expand Down Expand Up @@ -74,13 +78,19 @@ struct swappy_paint_brush {
GList *points;
};

struct swappy_paint_blur {
double radius;
GList *points;
};

struct swappy_paint {
enum swappy_paint_type type;
bool can_draw;
union {
struct swappy_paint_brush brush;
struct swappy_paint_shape shape;
struct swappy_paint_text text;
struct swappy_paint_blur blur;
} content;
};

Expand All @@ -98,6 +108,7 @@ struct swappy_state_settings {
double a;
double w;
double t;
guint32 blur_radius;
};

struct swappy_state_ui {
Expand All @@ -115,13 +126,15 @@ struct swappy_state_ui {
GtkRadioButton *rectangle;
GtkRadioButton *ellipse;
GtkRadioButton *arrow;
GtkRadioButton *blur;

GtkRadioButton *red;
GtkRadioButton *green;
GtkRadioButton *blue;
GtkRadioButton *custom;
GtkColorButton *color;

GtkButton *blur_radius;
GtkButton *line_size;
GtkButton *text_size;
};
Expand Down Expand Up @@ -173,6 +186,7 @@ struct swappy_config {
char *save_dir;
guint32 line_size;
guint32 text_size;
guint32 blur_radius;
char *text_font;
};

Expand Down
119 changes: 114 additions & 5 deletions res/swappy.ui
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,26 @@
<property name="can_focus">False</property>
<property name="icon_name">zoom-in</property>
</object>
<object class="GtkImage" id="zoom-in2">
<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>
<property name="icon_name">zoom-out</property>
</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>
<object class="GtkImage" id="zoom-out2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">zoom-out</property>
</object>
<object class="GtkApplicationWindow" id="paint-window">
<property name="visible">True</property>
<property name="can_focus">False</property>
Expand Down Expand Up @@ -242,6 +257,18 @@
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">D</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
Expand Down Expand Up @@ -336,6 +363,22 @@
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="blur">
<property name="label" translatable="yes">💧</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="draw_indicator">False</property>
<property name="group">brush</property>
<signal name="clicked" handler="blur_clicked_handler" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
<style>
<class name="drawing"/>
</style>
Expand Down Expand Up @@ -581,6 +624,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>
Expand Down Expand Up @@ -646,6 +690,76 @@
<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 Radius</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_radius_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_radius_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_radius_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>
Expand Down Expand Up @@ -688,9 +802,4 @@
</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>
Loading

0 comments on commit fae0aea

Please sign in to comment.