Rev 7257 | Rev 7260 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7257 | leency | 1 | #define TOIMAGE 1 |
2 | #define TOCANVAS 2 |
||
7254 | leency | 3 | |
7257 | leency | 4 | |
7254 | leency | 5 | struct Tool { |
6 | int id; |
||
7 | void (*activate)(); |
||
8 | void (*deactivate)(); |
||
9 | void (*onMouseEvent)(int x, int y, int lkm, int pkm); |
||
10 | void (*onKeyEvent)(dword keycode); |
||
11 | void (*onCanvasDraw)(); |
||
12 | }; |
||
13 | |||
7257 | leency | 14 | int previousTool = -1; |
7254 | leency | 15 | int currentTool = -1; |
7259 | leency | 16 | Tool tools[7]; |
7254 | leency | 17 | |
7257 | leency | 18 | enum { |
19 | TOOL_NONE = -1, |
||
20 | TOOL_PENCIL, |
||
21 | TOOL_PIPETTE, |
||
22 | TOOL_FILL, |
||
23 | TOOL_LINE, |
||
24 | TOOL_RECT, |
||
7259 | leency | 25 | TOOL_BAR, |
7257 | leency | 26 | TOOL_SELECT |
27 | }; |
||
28 | #include "tools/pencil.h"; |
||
29 | #include "tools/pipette.h"; |
||
30 | #include "tools/fill.h"; |
||
31 | #include "tools/selection.h"; |
||
32 | #include "tools/simple_figure.h"; |
||
7254 | leency | 33 | |
7257 | leency | 34 | |
35 | void initTools() |
||
36 | { |
||
7259 | leency | 37 | tools[TOOL_PENCIL].id = TOOL_PENCIL; |
38 | tools[TOOL_PENCIL].onMouseEvent = #PencilTool_onMouseEvent; |
||
39 | tools[TOOL_PENCIL].deactivate = #PencilTool_reset; |
||
7257 | leency | 40 | |
7259 | leency | 41 | tools[TOOL_PIPETTE].id = TOOL_PIPETTE; |
42 | tools[TOOL_PIPETTE].activate = #PipetteTool_activate; |
||
43 | tools[TOOL_PIPETTE].onMouseEvent = #PipetteTool_onMouseEvent; |
||
7257 | leency | 44 | |
7259 | leency | 45 | tools[TOOL_FILL].id = TOOL_FILL; |
46 | tools[TOOL_FILL].onMouseEvent = #FillTool_onMouseEvent; |
||
7257 | leency | 47 | |
7259 | leency | 48 | tools[TOOL_LINE].id = TOOL_LINE; |
49 | tools[TOOL_LINE].activate = #SimpleFigureTool_Reset; |
||
50 | tools[TOOL_LINE].deactivate = #SimpleFigureTool_Reset; |
||
51 | tools[TOOL_LINE].onMouseEvent = #SimpleFigureTool_onMouseEvent; |
||
52 | tools[TOOL_LINE].onCanvasDraw = #SimpleFigureTool_onCanvasDraw; |
||
7257 | leency | 53 | |
7259 | leency | 54 | tools[TOOL_RECT].id = TOOL_RECT; |
55 | tools[TOOL_RECT].activate = #SimpleFigureTool_Reset; |
||
56 | tools[TOOL_RECT].deactivate = #SimpleFigureTool_Reset; |
||
57 | tools[TOOL_RECT].onMouseEvent = #SimpleFigureTool_onMouseEvent; |
||
58 | tools[TOOL_RECT].onCanvasDraw = #SimpleFigureTool_onCanvasDraw; |
||
7257 | leency | 59 | |
7259 | leency | 60 | tools[TOOL_BAR].id = TOOL_BAR; |
61 | tools[TOOL_BAR].activate = #SimpleFigureTool_Reset; |
||
62 | tools[TOOL_BAR].deactivate = #SimpleFigureTool_Reset; |
||
63 | tools[TOOL_BAR].onMouseEvent = #SimpleFigureTool_onMouseEvent; |
||
64 | tools[TOOL_BAR].onCanvasDraw = #SimpleFigureTool_onCanvasDraw; |
||
65 | |||
66 | tools[TOOL_SELECT].id = TOOL_SELECT; |
||
67 | tools[TOOL_SELECT].activate = #SelectTool_activate; |
||
68 | tools[TOOL_SELECT].deactivate = #SelectTool_deactivate; |
||
69 | tools[TOOL_SELECT].onMouseEvent = #SelectTool_onMouseEvent; |
||
70 | tools[TOOL_SELECT].onCanvasDraw = #SelectTool_onCanvasDraw; |
||
71 | tools[TOOL_SELECT].onKeyEvent = #SelectTool_onKeyEvent; |
||
7257 | leency | 72 | } |
73 | |||
74 | |||
7254 | leency | 75 | void resetCurrentTool() { |
76 | if ((currentTool != TOOL_NONE) && (tools[currentTool].deactivate != 0)) { |
||
77 | tools[currentTool].deactivate(); |
||
78 | } |
||
79 | currentTool = TOOL_NONE; |
||
80 | } |
||
81 | |||
82 | void setCurrentTool(int index) { |
||
7257 | leency | 83 | previousTool = currentTool; |
7254 | leency | 84 | resetCurrentTool(); |
85 | |||
86 | currentTool = index; |
||
87 | |||
88 | if ((index != TOOL_NONE) && (tools[index].activate != 0)) |
||
89 | tools[index].activate(); |
||
90 | |||
91 | DrawLeftPanel(); |
||
92 | DrawCanvas(); |
||
93 | } |
||
94 |