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