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#ifndef TRANSFORM_BOX_H
9#define TRANSFORM_BOX_H
10
11#include <List.h>
12
13#include "ChannelTransform.h"
14#include "Manipulator.h"
15
16
17namespace TransformBoxStates {
18	class DragState;
19}
20
21class Command;
22class StateView;
23class TransformBox;
24class TransformCommand;
25
26
27class TransformBoxListener {
28public:
29								TransformBoxListener() {}
30	virtual						~TransformBoxListener() {}
31
32	virtual	void				TransformBoxDeleted(
33									const TransformBox* box) = 0;
34};
35
36class TransformBox : public ChannelTransform,
37					 public Manipulator {
38public:
39								TransformBox(StateView* view, BRect box);
40	virtual						~TransformBox();
41
42	// Manipulator interface
43	virtual	void				Draw(BView* into, BRect updateRect);
44
45	virtual	bool				MouseDown(BPoint where);
46	virtual	void				MouseMoved(BPoint where);
47	virtual	Command*			MouseUp();
48	virtual	bool				MouseOver(BPoint where);
49	virtual	bool				DoubleClicked(BPoint where);
50
51	virtual	BRect				Bounds();
52	virtual	BRect				TrackingBounds(BView* withinView);
53
54	virtual	void				ModifiersChanged(uint32 modifiers);
55	virtual	bool				HandleKeyDown(uint32 key,
56									uint32 modifiers, Command** _command);
57	virtual	bool				HandleKeyUp(uint32 key,
58									uint32 modifiers, Command** _command);
59
60	virtual	bool				UpdateCursor();
61
62	virtual	void				AttachedToView(BView* view);
63	virtual	void				DetachedFromView(BView* view);
64
65	// TransformBox
66	virtual	void				Update(bool deep = true);
67
68			void				OffsetCenter(BPoint offset);
69			BPoint				Center() const;
70			void				SetBox(BRect box);
71			BRect				Box() const
72									{ return fOriginalBox; }
73
74			Command*			FinishTransaction();
75
76			void				NudgeBy(BPoint offset);
77			bool				IsNudging() const
78									{ return fNudging; }
79			Command*			FinishNudging();
80
81	virtual	void				TransformFromCanvas(BPoint& point) const;
82	virtual	void				TransformToCanvas(BPoint& point) const;
83	virtual	float				ZoomLevel() const;
84
85
86	virtual	TransformCommand*	MakeCommand(const char* actionName) = 0;
87
88			bool				IsRotating() const
89									{ return fCurrentState == fRotateState; }
90	virtual	double				ViewSpaceRotation() const;
91
92	// Listener support
93			bool				AddListener(TransformBoxListener* listener);
94			bool				RemoveListener(TransformBoxListener* listener);
95
96private:
97			TransformBoxStates::DragState* _DragStateFor(
98									BPoint canvasWhere, float canvasZoom);
99			void				_StrokeBWLine(BView* into,
100									BPoint from, BPoint to) const;
101			void				_StrokeBWPoint(BView* into,
102									BPoint point, double angle) const;
103
104private:
105			BRect				fOriginalBox;
106
107			BPoint				fLeftTop;
108			BPoint				fRightTop;
109			BPoint				fLeftBottom;
110			BPoint				fRightBottom;
111
112			BPoint				fPivot;
113			BPoint				fPivotOffset;
114
115			TransformCommand*	fCurrentCommand;
116			TransformBoxStates::DragState* fCurrentState;
117
118			bool				fDragging;
119			BPoint				fMousePos;
120			uint32				fModifiers;
121
122			bool				fNudging;
123
124			BList				fListeners;
125
126protected:
127			void				_NotifyDeleted() const;
128
129			// "static" state objects
130			StateView*			fView;
131
132			TransformBoxStates::DragState* fDragLTState;
133			TransformBoxStates::DragState* fDragRTState;
134			TransformBoxStates::DragState* fDragLBState;
135			TransformBoxStates::DragState* fDragRBState;
136
137			TransformBoxStates::DragState* fDragLState;
138			TransformBoxStates::DragState* fDragRState;
139			TransformBoxStates::DragState* fDragTState;
140			TransformBoxStates::DragState* fDragBState;
141
142			TransformBoxStates::DragState* fRotateState;
143			TransformBoxStates::DragState* fTranslateState;
144			TransformBoxStates::DragState* fOffsetCenterState;
145};
146
147#endif // TRANSFORM_BOX_H
148