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