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