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 0000000000..fda0b15b29 Binary files /dev/null and b/programs/cmm/iconedit/paint_tools.png differ