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