Rev 7150 | Rev 7152 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7089 | leency | 1 | /* |
2 | * BACKGEN - Background generator |
||
3 | * Author: Leency |
||
4 | * Licence: GPL v2 |
||
5 | */ |
||
6 | |||
7151 | leency | 7 | /* |
8 | TODO/BUGS |
||
9 | Flip first pixel doesn't work well |
||
10 | Open with param |
||
11 | Set minimal window size |
||
12 | Scroll mouse, +/- keyboard |
||
13 | */ |
||
14 | |||
7096 | leency | 15 | #define MEMSIZE 4096*40 |
7089 | leency | 16 | |
17 | #include "../lib/gui.h" |
||
7151 | leency | 18 | #include "../lib/random.h" |
19 | #include "../lib/mem.h" |
||
7096 | leency | 20 | #include "../lib/obj/libimg.h" |
7089 | leency | 21 | #include "../lib/patterns/rgb.h" |
7096 | leency | 22 | #include "../lib/patterns/libimg_load_skin.h" |
7089 | leency | 23 | |
7151 | leency | 24 | #include "colors_mas.h" |
25 | |||
7089 | leency | 26 | //===================================================// |
27 | // // |
||
28 | // DATA // |
||
29 | // // |
||
30 | //===================================================// |
||
31 | |||
7151 | leency | 32 | #define T_TITLE "Icon Editor 0.08" |
7096 | leency | 33 | |
7151 | leency | 34 | #define TOOLBAR_H 24+9 |
7096 | leency | 35 | #define PALLETE_SIZE 116 |
7089 | leency | 36 | |
7151 | leency | 37 | rect wrapper = { 10, TOOLBAR_H, NULL, NULL }; |
38 | rect right_bar = { NULL, TOOLBAR_H, 280, NULL }; |
||
39 | rect canvas = { NULL, NULL, NULL, NULL }; |
||
7089 | leency | 40 | |
7150 | leency | 41 | dword active_color_1 = 0x000000; |
42 | dword active_color_2 = 0xFFFfff; |
||
7089 | leency | 43 | |
44 | enum { |
||
7096 | leency | 45 | BTN_NEW = 40, |
46 | BTN_OPEN, |
||
47 | BTN_SAVE, |
||
48 | BTN_MOVE_LEFT, |
||
49 | BTN_MOVE_RIGHT, |
||
50 | BTN_MOVE_UP, |
||
51 | BTN_MOVE_DOWN, |
||
52 | BTN_FLIP_HOR, |
||
53 | BTN_FLIP_VER, |
||
54 | BTN_ROTATE_LEFT, |
||
55 | BTN_ROTATE_RIGHT, |
||
56 | BTN_PICK, |
||
57 | BTN_PALETTE_COLOR_MAS = 100, |
||
7089 | leency | 58 | }; |
59 | |||
60 | proc_info Form; |
||
61 | |||
7096 | leency | 62 | bool pick_active = false; |
63 | |||
7151 | leency | 64 | #define ZOOM_IN 22 |
65 | #define ZOOM_OUT 23 |
||
66 | more_less_box zoom = { NULL, NULL, 11, 1, 40, ZOOM_IN, ZOOM_OUT, "Zoom" }; |
||
7150 | leency | 67 | |
68 | dword palette_colors[] = { |
||
7089 | leency | 69 | 0x330000,0x331900,0x333300,0x193300,0x003300,0x003319,0x003333,0x001933,0x000033,0x190033,0x330033,0x330019,0x000000, |
70 | 0x660000,0x663300,0x666600,0x336600,0x006600,0x006633,0x006666,0x003366,0x000066,0x330066,0x660066,0x660033,0x202020, |
||
71 | 0x990000,0x994C00,0x999900,0x4C9900,0x009900,0x00994C,0x009999,0x004C99,0x000099,0x4C0099,0x990099,0x99004C,0x404040, |
||
72 | 0xCC0000,0xCC6600,0xCCCC00,0x66CC00,0x00CC00,0x00CC66,0x00CCCC,0x0066CC,0x0000CC,0x6600CC,0xCC00CC,0xCC0066,0x606060, |
||
73 | 0xFF0000,0xFF8000,0xFFFF00,0x80FF00,0x00FF00,0x00FF80,0x00FFFF,0x0080FF,0x0000FF,0x7F00FF,0xFF00FF,0xFF007F,0x808080, |
||
74 | 0xFF3333,0xFF9933,0xFFFF33,0x99FF33,0x33FF33,0x33FF99,0x33FFFF,0x3399FF,0x3333FF,0x9933FF,0xFF33FF,0xFF3399,0xA0A0A0, |
||
75 | 0xFF6666,0xFFB266,0xFFFF66,0xB2FF66,0x66FF66,0x66FFB2,0x66FFFF,0x66B2FF,0x6666FF,0xB266FF,0xFF66FF,0xFF66B2,0xC0C0C0, |
||
76 | 0xFF9999,0xFFCC99,0xFFFF99,0xCCFF99,0x99FF99,0x99FFCC,0x99FFFF,0x99CCFF,0x9999FF,0xCC99FF,0xFF99FF,0xFF99CC,0xE0E0E0, |
||
77 | 0xFFCCCC,0xFFE5CC,0xFFFFCC,0xE5FFCC,0xCCFFCC,0xCCFFE5,0xCCFFFF,0xCCE5FF,0xCCCCFF,0xE5CCFF,0xFFCCFF,0xFFCCE5,0xFFFFFF |
||
78 | }; |
||
79 | |||
7151 | leency | 80 | _colors image; |
7148 | leency | 81 | |
7151 | leency | 82 | libimg_image open_image; |
83 | |||
7089 | leency | 84 | //===================================================// |
85 | // // |
||
86 | // CODE // |
||
87 | // // |
||
88 | //===================================================// |
||
89 | |||
90 | void main() |
||
91 | { |
||
92 | word btn; |
||
93 | |||
7096 | leency | 94 | load_dll(libio, #libio_init, 1); |
95 | load_dll(libimg, #libimg_init, 1); |
||
96 | Libimg_LoadImage(#skin, "/sys/icons16.png"); |
||
97 | |||
7151 | leency | 98 | CreateCanvas(); |
7089 | leency | 99 | |
7151 | leency | 100 | /* |
101 | if (param) { |
||
102 | Libimg_LoadImage(#open_image, #param); |
||
103 | if (open_image.w==32) && (open_image.h==32) { |
||
104 | memmov(#image.mas, open_image.image, 32*32*3); |
||
105 | } |
||
106 | else { |
||
107 | notify("'Error: image format is unacceptable.\nOnly images created in IconEditor (BMP, 32x32x16b) can be opened!' -E"); |
||
108 | } |
||
109 | } |
||
110 | */ |
||
111 | |||
7096 | leency | 112 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
113 | |||
7089 | leency | 114 | loop() switch(WaitEvent()) |
115 | { |
||
7096 | leency | 116 | case evMouse: |
117 | mouse.get(); |
||
7150 | leency | 118 | if (pick_active) EventPickColor(mouse.lkm, mouse.pkm); |
7148 | leency | 119 | else { |
7151 | leency | 120 | if (mouse.x>canvas.x) && (mouse.y>canvas.y) |
7150 | leency | 121 | && (mouse.y |
7148 | leency | 122 | { |
7151 | leency | 123 | if (mouse.lkm) image.set_pixel(mouse.y-canvas.y/zoom.value, |
124 | mouse.x-canvas.x/zoom.value, active_color_1); |
||
125 | if (mouse.pkm) image.set_pixel(mouse.y-canvas.y/zoom.value, |
||
126 | mouse.x-canvas.x/zoom.value, active_color_2); |
||
127 | DrawCanvas(); |
||
7148 | leency | 128 | } |
129 | } |
||
130 | break; |
||
7096 | leency | 131 | |
7089 | leency | 132 | case evButton: |
7148 | leency | 133 | btn = GetButtonID(); |
7096 | leency | 134 | switch(btn) |
135 | { |
||
7151 | leency | 136 | case BTN_NEW: |
137 | CreateCanvas(); |
||
138 | DrawCanvas(); |
||
139 | break; |
||
140 | case BTN_OPEN: |
||
141 | RunProgram("/sys/lod", sprintf(#param, "*bmp* %s",#program_path)); |
||
142 | break; |
||
143 | case BTN_SAVE: |
||
144 | EventSave(); |
||
145 | break; |
||
7096 | leency | 146 | case BTN_MOVE_LEFT: |
7151 | leency | 147 | image.move(MOVE_LEFT); |
148 | DrawCanvas(); |
||
7096 | leency | 149 | break; |
150 | case BTN_MOVE_RIGHT: |
||
7151 | leency | 151 | image.move(MOVE_RIGHT); |
152 | DrawCanvas(); |
||
7096 | leency | 153 | break; |
7147 | leency | 154 | case BTN_MOVE_UP: |
7151 | leency | 155 | image.move(MOVE_UP); |
156 | DrawCanvas(); |
||
7147 | leency | 157 | break; |
158 | case BTN_MOVE_DOWN: |
||
7151 | leency | 159 | image.move(MOVE_DOWN); |
160 | DrawCanvas(); |
||
7147 | leency | 161 | break; |
7151 | leency | 162 | case BTN_FLIP_VER: |
163 | image.move(FLIP_VER); |
||
164 | DrawCanvas(); |
||
165 | break; |
||
166 | case BTN_FLIP_HOR: |
||
167 | image.move(FLIP_HOR); |
||
168 | DrawCanvas(); |
||
169 | break; |
||
7096 | leency | 170 | case CLOSE_BTN: |
171 | ExitProcess(); |
||
172 | case BTN_PICK: |
||
173 | EventPickActivate(); |
||
174 | break; |
||
175 | } |
||
176 | if (btn >= BTN_PALETTE_COLOR_MAS) && (btn < BTN_PALETTE_COLOR_MAS+PALLETE_SIZE) |
||
7089 | leency | 177 | { |
7151 | leency | 178 | if (mouse.lkm) active_color_1 = palette_colors[btn-BTN_PALETTE_COLOR_MAS]; |
179 | if (mouse.pkm) active_color_2 = palette_colors[btn-BTN_PALETTE_COLOR_MAS]; |
||
7089 | leency | 180 | DrawActiveColor(NULL); |
181 | } |
||
7151 | leency | 182 | if (zoom.click(btn)) DrawEditArea(); |
7089 | leency | 183 | break; |
184 | |||
185 | case evKey: |
||
186 | GetKeys(); |
||
7151 | leency | 187 | if (key_scancode == SCAN_CODE_ESC) pick_active=false; |
7096 | leency | 188 | if (key_scancode == SCAN_CODE_KEY_I) EventPickActivate(); |
7089 | leency | 189 | break; |
190 | |||
191 | case evReDraw: |
||
192 | draw_window(); |
||
193 | break; |
||
194 | } |
||
195 | } |
||
196 | |||
7096 | leency | 197 | void DrawToolbarButton(dword _id, _x, _icon_n) |
198 | { |
||
199 | DrawWideRectangle(_x, 4, 24, 24, 4, 0xFFFfff); |
||
200 | DefineHiddenButton(_x, 4, 23, 23, _id); |
||
201 | img_draw stdcall(skin.image, _x+4, 8, 16, 16, 0, _icon_n*16); |
||
202 | } |
||
203 | |||
7148 | leency | 204 | void DrawStatusBar() |
205 | { |
||
7150 | leency | 206 | zoom.y = wrapper.y + wrapper.h + 6; |
207 | zoom.x = wrapper.x; |
||
208 | zoom.draw(); |
||
209 | |||
7151 | leency | 210 | sprintf(#param,"Canvas: %ix%i", image.rows, image.columns); |
7150 | leency | 211 | WriteText(wrapper.x+wrapper.w-calc(strlen(#param)*8), zoom.y+2, 0x90, system.color.work_text, #param); |
7148 | leency | 212 | } |
213 | |||
7089 | leency | 214 | void draw_window() |
215 | { |
||
7096 | leency | 216 | #define TB_ICON_PADDING 26 |
217 | incn tx; |
||
7089 | leency | 218 | system.color.get(); |
7151 | leency | 219 | DefineAndDrawWindow(115+random(100), 50+random(100), 700, 540, 0x33, system.color.work, T_TITLE, 0); |
7089 | leency | 220 | GetProcessInfo(#Form, SelfInfo); |
7150 | leency | 221 | right_bar.x = Form.cwidth - right_bar.w; |
7089 | leency | 222 | |
7150 | leency | 223 | tx.n = wrapper.x - TB_ICON_PADDING; |
7148 | leency | 224 | DrawToolbarButton(BTN_NEW, tx.inc(TB_ICON_PADDING), 2); //not implemented |
225 | DrawToolbarButton(BTN_OPEN, tx.inc(TB_ICON_PADDING), 0); //not implemented |
||
7151 | leency | 226 | DrawToolbarButton(BTN_SAVE, tx.inc(TB_ICON_PADDING), 5); |
7148 | leency | 227 | DrawToolbarButton(BTN_MOVE_LEFT, tx.inc(TB_ICON_PADDING+8), 30); |
7096 | leency | 228 | DrawToolbarButton(BTN_MOVE_RIGHT, tx.inc(TB_ICON_PADDING), 31); |
7147 | leency | 229 | DrawToolbarButton(BTN_MOVE_UP, tx.inc(TB_ICON_PADDING), 32); |
230 | DrawToolbarButton(BTN_MOVE_DOWN, tx.inc(TB_ICON_PADDING), 33); |
||
231 | |||
7148 | leency | 232 | DrawToolbarButton(BTN_FLIP_HOR, tx.inc(TB_ICON_PADDING+8), 34); //not implemented |
233 | DrawToolbarButton(BTN_FLIP_VER, tx.inc(TB_ICON_PADDING), 35); //not implemented |
||
234 | DrawToolbarButton(BTN_ROTATE_LEFT, tx.inc(TB_ICON_PADDING), 36); //not implemented |
||
235 | DrawToolbarButton(BTN_ROTATE_RIGHT, tx.inc(TB_ICON_PADDING), 37); //not implemented |
||
236 | |||
7147 | leency | 237 | DrawToolbarButton(BTN_PICK, tx.inc(TB_ICON_PADDING+8), 38); |
7096 | leency | 238 | |
7150 | leency | 239 | DrawEditArea(); |
7096 | leency | 240 | |
7150 | leency | 241 | DrawDefaultColors(right_bar.x, right_bar.y); |
7151 | leency | 242 | DrawActiveColor(right_bar.y + 200); |
7089 | leency | 243 | |
7148 | leency | 244 | DrawStatusBar(); |
7089 | leency | 245 | } |
246 | |||
7151 | leency | 247 | void DrawEditArea() |
7089 | leency | 248 | { |
7150 | leency | 249 | dword color1=0xC0C0C0; |
250 | int left_padding; |
||
251 | int top_padding; |
||
7089 | leency | 252 | |
7150 | leency | 253 | wrapper.w = Form.cwidth - right_bar.w - 30; |
254 | wrapper.h = Form.cheight - TOOLBAR_H - 35; |
||
7148 | leency | 255 | |
7150 | leency | 256 | //canvas{ |
7151 | leency | 257 | canvas.w = image.columns * zoom.value; |
258 | canvas.h = image.rows * zoom.value; |
||
259 | if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) { |
||
260 | zoom.value--; |
||
261 | DrawEditArea(); |
||
262 | return; |
||
263 | } |
||
264 | canvas.x = -zoom.value*image.columns+wrapper.w/2 + wrapper.x; |
||
265 | canvas.y = -zoom.value*image.rows+wrapper.h/2 + wrapper.y; |
||
7150 | leency | 266 | DrawRectangle(canvas.x-1, canvas.y-1, canvas.w+1, canvas.h+1, 0x808080); |
7151 | leency | 267 | DrawCanvas(); |
7150 | leency | 268 | //} |
7089 | leency | 269 | |
7150 | leency | 270 | left_padding = canvas.x-wrapper.x-1; |
271 | top_padding = canvas.y-wrapper.y-1; |
||
7148 | leency | 272 | |
7150 | leency | 273 | DrawRectangle(wrapper.x-1, wrapper.y-1, wrapper.w+1, wrapper.h+1, system.color.work_graph); |
274 | |||
275 | if (left_padding>0) |
||
276 | { |
||
7151 | leency | 277 | DrawBar(wrapper.x, wrapper.y, wrapper.w, top_padding, color1); //top |
278 | DrawBar(wrapper.x, wrapper.y+wrapper.h-top_padding, wrapper.w, top_padding, color1); //bottom |
||
7150 | leency | 279 | } |
280 | if (top_padding>0) |
||
281 | { |
||
7151 | leency | 282 | DrawBar(wrapper.x, wrapper.y+top_padding, left_padding, wrapper.h-top_padding-top_padding, color1); //left |
283 | DrawBar(wrapper.x+wrapper.w-left_padding, wrapper.y+top_padding, left_padding, wrapper.h-top_padding-top_padding, color1); //right |
||
7150 | leency | 284 | } |
7089 | leency | 285 | } |
286 | |||
287 | void DrawActiveColor(dword iny) |
||
288 | { |
||
289 | static dword outy; |
||
290 | if (iny != NULL) outy = iny; |
||
7150 | leency | 291 | DrawBar(right_bar.x, outy, 20, 20, active_color_1); |
292 | sprintf(#param, "%A", active_color_1); |
||
7089 | leency | 293 | EDI = system.color.work; |
7148 | leency | 294 | WriteText(right_bar.x + 30, outy + 3, 0xD0, system.color.work_text, #param+4); |
7151 | leency | 295 | |
296 | DrawBar(right_bar.x+110, outy, 20, 20, active_color_2); |
||
297 | sprintf(#param, "%A", active_color_2); |
||
298 | EDI = system.color.work; |
||
299 | WriteText(right_bar.x+110 + 30, outy + 3, 0xD0, system.color.work_text, #param+4); |
||
7089 | leency | 300 | } |
301 | |||
302 | void DrawDefaultColors(dword _x, _y) |
||
303 | { |
||
304 | int r, c, i; |
||
7148 | leency | 305 | int cellw = 20; |
306 | |||
7089 | leency | 307 | i = 0; |
308 | for (r = 0; r < 9; r++) |
||
309 | { |
||
310 | for (c = 0; c < 13; c++) |
||
311 | { |
||
7150 | leency | 312 | DrawBar(c*cellw + _x, r*cellw + _y, cellw, cellw, palette_colors[PALLETE_SIZE-i]); |
7148 | leency | 313 | DefineHiddenButton(c*cellw + _x, r*cellw + _y, cellw-1, cellw-1, BTN_PALETTE_COLOR_MAS+PALLETE_SIZE-i); |
7089 | leency | 314 | i++; |
315 | } |
||
316 | } |
||
7148 | leency | 317 | DrawRectangle(_x-1, _y-1, c*cellw+1, r*cellw+1, system.color.work_light); |
318 | DrawRectangle(_x-2, _y-2, c*cellw+3, r*cellw+3, system.color.work_dark); |
||
7089 | leency | 319 | } |
320 | |||
321 | |||
322 | //===================================================// |
||
323 | // // |
||
324 | // EVENTS // |
||
325 | // // |
||
326 | //===================================================// |
||
327 | |||
7096 | leency | 328 | void EventPickActivate() |
329 | { |
||
330 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE); |
||
331 | pick_active = true; |
||
332 | } |
||
333 | |||
7150 | leency | 334 | void EventPickColor(dword lkm_status, pkm_status) |
7096 | leency | 335 | { |
7150 | leency | 336 | active_color_1 = GetPixelColorFromScreen(mouse.x + Form.left + 5, mouse.y + Form.top + skin_height); |
7096 | leency | 337 | DrawActiveColor(NULL); |
338 | if (mouse.down) && (mouse.key&MOUSE_LEFT) { |
||
339 | pick_active = false; |
||
340 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
||
341 | } |
||
342 | } |
||
7150 | leency | 343 | |
7151 | leency | 344 | dword bmp_32x32x16_header[] = FROM "bmp32x32header"; |
345 | void EventSave() |
||
7150 | leency | 346 | { |
7151 | leency | 347 | char save_buf[3126]; |
348 | dword image_buf = image.get_image(); |
||
349 | memmov(#save_buf, #bmp_32x32x16_header, sizeof(bmp_32x32x16_header)); |
||
350 | memmov(#save_buf+sizeof(bmp_32x32x16_header), image_buf, sizeof(save_buf)-sizeof(bmp_32x32x16_header)); |
||
351 | if (WriteFile(sizeof(save_buf), #save_buf, "/rd/1/saved_image.bmp")==0) |
||
352 | { |
||
353 | notify("'File saved as /rd/1/saved_image.bmp' -O"); |
||
7150 | leency | 354 | } |
7151 | leency | 355 | else { |
356 | notify("'Error saving BPM file, probably not enought space on ramdisk!' -E"); |
||
357 | } |
||
7150 | leency | 358 | } |
7151 | leency | 359 | |
360 | void CreateCanvas() |
||
361 | { |
||
362 | int i; |
||
363 | image.columns = 32; |
||
364 | image.rows = 32; |
||
365 | for (i = 0; i < image.columns*image.rows; i++) image.mas[i]=0xBFCAD2; |
||
366 | } |
||
367 | |||
368 | void DrawCanvas() |
||
369 | { |
||
370 | int r, c; |
||
371 | for (r = 0; r < image.rows; r++) |
||
372 | { |
||
373 | for (c = 0; c < image.columns; c++) |
||
374 | { |
||
375 | DrawBar(c*zoom.value + canvas.x, r*zoom.value + canvas.y, |
||
376 | zoom.value, zoom.value, image.get_pixel(r, c)); |
||
377 | } |
||
378 | } |
||
379 | }>>>>>> |