From 0f03e64a66fe5c03ac063d186ead37edb95c0800 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Wed, 14 Mar 2018 18:22:55 +0000 Subject: [PATCH] iconedit 0.3 by Nikolas git-svn-id: svn://kolibrios.org@7186 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/iconedit/iconedit.c | 395 +++++++++++++++++++++----- programs/cmm/iconedit/paint_tools.png | Bin 0 -> 499 bytes 2 files changed, 329 insertions(+), 66 deletions(-) create mode 100644 programs/cmm/iconedit/paint_tools.png diff --git a/programs/cmm/iconedit/iconedit.c b/programs/cmm/iconedit/iconedit.c index 8a8a148c8d..1a51978526 100644 --- a/programs/cmm/iconedit/iconedit.c +++ b/programs/cmm/iconedit/iconedit.c @@ -1,6 +1,6 @@ /* * Icon Editor for KolibriOS - * Author: Leency + * Authors: Leency, * Licence: GPL v2 */ @@ -28,7 +28,7 @@ enhance icon // // //===================================================// -#define T_TITLE "Icon Editor 0.15" +#define T_TITLE "Icon Editor 0.3" #define TOOLBAR_H 24+8 #define PALLETE_SIZE 116 @@ -54,6 +54,8 @@ enum { BTN_ROTATE_RIGHT, BTN_PICK, BTN_FILL, + BTN_LINE, + BTN_RECT, BTN_ZOOM_IN, BTN_ZOOM_OUT, BTNS_PALETTE_COLOR_MAS = 100, @@ -82,14 +84,47 @@ dword last_used_colors[13*2] = { _image image; +libimg_image tools_icons; + libimg_image open_image; enum { - PENCIL, - FILL, - PIPET + TOOL_NONE = -1, + TOOL_FILL = 0, + TOOL_PIPETTE = 1, + TOOL_PENCIL = 2, + TOOL_LINE = 3, + TOOL_RECT = 4, }; -int active_tool = PENCIL; + +struct Tool { + int id; + + void (*activate)(); + void (*deactivate)(); + void (*onMouseEvent)(int x, int y, int lkm, int pkm); + void (*onCanvasDraw)(); +}; + +Tool tools[5]; +int currentTool = -1; + +void resetCurrentTool() { + if ((currentTool != TOOL_NONE) && (tools[currentTool].deactivate != 0)) { + tools[currentTool].deactivate(); + } + + currentTool = TOOL_NONE; +} + +void setCurrentTool(int index) { + resetCurrentTool(); + + if ((index != TOOL_NONE) && (tools[index].activate != 0)) + tools[index].activate(); + + currentTool = index; +} //===================================================// // // @@ -97,6 +132,192 @@ int active_tool = PENCIL; // // //===================================================// +void FillTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) { + if (mouseX>canvas.x) && (mouseY>canvas.y) + && (mouseYcanvas.x) && (mouseY>canvas.y) + && (mouseYcanvas.x) && (mouseY>canvas.y) + && (mouseY= 0) && (LineTool_startY >= 0)) { + if ((calc(mouseX - canvas.x/zoom.value) != LineTool_lastTempPosX) + || (calc(mouseY - canvas.y/zoom.value) != LineTool_lastTempPosY)) + { + DrawCanvas(); + } + } + } +} + +void LineTool_onCanvasDraw() { + if ((LineTool_startX >= 0) && (LineTool_startY >= 0)) { + DrawLine(LineTool_startX - canvas.x/zoom.value, LineTool_startY - canvas.y/zoom.value, mouse.x - canvas.x/zoom.value, mouse.y - canvas.y/zoom.value, active_color_1, 2); + LineTool_lastTempPosX = mouse.x - canvas.x/zoom.value; + LineTool_lastTempPosY = mouse.y - canvas.y/zoom.value; + } +} + +// Rect tool +int RectTool_startX = -1; +int RectTool_startY = -1; +int RectTool_lastTempPosX = -1; +int RectTool_lastTempPosY = -1; + +void RectTool_reset() { + RectTool_startX = -1; + RectTool_startY = -1; + RectTool_lastTempPosX = -1; + RectTool_lastTempPosY = -1; +} + +void RectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) { + if ((mouseX>canvas.x) && (mouseY>canvas.y) + && (mouseY= 0) && (RectTool_startY >= 0)) { + if ((calc(mouseX - canvas.x/zoom.value) != RectTool_lastTempPosX) + || (calc(mouseY - canvas.y/zoom.value) != RectTool_lastTempPosY)) + { + DrawCanvas(); + } + } + } +} + +void RectTool_onCanvasDraw() { + if ((RectTool_startX >= 0) && (RectTool_startY >= 0)) { + DrawRectangleInCanvas(RectTool_startX - canvas.x/zoom.value, + RectTool_startY - canvas.y/zoom.value, + mouse.x - canvas.x/zoom.value, + mouse.y - canvas.y/zoom.value, active_color_1, 2); + + RectTool_lastTempPosX = mouse.x - canvas.x/zoom.value; + RectTool_lastTempPosY = mouse.y - canvas.y/zoom.value; + } +} + +void initTools() +{ + tools[0].id = TOOL_FILL; + tools[0].onMouseEvent = #FillTool_onMouseEvent; + + tools[1].id = TOOL_PIPETTE; + tools[1].activate = #PipetteTool_activate; + tools[1].onMouseEvent = #PipetteTool_onMouseEvent; + + tools[2].id = TOOL_PENCIL; + tools[2].onMouseEvent = #PencilTool_onMouseEvent; + + tools[3].id = TOOL_PENCIL; + tools[3].activate = #LineTool_reset; + tools[3].deactivate = #LineTool_reset; + tools[3].onMouseEvent = #LineTool_onMouseEvent; + tools[3].onCanvasDraw = #LineTool_onCanvasDraw; + + tools[4].id = TOOL_RECT; + tools[4].activate = #RectTool_reset; + tools[4].deactivate = #RectTool_reset; + tools[4].onMouseEvent = #RectTool_onMouseEvent; + tools[4].onCanvasDraw = #RectTool_onCanvasDraw; +} + void main() { word btn; @@ -104,9 +325,10 @@ void main() load_dll(libio, #libio_init, 1); load_dll(libimg, #libimg_init, 1); Libimg_LoadImage(#skin, "/sys/icons16.png"); + Libimg_LoadImage(#tools_icons, abspath("paint_tools.png")); //system.color.get(); //Libimg_ReplaceColor(skin.image, skin.w, skin.h, 0xFFfffFFF, system.color.work_text); - + image.create(32, 32); if (param[0]) { @@ -119,43 +341,25 @@ void main() } } + initTools(); + setCurrentTool(TOOL_PENCIL); + SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); loop() switch(WaitEvent()) { case evMouse: mouse.get(); + + if (currentTool != TOOL_NONE) + tools[currentTool].onMouseEvent(mouse.x, mouse.y, mouse.lkm, mouse.pkm); + if (mouse.vert) { if (mouse.vert==65535) zoom.click(BTN_ZOOM_IN); if (mouse.vert==1) zoom.click(BTN_ZOOM_OUT); DrawEditArea(); } - if (active_tool == PIPET) - { - EventPickColor(mouse.lkm, mouse.pkm); - } - if (active_tool == PENCIL) { - if (mouse.x>canvas.x) && (mouse.y>canvas.y) - && (mouse.ycanvas.x) && (mouse.y>canvas.y) - && (mouse.y calc(-dy)) + { + error -= dy; + x1 += signX; + } + + if(error2 < dx) + { + error += dx; + y1 += signY; + } + } + +} + +void DrawRectangleInCanvas(int x1, int y1, int x2, int y2, dword color, int target) { + DrawLine(x1, y1, x2, y1, color, target); + DrawLine(x2, y1, x2, y2, color, target); + DrawLine(x2, y2, x1, y2, color, target); + DrawLine(x1, y2, x1, y1, color, target); +} \ No newline at end of file diff --git a/programs/cmm/iconedit/paint_tools.png b/programs/cmm/iconedit/paint_tools.png new file mode 100644 index 0000000000000000000000000000000000000000..fda0b15b29a82bb64939a64a8fbbdae1f996a121 GIT binary patch literal 499 zcmVxTHuOAHLidXD8nbtR6-|kf)40_4zed(V8-^$thBqz+LuHj@5LBGJ%5~xbM5aX064G3-^5w0RGi2VpI^W zHU&p-feVuY3Z_0I1ycAX(7;|W48!9B2L^yw(==$?_5pHW0I0jJBQJ1Z0H~H_xt)dc zJTXlZ3kEJ5Y1=j&$ANWS*)SkDjj$tV`DNi_MGZvqYM1zH#g@`4lwfZ9PC7$|w+zY4~2T>_F1{|1*UX?NC&0R2R zJc?}z3?v?-II(D8QXoz&C9HpfAi0%)WCp(RlplC)B6v5vR{QhYyVLj6~iUkf< z7n)RgBNAvN*)_;XSiN&flI)#1l5FpsldyZ|*pH}>voCeEP4}Z`;%=O9O={`_2X-U6 pm2+@3y;BnL|43ILTke;bh%fTU9kv