Rev 8381 | Rev 8822 | 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 | |||
7521 | leency | 7 | #define MEMSIZE 1024*2000 |
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" |
7447 | leency | 13 | #include "../lib/list_box.h" |
7521 | leency | 14 | #include "../lib/events.h" |
7255 | leency | 15 | |
7096 | leency | 16 | #include "../lib/obj/libimg.h" |
7255 | leency | 17 | #include "../lib/obj/box_lib.h" |
18 | |||
7089 | leency | 19 | #include "../lib/patterns/rgb.h" |
20 | |||
7151 | leency | 21 | #include "colors_mas.h" |
22 | |||
7359 | leency | 23 | #ifndef AUTOBUILD |
7358 | leency | 24 | #include "lang.h--" |
7359 | leency | 25 | #endif |
7358 | leency | 26 | |
7089 | leency | 27 | //===================================================// |
28 | // // |
||
29 | // DATA // |
||
30 | // // |
||
31 | //===================================================// |
||
32 | |||
7358 | leency | 33 | #ifdef LANG_RUS |
7977 | leency | 34 | char edit_menu_items[] = |
35 | "Вырезать|Ctrl+X |
||
36 | Копировать|Ctrl+C |
||
37 | Вставить|Ctrl+V"; |
||
7447 | leency | 38 | char image_menu_items[] = |
39 | "Количество использованных цветов |
||
40 | Заменить все цвета 1 на 2"; |
||
41 | ?define T_MENU_IMAGE "Иконка" |
||
42 | ?define T_TEST_ICON "Проверить иконку" |
||
8256 | leency | 43 | ?define T_TITLE "Редактор иконок 0.70a Beta" |
7823 | leency | 44 | ?define T_UNIC_COLORS_COUNT "'Уникальных цветов: %i.' -I" |
45 | ?define T_TOO_BIG_IMAGE_FOR_PREVIEW "'IconEdit |
||
46 | Изображение слишком большое для предпросмотра!' -tE" |
||
47 | ?define T_ERROR_CROP_TOOL "'Для обрезки изображения вначале нужно выделить область.' -W" |
||
48 | ?define T_ERROR_IMA_ICONEDIT "'Это просто редактор иконок, выбраное |
||
49 | изображение слишком велико для него!' -E" |
||
7358 | leency | 50 | #else |
7977 | leency | 51 | char edit_menu_items[] = |
52 | "Cut|Ctrl+X |
||
53 | Copy|Ctrl+C |
||
54 | Paste|Ctrl+V"; |
||
7447 | leency | 55 | char image_menu_items[] = |
56 | "Count colors used |
||
57 | Replace all colors equal to 1 by 2"; |
||
58 | ?define T_MENU_IMAGE "Icon" |
||
59 | ?define T_TEST_ICON "Test Icon" |
||
7977 | leency | 60 | ?define T_TITLE "Icon Editor 0.70 Beta" |
7823 | leency | 61 | ?define T_UNIC_COLORS_COUNT "'Image has %i unique colors.' -I" |
62 | ?define T_TOO_BIG_IMAGE_FOR_PREVIEW "'IconEdit |
||
63 | Image is too big for preview!' -tE" |
||
64 | ?define T_ERROR_CROP_TOOL "'You need to select something before using crop tool.' -W" |
||
65 | ?define T_ERROR_IMA_ICONEDIT "'Hey, this is just an icon editor, |
||
66 | selected image is too big to open!' -E" |
||
7358 | leency | 67 | #endif |
68 | |||
69 | |||
7096 | leency | 70 | |
7271 | leency | 71 | #define TOPBAR_H 24+8 |
72 | #define LEFTBAR_W 16+5+5+3+3 |
||
7096 | leency | 73 | #define PALLETE_SIZE 116 |
7089 | leency | 74 | |
7194 | leency | 75 | #define PAL_ITEMS_X_COUNT 13 |
76 | #define COLSIZE 18 |
||
7200 | leency | 77 | #define RIGHT_BAR_W PAL_ITEMS_X_COUNT*COLSIZE |
7187 | leency | 78 | |
7253 | leency | 79 | #define TO_CANVAS_X(xval) xval - canvas.x/zoom.value |
80 | #define TO_CANVAS_Y(yval) yval - canvas.y/zoom.value |
||
81 | |||
7200 | leency | 82 | block canvas = { NULL, NULL, NULL, NULL }; |
7271 | leency | 83 | block wrapper = { LEFTBAR_W, TOPBAR_H, NULL, NULL }; |
84 | block right_bar = { NULL, 10+TOPBAR_H, RIGHT_BAR_W+10, NULL }; |
||
7447 | leency | 85 | block image_menu_btn = { NULL, 4, NULL, 22 }; |
7200 | leency | 86 | |
7422 | leency | 87 | dword linear_gradient[RIGHT_BAR_W]; |
88 | block b_color_gradient = {NULL, 40+TOPBAR_H, RIGHT_BAR_W, 25}; |
||
89 | //block b_opacity_gradient = {NULL, 75+TOPBAR_H, RIGHT_BAR_W, 15}; |
||
90 | block b_last_colors = {NULL, 75+TOPBAR_H, RIGHT_BAR_W, COLSIZE}; |
||
91 | block b_default_palette = {NULL, COLSIZE+10+75+TOPBAR_H, RIGHT_BAR_W, COLSIZE*9}; |
||
7200 | leency | 92 | |
7422 | leency | 93 | dword transparent = 0xBFCAD2; |
7207 | leency | 94 | dword color1 = 0x000000; |
7255 | leency | 95 | dword color2 = 0xBFCAD2; |
7207 | leency | 96 | dword tool_color; |
7089 | leency | 97 | |
7257 | leency | 98 | signed hoverX; |
99 | signed hoverY; |
||
100 | signed priorHoverX; |
||
101 | signed priorHoverY; |
||
102 | bool canvasMouseMoved = false; |
||
103 | |||
7521 | leency | 104 | EVENTS button; |
105 | EVENTS key; |
||
106 | |||
7089 | leency | 107 | enum { |
7155 | leency | 108 | BTNS_PALETTE_COLOR_MAS = 100, |
109 | BTNS_LAST_USED_COLORS = 400 |
||
7089 | leency | 110 | }; |
111 | |||
112 | proc_info Form; |
||
7255 | leency | 113 | dword semi_white; |
7422 | leency | 114 | bool bg_dark=false; |
7089 | leency | 115 | |
7243 | leency | 116 | more_less_box zoom = { 11, 1, 40, "Zoom" }; |
7150 | leency | 117 | |
7152 | leency | 118 | dword default_palette[] = { |
7190 | leency | 119 | 0x330000,0x331900,0x333300,0x193300,0x003300,0x003319,0x003333,0x001933,0x000033,0x190033, |
120 | 0x330033,0x330019,0x000000,0x660000,0x663300,0x666600,0x336600,0x006600,0x006633,0x006666, |
||
121 | 0x003366,0x000066,0x330066,0x660066,0x660033,0x202020,0x990000,0x994C00,0x999900,0x4C9900, |
||
122 | 0x009900,0x00994C,0x009999,0x004C99,0x000099,0x4C0099,0x990099,0x99004C,0x404040,0xCC0000, |
||
123 | 0xCC6600,0xCCCC00,0x66CC00,0x00CC00,0x00CC66,0x00CCCC,0x0066CC,0x0000CC,0x6600CC,0xCC00CC, |
||
124 | 0xCC0066,0x606060,0xFF0000,0xFF8000,0xFFFF00,0x80FF00,0x00FF00,0x00FF80,0x00FFFF,0x0080FF, |
||
125 | 0x0000FF,0x7F00FF,0xFF00FF,0xFF007F,0x808080,0xFF3333,0xFF9933,0xFFFF33,0x99FF33,0x33FF33, |
||
126 | 0x33FF99,0x33FFFF,0x3399FF,0x3333FF,0x9933FF,0xFF33FF,0xFF3399,0xA0A0A0,0xFF6666,0xFFB266, |
||
127 | 0xFFFF66,0xB2FF66,0x66FF66,0x66FFB2,0x66FFFF,0x66B2FF,0x6666FF,0xB266FF,0xFF66FF,0xFF66B2, |
||
128 | 0xC0C0C0,0xFF9999,0xFFCC99,0xFFFF99,0xCCFF99,0x99FF99,0x99FFCC,0x99FFFF,0x99CCFF,0x9999FF, |
||
129 | 0xCC99FF,0xFF99FF,0xFF99CC,0xE0E0E0,0xFFCCCC,0xFFE5CC,0xFFFFCC,0xE5FFCC,0xCCFFCC,0xCCFFE5, |
||
130 | 0xCCFFFF,0xCCE5FF,0xCCCCFF,0xE5CCFF,0xFFCCFF,0xFFCCE5,0xFFFFFF |
||
7089 | leency | 131 | }; |
7422 | leency | 132 | |
133 | #define LAST_USED_MAX 13 |
||
134 | dword last_used_colors[LAST_USED_MAX] = { |
||
7190 | leency | 135 | 0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF, |
7422 | leency | 136 | 0xFFFFFF,0xFFFFFF,0xFFFFFF |
7155 | leency | 137 | }; |
7089 | leency | 138 | |
7262 | leency | 139 | CustomCursor Cursor; |
140 | dword CursorBar = FROM "cursors/bar.cur"; |
||
141 | dword CursorFill = FROM "cursors/fill.cur"; |
||
142 | dword CursorLine = FROM "cursors/line.cur"; |
||
143 | dword CursorPencil = FROM "cursors/pencil.cur"; |
||
144 | dword CursorPipette = FROM "cursors/pipette.cur"; |
||
145 | dword CursorRectangle = FROM "cursors/rectangle.cur"; |
||
146 | dword CursorSelect = FROM "cursors/select.cur"; |
||
147 | |||
7155 | leency | 148 | _image image; |
7148 | leency | 149 | |
7204 | leency | 150 | #include "actions_history.h" |
151 | |||
152 | _ActionsHistory actionsHistory; |
||
7151 | leency | 153 | |
7254 | leency | 154 | #include "tools.h" |
7274 | leency | 155 | #include "canvas_resize.h" |
7156 | leency | 156 | |
7089 | leency | 157 | //===================================================// |
158 | // // |
||
159 | // CODE // |
||
160 | // // |
||
161 | //===================================================// |
||
162 | |||
7266 | leency | 163 | libimg_image top_icons; |
164 | libimg_image left_icons; |
||
165 | |||
7089 | leency | 166 | void main() |
167 | { |
||
168 | word btn; |
||
7257 | leency | 169 | libimg_image open_image; |
7089 | leency | 170 | |
7096 | leency | 171 | load_dll(libimg, #libimg_init, 1); |
7255 | leency | 172 | load_dll(boxlib, #box_lib_init,0); |
173 | |||
7977 | leency | 174 | top_icons.load("/sys/icons16.png"); |
175 | left_icons.load("/sys/icons16.png"); |
||
7266 | leency | 176 | |
7806 | leency | 177 | sc.get(); |
7780 | leency | 178 | bg_dark = skin_is_dark(); |
7422 | leency | 179 | |
7806 | leency | 180 | semi_white = MixColors(sc.work, 0xFFFfff, bg_dark*90 + 96); |
7977 | leency | 181 | top_icons.replace_color(0xffFFFfff, semi_white); |
182 | top_icons.replace_color(0xffCACBD6, MixColors(semi_white, 0, 220)); |
||
7089 | leency | 183 | |
7977 | leency | 184 | left_icons.replace_color(0xffFFFfff, sc.work); |
185 | left_icons.replace_color(0xffCACBD6, MixColors(sc.work, 0, 200)); |
||
7266 | leency | 186 | |
7422 | leency | 187 | //fix line and rectandle color for dark skins |
7977 | leency | 188 | if (bg_dark) left_icons.replace_color(0xff545454, 0xffD3D3D4); |
7422 | leency | 189 | |
190 | EventSetActiveColor(1, color1); |
||
191 | |||
7254 | leency | 192 | if (!param[0]) { |
193 | image.create(32, 32); |
||
194 | } |
||
195 | else |
||
196 | { |
||
7995 | leency | 197 | open_image.load(#param); |
198 | open_image.convert_into(IMAGE_BPP24); |
||
7254 | leency | 199 | |
200 | if (open_image.w*open_image.h>MAX_CELL_SIZE*MAX_CELL_SIZE) { |
||
7823 | leency | 201 | notify(T_ERROR_IMA_ICONEDIT); |
7254 | leency | 202 | ExitProcess(); |
7151 | leency | 203 | } |
204 | else { |
||
7422 | leency | 205 | image.create(open_image.h, open_image.w); |
7254 | leency | 206 | image.set_image(open_image.imgsrc); |
7151 | leency | 207 | } |
208 | } |
||
209 | |||
7204 | leency | 210 | actionsHistory.init(); |
211 | |||
7186 | leency | 212 | initTools(); |
213 | setCurrentTool(TOOL_PENCIL); |
||
214 | |||
7096 | leency | 215 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
216 | |||
7089 | leency | 217 | loop() switch(WaitEvent()) |
218 | { |
||
7096 | leency | 219 | case evMouse: |
7274 | leency | 220 | if (Window_CanvasReSize.thread_exists()) break; |
7096 | leency | 221 | mouse.get(); |
7186 | leency | 222 | |
7207 | leency | 223 | if (mouse.lkm) tool_color = color1; |
224 | if (mouse.pkm) tool_color = color2; |
||
225 | if (mouse.mkm) break; |
||
226 | |||
7257 | leency | 227 | hoverX = mouse.x - canvas.x / zoom.value; |
228 | hoverY = mouse.y - canvas.y / zoom.value; |
||
229 | if (hoverX<0) hoverX = 0; |
||
230 | if (hoverY<0) hoverY = 0; |
||
231 | if (hoverX>image.columns-1) hoverX = image.columns-1; |
||
232 | if (hoverY>image.rows-1) hoverY = image.rows-1; |
||
233 | canvasMouseMoved = false; |
||
234 | if (priorHoverX != hoverX) canvasMouseMoved = true; |
||
235 | if (priorHoverY != hoverY) canvasMouseMoved = true; |
||
236 | priorHoverX = hoverX; |
||
237 | priorHoverY = hoverY; |
||
238 | //DrawBar(Form.cwidth-100, 3, 80, 12, 0xFFFfff); |
||
239 | //WriteText(Form.cwidth-100, 3, 0x80, 0x000000, |
||
240 | // sprintf(#param, "%i %i", hoverX, hoverY)); |
||
241 | |||
7186 | leency | 242 | if (currentTool != TOOL_NONE) |
243 | tools[currentTool].onMouseEvent(mouse.x, mouse.y, mouse.lkm, mouse.pkm); |
||
244 | |||
7156 | leency | 245 | if (mouse.vert) { |
7243 | leency | 246 | if (mouse.vert==65535) zoom.inc(); |
247 | if (mouse.vert==1) zoom.dec(); |
||
7152 | leency | 248 | DrawEditArea(); |
249 | } |
||
7186 | leency | 250 | |
7262 | leency | 251 | if (wrapper.hovered()) SetCursor(); |
252 | else Cursor.Restore(); |
||
253 | |||
7200 | leency | 254 | if (mouse.down) { |
255 | if (b_color_gradient.hovered()) |
||
256 | || (b_last_colors.hovered()) |
||
257 | || (b_default_palette.hovered()) { |
||
258 | if (mouse.key&MOUSE_LEFT) EventSetActiveColor(1, GetPixelUnderMouse()); |
||
259 | if (mouse.key&MOUSE_RIGHT) EventSetActiveColor(2, GetPixelUnderMouse()); |
||
260 | } |
||
261 | } |
||
262 | |||
7148 | leency | 263 | break; |
7096 | leency | 264 | |
7089 | leency | 265 | case evButton: |
7274 | leency | 266 | if (Window_CanvasReSize.thread_exists()) break; |
7148 | leency | 267 | btn = GetButtonID(); |
7253 | leency | 268 | |
7255 | leency | 269 | if (zoom.click(btn)) DrawEditArea(); |
270 | |||
7521 | leency | 271 | button.press(btn); |
7089 | leency | 272 | |
273 | case evKey: |
||
274 | GetKeys(); |
||
7253 | leency | 275 | |
7521 | leency | 276 | if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) key.press(ECTRL + key_scancode); |
7422 | leency | 277 | |
278 | if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) { |
||
279 | if (key_scancode == SCAN_CODE_DEL) EventCleanCanvas(); |
||
280 | } |
||
281 | |||
7253 | leency | 282 | if (currentTool != TOOL_NONE) && (tools[currentTool].onKeyEvent != 0) |
283 | tools[currentTool].onKeyEvent(key_scancode); |
||
284 | |||
7521 | leency | 285 | key.press(key_scancode); |
7204 | leency | 286 | |
7267 | leency | 287 | if (key_scancode == SCAN_CODE_KEY_Z) actionsHistory.undoLastAction(); |
288 | if (key_scancode == SCAN_CODE_KEY_Y) actionsHistory.redoLastAction(); |
||
7204 | leency | 289 | |
7253 | leency | 290 | if (key_scancode == SCAN_CODE_MINUS) {zoom.dec(); DrawEditArea();} |
7274 | leency | 291 | if (key_scancode == SCAN_CODE_PLUS) {zoom.inc(); DrawEditArea();} |
7253 | leency | 292 | |
7089 | leency | 293 | break; |
294 | |||
295 | case evReDraw: |
||
7274 | leency | 296 | Window_CanvasReSize.thread_exists(); |
7781 | leency | 297 | if (CheckActiveProcess(Form.ID)) EventCheckMenuItemSelected(); |
7275 | leency | 298 | DrawWindow(); |
7089 | leency | 299 | break; |
300 | } |
||
301 | } |
||
302 | |||
7521 | leency | 303 | void DrawTopPanelButton(dword _event, _hotkey, _x, _icon_n) |
7096 | leency | 304 | { |
7255 | leency | 305 | DrawWideRectangle(_x, 4, 22, 22, 3, semi_white); |
7806 | leency | 306 | PutPixel(_x,4,sc.work); |
307 | PutPixel(_x,4+21,sc.work); |
||
308 | PutPixel(_x+21,4,sc.work); |
||
309 | PutPixel(_x+21,4+21,sc.work); |
||
7521 | leency | 310 | DefineHiddenButton(_x, 4, 21, 21, button.add(_event)); |
7266 | leency | 311 | img_draw stdcall(top_icons.image, _x+3, 7, 16, 16, 0, _icon_n*16); |
7521 | leency | 312 | if (_hotkey) key.add_n(_hotkey, _event); |
7096 | leency | 313 | } |
314 | |||
7521 | leency | 315 | |
7447 | leency | 316 | int DrawFlatPanelButton(dword _id, _x, _y, _text) |
317 | { |
||
318 | #define P 10 |
||
319 | int w = strlen(_text)*6 + P + P; |
||
320 | DrawBar(_x, _y, w, 22, semi_white); |
||
7806 | leency | 321 | PutPixel(_x,_y,sc.work); |
322 | PutPixel(_x,_y+21,sc.work); |
||
323 | PutPixel(_x+w-1,_y,sc.work); |
||
324 | PutPixel(_x+w-1,_y+21,sc.work); |
||
7447 | leency | 325 | DefineHiddenButton(_x, _y, w, 21, _id); |
7806 | leency | 326 | WriteText(_x+P, _y+7, 0x80, sc.work_text, _text); |
7447 | leency | 327 | return w; |
328 | } |
||
329 | |||
7521 | leency | 330 | void DrawLeftPanelButton(dword _event, _hotkey, _y, _icon_n) |
7187 | leency | 331 | { |
332 | int x = 5; |
||
7806 | leency | 333 | DrawRectangle(x, _y, 22-1, 22-1, sc.work); |
7521 | leency | 334 | DefineHiddenButton(x, _y, 21, 21, button.add(_event)); |
7266 | leency | 335 | img_draw stdcall(left_icons.image, x+3, _y+3, 16, 16, 0, _icon_n*16); |
7521 | leency | 336 | key.add_n(_hotkey, _event); |
7187 | leency | 337 | } |
7148 | leency | 338 | void DrawStatusBar() |
339 | { |
||
7243 | leency | 340 | zoom.draw(wrapper.x, wrapper.y + wrapper.h + 6); |
7150 | leency | 341 | |
7275 | leency | 342 | sprintf(#param,"%i x %i", image.columns, image.rows); |
7274 | leency | 343 | DrawCaptButton( |
7275 | leency | 344 | wrapper.x+wrapper.w-calc(strlen(#param)*8) -6 - 1, |
7274 | leency | 345 | zoom.y, |
7275 | leency | 346 | calc(strlen(#param)*8)+6, |
7274 | leency | 347 | 18, |
7521 | leency | 348 | button.add(#EventCanvasResize), |
7806 | leency | 349 | sc.button, |
350 | sc.button_text, |
||
7275 | leency | 351 | #param |
7274 | leency | 352 | ); |
7148 | leency | 353 | } |
354 | |||
7521 | leency | 355 | |
7275 | leency | 356 | void DrawWindow() |
7089 | leency | 357 | { |
7521 | leency | 358 | #define GAPH 27 |
359 | #define GAPV 28 |
||
7266 | leency | 360 | #define BLOCK_SPACE 10 |
7096 | leency | 361 | incn tx; |
7521 | leency | 362 | incn ty; |
7806 | leency | 363 | sc.get(); |
7271 | leency | 364 | DefineAndDrawWindow(115+random(100), 50+random(100), 700, 540, 0x73, NULL, T_TITLE, 0); |
7089 | leency | 365 | GetProcessInfo(#Form, SelfInfo); |
7152 | leency | 366 | if (Form.status_window>2) return; |
367 | if (Form.width < 560) { MoveSize(OLD,OLD,560,OLD); return; } |
||
368 | if (Form.height < 430) { MoveSize(OLD,OLD,OLD,430); return; } |
||
7521 | leency | 369 | button.init(40); |
370 | key.init(40); |
||
7152 | leency | 371 | |
7150 | leency | 372 | right_bar.x = Form.cwidth - right_bar.w; |
7200 | leency | 373 | b_color_gradient.x = b_last_colors.x = b_default_palette.x = right_bar.x; |
7806 | leency | 374 | DrawBar(0, 0, Form.cwidth, TOPBAR_H-1, sc.work); |
375 | DrawBar(0, TOPBAR_H-1, Form.cwidth, 1, sc.work_graph); |
||
7089 | leency | 376 | |
7977 | leency | 377 | DrawTopPanelButton(#EventCreateNewIcon, ECTRL + SCAN_CODE_KEY_N, tx.set(5), 2); |
7521 | leency | 378 | DrawTopPanelButton(#EventOpenIcon, ECTRL + SCAN_CODE_KEY_O, tx.inc(GAPH), 0); |
379 | DrawTopPanelButton(#EventSaveIconToFile, ECTRL + SCAN_CODE_KEY_S, tx.inc(GAPH), 5); |
||
7977 | leency | 380 | DrawTopPanelButton(#EventMoveLeft, ECTRL + SCAN_CODE_LEFT, tx.inc(GAPH+BLOCK_SPACE), 30); |
7521 | leency | 381 | DrawTopPanelButton(#EventMoveRight, ECTRL + SCAN_CODE_RIGHT, tx.inc(GAPH), 31); |
7977 | leency | 382 | DrawTopPanelButton(#EventMoveUp, ECTRL + SCAN_CODE_UP, tx.inc(GAPH), 32); |
383 | DrawTopPanelButton(#EventMoveDown, ECTRL + SCAN_CODE_DOWN, tx.inc(GAPH), 33); |
||
7521 | leency | 384 | DrawTopPanelButton(#EventFlipHor, 0, tx.inc(GAPH+BLOCK_SPACE), 34); |
385 | DrawTopPanelButton(#EventFlipVer, 0, tx.inc(GAPH), 35); |
||
386 | DrawTopPanelButton(#EventRotateLeft, ECTRL + SCAN_CODE_KEY_L, tx.inc(GAPH), 37); |
||
387 | DrawTopPanelButton(#EventRotateRight, ECTRL + SCAN_CODE_KEY_R, tx.inc(GAPH), 36); |
||
388 | DrawTopPanelButton(#EventTestIcon, ECTRL + SCAN_CODE_KEY_T, tx.inc(GAPH+BLOCK_SPACE), 12); |
||
389 | DrawTopPanelButton(#EventCrop, 0, tx.inc(GAPH+BLOCK_SPACE), 46); |
||
7265 | leency | 390 | |
7977 | leency | 391 | image_menu_btn.x = tx.inc(GAPH+BLOCK_SPACE); |
7521 | leency | 392 | image_menu_btn.w = DrawFlatPanelButton(button.add(#EventShowImageMenu), image_menu_btn.x, image_menu_btn.y, T_MENU_IMAGE); |
7447 | leency | 393 | //tx.inc(image_menu_btn.w + BLOCK_SPACE); |
7186 | leency | 394 | |
7150 | leency | 395 | DrawEditArea(); |
7096 | leency | 396 | |
7806 | leency | 397 | DrawBar(0, TOPBAR_H, LEFTBAR_W-1, Form.cheight - TOPBAR_H, sc.work); |
7274 | leency | 398 | |
7521 | leency | 399 | ty.n = right_bar.y - GAPV - 2; |
400 | |||
401 | DrawLeftPanelButton(#EventSelectToolPencil, SCAN_CODE_KEY_P, ty.inc(GAPV), 38); |
||
402 | DrawLeftPanelButton(#EventSelectToolPick, SCAN_CODE_KEY_I, ty.inc(GAPV), 39); |
||
403 | DrawLeftPanelButton(#EventSelectToolFill, SCAN_CODE_KEY_F, ty.inc(GAPV), 40); |
||
404 | DrawLeftPanelButton(#EventSelectToolLine, SCAN_CODE_KEY_L, ty.inc(GAPV), 41); |
||
405 | DrawLeftPanelButton(#EventSelectToolRect, SCAN_CODE_KEY_R, ty.inc(GAPV), 42); |
||
406 | DrawLeftPanelButton(#EventSelectToolBar, SCAN_CODE_KEY_B, ty.inc(GAPV), 43); |
||
407 | DrawLeftPanelButton(#EventSelectToolSelect, SCAN_CODE_KEY_S, ty.inc(GAPV), 44); |
||
408 | DrawLeftPanelButton(#EventSelectToolScrCopy,SCAN_CODE_KEY_Q, ty.inc(GAPV), 45); |
||
409 | DrawLeftPanelSelection(); |
||
410 | |||
411 | button.add_n(1, #EventExitIconEdit); |
||
412 | |||
7271 | leency | 413 | DrawBar(wrapper.x+wrapper.w, TOPBAR_H, Form.cwidth-wrapper.x-wrapper.w, |
7806 | leency | 414 | Form.cheight - TOPBAR_H, sc.work); |
7274 | leency | 415 | DrawActiveColor(right_bar.y); |
416 | DrawColorPallets(); |
||
417 | DrawPreview(); |
||
418 | |||
7271 | leency | 419 | DrawBar(LEFTBAR_W-1, wrapper.y + wrapper.h, wrapper.w+1, |
7806 | leency | 420 | Form.cheight - wrapper.y - wrapper.h, sc.work); |
7148 | leency | 421 | DrawStatusBar(); |
7089 | leency | 422 | } |
423 | |||
7521 | leency | 424 | void DrawLeftPanelSelection() |
7187 | leency | 425 | { |
7806 | leency | 426 | if (previousTool!=-1) DrawRectangle3D(5, previousTool*GAPV+right_bar.y-2, 16+3+2, 16+3+2, sc.work, sc.work); |
7521 | leency | 427 | DrawRectangle3D(5, currentTool*GAPV+right_bar.y-2, 16+3+2, 16+3+2, 0x333333, 0x777777); |
7187 | leency | 428 | } |
429 | |||
7151 | leency | 430 | void DrawEditArea() |
7089 | leency | 431 | { |
7150 | leency | 432 | dword color1=0xC0C0C0; |
7155 | leency | 433 | int top_side; |
434 | int left_side; |
||
7089 | leency | 435 | |
7194 | leency | 436 | wrapper.w = Form.cwidth - right_bar.w - 10 - wrapper.x; |
7271 | leency | 437 | wrapper.h = Form.cheight - TOPBAR_H - 35; |
7148 | leency | 438 | |
7150 | leency | 439 | //canvas{ |
7151 | leency | 440 | canvas.w = image.columns * zoom.value; |
441 | canvas.h = image.rows * zoom.value; |
||
442 | if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) { |
||
7254 | leency | 443 | zoom.value--; |
7422 | leency | 444 | if (zoom.x) zoom.redraw(); |
7151 | leency | 445 | DrawEditArea(); |
446 | return; |
||
447 | } |
||
448 | canvas.x = -zoom.value*image.columns+wrapper.w/2 + wrapper.x; |
||
449 | canvas.y = -zoom.value*image.rows+wrapper.h/2 + wrapper.y; |
||
450 | DrawCanvas(); |
||
7150 | leency | 451 | //} |
7089 | leency | 452 | |
7155 | leency | 453 | left_side = canvas.x-wrapper.x-1; |
454 | top_side = canvas.y-wrapper.y-1; |
||
7148 | leency | 455 | |
7806 | leency | 456 | DrawRectangle(wrapper.x-1, wrapper.y-1, wrapper.w, wrapper.h, sc.work_graph); |
7150 | leency | 457 | |
7155 | leency | 458 | if (left_side>0) |
7150 | leency | 459 | { |
7155 | leency | 460 | DrawBar(wrapper.x, wrapper.y, wrapper.w-1, top_side, color1); //top |
461 | DrawBar(wrapper.x, wrapper.y+wrapper.h-top_side-1, wrapper.w-1, top_side, color1); //bottom |
||
7150 | leency | 462 | } |
7155 | leency | 463 | if (top_side>0) |
7150 | leency | 464 | { |
7190 | leency | 465 | //left |
466 | DrawBar(wrapper.x, wrapper.y+top_side, left_side, |
||
467 | wrapper.h-top_side-top_side, color1); |
||
468 | //right |
||
469 | DrawBar(wrapper.x+wrapper.w-left_side-1, wrapper.y+top_side, left_side, |
||
470 | wrapper.h-top_side-top_side, color1); |
||
7150 | leency | 471 | } |
7194 | leency | 472 | DrawRectangle(canvas.x-1, canvas.y-1, canvas.w+1, canvas.h+1, 0x808080); |
7089 | leency | 473 | } |
474 | |||
475 | void DrawActiveColor(dword iny) |
||
476 | { |
||
7255 | leency | 477 | #define CELL 20 |
7089 | leency | 478 | static dword outy; |
479 | if (iny != NULL) outy = iny; |
||
7255 | leency | 480 | DrawFrame(right_bar.x, outy, CELL, CELL, NULL); |
481 | DrawBar(right_bar.x+2, outy+2, CELL-4, CELL-4, color1); |
||
7151 | leency | 482 | |
7422 | leency | 483 | DrawFrame(right_bar.x+CELL+5, outy, CELL, CELL, NULL); |
484 | DrawBar(right_bar.x+CELL+5+2, outy+2, CELL-4, CELL-4, color2); |
||
485 | |||
486 | //sprintf(#param, "%A", color1); |
||
7806 | leency | 487 | //WriteTextWithBg(right_bar.x+30, outy+3, 0xD0, sc.work_text, #param+4, sc.work); |
7422 | leency | 488 | DrawCurrentColorGradient(); |
7089 | leency | 489 | } |
490 | |||
7422 | leency | 491 | int lmax; |
492 | void GenerateCurrentColorGradient() |
||
7194 | leency | 493 | { |
7422 | leency | 494 | int i, avg, rmax; |
495 | |||
496 | rgb.DwordToRgb(color1); |
||
497 | avg = 255 - calc(rgb.r + rgb.g + rgb.b / 3); |
||
498 | |||
499 | lmax = b_color_gradient.w *avg/255 | 1; |
||
500 | rmax = b_color_gradient.w - lmax | 1; |
||
501 | if (lmax == 0) lmax=1; |
||
502 | if (rmax == 0) rmax=1; |
||
503 | |||
504 | for (i=0; i |
||
505 | linear_gradient[i] = MixColors(color1,0xFFFfff,255*i/lmax); |
||
506 | } |
||
507 | |||
508 | for (i=0 ; i<=rmax; i++) { |
||
509 | linear_gradient[lmax+rmax - i] = MixColors(color1,0x000000,255*i/rmax); |
||
510 | } |
||
511 | } |
||
512 | |||
7444 | leency | 513 | int DrawGradientMarker(dword marker_x, marker_color) |
514 | { |
||
515 | if (marker_x > b_color_gradient.w - 1) marker_x = b_color_gradient.w - 1; |
||
516 | DrawBar(b_color_gradient.x + marker_x-2, b_color_gradient.y-3, 5, 1, marker_color); |
||
517 | DrawBar(b_color_gradient.x + marker_x-1, b_color_gradient.y-2, 3, 1, marker_color); |
||
518 | PutPixel(b_color_gradient.x + marker_x, b_color_gradient.y-1, marker_color); |
||
519 | return marker_x; |
||
520 | } |
||
521 | |||
522 | int old_marker_pos; |
||
7422 | leency | 523 | void DrawCurrentColorGradient() |
524 | { |
||
7194 | leency | 525 | int i; |
7422 | leency | 526 | for (i=0 ; i |
527 | DrawBar(b_color_gradient.x+i, b_color_gradient.y, 1, b_color_gradient.h, linear_gradient[i]); |
||
528 | } |
||
7806 | leency | 529 | DrawGradientMarker(old_marker_pos, sc.work); |
7444 | leency | 530 | old_marker_pos = DrawGradientMarker(lmax, 0xFFFfff * bg_dark); |
7194 | leency | 531 | } |
532 | |||
7200 | leency | 533 | void DrawColorPallets() |
7089 | leency | 534 | { |
7155 | leency | 535 | int r, c, i=0; |
536 | //Last used colors |
||
7422 | leency | 537 | for (r = 0; r < LAST_USED_MAX/PAL_ITEMS_X_COUNT; r++) |
7155 | leency | 538 | { |
7194 | leency | 539 | for (c = 0; c < PAL_ITEMS_X_COUNT; c++, i++) |
7155 | leency | 540 | { |
7200 | leency | 541 | DrawBar(c*COLSIZE + b_last_colors.x, r*COLSIZE + b_last_colors.y, |
542 | COLSIZE, COLSIZE, last_used_colors[i]); |
||
7155 | leency | 543 | } |
544 | } |
||
545 | i=0; |
||
546 | //Default colors |
||
7089 | leency | 547 | for (r = 0; r < 9; r++) |
548 | { |
||
7194 | leency | 549 | for (c = 0; c < PAL_ITEMS_X_COUNT; c++, i++) |
7089 | leency | 550 | { |
7200 | leency | 551 | DrawBar(c*COLSIZE + b_default_palette.x, r*COLSIZE + b_default_palette.y, |
552 | COLSIZE, COLSIZE, default_palette[PALLETE_SIZE-i]); |
||
7089 | leency | 553 | } |
554 | } |
||
555 | } |
||
556 | |||
7257 | leency | 557 | void DrawCanvasPixel(dword _r,_c,_color) |
558 | { |
||
559 | DrawBar(_c*zoom.value + canvas.x, _r*zoom.value + canvas.y, |
||
560 | zoom.value, zoom.value, _color); |
||
561 | } |
||
562 | |||
7155 | leency | 563 | void DrawCanvas() |
564 | { |
||
565 | int r, c; |
||
7257 | leency | 566 | dword color; |
567 | |||
568 | if ((currentTool != TOOL_NONE) && (tools[currentTool].onCanvasDraw != 0)) |
||
569 | { |
||
570 | tools[currentTool].onCanvasDraw(); |
||
571 | } |
||
572 | |||
7155 | leency | 573 | for (r = 0; r < image.rows; r++) |
574 | { |
||
575 | for (c = 0; c < image.columns; c++) |
||
576 | { |
||
7257 | leency | 577 | if (image.pixel_state.is_drawable(r,c)) |
578 | DrawCanvasPixel(r, c, image.get_pixel(r,c)); |
||
7155 | leency | 579 | } |
580 | } |
||
7257 | leency | 581 | image.pixel_state.reset_and_set_all_drawable(); |
7186 | leency | 582 | |
7200 | leency | 583 | DrawPreview(); |
7155 | leency | 584 | } |
585 | |||
7200 | leency | 586 | void DrawPreview() |
587 | { |
||
588 | int x = right_bar.x; |
||
7444 | leency | 589 | int y = b_default_palette.y + b_default_palette.h + 6; |
590 | int preview_h = Form.cheight - y; |
||
591 | |||
592 | if (image.columns > right_bar.w) return; |
||
593 | if (image.rows > preview_h) return; |
||
594 | |||
595 | _PutImage(right_bar.w - image.columns / 2 + x - 3, |
||
596 | preview_h - image.rows / 2 + y, |
||
597 | image.columns, image.rows, image.get_image() |
||
598 | ); |
||
7200 | leency | 599 | } |
7155 | leency | 600 | |
7200 | leency | 601 | dword GetPixelUnderMouse() |
602 | { |
||
603 | return GetPixelColorFromScreen(mouse.x + Form.left + 5, mouse.y + Form.top + skin_height); |
||
604 | } |
||
605 | |||
7265 | leency | 606 | int preview_size = 128; |
607 | void DrawImageWithBg(dword _x, _y, _col_to) |
||
608 | { |
||
609 | _x *= preview_size; |
||
610 | _y *= preview_size; |
||
611 | DrawWideRectangle(_x,_y, preview_size, preview_size, preview_size-image.columns/2, _col_to); |
||
612 | _PutImage(preview_size - image.columns / 2 + _x, preview_size - image.rows / 2 + _y, |
||
613 | image.columns, image.rows, image.get_image_with_replaced_color(color2, _col_to)); |
||
614 | } |
||
615 | |||
616 | void ShowWindow_TestIcon() |
||
617 | { |
||
7422 | leency | 618 | if (image.rows>=preview_size) || (image.columns>=preview_size) { |
7823 | leency | 619 | notify(T_TOO_BIG_IMAGE_FOR_PREVIEW); |
7422 | leency | 620 | return; |
621 | } |
||
7265 | leency | 622 | loop() switch(WaitEvent()) |
623 | { |
||
624 | case evButton: |
||
625 | if (GetButtonID()) ExitProcess(); |
||
626 | break; |
||
627 | |||
628 | case evKey: |
||
629 | GetKeys(); |
||
630 | if (key_scancode == SCAN_CODE_ESC) ExitProcess(); |
||
631 | break; |
||
632 | |||
633 | case evReDraw: |
||
634 | DefineAndDrawWindow(Form.left+100, Form.top+100, preview_size*2+9, |
||
7447 | leency | 635 | preview_size*2+skin_height+4, 0x74, NULL, T_TEST_ICON, 0); |
7265 | leency | 636 | DrawImageWithBg(0, 0, 0x000000); |
637 | DrawImageWithBg(1, 0, 0xFFFfff); |
||
638 | DrawImageWithBg(0, 1, GetPixelColorFromScreen(0, 0)); |
||
7806 | leency | 639 | DrawImageWithBg(1, 1, sc.work); |
7265 | leency | 640 | break; |
641 | } |
||
642 | } |
||
643 | |||
7089 | leency | 644 | //===================================================// |
645 | // // |
||
646 | // EVENTS // |
||
647 | // // |
||
648 | //===================================================// |
||
649 | |||
7274 | leency | 650 | void EventCreateNewIcon() |
651 | { |
||
652 | EventSaveIconToFile(); |
||
653 | Window_CanvasReSize.create(); |
||
654 | } |
||
655 | |||
7422 | leency | 656 | void EventOpenIcon() |
657 | { |
||
658 | RunProgram("/sys/lod", sprintf(#param, "*png* %s",#program_path)); |
||
659 | } |
||
660 | |||
7257 | leency | 661 | void EventSaveIconToFile() |
7150 | leency | 662 | { |
7257 | leency | 663 | int i=0; |
664 | char save_file_name[4096]; |
||
665 | char save_path_stable[4096]; |
||
666 | strcpy(#save_path_stable, "/tmp0/1"); |
||
667 | do { |
||
668 | i++; |
||
669 | sprintf(#save_file_name, "%s/saved_icon_%i.png", #save_path_stable, i); |
||
670 | } while (file_exists(#save_file_name)); |
||
671 | save_image(image.get_image(), image.columns, image.rows, #save_file_name); |
||
7150 | leency | 672 | } |
7151 | leency | 673 | |
7257 | leency | 674 | void EventCleanCanvas() |
675 | { |
||
7274 | leency | 676 | image.create(image.rows, image.columns); |
677 | actionsHistory.saveCurrentState(); |
||
7257 | leency | 678 | DrawCanvas(); |
679 | } |
||
680 | |||
681 | void EventExitIconEdit() |
||
682 | { |
||
683 | EventSaveIconToFile(); |
||
684 | ExitProcess(); |
||
685 | } |
||
686 | |||
7155 | leency | 687 | void EventSetActiveColor(int _number, _color) |
7151 | leency | 688 | { |
689 | int i; |
||
7422 | leency | 690 | if (last_used_colors[0] == _color) return; |
691 | for (i=LAST_USED_MAX-1; i>0; i--) { |
||
7155 | leency | 692 | last_used_colors[i] = last_used_colors[i-1]; |
693 | } |
||
694 | last_used_colors[0] = _color; |
||
7151 | leency | 695 | |
7207 | leency | 696 | if (_number == 1) color1 = _color; |
697 | if (_number == 2) color2 = _color; |
||
7155 | leency | 698 | |
7422 | leency | 699 | if (b_color_gradient.hovered()) { |
700 | lmax = mouse.x - b_color_gradient.x; |
||
701 | } |
||
702 | else { |
||
703 | GenerateCurrentColorGradient(); |
||
704 | } |
||
7155 | leency | 705 | DrawActiveColor(NULL); |
7200 | leency | 706 | DrawColorPallets(); |
7156 | leency | 707 | } |
7257 | leency | 708 | |
7265 | leency | 709 | void EventTestIcon() |
710 | { |
||
711 | CreateThread(#ShowWindow_TestIcon, #test_icon_stak+4092); |
||
712 | } |
||
713 | |||
7267 | leency | 714 | void EventMove(dword _action) |
715 | { |
||
7273 | leency | 716 | if (selection.state) { |
717 | selection.buf.move(_action); |
||
7271 | leency | 718 | SelectTool_onCanvasDraw(); |
7267 | leency | 719 | } |
720 | else { |
||
721 | image.move(_action); |
||
722 | DrawCanvas(); |
||
7271 | leency | 723 | } |
724 | actionsHistory.saveCurrentState(); |
||
7267 | leency | 725 | } |
726 | |||
7275 | leency | 727 | void EventCrop() |
728 | { |
||
729 | if (selection.state) { |
||
730 | EventSaveIconToFile(); |
||
731 | image.create(selection.buf.rows, selection.buf.columns); |
||
732 | selection.move_to_point(0,0); |
||
733 | selection.apply_to_image(); |
||
734 | selection.reset(); |
||
735 | actionsHistory.init(); |
||
736 | DrawWindow(); |
||
737 | } |
||
738 | else { |
||
7823 | leency | 739 | notify(T_ERROR_CROP_TOOL); |
7275 | leency | 740 | } |
741 | } |
||
742 | |||
7447 | leency | 743 | void EventShowImageMenu() |
744 | { |
||
8020 | leency | 745 | open_lmenu(image_menu_btn.x, image_menu_btn.y + image_menu_btn.h, |
746 | MENU_TOP_LEFT, NULL, #image_menu_items); |
||
7447 | leency | 747 | } |
748 | |||
7977 | leency | 749 | void EventShowEditMenu() |
750 | { |
||
8020 | leency | 751 | open_lmenu(image_menu_btn.x, image_menu_btn.y + image_menu_btn.h, |
752 | MENU_TOP_LEFT, NULL, #edit_menu_items); |
||
7977 | leency | 753 | } |
754 | |||
7447 | leency | 755 | void EventCheckMenuItemSelected() |
756 | { |
||
7781 | leency | 757 | switch(get_menu_click()) { |
758 | case 1: |
||
759 | EventCountColorsUsed(); |
||
760 | break; |
||
761 | case 2: |
||
762 | EventReplaceImageColors(color1, color2); |
||
763 | break; |
||
7447 | leency | 764 | } |
765 | } |
||
766 | |||
767 | void EventCountColorsUsed() |
||
768 | { |
||
769 | char res_str[64]; |
||
770 | int cur, prev; |
||
771 | int max = image.rows*image.columns; |
||
772 | int resi=0; |
||
773 | bool unic; |
||
774 | for (cur=0; cur |
||
775 | unic = true; |
||
776 | for (prev=0; prev |
||
777 | if (image.mas[prev] == image.mas[cur]) {unic=false; break;} |
||
778 | } |
||
779 | if (unic) resi++; |
||
780 | } |
||
7823 | leency | 781 | notify( sprintf(#res_str, T_UNIC_COLORS_COUNT, resi) ); |
7447 | leency | 782 | } |
783 | |||
784 | void EventReplaceImageColors(dword c1, c2) |
||
785 | { |
||
786 | int max = image.rows*image.columns; |
||
787 | int cur; |
||
788 | for (cur=0; cur |
||
789 | if (image.mas[cur] == color1) image.mas[cur] = color2; |
||
790 | } |
||
791 | } |
||
792 | |||
7521 | leency | 793 | void EventCanvasResize() |
794 | { |
||
795 | notify("Sorry, not implemented yet."); |
||
796 | } |
||
797 | |||
798 | void EventMoveLeft() { EventMove(MOVE_LEFT); } |
||
799 | void EventMoveRight() { EventMove(MOVE_RIGHT); } |
||
800 | void EventMoveUp() { EventMove(MOVE_UP); } |
||
801 | void EventMoveDown() { EventMove(MOVE_DOWN); } |
||
802 | void EventFlipHor() { EventMove(FLIP_HOR); } |
||
803 | void EventFlipVer() { EventMove(FLIP_VER); } |
||
804 | void EventRotateLeft() { EventMove(ROTATE_LEFT); } |
||
805 | void EventRotateRight() { EventMove(ROTATE_RIGHT); } |
||
806 | |||
7977 | leency | 807 | void EventSelectToolPencil() { setCurrentTool(TOOL_PENCIL); } |
808 | void EventSelectToolPick() { setCurrentTool(TOOL_PIPETTE); } |
||
809 | void EventSelectToolFill() { setCurrentTool(TOOL_FILL); } |
||
810 | void EventSelectToolLine() { setCurrentTool(TOOL_LINE); } |
||
811 | void EventSelectToolRect() { setCurrentTool(TOOL_RECT); } |
||
812 | void EventSelectToolBar() { setCurrentTool(TOOL_BAR); } |
||
813 | void EventSelectToolSelect() { setCurrentTool(TOOL_SELECT); } |
||
814 | void EventSelectToolScrCopy() { setCurrentTool(TOOL_SCREEN_COPY); } |
||
7521 | leency | 815 | |
816 | char test_icon_stak22[4096]; |
||
817 | |||
7265 | leency | 818 | stop: |
819 | |||
820 | char test_icon_stak[4096];>>>>>>=rmax;>>>0)>0)> |