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