xref: /haiku/src/apps/icon-o-matic/shape/PathManipulator.h (revision b028e77473189065f2baefc6f5e10d451cf591e2)
1 /*
2  * Copyright 2006-2007, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 
9 #ifndef PATH_MANIPULATOR_H
10 #define PATH_MANIPULATOR_H
11 
12 #include "Manipulator.h"
13 #include "VectorPath.h"
14 
15 class AddPointCommand;
16 class CanvasView;
17 class ChangePointCommand;
18 class InsertPointCommand;
19 class NudgePointsCommand;
20 class TransformPointsBox;
21 
22 //class PathSelection {
23 // public:
24 //								PathSelection();
25 //	virtual						~PathSelection();
26 //
27 //	virtual	PathSelection*		Clone() const;
28 //	virtual	bool				SetTo(const PathSelection* other);
29 //
30 //	virtual	Command*			Delete();
31 //};
32 
33 class PathManipulator : public Manipulator,
34 						public PathListener {
35  public:
36 								PathManipulator(VectorPath* path);
37 	virtual						~PathManipulator();
38 
39 	// Manipulator interface
40 	virtual	void				Draw(BView* into, BRect updateRect);
41 
42 	virtual	bool				MouseDown(BPoint where);
43 	virtual	void				MouseMoved(BPoint where);
44 	virtual	Command*			MouseUp();
45 	virtual	bool				MouseOver(BPoint where);
46 	virtual	bool				DoubleClicked(BPoint where);
47 
48 	virtual	bool				ShowContextMenu(BPoint where);
49 
50 	virtual	BRect				Bounds();
51 	virtual	BRect				TrackingBounds(BView* withinView);
52 
53 	virtual	bool				MessageReceived(BMessage* message,
54 												Command** _command);
55 
56 	virtual	void				ModifiersChanged(uint32 modifiers);
57 	virtual	bool				HandleKeyDown(uint32 key, uint32 modifiers,
58 											  Command** _command);
59 	virtual	bool				HandleKeyUp(uint32 key, uint32 modifiers,
60 											Command** _command);
61 
62 	virtual	bool				UpdateCursor();
63 
64 	virtual	void				AttachedToView(BView* view);
65 	virtual	void				DetachedFromView(BView* view);
66 
67 	// Observer interface (Manipulator)
68 	virtual	void				ObjectChanged(const Observable* object);
69 
70 	// PathListener interface
71 	virtual	void				PointAdded(int32 index);
72 	virtual	void				PointRemoved(int32 index);
73 	virtual	void				PointChanged(int32 index);
74 	virtual	void				PathChanged();
75 	virtual	void				PathClosedChanged();
76 	virtual	void				PathReversed();
77 
78 	// PathManipulator
79 			uint32				ControlFlags() const;
80 
81 //			PathSelection*		Selection() const;
82 //
83 			// path manipulation
84 			void				ReversePath();
85 
86  private:
87 			friend	class		PathCommand;
88 			friend	class		PointSelection;
89 			friend	class		EnterTransformPointsCommand;
90 			friend	class		ExitTransformPointsCommand;
91 			friend	class		TransformPointsCommand;
92 //			friend	class		NewPathCommand;
93 //			friend	class		RemovePathCommand;
94 			friend	class		ReversePathCommand;
95 //			friend	class		SelectPathCommand;
96 
97 			void				_SetMode(uint32 mode);
98 			void				_SetTransformBox(
99 									TransformPointsBox* transformBox);
100 
101 			// BEGIN functions that need to be undoable
102 			void				_AddPoint(BPoint where);
103 			void				_InsertPoint(BPoint where, int32 index);
104 			void				_SetInOutConnected(int32 index,
105 												   bool connected);
106 			void				_SetSharp(int32 index);
107 
108 			void				_RemoveSelection();
109 			void				_RemovePoint(int32 index);
110 			void				_RemovePointIn(int32 index);
111 			void				_RemovePointOut(int32 index);
112 
113 			Command*			_Delete();
114 
115 			void				_Select(BRect canvasRect);
116 			void				_Select(int32 index, bool extend = false);
117 			void				_Select(const int32* indices,
118 										int32 count, bool extend = false);
119 			void				_Deselect(int32 index);
120 			void				_ShiftSelection(int32 startIndex,
121 												int32 direction);
122 			bool				_IsSelected(int32 index) const;
123 			// END functions that need to be undoable
124 
125 			void				_InvalidateCanvas(BRect rect) const;
126 			void				_InvalidateHighlightPoints(int32 newIndex,
127 														   uint32 newMode);
128 
129 			void				_UpdateSelection() const;
130 
131 			BRect				_ControlPointRect() const;
132 			BRect				_ControlPointRect(int32 index,
133 												  uint32 mode) const;
134 			void				_GetChangableAreas(BRect* pathArea,
135 												   BRect* controlPointArea) const;
136 
137 			void				_SetModeForMousePos(BPoint canvasWhere);
138 
139 			void				_Nudge(BPoint direction);
140 			Command*			_FinishNudging();
141 
142 			CanvasView*			fCanvasView;
143 
144 			bool				fCommandDown;
145 			bool				fOptionDown;
146 			bool				fShiftDown;
147 			bool				fAltDown;
148 
149 			bool				fClickToClose;
150 
151 			uint32				fMode;
152 			uint32				fFallBackMode;
153 
154 			bool				fMouseDown;
155 			BPoint				fTrackingStart;
156 			BPoint				fLastCanvasPos;
157 
158 			VectorPath*			fPath;
159 			int32				fCurrentPathPoint;
160 			BRect				fPreviousBounds;
161 
162 			ChangePointCommand*	fChangePointCommand;
163 			InsertPointCommand*	fInsertPointCommand;
164 			AddPointCommand*	fAddPointCommand;
165 
166 			class Selection;
167 			Selection*			fSelection;
168 			Selection*			fOldSelection;
169 			TransformPointsBox*	fTransformBox;
170 
171 			// stuff needed for nudging
172 			BPoint				fNudgeOffset;
173 			bigtime_t			fLastNudgeTime;
174 			NudgePointsCommand*	fNudgeCommand;
175 };
176 
177 #endif	// SHAPE_STATE_H
178