1 #pragma once
2 
3 #include <glib-2.0/glib.h>
4 #include <gtk/gtk.h>
5 #include <stdbool.h>
6 #include <stdint.h>
7 #include <stdlib.h>
8 
9 #define MAX_PATH 4096
10 
11 #define SWAPPY_LINE_SIZE_MIN 1
12 #define SWAPPY_LINE_SIZE_MAX 50
13 
14 #define SWAPPY_TEXT_SIZE_MIN 10
15 #define SWAPPY_TEXT_SIZE_MAX 50
16 
17 enum swappy_paint_type {
18   SWAPPY_PAINT_MODE_BRUSH = 0, /* Brush mode to draw arbitrary shapes */
19   SWAPPY_PAINT_MODE_TEXT,      /* Mode to draw texts */
20   SWAPPY_PAINT_MODE_RECTANGLE, /* Rectangle shapes */
21   SWAPPY_PAINT_MODE_ELLIPSE,   /* Ellipse shapes */
22   SWAPPY_PAINT_MODE_ARROW,     /* Arrow shapes */
23   SWAPPY_PAINT_MODE_BLUR,      /* Blur mode */
24 };
25 
26 enum swappy_paint_shape_operation {
27   SWAPPY_PAINT_SHAPE_OPERATION_STROKE = 0, /* Used to stroke the shape */
28   SWAPPY_PAINT_SHAPE_OPERATION_FILL,       /* Used to fill the shape */
29 };
30 
31 enum swappy_text_mode {
32   SWAPPY_TEXT_MODE_EDIT = 0,
33   SWAPPY_TEXT_MODE_DONE,
34 };
35 
36 struct swappy_point {
37   gdouble x;
38   gdouble y;
39 };
40 
41 struct swappy_paint_text {
42   double r;
43   double g;
44   double b;
45   double a;
46   double s;
47   gchar *font;
48   gchar *text;
49   glong cursor;
50   struct swappy_point from;
51   struct swappy_point to;
52   enum swappy_text_mode mode;
53 };
54 
55 struct swappy_paint_shape {
56   double r;
57   double g;
58   double b;
59   double a;
60   double w;
61   bool should_center_at_from;
62   struct swappy_point from;
63   struct swappy_point to;
64   enum swappy_paint_type type;
65   enum swappy_paint_shape_operation operation;
66 };
67 
68 struct swappy_paint_brush {
69   double r;
70   double g;
71   double b;
72   double a;
73   double w;
74   GList *points;
75 };
76 
77 struct swappy_paint_blur {
78   struct swappy_point from;
79   struct swappy_point to;
80   cairo_surface_t *surface;
81 };
82 
83 struct swappy_paint {
84   enum swappy_paint_type type;
85   bool can_draw;
86   bool is_committed;
87   union {
88     struct swappy_paint_brush brush;
89     struct swappy_paint_shape shape;
90     struct swappy_paint_text text;
91     struct swappy_paint_blur blur;
92   } content;
93 };
94 
95 struct swappy_box {
96   int32_t x;
97   int32_t y;
98   int32_t width;
99   int32_t height;
100 };
101 
102 struct swappy_state_settings {
103   double r;
104   double g;
105   double b;
106   double a;
107   double w;
108   double t;
109 };
110 
111 struct swappy_state_ui {
112   gboolean panel_toggled;
113 
114   GtkWindow *window;
115   GtkWidget *area;
116 
117   GtkToggleButton *panel_toggle_button;
118 
119   // Undo / Redo
120   GtkButton *undo;
121   GtkButton *redo;
122 
123   // Painting Area
124   GtkBox *painting_box;
125   GtkRadioButton *brush;
126   GtkRadioButton *text;
127   GtkRadioButton *rectangle;
128   GtkRadioButton *ellipse;
129   GtkRadioButton *arrow;
130   GtkRadioButton *blur;
131 
132   GtkRadioButton *red;
133   GtkRadioButton *green;
134   GtkRadioButton *blue;
135   GtkRadioButton *custom;
136   GtkColorButton *color;
137 
138   GtkButton *line_size;
139   GtkButton *text_size;
140 };
141 
142 struct swappy_config {
143   char *config_file;
144   char *save_dir;
145   char *save_filename_format;
146   gboolean show_panel;
147   guint32 line_size;
148   guint32 text_size;
149   char *text_font;
150 };
151 
152 struct swappy_state {
153   GtkApplication *app;
154 
155   struct swappy_state_ui *ui;
156   struct swappy_config *config;
157 
158   GdkPixbuf *original_image;
159   cairo_surface_t *original_image_surface;
160   cairo_surface_t *rendering_surface;
161 
162   gdouble scaling_factor;
163 
164   enum swappy_paint_type mode;
165 
166   /* Options */
167   char *file_str;
168   char *output_file;
169 
170   char *temp_file_str;
171 
172   struct swappy_box *window;
173   struct swappy_box *geometry;
174 
175   GList *paints;
176   GList *redo_paints;
177   struct swappy_paint *temp_paint;
178 
179   struct swappy_state_settings settings;
180 
181   int argc;
182   char **argv;
183 };
184