Rev 7265 | Rev 7267 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7089 | leency | 1 | /* |
7154 | leency | 2 | * Icon Editor for KolibriOS |
7187 | leency | 3 | * Authors: Leency, Nicolas |
7089 | leency | 4 | * Licence: GPL v2 |
5 | */ |
||
6 | |||
7151 | leency | 7 | /* |
7156 | leency | 8 | TODO: |
9 | window colors |
||
10 | enhance icon |
||
7194 | leency | 11 | pipet aside color view |
7151 | leency | 12 | */ |
13 | |||
7260 | leency | 14 | #define MEMSIZE 4096*250 |
7089 | leency | 15 | |
16 | #include "../lib/gui.h" |
||
7151 | leency | 17 | #include "../lib/random.h" |
18 | #include "../lib/mem.h" |
||
7262 | leency | 19 | #include "../lib/cursor.h" |
7255 | leency | 20 | |
7096 | leency | 21 | #include "../lib/obj/libimg.h" |
7255 | leency | 22 | #include "../lib/obj/box_lib.h" |
23 | |||
7089 | leency | 24 | #include "../lib/patterns/rgb.h" |
7253 | leency | 25 | #include "../lib/patterns/libimg_load_skin.h" |
7089 | leency | 26 | |
7151 | leency | 27 | #include "colors_mas.h" |
28 | |||
7089 | leency | 29 | //===================================================// |
30 | // // |
||
31 | // DATA // |
||
32 | // // |
||
33 | //===================================================// |
||
34 | |||
7266 | leency | 35 | #define T_TITLE "Icon Editor 0.53.1 Alpha" |
7096 | leency | 36 | |
7152 | leency | 37 | #define TOOLBAR_H 24+8 |
7187 | leency | 38 | #define PANEL_LEFT_W 16+5+5+3+3 |
7096 | leency | 39 | #define PALLETE_SIZE 116 |
7089 | leency | 40 | |
7194 | leency | 41 | #define PAL_ITEMS_X_COUNT 13 |
42 | #define COLSIZE 18 |
||
7200 | leency | 43 | #define RIGHT_BAR_W PAL_ITEMS_X_COUNT*COLSIZE |
7187 | leency | 44 | |
7253 | leency | 45 | #define TO_CANVAS_X(xval) xval - canvas.x/zoom.value |
46 | #define TO_CANVAS_Y(yval) yval - canvas.y/zoom.value |
||
47 | |||
7200 | leency | 48 | block canvas = { NULL, NULL, NULL, NULL }; |
49 | block wrapper = { PANEL_LEFT_W, TOOLBAR_H, NULL, NULL }; |
||
7255 | leency | 50 | block right_bar = { NULL, 10+TOOLBAR_H, RIGHT_BAR_W+10, NULL }; |
7200 | leency | 51 | |
7255 | leency | 52 | block b_color_gradient = {NULL, 40+TOOLBAR_H, RIGHT_BAR_W, 30}; |
53 | block b_last_colors = {NULL, 80+TOOLBAR_H, RIGHT_BAR_W, COLSIZE*2}; |
||
54 | block b_default_palette = {NULL, COLSIZE*2+10+80+TOOLBAR_H, RIGHT_BAR_W, COLSIZE*9}; |
||
7200 | leency | 55 | |
7207 | leency | 56 | dword color1 = 0x000000; |
7255 | leency | 57 | dword color2 = 0xBFCAD2; |
7207 | leency | 58 | dword tool_color; |
7089 | leency | 59 | |
7257 | leency | 60 | signed hoverX; |
61 | signed hoverY; |
||
62 | signed priorHoverX; |
||
63 | signed priorHoverY; |
||
64 | bool canvasMouseMoved = false; |
||
65 | |||
7089 | leency | 66 | enum { |
7096 | leency | 67 | BTN_NEW = 40, |
68 | BTN_OPEN, |
||
69 | BTN_SAVE, |
||
70 | BTN_MOVE_LEFT, |
||
71 | BTN_MOVE_RIGHT, |
||
72 | BTN_MOVE_UP, |
||
73 | BTN_MOVE_DOWN, |
||
74 | BTN_FLIP_HOR, |
||
75 | BTN_FLIP_VER, |
||
76 | BTN_ROTATE_LEFT, |
||
77 | BTN_ROTATE_RIGHT, |
||
7265 | leency | 78 | BTN_TEST_ICON, |
7187 | leency | 79 | BTN_PENCIL, |
7096 | leency | 80 | BTN_PICK, |
7156 | leency | 81 | BTN_FILL, |
7186 | leency | 82 | BTN_LINE, |
83 | BTN_RECT, |
||
7259 | leency | 84 | BTN_BAR, |
7253 | leency | 85 | BTN_SELECT, |
7260 | leency | 86 | BTN_SCREEN_COPY, |
7253 | leency | 87 | BTN_ZOOM_IN, |
88 | BTN_ZOOM_OUT, |
||
7155 | leency | 89 | BTNS_PALETTE_COLOR_MAS = 100, |
90 | BTNS_LAST_USED_COLORS = 400 |
||
7089 | leency | 91 | }; |
92 | |||
93 | proc_info Form; |
||
7255 | leency | 94 | dword semi_white; |
7089 | leency | 95 | |
7243 | leency | 96 | more_less_box zoom = { 11, 1, 40, "Zoom" }; |
7150 | leency | 97 | |
7152 | leency | 98 | dword default_palette[] = { |
7190 | leency | 99 | 0x330000,0x331900,0x333300,0x193300,0x003300,0x003319,0x003333,0x001933,0x000033,0x190033, |
100 | 0x330033,0x330019,0x000000,0x660000,0x663300,0x666600,0x336600,0x006600,0x006633,0x006666, |
||
101 | 0x003366,0x000066,0x330066,0x660066,0x660033,0x202020,0x990000,0x994C00,0x999900,0x4C9900, |
||
102 | 0x009900,0x00994C,0x009999,0x004C99,0x000099,0x4C0099,0x990099,0x99004C,0x404040,0xCC0000, |
||
103 | 0xCC6600,0xCCCC00,0x66CC00,0x00CC00,0x00CC66,0x00CCCC,0x0066CC,0x0000CC,0x6600CC,0xCC00CC, |
||
104 | 0xCC0066,0x606060,0xFF0000,0xFF8000,0xFFFF00,0x80FF00,0x00FF00,0x00FF80,0x00FFFF,0x0080FF, |
||
105 | 0x0000FF,0x7F00FF,0xFF00FF,0xFF007F,0x808080,0xFF3333,0xFF9933,0xFFFF33,0x99FF33,0x33FF33, |
||
106 | 0x33FF99,0x33FFFF,0x3399FF,0x3333FF,0x9933FF,0xFF33FF,0xFF3399,0xA0A0A0,0xFF6666,0xFFB266, |
||
107 | 0xFFFF66,0xB2FF66,0x66FF66,0x66FFB2,0x66FFFF,0x66B2FF,0x6666FF,0xB266FF,0xFF66FF,0xFF66B2, |
||
108 | 0xC0C0C0,0xFF9999,0xFFCC99,0xFFFF99,0xCCFF99,0x99FF99,0x99FFCC,0x99FFFF,0x99CCFF,0x9999FF, |
||
109 | 0xCC99FF,0xFF99FF,0xFF99CC,0xE0E0E0,0xFFCCCC,0xFFE5CC,0xFFFFCC,0xE5FFCC,0xCCFFCC,0xCCFFE5, |
||
110 | 0xCCFFFF,0xCCE5FF,0xCCCCFF,0xE5CCFF,0xFFCCFF,0xFFCCE5,0xFFFFFF |
||
7089 | leency | 111 | }; |
7155 | leency | 112 | dword last_used_colors[13*2] = { |
7190 | leency | 113 | 0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF, |
114 | 0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF, |
||
115 | 0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF |
||
7155 | leency | 116 | }; |
7089 | leency | 117 | |
7262 | leency | 118 | CustomCursor Cursor; |
119 | dword CursorBar = FROM "cursors/bar.cur"; |
||
120 | dword CursorFill = FROM "cursors/fill.cur"; |
||
121 | dword CursorLine = FROM "cursors/line.cur"; |
||
122 | dword CursorPencil = FROM "cursors/pencil.cur"; |
||
123 | dword CursorPipette = FROM "cursors/pipette.cur"; |
||
124 | dword CursorRectangle = FROM "cursors/rectangle.cur"; |
||
125 | dword CursorSelect = FROM "cursors/select.cur"; |
||
126 | |||
7155 | leency | 127 | _image image; |
7148 | leency | 128 | |
7204 | leency | 129 | #include "actions_history.h" |
130 | |||
131 | _ActionsHistory actionsHistory; |
||
7151 | leency | 132 | |
7254 | leency | 133 | #include "tools.h" |
7156 | leency | 134 | |
7089 | leency | 135 | //===================================================// |
136 | // // |
||
137 | // CODE // |
||
138 | // // |
||
139 | //===================================================// |
||
140 | |||
7266 | leency | 141 | libimg_image top_icons; |
142 | libimg_image left_icons; |
||
143 | |||
7089 | leency | 144 | void main() |
145 | { |
||
146 | word btn; |
||
7257 | leency | 147 | libimg_image open_image; |
7089 | leency | 148 | |
7096 | leency | 149 | load_dll(libio, #libio_init, 1); |
150 | load_dll(libimg, #libimg_init, 1); |
||
7255 | leency | 151 | load_dll(boxlib, #box_lib_init,0); |
152 | |||
7266 | leency | 153 | Libimg_LoadImage(#top_icons, "/sys/icons16.png"); |
154 | Libimg_LoadImage(#left_icons, "/sys/icons16.png"); |
||
155 | |||
7255 | leency | 156 | system.color.get(); |
7266 | leency | 157 | semi_white = MixColors(system.color.work, 0xFFFfff, 96); |
158 | Libimg_ReplaceColor(top_icons.image, top_icons.w, top_icons.h, 0xffFFFfff, semi_white); |
||
159 | Libimg_ReplaceColor(top_icons.image, top_icons.w, top_icons.h, 0xffCACBD6, MixColors(semi_white, 0, 220)); |
||
7089 | leency | 160 | |
7266 | leency | 161 | Libimg_ReplaceColor(left_icons.image, left_icons.w, left_icons.h, 0xffFFFfff, system.color.work); |
162 | Libimg_ReplaceColor(left_icons.image, left_icons.w, left_icons.h, 0xffCACBD6, MixColors(system.color.work, 0, 200)); |
||
163 | |||
7254 | leency | 164 | if (!param[0]) { |
165 | image.create(32, 32); |
||
166 | } |
||
167 | else |
||
168 | { |
||
7151 | leency | 169 | Libimg_LoadImage(#open_image, #param); |
7254 | leency | 170 | |
171 | if (open_image.w*open_image.h>MAX_CELL_SIZE*MAX_CELL_SIZE) { |
||
172 | notify("'Hey, this is just an icon editor,\nselected image is too big to open!' -E"); |
||
173 | ExitProcess(); |
||
7151 | leency | 174 | } |
175 | else { |
||
7254 | leency | 176 | image.create(open_image.w, open_image.h); |
177 | image.set_image(open_image.imgsrc); |
||
7151 | leency | 178 | } |
179 | } |
||
180 | |||
7204 | leency | 181 | actionsHistory.init(); |
182 | |||
7186 | leency | 183 | initTools(); |
184 | setCurrentTool(TOOL_PENCIL); |
||
185 | |||
7096 | leency | 186 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
187 | |||
7089 | leency | 188 | loop() switch(WaitEvent()) |
189 | { |
||
7096 | leency | 190 | case evMouse: |
191 | mouse.get(); |
||
7186 | leency | 192 | |
7207 | leency | 193 | if (mouse.lkm) tool_color = color1; |
194 | if (mouse.pkm) tool_color = color2; |
||
195 | if (mouse.mkm) break; |
||
196 | |||
7257 | leency | 197 | hoverX = mouse.x - canvas.x / zoom.value; |
198 | hoverY = mouse.y - canvas.y / zoom.value; |
||
199 | if (hoverX<0) hoverX = 0; |
||
200 | if (hoverY<0) hoverY = 0; |
||
201 | if (hoverX>image.columns-1) hoverX = image.columns-1; |
||
202 | if (hoverY>image.rows-1) hoverY = image.rows-1; |
||
203 | canvasMouseMoved = false; |
||
204 | if (priorHoverX != hoverX) canvasMouseMoved = true; |
||
205 | if (priorHoverY != hoverY) canvasMouseMoved = true; |
||
206 | priorHoverX = hoverX; |
||
207 | priorHoverY = hoverY; |
||
208 | //DrawBar(Form.cwidth-100, 3, 80, 12, 0xFFFfff); |
||
209 | //WriteText(Form.cwidth-100, 3, 0x80, 0x000000, |
||
210 | // sprintf(#param, "%i %i", hoverX, hoverY)); |
||
211 | |||
7186 | leency | 212 | if (currentTool != TOOL_NONE) |
213 | tools[currentTool].onMouseEvent(mouse.x, mouse.y, mouse.lkm, mouse.pkm); |
||
214 | |||
7156 | leency | 215 | if (mouse.vert) { |
7243 | leency | 216 | if (mouse.vert==65535) zoom.inc(); |
217 | if (mouse.vert==1) zoom.dec(); |
||
7152 | leency | 218 | DrawEditArea(); |
219 | } |
||
7186 | leency | 220 | |
7262 | leency | 221 | if (wrapper.hovered()) SetCursor(); |
222 | else Cursor.Restore(); |
||
223 | |||
7200 | leency | 224 | if (mouse.down) { |
225 | if (b_color_gradient.hovered()) |
||
226 | || (b_last_colors.hovered()) |
||
227 | || (b_default_palette.hovered()) { |
||
228 | if (mouse.key&MOUSE_LEFT) EventSetActiveColor(1, GetPixelUnderMouse()); |
||
229 | if (mouse.key&MOUSE_RIGHT) EventSetActiveColor(2, GetPixelUnderMouse()); |
||
230 | } |
||
231 | } |
||
232 | |||
7148 | leency | 233 | break; |
7096 | leency | 234 | |
7089 | leency | 235 | case evButton: |
7148 | leency | 236 | btn = GetButtonID(); |
7253 | leency | 237 | |
7255 | leency | 238 | if (zoom.click(btn)) DrawEditArea(); |
239 | |||
7096 | leency | 240 | switch(btn) |
241 | { |
||
7151 | leency | 242 | case BTN_NEW: |
7257 | leency | 243 | EventCleanCanvas(); |
7151 | leency | 244 | break; |
245 | case BTN_OPEN: |
||
7190 | leency | 246 | RunProgram("/sys/lod", sprintf(#param, "*png* %s",#program_path)); |
7151 | leency | 247 | break; |
248 | case BTN_SAVE: |
||
7257 | leency | 249 | EventSaveIconToFile(); |
7151 | leency | 250 | break; |
7096 | leency | 251 | case BTN_MOVE_LEFT: |
7151 | leency | 252 | image.move(MOVE_LEFT); |
253 | DrawCanvas(); |
||
7096 | leency | 254 | break; |
255 | case BTN_MOVE_RIGHT: |
||
7151 | leency | 256 | image.move(MOVE_RIGHT); |
257 | DrawCanvas(); |
||
7096 | leency | 258 | break; |
7147 | leency | 259 | case BTN_MOVE_UP: |
7151 | leency | 260 | image.move(MOVE_UP); |
261 | DrawCanvas(); |
||
7147 | leency | 262 | break; |
263 | case BTN_MOVE_DOWN: |
||
7151 | leency | 264 | image.move(MOVE_DOWN); |
265 | DrawCanvas(); |
||
7147 | leency | 266 | break; |
7151 | leency | 267 | case BTN_FLIP_VER: |
268 | image.move(FLIP_VER); |
||
269 | DrawCanvas(); |
||
270 | break; |
||
271 | case BTN_FLIP_HOR: |
||
272 | image.move(FLIP_HOR); |
||
273 | DrawCanvas(); |
||
274 | break; |
||
7265 | leency | 275 | case BTN_TEST_ICON: |
276 | EventTestIcon(); |
||
277 | break; |
||
7187 | leency | 278 | case BTN_PENCIL: |
279 | setCurrentTool(TOOL_PENCIL); |
||
280 | break; |
||
7096 | leency | 281 | case BTN_PICK: |
7186 | leency | 282 | setCurrentTool(TOOL_PIPETTE); |
7096 | leency | 283 | break; |
7156 | leency | 284 | case BTN_FILL: |
7186 | leency | 285 | setCurrentTool(TOOL_FILL); |
7156 | leency | 286 | break; |
7186 | leency | 287 | case BTN_LINE: |
288 | setCurrentTool(TOOL_LINE); |
||
289 | break; |
||
290 | case BTN_RECT: |
||
291 | setCurrentTool(TOOL_RECT); |
||
292 | break; |
||
7259 | leency | 293 | case BTN_BAR: |
294 | setCurrentTool(TOOL_BAR); |
||
295 | break; |
||
7253 | leency | 296 | case BTN_SELECT: |
297 | setCurrentTool(TOOL_SELECT); |
||
298 | break; |
||
7260 | leency | 299 | case BTN_SCREEN_COPY: |
300 | setCurrentTool(TOOL_SCREEN_COPY); |
||
301 | break; |
||
7152 | leency | 302 | case CLOSE_BTN: |
7257 | leency | 303 | EventExitIconEdit(); |
7152 | leency | 304 | break; |
7089 | leency | 305 | } |
306 | break; |
||
307 | |||
308 | case evKey: |
||
309 | GetKeys(); |
||
7253 | leency | 310 | |
311 | if (currentTool != TOOL_NONE) && (tools[currentTool].onKeyEvent != 0) |
||
312 | tools[currentTool].onKeyEvent(key_scancode); |
||
313 | |||
7186 | leency | 314 | if (key_scancode == SCAN_CODE_ESC) setCurrentTool(TOOL_PENCIL); |
7187 | leency | 315 | if (key_scancode == SCAN_CODE_KEY_P) setCurrentTool(TOOL_PENCIL); |
7186 | leency | 316 | if (key_scancode == SCAN_CODE_KEY_I) setCurrentTool(TOOL_PIPETTE); |
7187 | leency | 317 | if (key_scancode == SCAN_CODE_KEY_F) setCurrentTool(TOOL_FILL); |
318 | if (key_scancode == SCAN_CODE_KEY_L) setCurrentTool(TOOL_LINE); |
||
319 | if (key_scancode == SCAN_CODE_KEY_R) setCurrentTool(TOOL_RECT); |
||
7260 | leency | 320 | if (key_scancode == SCAN_CODE_KEY_B) setCurrentTool(TOOL_BAR); |
321 | if (key_scancode == SCAN_CODE_KEY_S) setCurrentTool(TOOL_SELECT); |
||
7204 | leency | 322 | |
7265 | leency | 323 | if (key_scancode == SCAN_CODE_KEY_T) EventTestIcon(); |
324 | |||
7253 | leency | 325 | if (key_scancode == SCAN_CODE_KEY_Z) && (key_modifier&KEY_LCTRL) actionsHistory.undoLastAction(); |
326 | if (key_scancode == SCAN_CODE_KEY_Y) && (key_modifier&KEY_LCTRL) actionsHistory.redoLastAction(); |
||
7204 | leency | 327 | |
7253 | leency | 328 | if (key_scancode == SCAN_CODE_MINUS) {zoom.dec(); DrawEditArea();} |
329 | if (key_scancode == SCAN_CODE_PLUS) {zoom.inc(); DrawEditArea();} |
||
330 | |||
7089 | leency | 331 | break; |
332 | |||
333 | case evReDraw: |
||
334 | draw_window(); |
||
335 | break; |
||
336 | } |
||
337 | } |
||
338 | |||
7266 | leency | 339 | void DrawTopPanelButton(dword _id, _x, _icon_n) |
7096 | leency | 340 | { |
7255 | leency | 341 | DrawWideRectangle(_x, 4, 22, 22, 3, semi_white); |
7152 | leency | 342 | DefineHiddenButton(_x, 4, 21, 21, _id); |
7266 | leency | 343 | img_draw stdcall(top_icons.image, _x+3, 7, 16, 16, 0, _icon_n*16); |
7096 | leency | 344 | } |
345 | |||
7187 | leency | 346 | void DrawLeftPanelButton(dword _id, _y, _icon_n) |
347 | { |
||
348 | int x = 5; |
||
7266 | leency | 349 | DrawRectangle(x, _y, 22-1, 22-1, system.color.work); |
7187 | leency | 350 | DefineHiddenButton(x, _y, 21, 21, _id); |
7266 | leency | 351 | img_draw stdcall(left_icons.image, x+3, _y+3, 16, 16, 0, _icon_n*16); |
7187 | leency | 352 | } |
353 | |||
7148 | leency | 354 | void DrawStatusBar() |
355 | { |
||
7243 | leency | 356 | zoom.draw(wrapper.x, wrapper.y + wrapper.h + 6); |
7150 | leency | 357 | |
7151 | leency | 358 | sprintf(#param,"Canvas: %ix%i", image.rows, image.columns); |
7150 | leency | 359 | WriteText(wrapper.x+wrapper.w-calc(strlen(#param)*8), zoom.y+2, 0x90, system.color.work_text, #param); |
7148 | leency | 360 | } |
361 | |||
7089 | leency | 362 | void draw_window() |
363 | { |
||
7266 | leency | 364 | #define GAP 27 |
365 | #define BLOCK_SPACE 10 |
||
7096 | leency | 366 | incn tx; |
7089 | leency | 367 | system.color.get(); |
7151 | leency | 368 | DefineAndDrawWindow(115+random(100), 50+random(100), 700, 540, 0x33, system.color.work, T_TITLE, 0); |
7089 | leency | 369 | GetProcessInfo(#Form, SelfInfo); |
7152 | leency | 370 | if (Form.status_window>2) return; |
371 | if (Form.width < 560) { MoveSize(OLD,OLD,560,OLD); return; } |
||
372 | if (Form.height < 430) { MoveSize(OLD,OLD,OLD,430); return; } |
||
373 | |||
7150 | leency | 374 | right_bar.x = Form.cwidth - right_bar.w; |
7200 | leency | 375 | b_color_gradient.x = b_last_colors.x = b_default_palette.x = right_bar.x; |
7255 | leency | 376 | DrawBar(0, TOOLBAR_H-1, Form.cwidth, 1, system.color.work_graph); |
7089 | leency | 377 | |
7266 | leency | 378 | tx.n = 5-GAP; |
379 | DrawTopPanelButton(BTN_NEW, tx.inc(GAP), 2); //not implemented |
||
380 | DrawTopPanelButton(BTN_OPEN, tx.inc(GAP), 0); //not implemented |
||
381 | DrawTopPanelButton(BTN_SAVE, tx.inc(GAP), 5); |
||
382 | DrawTopPanelButton(BTN_MOVE_LEFT, tx.inc(GAP+BLOCK_SPACE), 30); |
||
383 | DrawTopPanelButton(BTN_MOVE_RIGHT, tx.inc(GAP), 31); |
||
384 | DrawTopPanelButton(BTN_MOVE_UP, tx.inc(GAP), 32); |
||
385 | DrawTopPanelButton(BTN_MOVE_DOWN, tx.inc(GAP), 33); |
||
7147 | leency | 386 | |
7266 | leency | 387 | DrawTopPanelButton(BTN_FLIP_HOR, tx.inc(GAP+BLOCK_SPACE), 34); |
388 | DrawTopPanelButton(BTN_FLIP_VER, tx.inc(GAP), 35); |
||
7265 | leency | 389 | |
7266 | leency | 390 | DrawTopPanelButton(BTN_TEST_ICON, tx.inc(GAP+BLOCK_SPACE), 12); |
391 | // DrawTopPanelButton(BTN_ROTATE_LEFT, tx.inc(GAP), 36); //not implemented |
||
392 | // DrawTopPanelButton(BTN_ROTATE_RIGHT, tx.inc(GAP), 37); //not implemented |
||
7148 | leency | 393 | |
7187 | leency | 394 | DrawLeftPanel(); |
7186 | leency | 395 | |
7150 | leency | 396 | DrawEditArea(); |
7096 | leency | 397 | |
7155 | leency | 398 | DrawActiveColor(right_bar.y); |
7200 | leency | 399 | DrawColorPallets(); |
7089 | leency | 400 | |
7148 | leency | 401 | DrawStatusBar(); |
7089 | leency | 402 | } |
403 | |||
7187 | leency | 404 | void DrawLeftPanel() |
405 | { |
||
7266 | leency | 406 | #define GAP 28 |
7187 | leency | 407 | incn ty; |
7266 | leency | 408 | ty.n = right_bar.y - GAP - 2; |
409 | DrawLeftPanelButton(BTN_PENCIL, ty.inc(GAP), 38); |
||
410 | DrawLeftPanelButton(BTN_PICK, ty.inc(GAP), 39); |
||
411 | DrawLeftPanelButton(BTN_FILL, ty.inc(GAP), 40); |
||
412 | DrawLeftPanelButton(BTN_LINE, ty.inc(GAP), 41); |
||
413 | DrawLeftPanelButton(BTN_RECT, ty.inc(GAP), 42); |
||
414 | DrawLeftPanelButton(BTN_BAR, ty.inc(GAP), 43); |
||
415 | DrawLeftPanelButton(BTN_SELECT, ty.inc(GAP), 44); |
||
416 | DrawLeftPanelButton(BTN_SCREEN_COPY, ty.inc(GAP), 45); |
||
417 | DrawRectangle3D(5, currentTool*GAP+right_bar.y-2, 16+3+2, 16+3+2, 0x333333, 0x777777); |
||
7187 | leency | 418 | } |
419 | |||
7151 | leency | 420 | void DrawEditArea() |
7089 | leency | 421 | { |
7150 | leency | 422 | dword color1=0xC0C0C0; |
7155 | leency | 423 | int top_side; |
424 | int left_side; |
||
7089 | leency | 425 | |
7194 | leency | 426 | wrapper.w = Form.cwidth - right_bar.w - 10 - wrapper.x; |
7150 | leency | 427 | wrapper.h = Form.cheight - TOOLBAR_H - 35; |
7148 | leency | 428 | |
7150 | leency | 429 | //canvas{ |
7151 | leency | 430 | canvas.w = image.columns * zoom.value; |
431 | canvas.h = image.rows * zoom.value; |
||
432 | if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) { |
||
7254 | leency | 433 | zoom.value--; |
7151 | leency | 434 | DrawEditArea(); |
435 | return; |
||
436 | } |
||
437 | canvas.x = -zoom.value*image.columns+wrapper.w/2 + wrapper.x; |
||
438 | canvas.y = -zoom.value*image.rows+wrapper.h/2 + wrapper.y; |
||
439 | DrawCanvas(); |
||
7150 | leency | 440 | //} |
7089 | leency | 441 | |
7155 | leency | 442 | left_side = canvas.x-wrapper.x-1; |
443 | top_side = canvas.y-wrapper.y-1; |
||
7148 | leency | 444 | |
7155 | leency | 445 | DrawRectangle(wrapper.x-1, wrapper.y-1, wrapper.w, wrapper.h, system.color.work_graph); |
7150 | leency | 446 | |
7155 | leency | 447 | if (left_side>0) |
7150 | leency | 448 | { |
7155 | leency | 449 | DrawBar(wrapper.x, wrapper.y, wrapper.w-1, top_side, color1); //top |
450 | DrawBar(wrapper.x, wrapper.y+wrapper.h-top_side-1, wrapper.w-1, top_side, color1); //bottom |
||
7150 | leency | 451 | } |
7155 | leency | 452 | if (top_side>0) |
7150 | leency | 453 | { |
7190 | leency | 454 | //left |
455 | DrawBar(wrapper.x, wrapper.y+top_side, left_side, |
||
456 | wrapper.h-top_side-top_side, color1); |
||
457 | //right |
||
458 | DrawBar(wrapper.x+wrapper.w-left_side-1, wrapper.y+top_side, left_side, |
||
459 | wrapper.h-top_side-top_side, color1); |
||
7150 | leency | 460 | } |
7194 | leency | 461 | DrawRectangle(canvas.x-1, canvas.y-1, canvas.w+1, canvas.h+1, 0x808080); |
7089 | leency | 462 | } |
463 | |||
464 | void DrawActiveColor(dword iny) |
||
465 | { |
||
7255 | leency | 466 | #define CELL 20 |
7089 | leency | 467 | static dword outy; |
468 | if (iny != NULL) outy = iny; |
||
7255 | leency | 469 | DrawFrame(right_bar.x, outy, CELL, CELL, NULL); |
470 | DrawBar(right_bar.x+2, outy+2, CELL-4, CELL-4, color1); |
||
7207 | leency | 471 | sprintf(#param, "%A", color1); |
7089 | leency | 472 | EDI = system.color.work; |
7148 | leency | 473 | WriteText(right_bar.x + 30, outy + 3, 0xD0, system.color.work_text, #param+4); |
7151 | leency | 474 | |
7255 | leency | 475 | DrawFrame(right_bar.x+110, outy, CELL, CELL, NULL); |
476 | DrawBar(right_bar.x+110+2, outy+2, CELL-4, CELL-4, color2); |
||
7207 | leency | 477 | sprintf(#param, "%A", color2); |
7151 | leency | 478 | EDI = system.color.work; |
479 | WriteText(right_bar.x+110 + 30, outy + 3, 0xD0, system.color.work_text, #param+4); |
||
7200 | leency | 480 | DrawCurrentColorGradientByLightness(); |
7089 | leency | 481 | } |
482 | |||
7200 | leency | 483 | void DrawCurrentColorGradientByLightness() |
7194 | leency | 484 | { |
485 | int i; |
||
486 | int w = right_bar.w-10/2; |
||
487 | for (i=0; i |
||
7200 | leency | 488 | DrawBar(b_color_gradient.x+i, b_color_gradient.y, |
7207 | leency | 489 | 1, b_color_gradient.h, MixColors(color1,0xFFFfff,255*i/w)); |
7194 | leency | 490 | for (i=0 ; i<=w; i++) |
7200 | leency | 491 | DrawBar(b_color_gradient.x+w+w-i, b_color_gradient.y, |
7207 | leency | 492 | 1, b_color_gradient.h, MixColors(color1,0x000000,255*i/w)); |
7194 | leency | 493 | } |
494 | |||
7200 | leency | 495 | void DrawColorPallets() |
7089 | leency | 496 | { |
7155 | leency | 497 | int r, c, i=0; |
498 | //Last used colors |
||
499 | for (r = 0; r < 2; r++) |
||
500 | { |
||
7194 | leency | 501 | for (c = 0; c < PAL_ITEMS_X_COUNT; c++, i++) |
7155 | leency | 502 | { |
7200 | leency | 503 | DrawBar(c*COLSIZE + b_last_colors.x, r*COLSIZE + b_last_colors.y, |
504 | COLSIZE, COLSIZE, last_used_colors[i]); |
||
7155 | leency | 505 | } |
506 | } |
||
507 | i=0; |
||
508 | //Default colors |
||
7089 | leency | 509 | for (r = 0; r < 9; r++) |
510 | { |
||
7194 | leency | 511 | for (c = 0; c < PAL_ITEMS_X_COUNT; c++, i++) |
7089 | leency | 512 | { |
7200 | leency | 513 | DrawBar(c*COLSIZE + b_default_palette.x, r*COLSIZE + b_default_palette.y, |
514 | COLSIZE, COLSIZE, default_palette[PALLETE_SIZE-i]); |
||
7089 | leency | 515 | } |
516 | } |
||
517 | } |
||
518 | |||
7257 | leency | 519 | void DrawCanvasPixel(dword _r,_c,_color) |
520 | { |
||
521 | DrawBar(_c*zoom.value + canvas.x, _r*zoom.value + canvas.y, |
||
522 | zoom.value, zoom.value, _color); |
||
523 | } |
||
524 | |||
7155 | leency | 525 | void DrawCanvas() |
526 | { |
||
527 | int r, c; |
||
7257 | leency | 528 | dword color; |
529 | |||
530 | if ((currentTool != TOOL_NONE) && (tools[currentTool].onCanvasDraw != 0)) |
||
531 | { |
||
532 | tools[currentTool].onCanvasDraw(); |
||
533 | } |
||
534 | |||
7155 | leency | 535 | for (r = 0; r < image.rows; r++) |
536 | { |
||
537 | for (c = 0; c < image.columns; c++) |
||
538 | { |
||
7257 | leency | 539 | if (image.pixel_state.is_drawable(r,c)) |
540 | DrawCanvasPixel(r, c, image.get_pixel(r,c)); |
||
7155 | leency | 541 | } |
542 | } |
||
7257 | leency | 543 | image.pixel_state.reset_and_set_all_drawable(); |
7186 | leency | 544 | |
7200 | leency | 545 | DrawPreview(); |
7155 | leency | 546 | } |
547 | |||
7200 | leency | 548 | void DrawPreview() |
549 | { |
||
550 | int x = right_bar.x; |
||
551 | int y = wrapper.y + wrapper.h - image.rows-2; |
||
552 | DrawRectangle(x, y, image.columns+1, image.rows+1, system.color.work_graph); |
||
553 | _PutImage(x+1,y+1, image.columns, image.rows, image.get_image()); |
||
554 | } |
||
7155 | leency | 555 | |
7200 | leency | 556 | dword GetPixelUnderMouse() |
557 | { |
||
558 | return GetPixelColorFromScreen(mouse.x + Form.left + 5, mouse.y + Form.top + skin_height); |
||
559 | } |
||
560 | |||
7265 | leency | 561 | int preview_size = 128; |
562 | void DrawImageWithBg(dword _x, _y, _col_to) |
||
563 | { |
||
564 | _x *= preview_size; |
||
565 | _y *= preview_size; |
||
566 | DrawWideRectangle(_x,_y, preview_size, preview_size, preview_size-image.columns/2, _col_to); |
||
567 | _PutImage(preview_size - image.columns / 2 + _x, preview_size - image.rows / 2 + _y, |
||
568 | image.columns, image.rows, image.get_image_with_replaced_color(color2, _col_to)); |
||
569 | } |
||
570 | |||
571 | void ShowWindow_TestIcon() |
||
572 | { |
||
573 | loop() switch(WaitEvent()) |
||
574 | { |
||
575 | case evButton: |
||
576 | if (GetButtonID()) ExitProcess(); |
||
577 | break; |
||
578 | |||
579 | case evKey: |
||
580 | GetKeys(); |
||
581 | if (key_scancode == SCAN_CODE_ESC) ExitProcess(); |
||
582 | break; |
||
583 | |||
584 | case evReDraw: |
||
585 | DefineAndDrawWindow(Form.left+100, Form.top+100, preview_size*2+9, |
||
586 | preview_size*2+skin_height+4, 0x74, NULL, "Test Icon", 0); |
||
587 | DrawImageWithBg(0, 0, 0x000000); |
||
588 | DrawImageWithBg(1, 0, 0xFFFfff); |
||
589 | DrawImageWithBg(0, 1, GetPixelColorFromScreen(0, 0)); |
||
590 | DrawImageWithBg(1, 1, system.color.work); |
||
591 | break; |
||
592 | } |
||
593 | } |
||
594 | |||
7089 | leency | 595 | //===================================================// |
596 | // // |
||
597 | // EVENTS // |
||
598 | // // |
||
599 | //===================================================// |
||
600 | |||
7257 | leency | 601 | void EventSaveIconToFile() |
7150 | leency | 602 | { |
7257 | leency | 603 | int i=0; |
604 | char save_file_name[4096]; |
||
605 | char save_path_stable[4096]; |
||
606 | strcpy(#save_path_stable, "/tmp0/1"); |
||
607 | do { |
||
608 | i++; |
||
609 | sprintf(#save_file_name, "%s/saved_icon_%i.png", #save_path_stable, i); |
||
610 | } while (file_exists(#save_file_name)); |
||
611 | save_image(image.get_image(), image.columns, image.rows, #save_file_name); |
||
7150 | leency | 612 | } |
7151 | leency | 613 | |
7257 | leency | 614 | void EventCleanCanvas() |
615 | { |
||
616 | EventSaveIconToFile(); |
||
617 | image.create(32, 32); |
||
618 | DrawCanvas(); |
||
619 | } |
||
620 | |||
621 | void EventExitIconEdit() |
||
622 | { |
||
623 | EventSaveIconToFile(); |
||
624 | ExitProcess(); |
||
625 | } |
||
626 | |||
7155 | leency | 627 | void EventSetActiveColor(int _number, _color) |
7151 | leency | 628 | { |
629 | int i; |
||
7155 | leency | 630 | for (i=13*2-1; i>0; i--) { |
631 | last_used_colors[i] = last_used_colors[i-1]; |
||
632 | } |
||
633 | last_used_colors[0] = _color; |
||
7151 | leency | 634 | |
7207 | leency | 635 | if (_number == 1) color1 = _color; |
636 | if (_number == 2) color2 = _color; |
||
7155 | leency | 637 | |
638 | DrawActiveColor(NULL); |
||
7200 | leency | 639 | DrawColorPallets(); |
7156 | leency | 640 | } |
7257 | leency | 641 | |
7265 | leency | 642 | void EventTestIcon() |
643 | { |
||
644 | CreateThread(#ShowWindow_TestIcon, #test_icon_stak+4092); |
||
645 | } |
||
646 | |||
647 | stop: |
||
648 | |||
649 | char test_icon_stak[4096];>>>>>>=w;>>>0)>0)> |