Subversion Repositories Kolibri OS

Rev

Rev 7260 | Rev 7271 | 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;
7262 leency 7
	dword cursor;
7254 leency 8
	void (*activate)();
9
	void (*deactivate)();
10
	void (*onMouseEvent)(int x, int y, int lkm, int pkm);
11
	void (*onKeyEvent)(dword keycode);
12
	void (*onCanvasDraw)();
13
};
14
 
7257 leency 15
int previousTool = -1;
7254 leency 16
int currentTool = -1;
7260 leency 17
Tool tools[8];
7254 leency 18
 
7257 leency 19
enum {
20
	TOOL_NONE = -1,
21
	TOOL_PENCIL,
22
	TOOL_PIPETTE,
23
	TOOL_FILL,
24
	TOOL_LINE,
25
	TOOL_RECT,
7259 leency 26
	TOOL_BAR,
7260 leency 27
	TOOL_SELECT,
28
	TOOL_SCREEN_COPY
7257 leency 29
};
30
#include "tools/pencil.h";
31
#include "tools/pipette.h";
32
#include "tools/fill.h";
7260 leency 33
#include "tools/simple_figure.h";
7257 leency 34
#include "tools/selection.h";
7260 leency 35
#include "tools/screen_copy.h";
7254 leency 36
 
7257 leency 37
 
38
void initTools()
39
{
7259 leency 40
	tools[TOOL_PENCIL].id = TOOL_PENCIL;
7262 leency 41
	tools[TOOL_PENCIL].cursor = #CursorPencil;
7259 leency 42
	tools[TOOL_PENCIL].onMouseEvent = #PencilTool_onMouseEvent;
43
	tools[TOOL_PENCIL].deactivate = #PencilTool_reset;
7257 leency 44
 
7259 leency 45
	tools[TOOL_PIPETTE].id = TOOL_PIPETTE;
7262 leency 46
	tools[TOOL_PIPETTE].cursor = #CursorPipette;
7259 leency 47
	tools[TOOL_PIPETTE].activate = #PipetteTool_activate;
48
	tools[TOOL_PIPETTE].onMouseEvent = #PipetteTool_onMouseEvent;
7257 leency 49
 
7259 leency 50
	tools[TOOL_FILL].id = TOOL_FILL;
7262 leency 51
	tools[TOOL_FILL].cursor = #CursorFill;
7259 leency 52
	tools[TOOL_FILL].onMouseEvent = #FillTool_onMouseEvent;
7257 leency 53
 
7259 leency 54
	tools[TOOL_LINE].id = TOOL_LINE;
7262 leency 55
	tools[TOOL_LINE].cursor = #CursorLine;
7259 leency 56
	tools[TOOL_LINE].activate = #SimpleFigureTool_Reset;
57
	tools[TOOL_LINE].deactivate = #SimpleFigureTool_Reset;
58
	tools[TOOL_LINE].onMouseEvent = #SimpleFigureTool_onMouseEvent;
59
	tools[TOOL_LINE].onCanvasDraw = #SimpleFigureTool_onCanvasDraw;
7257 leency 60
 
7259 leency 61
	tools[TOOL_RECT].id = TOOL_RECT;
7262 leency 62
	tools[TOOL_RECT].cursor = #CursorRectangle;
7259 leency 63
	tools[TOOL_RECT].activate = #SimpleFigureTool_Reset;
64
	tools[TOOL_RECT].deactivate = #SimpleFigureTool_Reset;
65
	tools[TOOL_RECT].onMouseEvent = #SimpleFigureTool_onMouseEvent;
66
	tools[TOOL_RECT].onCanvasDraw = #SimpleFigureTool_onCanvasDraw;
7257 leency 67
 
7259 leency 68
	tools[TOOL_BAR].id = TOOL_BAR;
7262 leency 69
	tools[TOOL_BAR].cursor = #CursorBar;
7259 leency 70
	tools[TOOL_BAR].activate = #SimpleFigureTool_Reset;
71
	tools[TOOL_BAR].deactivate = #SimpleFigureTool_Reset;
72
	tools[TOOL_BAR].onMouseEvent = #SimpleFigureTool_onMouseEvent;
73
	tools[TOOL_BAR].onCanvasDraw = #SimpleFigureTool_onCanvasDraw;
74
 
75
	tools[TOOL_SELECT].id = TOOL_SELECT;
7262 leency 76
	tools[TOOL_SELECT].cursor = #CursorSelect;
7259 leency 77
	tools[TOOL_SELECT].activate = #SelectTool_activate;
78
	tools[TOOL_SELECT].deactivate = #SelectTool_deactivate;
79
	tools[TOOL_SELECT].onMouseEvent = #SelectTool_onMouseEvent;
80
	tools[TOOL_SELECT].onCanvasDraw = #SelectTool_onCanvasDraw;
81
	tools[TOOL_SELECT].onKeyEvent = #SelectTool_onKeyEvent;
7260 leency 82
 
83
	tools[TOOL_SCREEN_COPY].id = TOOL_SCREEN_COPY;
7262 leency 84
	tools[TOOL_SCREEN_COPY].cursor = NULL;
7260 leency 85
	tools[TOOL_SCREEN_COPY].activate = #ScreenCopy_activate;
86
	tools[TOOL_SCREEN_COPY].onMouseEvent = #ScreenCopy_onMouseEvent;
7257 leency 87
}
88
 
89
 
7254 leency 90
void resetCurrentTool() {
91
	if ((currentTool != TOOL_NONE) && (tools[currentTool].deactivate != 0)) {
92
		tools[currentTool].deactivate();
93
	}
94
	currentTool = TOOL_NONE;
95
}
96
 
97
void setCurrentTool(int index) {
7257 leency 98
	previousTool = currentTool;
7254 leency 99
	resetCurrentTool();
100
 
101
	currentTool = index;
102
 
103
	if ((index != TOOL_NONE) && (tools[index].activate != 0))
104
		tools[index].activate();
105
 
7262 leency 106
	Cursor.Restore();
107
	if (wrapper.hovered()) SetCursor();
7254 leency 108
	DrawLeftPanel();
109
	DrawCanvas();
110
}
111
 
7262 leency 112
void SetCursor()
113
{
114
	if (tools[currentTool].cursor) && (!Cursor.CursorPointer) {
115
		Cursor.Load(tools[currentTool].cursor);
116
		Cursor.Set();
117
	}
118
}