-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpaint.h
More file actions
234 lines (184 loc) · 5.63 KB
/
Copy pathpaint.h
File metadata and controls
234 lines (184 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
* Copyright (c) 2021 Justin Meiners
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PAINT_H
#define PAINT_H
#include "layer.h"
#include "undo_queue.h"
#include "polygon.h"
/* no Xlib allowed here */
/*
TODO:
- [ ] fix window lifetime
- [ ] zoom in/out scrollbar coordinates/center point
- [ ] copy paste/files undo issue
- [x] use widechar on text layers. XmTextGetStringWcs
- [x] use glyph functions for lookup instead of codepoint (stb_truetype header)
- [x] only undo when active layer is main
- [x] review workflow for including pieces of other images
copy, open new image, paste
- [x] adjust eraser sizes to be bigger (and more extreme)
- [x] selecting out of bounds segfault
- [x] optimize font rendering buffer stuff
- [x] draggable text
- [x] dotted lines for selection box.
- [x] Zoom. Figure out box and blit/composite into destination.
- [x] switch tool then stop selection box.
- [x] draw ellipse
- [x] crop to selection
- [x] About window. (name author, etc)
- [x] composite mode for inverting colors below it
- [x] select copy/blend mode
- [x] fix magnifier
- [x] image save/load color shift
- [x] word wrap and alignment
- [x] x11 find out color format.
Either pick a format we want, or in the composite step swap bytes.
- [x] Cut/Copy/Paste with clipboard (last chapter of motif book)
Consider not integrating with OS.
- [x] open filename provided by argv
- [x] spray can timer
- [x] cleanup shm (at all costs)
- [x] new should clear open file path.
- [x] open/save should use open file path.
- [x] icon
- [x] font box life cycle
- [x] clear text when start new box.
- [x] resizing layers should update text.
- [x] cache stbtt fonts
- [x] window resize performance
- [x] undo checkpoints
- [x] initial text blit is wrong!!
- [x] don't bounds check square brush
- [x] type in color RGB
FUTURE:
- [x] compress undo/redo patches
- [x] text tool
- [x] tool icons (no icons for optioos)
- [ ] run unit test in debug
- [ ] redraw eyedropper
- polygon tool.
- polyogn select tool. (both need point in polygon tests.)
*/
typedef enum
{
TOOL_PENCIL = 0,
TOOL_BRUSH,
TOOL_PAINT_BUCKET,
TOOL_SPRAY_CAN,
TOOL_MAGNIFIER,
TOOL_EYE_DROPPER,
TOOL_LINE,
TOOL_TEXT,
TOOL_RECTANGLE,
TOOL_ELLIPSE,
TOOL_ERASER,
TOOL_POLYGON,
TOOL_SELECT_POLYGON,
TOOL_SELECT_RECTANGLE,
TOOL_COUNT,
} PaintTool;
typedef enum
{
SELECT_IGNORE_BG = 0,
SELECT_KEEP_BG,
} SelectMode;
typedef enum
{
SHAPE_FILL = 1 << 0,
SHAPE_STROKE = 1 << 1,
} ShapeFlags;
typedef enum
{
BUCKET_GLOBAL = 0,
BUCKET_CONTIGUOUS,
} BucketMode;
#define OS_PATH_MAX 2048
enum {
LAYER_INTERMEDIATE,
LAYER_MAIN,
LAYER_OVERLAY,
LAYER_COUNT
};
typedef struct
{
CcLayer layers[LAYER_COUNT];
int active_layer;
CcText text;
PaintTool tool;
PaintTool previous_tool;
ShapeFlags shape_flags;
SelectMode select_mode;
BucketMode bucket_mode;
CcViewport viewport;
int max_undo;
int zoom_level;
int line_width;
int brush_width;
int eraser_width;
int mouse_button;
int tool_x;
int tool_y;
int tool_min_x;
int tool_min_y;
int tool_max_x;
int tool_max_y;
int tool_force_align;
int request_tool_timer;
int line_x;
int line_y;
uint32_t fg_color;
uint32_t bg_color;
uint32_t view_bg_color;
size_t paste_board_size;
unsigned char* paste_board_data;
CcPolygon polygon;
CcUndo undo;
char open_file_path[OS_PATH_MAX];
} PaintContext;
void paint_undo(PaintContext* ctx);
void paint_redo(PaintContext* ctx);
const char* paint_file_path(PaintContext* ctx);
int paint_open_file(PaintContext* ctx, const char* path, const char** error_message);
int paint_save_file_as(PaintContext* ctx, const char* path);
int paint_save_file(PaintContext* ctx);
int paint_init(PaintContext* ctx);
void paint_invert_colors(PaintContext* ctx);
void paint_flip(PaintContext* ctx, int horiz);
void paint_rotate_90(PaintContext* ctx, int repeat);
void paint_rotate_angle(PaintContext* ctx, double angle);
void paint_stretch(PaintContext* ctx, int w, int h, int w_angle, int h_angle);
void paint_clear(PaintContext* ctx);
void paint_resize(PaintContext* ctx, int new_w, int new_h);
void paint_set_tool(PaintContext* ctx, PaintTool tool);
void paint_tool_down(PaintContext* ctx, int x, int y, int button);
void paint_tool_move(PaintContext* ctx, int x, int y);
void paint_tool_update(PaintContext* ctx);
void paint_tool_up(PaintContext* ctx, int x, int y, int button);
void paint_tool_cancel(PaintContext* ctx);
int paint_w(const PaintContext* ctx);
int paint_h(const PaintContext* ctx);
void paint_crop(PaintContext* ctx);
void paint_composite(PaintContext* ctx, CcBitmap *composite);
void paint_copy(PaintContext* ctx);
void paint_cut(PaintContext* ctx);
void paint_paste(PaintContext* ctx);
void paint_select_all(PaintContext* ctx);
void paint_select(PaintContext* ctx, int x, int y, int w, int h);
void paint_select_polygon(PaintContext* ctx);
void paint_select_clear(PaintContext* ctx);
void paint_set_color(PaintContext* ctx, uint32_t color, int fg);
int paint_is_editing_text(PaintContext* ctx);
#endif