Rev 7253 | Rev 7255 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7253 | Rev 7254 | ||
---|---|---|---|
Line 9... | Line 9... | ||
9 | window colors |
9 | window colors |
10 | enhance icon |
10 | enhance icon |
11 | pipet aside color view |
11 | pipet aside color view |
12 | */ |
12 | */ |
Line 13... | Line 13... | ||
13 | 13 | ||
Line 14... | Line 14... | ||
14 | #define MEMSIZE 4096*40 |
14 | #define MEMSIZE 4096*100 |
15 | 15 | ||
16 | #include "../lib/gui.h" |
16 | #include "../lib/gui.h" |
17 | #include "../lib/random.h" |
17 | #include "../lib/random.h" |
Line 26... | Line 26... | ||
26 | // // |
26 | // // |
27 | // DATA // |
27 | // DATA // |
28 | // // |
28 | // // |
29 | //===================================================// |
29 | //===================================================// |
Line 30... | Line 30... | ||
30 | 30 | ||
Line 31... | Line 31... | ||
31 | #define T_TITLE "Icon Editor 0.45" |
31 | #define T_TITLE "Icon Editor 0.46 Alpha" |
32 | 32 | ||
33 | #define TOOLBAR_H 24+8 |
33 | #define TOOLBAR_H 24+8 |
34 | #define PANEL_LEFT_W 16+5+5+3+3 |
34 | #define PANEL_LEFT_W 16+5+5+3+3 |
Line 107... | Line 107... | ||
107 | #include "actions_history.h" |
107 | #include "actions_history.h" |
Line 108... | Line 108... | ||
108 | 108 | ||
109 | libimg_image open_image; |
109 | libimg_image open_image; |
Line 110... | Line -... | ||
110 | _ActionsHistory actionsHistory; |
- | |
111 | - | ||
112 | enum { |
- | |
113 | TOOL_NONE = -1, |
- | |
114 | TOOL_PENCIL, |
- | |
115 | TOOL_PIPETTE, |
- | |
116 | TOOL_FILL, |
- | |
117 | TOOL_LINE, |
- | |
118 | TOOL_RECT, |
- | |
119 | TOOL_SELECT |
- | |
120 | }; |
- | |
121 | - | ||
122 | struct Tool { |
- | |
123 | int id; |
- | |
124 | - | ||
125 | void (*activate)(); |
- | |
126 | void (*deactivate)(); |
- | |
127 | void (*onMouseEvent)(int x, int y, int lkm, int pkm); |
- | |
128 | void (*onKeyEvent)(dword keycode); |
- | |
129 | void (*onCanvasDraw)(); |
- | |
130 | }; |
110 | _ActionsHistory actionsHistory; |
131 | - | ||
132 | Tool tools[6]; |
- | |
133 | int currentTool = -1; |
- | |
134 | - | ||
135 | void resetCurrentTool() { |
- | |
136 | if ((currentTool != TOOL_NONE) && (tools[currentTool].deactivate != 0)) { |
- | |
137 | tools[currentTool].deactivate(); |
- | |
138 | } |
- | |
139 | - | ||
140 | currentTool = TOOL_NONE; |
- | |
141 | } |
- | |
142 | - | ||
143 | void setCurrentTool(int index) { |
- | |
144 | resetCurrentTool(); |
- | |
145 | - | ||
146 | currentTool = index; |
- | |
147 | - | ||
148 | if ((index != TOOL_NONE) && (tools[index].activate != 0)) |
- | |
149 | tools[index].activate(); |
- | |
150 | - | ||
151 | DrawLeftPanel(); |
- | |
Line 152... | Line 111... | ||
152 | DrawCanvas(); |
111 | |
153 | } |
112 | #include "tools.h" |
154 | 113 | ||
155 | //===================================================// |
114 | //===================================================// |
156 | // // |
115 | // // |
Line 157... | Line -... | ||
157 | // CODE // |
- | |
158 | // // |
- | |
159 | //===================================================// |
- | |
160 | - | ||
161 | void FillTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) { |
- | |
162 | if (canvas.hovered()) && (currentTool==TOOL_FILL) && (mouse.up) |
- | |
163 | { |
- | |
164 | EventFill(mouseY-canvas.y/zoom.value, |
- | |
165 | mouseX-canvas.x/zoom.value, tool_color); |
- | |
166 | actionsHistory.saveCurrentState(); |
- | |
167 | DrawCanvas(); |
- | |
168 | } |
- | |
169 | } |
- | |
170 | - | ||
171 | void PipetteTool_activate() { |
- | |
172 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE); |
- | |
173 | } |
- | |
174 | - | ||
175 | void PipetteTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) { |
- | |
176 | tool_color = GetPixelUnderMouse(); |
- | |
177 | DrawBar(Form.cwidth-30, 5, 20, 20, tool_color); |
- | |
178 | - | ||
179 | if (mouse.down) { |
- | |
180 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
- | |
181 | if (mouse.key&MOUSE_LEFT) EventSetActiveColor(1, tool_color); |
- | |
182 | if (mouse.key&MOUSE_RIGHT) EventSetActiveColor(2, tool_color); |
- | |
183 | - | ||
184 | setCurrentTool(TOOL_PENCIL); |
- | |
185 | } |
- | |
186 | } |
- | |
187 | - | ||
188 | bool PencilTool_Drawing = false; |
- | |
189 | - | ||
190 | void PencilTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) { |
- | |
191 | if (canvas.hovered()) |
- | |
192 | { |
- | |
193 | if ((PencilTool_Drawing == true) && (!mouse.key)) { |
- | |
194 | actionsHistory.saveCurrentState(); |
- | |
195 | PencilTool_Drawing = false; |
- | |
196 | } |
- | |
197 | - | ||
198 | if (mouse.key) { |
- | |
199 | image.set_pixel(mouseY-canvas.y/zoom.value, |
- | |
200 | mouseX-canvas.x/zoom.value, tool_color); |
- | |
201 | PencilTool_Drawing = true; |
- | |
202 | } |
- | |
203 | DrawCanvas(); |
- | |
204 | } |
- | |
205 | } |
- | |
206 | - | ||
207 | void PencilTool_reset() { |
- | |
208 | PencilTool_Drawing = false; |
- | |
209 | } |
- | |
210 | - | ||
211 | // Line tool |
- | |
212 | struct SimpleFigureTool_State { |
- | |
213 | int startX, startY; |
- | |
214 | int lastTempPosX, lastTempPosY; |
- | |
215 | }; |
- | |
216 | - | ||
217 | enum { |
- | |
218 | TOOL_LINE_STATE, |
- | |
219 | TOOL_RECT_STATE |
- | |
220 | }; |
- | |
221 | - | ||
222 | dword currentFigToolState = -1; |
- | |
223 | SimpleFigureTool_State figTool_States[2]; |
- | |
224 | - | ||
225 | void SimpleFigureTool_Reset() { |
- | |
226 | if (currentTool == TOOL_LINE) |
- | |
227 | currentFigToolState = TOOL_LINE_STATE; |
- | |
228 | else if (currentTool == TOOL_RECT) |
- | |
229 | currentFigToolState = TOOL_RECT_STATE; |
- | |
230 | - | ||
231 | figTool_States[currentFigToolState].startX = -1; |
- | |
232 | figTool_States[currentFigToolState].startY = -1; |
- | |
233 | figTool_States[currentFigToolState].lastTempPosX = -1; |
- | |
234 | figTool_States[currentFigToolState].lastTempPosY = -1; |
- | |
235 | } |
- | |
236 | - | ||
237 | int mouseX_last; |
- | |
238 | int mouseY_last; |
- | |
239 | bool first_click_in_canvas = false; |
- | |
240 | - | ||
241 | void SimpleFigureTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) { |
- | |
242 | if (mouse.down) && (canvas.hovered()) first_click_in_canvas = true; |
- | |
243 | if (first_click_in_canvas) |
- | |
244 | { |
- | |
245 | if (mouseX>canvas.x+canvas.w-zoom.value) mouseX = canvas.x+canvas.w-zoom.value; |
- | |
246 | if (mouseY>canvas.y+canvas.h-zoom.value) mouseY = canvas.y+canvas.h-zoom.value; |
- | |
247 | if (mouseX |
- | |
248 | if (mouseY |
- | |
249 | - | ||
250 | if (mouse.key) { |
- | |
251 | if ((figTool_States[currentFigToolState].startX < 0) || (figTool_States[currentFigToolState].startY < 0)) { |
- | |
252 | figTool_States[currentFigToolState].startX = mouseX; |
- | |
253 | figTool_States[currentFigToolState].startY = mouseY; |
- | |
254 | } |
- | |
255 | else { |
- | |
256 | if ((calc(mouseX - canvas.x/zoom.value) != figTool_States[currentFigToolState].lastTempPosX) |
- | |
257 | || (calc(mouseY - canvas.y/zoom.value) != figTool_States[currentFigToolState].lastTempPosY)) |
- | |
258 | { |
- | |
259 | DrawCanvas(); |
- | |
260 | } |
- | |
261 | } |
- | |
262 | mouseX_last = mouseX; |
- | |
263 | mouseY_last = mouseY; |
- | |
264 | } |
- | |
265 | if (mouse.up) { |
- | |
266 | if ((figTool_States[currentFigToolState].startX >= 0) && (figTool_States[currentFigToolState].startY >= 0)) { |
- | |
267 | // Draw line from start position to current position |
- | |
268 | if (currentTool == TOOL_LINE) { |
- | |
269 | DrawLine(figTool_States[currentFigToolState].startX - canvas.x/zoom.value, |
- | |
270 | figTool_States[currentFigToolState].startY - canvas.y/zoom.value, |
- | |
271 | mouseX - canvas.x/zoom.value, |
- | |
272 | mouseY - canvas.y/zoom.value, |
- | |
273 | tool_color, |
- | |
274 | 1); |
- | |
275 | } |
- | |
276 | else if (currentTool == TOOL_RECT) { |
- | |
277 | DrawRectangleInCanvas(figTool_States[currentFigToolState].startX - canvas.x/zoom.value, |
- | |
278 | figTool_States[currentFigToolState].startY - canvas.y/zoom.value, |
- | |
279 | mouseX - canvas.x/zoom.value, |
- | |
280 | mouseY - canvas.y/zoom.value, tool_color, 1); |
- | |
281 | } |
- | |
282 | - | ||
283 | DrawCanvas(); |
- | |
284 | - | ||
285 | actionsHistory.saveCurrentState(); |
- | |
286 | - | ||
287 | // Reset start position |
- | |
288 | figTool_States[currentFigToolState].startX = -1; |
- | |
289 | figTool_States[currentFigToolState].startY = -1; |
- | |
290 | - | ||
291 | first_click_in_canvas = false; |
- | |
292 | } |
- | |
293 | } |
- | |
294 | } |
- | |
295 | } |
- | |
296 | - | ||
297 | void SimpleFigureTool_onCanvasDraw() { |
- | |
298 | if ((figTool_States[currentFigToolState].startX >= 0) && (figTool_States[currentFigToolState].startY >= 0) && (mouse.key)) { |
- | |
299 | if (currentTool == TOOL_LINE) { |
- | |
300 | DrawLine(figTool_States[currentFigToolState].startX - canvas.x/zoom.value, |
- | |
301 | figTool_States[currentFigToolState].startY - canvas.y/zoom.value, |
- | |
302 | mouseX_last - canvas.x/zoom.value, |
- | |
303 | mouseY_last - canvas.y/zoom.value, |
- | |
304 | tool_color, |
- | |
305 | 2); |
- | |
306 | } |
- | |
307 | else if (currentTool == TOOL_RECT) { |
- | |
308 | DrawRectangleInCanvas(figTool_States[currentFigToolState].startX - canvas.x/zoom.value, |
- | |
309 | figTool_States[currentFigToolState].startY - canvas.y/zoom.value, |
- | |
310 | mouseX_last - canvas.x/zoom.value, |
- | |
311 | mouseY_last - canvas.y/zoom.value, |
- | |
312 | tool_color, |
- | |
313 | 2); |
- | |
314 | } |
- | |
315 | - | ||
316 | figTool_States[currentFigToolState].lastTempPosX = mouseX_last - canvas.x/zoom.value; |
- | |
317 | figTool_States[currentFigToolState].lastTempPosY = mouseY_last - canvas.y/zoom.value; |
- | |
318 | } |
- | |
319 | } |
- | |
320 | - | ||
321 | // Selection |
- | |
322 | int selection_start_x = -1; |
- | |
323 | int selection_start_y = -1; |
- | |
324 | int selection_end_x = -1; |
- | |
325 | int selection_end_y = -1; |
- | |
326 | bool selection_active = false; |
- | |
327 | - | ||
328 | dword SelectionTool_buffer = 0; |
- | |
329 | dword SelectionTool_buffer_r = 0; |
- | |
330 | dword SelectionTool_buffer_c = 0; |
- | |
331 | - | ||
332 | bool selection_moving_started = false; |
- | |
333 | int selection_pivot_x = -1; |
- | |
334 | int selection_pivot_y = -1; |
- | |
335 | - | ||
336 | void SelectTool_normalizeSelection() { |
- | |
337 | int t; |
- | |
338 | - | ||
339 | // Restructuring of the selection coordinates |
- | |
340 | if (selection_end_x < selection_start_x) { |
- | |
341 | t = selection_start_x; |
- | |
342 | selection_start_x = selection_end_x; |
- | |
343 | selection_end_x = t; |
- | |
344 | } |
- | |
345 | - | ||
346 | if (selection_end_y < selection_start_y) { |
- | |
347 | t = selection_end_y; |
- | |
348 | selection_end_y = selection_start_y; |
- | |
349 | selection_start_y = t; |
- | |
350 | } |
- | |
351 | } |
- | |
352 | - | ||
353 | void reset_selection_moving() { |
- | |
354 | if (selection_moving_started) { |
- | |
355 | SelectTool_drawBuffer(selection_start_x, selection_start_y, 1); |
- | |
356 | - | ||
357 | selection_pivot_x = -1; |
- | |
358 | selection_pivot_y = -1; |
- | |
359 | - | ||
360 | selection_moving_started = false; |
- | |
361 | - | ||
362 | actionsHistory.saveCurrentState(); |
- | |
363 | DrawCanvas(); |
- | |
364 | } |
- | |
365 | } |
- | |
366 | - | ||
367 | bool is_selection_moving() { |
- | |
368 | return selection_moving_started; |
- | |
369 | } |
- | |
370 | - | ||
371 | void reset_selection() { |
- | |
372 | reset_selection_moving(); |
- | |
373 | - | ||
374 | selection_start_x = -1; |
- | |
375 | selection_start_y = -1; |
- | |
376 | selection_end_x = -1; |
- | |
377 | selection_end_y = -1; |
- | |
378 | } |
- | |
379 | - | ||
380 | void SelectTool_activate() { |
- | |
381 | reset_selection(); |
- | |
382 | - | ||
383 | selection_active = false; |
- | |
384 | } |
- | |
385 | - | ||
386 | void SelectTool_deactivate() { |
- | |
387 | reset_selection_moving(); |
- | |
388 | } |
- | |
389 | - | ||
390 | bool SelectTool_pointInSelection(int x, int y) { |
- | |
391 | if (x >= selection_start_x) && (x <= selection_end_x) && (y >= selection_start_y) && (y <= selection_end_y) |
- | |
392 | return true; |
- | |
393 | else |
- | |
394 | return false; |
- | |
395 | } |
- | |
396 | - | ||
397 | - | ||
398 | void SelectTool_copyToBuffer() { |
- | |
399 | dword offset, r, c; |
- | |
400 | - | ||
401 | if (SelectionTool_buffer != 0) |
- | |
402 | free(SelectionTool_buffer); |
- | |
403 | - | ||
404 | SelectionTool_buffer_r = selection_end_y - selection_start_y + 1; |
- | |
405 | SelectionTool_buffer_c = selection_end_x - selection_start_x + 1; |
- | |
406 | SelectionTool_buffer = malloc(SelectionTool_buffer_r * SelectionTool_buffer_c * 4); |
- | |
407 | - | ||
408 | for (r = selection_start_y; r <= selection_end_y; r++) { |
- | |
409 | for (c = selection_start_x; c <= selection_end_x; c++) { |
- | |
410 | offset = calc(SelectionTool_buffer_c * calc(r - selection_start_y) + calc(c - selection_start_x)) * 4; |
- | |
411 | - | ||
412 | ESDWORD[SelectionTool_buffer + offset] = image.get_pixel(r, c); |
- | |
413 | } |
- | |
414 | } |
- | |
415 | } |
- | |
416 | - | ||
417 | void SelectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) { |
- | |
418 | int click_x, click_y, dx, dy, m_x, m_y, r, c, color; |
- | |
419 | dword pixel; |
- | |
420 | - | ||
421 | m_x = TO_CANVAS_X(mouseX); |
- | |
422 | m_y = TO_CANVAS_Y(mouseY); |
- | |
423 | - | ||
424 | if (mouse.down) && (canvas.hovered()) && (!selection_active) { |
- | |
425 | if (selection_start_x != -1) && (SelectTool_pointInSelection(m_x, m_y)) { |
- | |
426 | if (selection_pivot_x == -1) { |
- | |
427 | selection_pivot_x = m_x; |
- | |
428 | selection_pivot_y = m_y; |
- | |
429 | - | ||
430 | GetKeys(); |
- | |
431 | - | ||
432 | if (!selection_moving_started) && ( !(key_modifier&KEY_LSHIFT) ) { |
- | |
433 | for (r = selection_start_y; r <= selection_end_y; r++) |
- | |
434 | for (c = selection_start_x; c <= selection_end_x; c++) { |
- | |
435 | image.set_pixel(r, c, color2); |
- | |
436 | } |
- | |
437 | } |
- | |
438 | - | ||
439 | selection_moving_started = true; |
- | |
440 | } |
- | |
441 | } |
- | |
442 | else { |
- | |
443 | - | ||
444 | reset_selection(); |
- | |
445 | selection_active = true; |
- | |
446 | } |
- | |
447 | } |
- | |
448 | - | ||
449 | if (selection_pivot_x != -1) { |
- | |
450 | dx = m_x - selection_pivot_x; |
- | |
451 | dy = m_y - selection_pivot_y; |
- | |
452 | - | ||
453 | if (selection_start_x + dx < 0) |
- | |
454 | dx = selection_start_x; |
- | |
455 | - | ||
456 | if (selection_end_x + dx >= 32) |
- | |
457 | dx = 31 - selection_end_x; |
- | |
458 | - | ||
459 | if (selection_start_y + dy < 0) |
- | |
460 | dy = selection_start_y; |
- | |
461 | - | ||
462 | if (selection_end_y + dy >= 32) |
- | |
463 | dy = 31 - selection_end_y; |
- | |
464 | - | ||
465 | - | ||
466 | selection_start_x += dx; |
- | |
467 | selection_end_x += dx; |
- | |
468 | - | ||
469 | selection_start_y += dy; |
- | |
470 | selection_end_y += dy; |
- | |
471 | - | ||
472 | selection_pivot_x += dx; |
- | |
473 | selection_pivot_y += dy; |
- | |
474 | - | ||
475 | DrawCanvas(); |
- | |
476 | } |
- | |
477 | - | ||
478 | if (selection_active) |
- | |
479 | { |
- | |
480 | if (mouseX>canvas.x+canvas.w-zoom.value) mouseX = canvas.x+canvas.w-zoom.value; |
- | |
481 | if (mouseY>canvas.y+canvas.h-zoom.value) mouseY = canvas.y+canvas.h-zoom.value; |
- | |
482 | - | ||
483 | if (mouseX |
- | |
484 | if (mouseY |
- | |
485 | - | ||
486 | if (mouse.key) { |
- | |
487 | selection_end_x = TO_CANVAS_X(mouseX); |
- | |
488 | selection_end_y = TO_CANVAS_Y(mouseY); |
- | |
489 | - | ||
490 | if ((selection_start_x < 0) || (selection_start_y < 0)) { |
- | |
491 | selection_start_x = TO_CANVAS_X(mouseX); |
- | |
492 | selection_start_y = TO_CANVAS_Y(mouseY); |
- | |
493 | } |
- | |
494 | else { |
- | |
495 | DrawCanvas(); |
- | |
496 | - | ||
497 | /**if ((calc(TO_CANVAS_X(mouseX)) != selection_end_x) |
- | |
498 | || (calc(TO_CANVAS_Y(mouseY)) != selection_end_y)) |
- | |
499 | { |
- | |
500 | DrawCanvas(); |
- | |
501 | }*/ |
- | |
502 | } |
- | |
503 | - | ||
504 | } |
- | |
505 | - | ||
506 | if (mouse.up) { |
- | |
507 | selection_active = false; |
- | |
508 | - | ||
509 | SelectTool_normalizeSelection(); |
- | |
510 | SelectTool_copyToBuffer(); |
- | |
511 | } |
- | |
512 | } |
- | |
513 | - | ||
514 | if (mouse.up) { |
- | |
515 | if (selection_pivot_x != -1) { |
- | |
516 | selection_pivot_x = -1; |
- | |
517 | selection_pivot_y = -1; |
- | |
518 | } |
- | |
519 | } |
- | |
520 | } |
- | |
521 | - | ||
522 | void SelectTool_onCanvasDraw() { |
- | |
523 | if (selection_moving_started) |
- | |
524 | SelectTool_drawBuffer(selection_start_x, selection_start_y, 2); |
- | |
525 | - | ||
526 | if ((selection_start_x >= 0) && (selection_start_y >= 0) && (selection_end_x >= 0) && (selection_end_y >= 0)) { |
- | |
527 | DrawSelection(selection_start_x, selection_start_y, selection_end_x, selection_end_y); |
- | |
528 | } |
- | |
529 | } |
- | |
530 | - | ||
531 | void SelectTool_drawBuffer(int insert_x, int insert_y, int target) { |
- | |
532 | dword color; |
- | |
533 | dword offset, r, c; |
- | |
534 | dword insert_to_x, insert_to_y; |
- | |
535 | - | ||
536 | if (SelectionTool_buffer != 0) { |
- | |
537 | insert_to_x = insert_x + SelectionTool_buffer_c - 1; |
- | |
538 | - | ||
539 | if (insert_to_x >= image.columns) |
- | |
540 | insert_to_x = image.columns-1; |
- | |
541 | - | ||
542 | insert_to_y = insert_y + SelectionTool_buffer_r - 1; |
- | |
543 | - | ||
544 | if (insert_to_y >= image.rows) |
- | |
545 | insert_to_y = image.rows-1; |
- | |
546 | - | ||
547 | for (r = insert_y; r <= insert_to_y; r++) { |
- | |
548 | for (c = insert_x; c <= insert_to_x; c++) { |
- | |
549 | offset = calc(SelectionTool_buffer_c * calc(r - insert_y) + calc(c - insert_x)) * 4; |
- | |
550 | - | ||
551 | color = ESDWORD[SelectionTool_buffer + offset]; |
- | |
552 | - | ||
553 | if (target == 1) |
- | |
554 | image.set_pixel(r, c, color); |
- | |
555 | else |
- | |
556 | DrawBar(c*zoom.value + canvas.x, r*zoom.value + canvas.y, |
- | |
557 | zoom.value, zoom.value, color); |
- | |
558 | } |
- | |
559 | } |
- | |
560 | } |
- | |
561 | } |
- | |
562 | - | ||
563 | void SelectTool_onKeyEvent(dword keycode) { |
- | |
564 | dword offset, r, c; |
- | |
565 | dword insert_x, insert_y, insert_to_x, insert_to_y; |
- | |
566 | - | ||
567 | if (keycode == SCAN_CODE_KEY_V) { |
- | |
568 | if (SelectionTool_buffer != 0) { |
- | |
569 | reset_selection(); |
- | |
570 | - | ||
571 | selection_moving_started = true; |
- | |
572 | selection_start_x = 0; |
- | |
573 | selection_end_x = SelectionTool_buffer_c - 1; |
- | |
574 | - | ||
575 | selection_start_y = 0; |
- | |
576 | selection_end_y = SelectionTool_buffer_r - 1; |
- | |
577 | - | ||
578 | DrawCanvas(); |
- | |
Line 579... | Line 116... | ||
579 | 116 | // CODE // |
|
580 | } |
117 | // // |
581 | } |
118 | //===================================================// |
582 | } |
119 | |
Line 622... | Line 159... | ||
622 | load_dll(libimg, #libimg_init, 1); |
159 | load_dll(libimg, #libimg_init, 1); |
623 | Libimg_LoadImage(#skin, "/sys/icons16.png"); |
160 | Libimg_LoadImage(#skin, "/sys/icons16.png"); |
624 | //system.color.get(); |
161 | //system.color.get(); |
625 | //Libimg_ReplaceColor(tools_img.image, tools_img.w, tools_img.h, 0xFFF8C0D0, system.color.work); |
162 | //Libimg_ReplaceColor(tools_img.image, tools_img.w, tools_img.h, 0xFFF8C0D0, system.color.work); |
Line -... | Line 163... | ||
- | 163 | ||
626 | 164 | if (!param[0]) { |
|
627 | image.create(32, 32); |
165 | image.create(32, 32); |
628 | 166 | } |
|
- | 167 | else |
|
629 | if (param[0]) { |
168 | { |
- | 169 | Libimg_LoadImage(#open_image, #param); |
|
630 | Libimg_LoadImage(#open_image, #param); |
170 | |
- | 171 | if (open_image.w*open_image.h>MAX_CELL_SIZE*MAX_CELL_SIZE) { |
|
631 | if (open_image.w==32) && (open_image.h==32) { |
172 | notify("'Hey, this is just an icon editor,\nselected image is too big to open!' -E"); |
632 | image.set_image(open_image.imgsrc); |
173 | ExitProcess(); |
633 | } |
174 | } |
634 | else { |
175 | else { |
- | 176 | image.create(open_image.w, open_image.h); |
|
635 | notify("'Error: image format is unacceptable (PNG, 32x32x16b expected)' -E"); |
177 | image.set_image(open_image.imgsrc); |
636 | } |
178 | } |
Line 637... | Line 179... | ||
637 | } |
179 | } |
Line 856... | Line 398... | ||
856 | 398 | ||
857 | //canvas{ |
399 | //canvas{ |
858 | canvas.w = image.columns * zoom.value; |
400 | canvas.w = image.columns * zoom.value; |
859 | canvas.h = image.rows * zoom.value; |
401 | canvas.h = image.rows * zoom.value; |
860 | if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) { |
402 | if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) { |
861 | zoom.dec(); |
403 | zoom.value--; |
862 | DrawEditArea(); |
404 | DrawEditArea(); |
863 | return; |
405 | return; |
864 | } |
406 | } |
865 | canvas.x = -zoom.value*image.columns+wrapper.w/2 + wrapper.x; |
407 | canvas.x = -zoom.value*image.columns+wrapper.w/2 + wrapper.x; |
Line 978... | Line 520... | ||
978 | // // |
520 | // // |
979 | //===================================================// |
521 | //===================================================// |
Line 980... | Line 522... | ||
980 | 522 | ||
981 | void EventSave() |
523 | void EventSave() |
982 | { |
- | |
983 | dword encoded_data=0; |
- | |
984 | dword encoded_size=0; |
- | |
985 | dword image_ptr = 0; |
- | |
986 | - | ||
987 | image_ptr = create_image(Image_bpp24, 32, 32); |
- | |
988 | - | ||
989 | if (image_ptr == 0) { |
- | |
990 | notify("'Error saving file, probably not enought memory!' -E"); |
- | |
991 | } |
- | |
992 | else { |
- | |
993 | EDI = image_ptr; |
524 | { |
994 | memmov(EDI._Image.Data, image.get_image(), image.rows * image.columns * 3); |
- | |
995 | - | ||
996 | encoded_data = encode_image(image_ptr, LIBIMG_FORMAT_PNG, 0, #encoded_size); |
- | |
997 | - | ||
998 | img_destroy stdcall(image_ptr); |
- | |
999 | - | ||
1000 | if(encoded_data == 0) { |
- | |
1001 | notify("'Error saving file, incorrect data!' -E"); |
- | |
1002 | } |
- | |
1003 | else { |
- | |
1004 | if (CreateFile(encoded_size, encoded_data, "/rd/1/saved_image.png") == 0) { |
- | |
1005 | notify("'File saved as /rd/1/saved_image.png' -O"); |
- | |
1006 | } |
- | |
1007 | else { |
- | |
1008 | notify("'Error saving file, probably not enought space on ramdisk!' -E"); |
- | |
1009 | } |
- | |
1010 | } |
- | |
1011 | } |
525 | save_image(image.get_image(), image.columns, image.rows, "/rd/1/saved_image.png"); |
Line 1012... | Line 526... | ||
1012 | } |
526 | } |
1013 | 527 | ||
1014 | void EventSetActiveColor(int _number, _color) |
528 | void EventSetActiveColor(int _number, _color) |
Line 1023... | Line 537... | ||
1023 | if (_number == 2) color2 = _color; |
537 | if (_number == 2) color2 = _color; |
Line 1024... | Line 538... | ||
1024 | 538 | ||
1025 | DrawActiveColor(NULL); |
539 | DrawActiveColor(NULL); |
1026 | DrawColorPallets(); |
540 | DrawColorPallets(); |
1027 | } |
- | |
1028 | - | ||
1029 | void EventFill(dword _r, _c, _color) |
- | |
1030 | { |
- | |
1031 | #define MARKED 6 |
- | |
1032 | int r, c, i, restart; |
- | |
1033 | - | ||
1034 | dword old_color = image.get_pixel(_r, _c); |
- | |
1035 | image.set_pixel(_r, _c, MARKED); |
- | |
1036 | - | ||
1037 | do { |
- | |
1038 | restart=false; |
- | |
1039 | for (r = 0; r < image.rows; r++) |
- | |
1040 | for (c = 0; c < image.columns; c++) |
- | |
1041 | { |
- | |
1042 | IF (image.get_pixel(r,c) != old_color) continue; |
- | |
1043 | IF (image.get_pixel(r,c) == MARKED) continue; |
- | |
1044 | - | ||
1045 | IF (c>0) && (image.get_pixel(r,c-1) == MARKED) image.set_pixel(r,c,MARKED); |
- | |
1046 | IF (r>0) && (image.get_pixel(r-1,c) == MARKED) image.set_pixel(r,c,MARKED); |
- | |
1047 | IF (c |
- | |
1048 | IF (r |
- | |
1049 | - | ||
1050 | IF (image.get_pixel(r,c)==MARKED) restart=true; |
- | |
1051 | } |
- | |
1052 | }while(restart); |
- | |
1053 | - | ||
1054 | for (i=0; i |
- | |
1055 | IF (image.mas[i]==MARKED) image.mas[i] = _color; |
- | |
1056 | } |
- | |
1057 | - | ||
1058 | // target - image (1) or canvas (2) |
- | |
1059 | void DrawLine(int x1, int y1, int x2, int y2, dword color, int target) { |
- | |
1060 | int dx, dy, signX, signY, error, error2; |
- | |
1061 | - | ||
1062 | dx = x2 - x1; |
- | |
1063 | - | ||
1064 | if (dx < 0) |
- | |
1065 | dx = -dx; |
- | |
1066 | - | ||
1067 | dy = y2 - y1; |
- | |
1068 | - | ||
1069 | if (dy < 0) |
- | |
1070 | dy = -dy; |
- | |
1071 | - | ||
1072 | if (x1 < x2) |
- | |
1073 | signX = 1; |
- | |
1074 | else |
- | |
1075 | signX = -1; |
- | |
1076 | - | ||
1077 | if (y1 < y2) |
- | |
1078 | signY = 1; |
- | |
1079 | else |
- | |
1080 | signY = -1; |
- | |
1081 | - | ||
1082 | error = dx - dy; |
- | |
1083 | - | ||
1084 | if (target == 1) |
- | |
1085 | image.set_pixel(y2, x2, color); |
- | |
1086 | else |
- | |
1087 | DrawBar(x2*zoom.value + canvas.x, y2*zoom.value + canvas.y, |
- | |
1088 | zoom.value, zoom.value, color); |
- | |
1089 | - | ||
1090 | while((x1 != x2) || (y1 != y2)) |
- | |
1091 | { |
- | |
1092 | if (target == 1) |
- | |
1093 | image.set_pixel(y1, x1, color); |
- | |
1094 | else |
- | |
1095 | DrawBar(x1*zoom.value + canvas.x, y1*zoom.value + canvas.y, |
- | |
1096 | zoom.value, zoom.value, color); |
- | |
1097 | - | ||
1098 | error2 = error * 2; |
- | |
1099 | - | ||
1100 | if(error2 > calc(-dy)) |
- | |
1101 | { |
- | |
1102 | error -= dy; |
- | |
1103 | x1 += signX; |
- | |
1104 | } |
- | |
1105 | - | ||
1106 | if(error2 < dx) |
- | |
1107 | { |
- | |
1108 | error += dx; |
- | |
1109 | y1 += signY; |
- | |
1110 | } |
- | |
1111 | } |
- | |
1112 | - | ||
1113 | } |
- | |
1114 | - | ||
1115 | void DrawRectangleInCanvas(int x1, int y1, int x2, int y2, dword color, int target) { |
- | |
1116 | DrawLine(x1, y1, x2, y1, color, target); |
- | |
1117 | DrawLine(x2, y1, x2, y2, color, target); |
- | |
1118 | DrawLine(x2, y2, x1, y2, color, target); |
- | |
1119 | DrawLine(x1, y2, x1, y1, color, target); |
- | |
1120 | } |
- | |
1121 | - | ||
1122 | #define SELECTION_COLOR 0xAAE5EF |
- | |
1123 | - | ||
1124 | void DrawSelection(int x1, int y1, int x2, int y2) { |
- | |
1125 | int p1x, p1y, p2x, p2y, r, c, old_color, new_color; |
- | |
1126 | dword offset; |
- | |
1127 | - | ||
1128 | if (x1 <= x2) { |
- | |
1129 | p1x = x1; |
- | |
1130 | p2x = x2; |
- | |
1131 | } |
- | |
1132 | else { |
- | |
1133 | p1x = x2; |
- | |
1134 | p2x = x1; |
- | |
1135 | } |
- | |
1136 | - | ||
1137 | if (y1 <= y2) { |
- | |
1138 | p2y = y1; |
- | |
1139 | p1y = y2; |
- | |
1140 | } |
- | |
1141 | else { |
- | |
1142 | p2y = y2; |
- | |
1143 | p1y = y1; |
- | |
1144 | } |
- | |
1145 | - | ||
1146 | for (r = p1y; r >= p2y; r--) { |
- | |
1147 | for (c = p1x; c <= p2x; c++) { |
- | |
1148 | - | ||
1149 | if (selection_moving_started) && (SelectTool_pointInSelection(c, r)) { |
- | |
1150 | offset = calc(SelectionTool_buffer_c * calc(r - selection_start_y) + calc(c - selection_start_x)) * 4; |
- | |
1151 | old_color = ESDWORD[SelectionTool_buffer + offset]; |
- | |
1152 | } |
- | |
1153 | else { |
- | |
1154 | old_color = image.get_pixel(r, c); |
- | |
1155 | } |
- | |
1156 | - | ||
1157 | new_color = MixColors(old_color, SELECTION_COLOR, 64); |
- | |
1158 | - | ||
1159 | DrawBar(c*zoom.value + canvas.x, r*zoom.value + canvas.y, |
- | |
1160 | zoom.value, zoom.value, new_color); |
- | |
1161 | - | ||
1162 | } |
- | |
1163 | } |
- | |
1164 | }=>=>=>>>>>>>>>>>>>>=w;>>>=>=>>>>>=>=>=>=>=>=>>>>> |
541 | }>>>>>>=w;>>> |