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