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