xref: /haiku/src/apps/icon-o-matic/transformable/TransformBoxStates.h (revision e1c4049fed1047bdb957b0529e1921e97ef94770)
1 /*
2  * Copyright 2006, 2023, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  *		Zardshard
8  */
9 
10 #ifndef TRANSFORM_BOX_STATES_H
11 #define TRANSFORM_BOX_STATES_H
12 
13 #include <Point.h>
14 
15 #include <agg_trans_affine.h>
16 
17 
18 class BView;
19 class TransformBox;
20 
21 
22 namespace TransformBoxStates {
23 
24 // base class
25 class DragState {
26  public:
27 								DragState(TransformBox* parent);
28 	virtual						~DragState() {}
29 
30 	virtual	void				SetOrigin(BPoint origin)
31 									{ fOrigin = origin; }
32 	virtual	void				DragTo(BPoint current, uint32 modifiers) = 0;
33 	virtual	void				UpdateViewCursor(BView* view, BPoint current) const = 0;
34 
35 	virtual	const char*			ActionName() const;
36 
37  protected:
38 			void				_SetViewCursor(BView* view, const uchar* cursorData) const;
39 
40 			BPoint				fOrigin;
41 			TransformBox*		fParent;
42 };
43 
44 // scaling states
45 class DragCornerState : public DragState {
46  public:
47 	enum {
48 		LEFT_TOP_CORNER,
49 		RIGHT_TOP_CORNER,
50 		LEFT_BOTTOM_CORNER,
51 		RIGHT_BOTTOM_CORNER,
52 	};
53 								DragCornerState(TransformBox* parent, uint32 corner);
54 	virtual						~DragCornerState() {}
55 
56 	virtual	void				SetOrigin(BPoint origin);
57 	virtual	void				DragTo(BPoint current, uint32 modifiers);
58 	virtual	void				UpdateViewCursor(BView* view, BPoint current) const;
59 
60 	virtual	const char*			ActionName() const;
61 
62  private:
63 			uint32				fCorner;
64 
65 			float				fXOffsetFromCorner;
66 			float				fYOffsetFromCorner;
67 			double				fOldXScale;
68 			double				fOldYScale;
69 			double				fOldWidth;
70 			double				fOldHeight;
71 			agg::trans_affine	fMatrix;
72 			BPoint				fOldOffset;
73 };
74 
75 class DragSideState : public DragState {
76  public:
77 	enum {
78 		LEFT_SIDE,
79 		TOP_SIDE,
80 		RIGHT_SIDE,
81 		BOTTOM_SIDE,
82 	};
83 								DragSideState(TransformBox* parent, uint32 side);
84 	virtual						~DragSideState() {}
85 
86 	virtual	void				SetOrigin(BPoint origin);
87 	virtual	void				DragTo(BPoint current, uint32 modifiers);
88 	virtual	void				UpdateViewCursor(BView* view, BPoint current) const;
89 
90 	virtual	const char*			ActionName() const;
91 
92  private:
93 			uint32				fSide;
94 
95 			float				fOffsetFromSide;
96 			double				fOldXScale;
97 			double				fOldYScale;
98 			double				fOldSideDist;
99 			agg::trans_affine	fMatrix;
100 			BPoint				fOldOffset;
101 };
102 
103 // translate state
104 class DragBoxState : public DragState {
105  public:
106 								DragBoxState(TransformBox* parent)
107 									: DragState(parent) {}
108 	virtual						~DragBoxState() {}
109 
110 	virtual	void				SetOrigin(BPoint origin);
111 	virtual	void				DragTo(BPoint current, uint32 modifiers);
112 	virtual	void				UpdateViewCursor(BView* view, BPoint current) const;
113 
114 	virtual	const char*			ActionName() const;
115 
116  private:
117 			BPoint				fOldTranslation;
118 };
119 
120 // rotate state
121 class RotateBoxState : public DragState {
122  public:
123 								RotateBoxState(TransformBox* parent);
124 	virtual						~RotateBoxState() {}
125 
126 	virtual	void				SetOrigin(BPoint origin);
127 	virtual	void				DragTo(BPoint current, uint32 modifiers);
128 	virtual	void				UpdateViewCursor(BView* view, BPoint current) const;
129 
130 	virtual	const char*			ActionName() const;
131 
132  private:
133 			double				fOldAngle;
134 };
135 
136 // offset center state
137 class OffsetCenterState : public DragState {
138  public:
139 								OffsetCenterState(TransformBox* parent)
140 									: DragState(parent) {}
141 	virtual						~OffsetCenterState() {}
142 
143 	virtual	void				SetOrigin(BPoint origin);
144 	virtual	void				DragTo(BPoint current, uint32 modifiers);
145 	virtual	void				UpdateViewCursor(BView* view, BPoint current) const;
146 
147 	virtual	const char*			ActionName() const;
148 };
149 
150 } // TransformBoxStates namespace
151 
152 #endif // TRANSFORM_BOX_STATES_H
153