2018-04-24 18:14:08 +03:00
|
|
|
#define TOIMAGE 1
|
|
|
|
#define TOCANVAS 2
|
|
|
|
|
2018-04-22 16:33:01 +03:00
|
|
|
|
|
|
|
struct Tool {
|
|
|
|
int id;
|
2018-04-29 23:42:03 +03:00
|
|
|
dword cursor;
|
2018-04-22 16:33:01 +03:00
|
|
|
void (*activate)();
|
|
|
|
void (*deactivate)();
|
|
|
|
void (*onMouseEvent)(int x, int y, int lkm, int pkm);
|
|
|
|
void (*onKeyEvent)(dword keycode);
|
|
|
|
void (*onCanvasDraw)();
|
|
|
|
};
|
|
|
|
|
2018-04-24 18:14:08 +03:00
|
|
|
int previousTool = -1;
|
2018-04-22 16:33:01 +03:00
|
|
|
int currentTool = -1;
|
2018-04-25 22:09:26 +03:00
|
|
|
Tool tools[8];
|
2018-04-22 16:33:01 +03:00
|
|
|
|
2018-04-24 18:14:08 +03:00
|
|
|
enum {
|
|
|
|
TOOL_NONE = -1,
|
|
|
|
TOOL_PENCIL,
|
|
|
|
TOOL_PIPETTE,
|
|
|
|
TOOL_FILL,
|
|
|
|
TOOL_LINE,
|
|
|
|
TOOL_RECT,
|
2018-04-25 14:18:22 +03:00
|
|
|
TOOL_BAR,
|
2018-04-25 22:09:26 +03:00
|
|
|
TOOL_SELECT,
|
|
|
|
TOOL_SCREEN_COPY
|
2018-04-24 18:14:08 +03:00
|
|
|
};
|
|
|
|
#include "tools/pencil.h";
|
|
|
|
#include "tools/pipette.h";
|
|
|
|
#include "tools/fill.h";
|
|
|
|
#include "tools/simple_figure.h";
|
2018-04-25 22:09:26 +03:00
|
|
|
#include "tools/selection.h";
|
|
|
|
#include "tools/screen_copy.h";
|
2018-04-24 18:14:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
void initTools()
|
|
|
|
{
|
2018-04-25 14:18:22 +03:00
|
|
|
tools[TOOL_PENCIL].id = TOOL_PENCIL;
|
2018-04-29 23:42:03 +03:00
|
|
|
tools[TOOL_PENCIL].cursor = #CursorPencil;
|
2018-04-25 14:18:22 +03:00
|
|
|
tools[TOOL_PENCIL].onMouseEvent = #PencilTool_onMouseEvent;
|
|
|
|
tools[TOOL_PENCIL].deactivate = #PencilTool_reset;
|
2018-04-24 18:14:08 +03:00
|
|
|
|
2018-04-25 14:18:22 +03:00
|
|
|
tools[TOOL_PIPETTE].id = TOOL_PIPETTE;
|
2018-04-29 23:42:03 +03:00
|
|
|
tools[TOOL_PIPETTE].cursor = #CursorPipette;
|
2018-04-25 14:18:22 +03:00
|
|
|
tools[TOOL_PIPETTE].activate = #PipetteTool_activate;
|
|
|
|
tools[TOOL_PIPETTE].onMouseEvent = #PipetteTool_onMouseEvent;
|
2018-05-06 18:02:12 +03:00
|
|
|
tools[TOOL_PIPETTE].onKeyEvent = #PipetteTool_onKeyEvent;
|
2018-04-24 18:14:08 +03:00
|
|
|
|
2018-04-25 14:18:22 +03:00
|
|
|
tools[TOOL_FILL].id = TOOL_FILL;
|
2018-04-29 23:42:03 +03:00
|
|
|
tools[TOOL_FILL].cursor = #CursorFill;
|
2018-04-25 14:18:22 +03:00
|
|
|
tools[TOOL_FILL].onMouseEvent = #FillTool_onMouseEvent;
|
2018-04-24 18:14:08 +03:00
|
|
|
|
2018-04-25 14:18:22 +03:00
|
|
|
tools[TOOL_LINE].id = TOOL_LINE;
|
2018-04-29 23:42:03 +03:00
|
|
|
tools[TOOL_LINE].cursor = #CursorLine;
|
2018-04-25 14:18:22 +03:00
|
|
|
tools[TOOL_LINE].activate = #SimpleFigureTool_Reset;
|
|
|
|
tools[TOOL_LINE].deactivate = #SimpleFigureTool_Reset;
|
|
|
|
tools[TOOL_LINE].onMouseEvent = #SimpleFigureTool_onMouseEvent;
|
|
|
|
tools[TOOL_LINE].onCanvasDraw = #SimpleFigureTool_onCanvasDraw;
|
2018-04-24 18:14:08 +03:00
|
|
|
|
2018-04-25 14:18:22 +03:00
|
|
|
tools[TOOL_RECT].id = TOOL_RECT;
|
2018-04-29 23:42:03 +03:00
|
|
|
tools[TOOL_RECT].cursor = #CursorRectangle;
|
2018-04-25 14:18:22 +03:00
|
|
|
tools[TOOL_RECT].activate = #SimpleFigureTool_Reset;
|
|
|
|
tools[TOOL_RECT].deactivate = #SimpleFigureTool_Reset;
|
|
|
|
tools[TOOL_RECT].onMouseEvent = #SimpleFigureTool_onMouseEvent;
|
|
|
|
tools[TOOL_RECT].onCanvasDraw = #SimpleFigureTool_onCanvasDraw;
|
2018-04-24 18:14:08 +03:00
|
|
|
|
2018-04-25 14:18:22 +03:00
|
|
|
tools[TOOL_BAR].id = TOOL_BAR;
|
2018-04-29 23:42:03 +03:00
|
|
|
tools[TOOL_BAR].cursor = #CursorBar;
|
2018-04-25 14:18:22 +03:00
|
|
|
tools[TOOL_BAR].activate = #SimpleFigureTool_Reset;
|
|
|
|
tools[TOOL_BAR].deactivate = #SimpleFigureTool_Reset;
|
|
|
|
tools[TOOL_BAR].onMouseEvent = #SimpleFigureTool_onMouseEvent;
|
|
|
|
tools[TOOL_BAR].onCanvasDraw = #SimpleFigureTool_onCanvasDraw;
|
|
|
|
|
|
|
|
tools[TOOL_SELECT].id = TOOL_SELECT;
|
2018-04-29 23:42:03 +03:00
|
|
|
tools[TOOL_SELECT].cursor = #CursorSelect;
|
2018-04-25 14:18:22 +03:00
|
|
|
tools[TOOL_SELECT].activate = #SelectTool_activate;
|
|
|
|
tools[TOOL_SELECT].deactivate = #SelectTool_deactivate;
|
|
|
|
tools[TOOL_SELECT].onMouseEvent = #SelectTool_onMouseEvent;
|
|
|
|
tools[TOOL_SELECT].onCanvasDraw = #SelectTool_onCanvasDraw;
|
|
|
|
tools[TOOL_SELECT].onKeyEvent = #SelectTool_onKeyEvent;
|
2018-04-25 22:09:26 +03:00
|
|
|
|
|
|
|
tools[TOOL_SCREEN_COPY].id = TOOL_SCREEN_COPY;
|
2018-04-29 23:42:03 +03:00
|
|
|
tools[TOOL_SCREEN_COPY].cursor = NULL;
|
2018-04-25 22:09:26 +03:00
|
|
|
tools[TOOL_SCREEN_COPY].activate = #ScreenCopy_activate;
|
|
|
|
tools[TOOL_SCREEN_COPY].onMouseEvent = #ScreenCopy_onMouseEvent;
|
2018-04-24 18:14:08 +03:00
|
|
|
}
|
|
|
|
|
2018-04-22 16:33:01 +03:00
|
|
|
|
|
|
|
void resetCurrentTool() {
|
|
|
|
if ((currentTool != TOOL_NONE) && (tools[currentTool].deactivate != 0)) {
|
|
|
|
tools[currentTool].deactivate();
|
|
|
|
}
|
|
|
|
currentTool = TOOL_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCurrentTool(int index) {
|
2018-04-24 18:14:08 +03:00
|
|
|
previousTool = currentTool;
|
2018-04-22 16:33:01 +03:00
|
|
|
resetCurrentTool();
|
|
|
|
|
|
|
|
currentTool = index;
|
|
|
|
|
|
|
|
if ((index != TOOL_NONE) && (tools[index].activate != 0))
|
|
|
|
tools[index].activate();
|
|
|
|
|
2018-04-29 23:42:03 +03:00
|
|
|
Cursor.Restore();
|
|
|
|
if (wrapper.hovered()) SetCursor();
|
2018-04-22 16:33:01 +03:00
|
|
|
DrawLeftPanel();
|
|
|
|
DrawCanvas();
|
|
|
|
}
|
|
|
|
|
2018-04-29 23:42:03 +03:00
|
|
|
void SetCursor()
|
|
|
|
{
|
|
|
|
if (tools[currentTool].cursor) && (!Cursor.CursorPointer) {
|
|
|
|
Cursor.Load(tools[currentTool].cursor);
|
|
|
|
Cursor.Set();
|
|
|
|
}
|
|
|
|
}
|