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