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