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