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