xref: /haiku/src/tests/servers/app/playground/States.h (revision 3e216965baa8d58a67bf7372e2bfa13d999f5a9d)
1 // States.h
2 
3 #ifndef STATES_H
4 #define STATES_H
5 
6 #include <GraphicsDefs.h>
7 #include <Point.h>
8 
9 class BView;
10 
11 enum {
12 	OBJECT_LINE = 0,
13 	OBJECT_RECT,
14 	OBJECT_ROUND_RECT,
15 	OBJECT_ELLIPSE,
16 	OBJECT_TRIANGLE,
17 	OBJECT_SHAPE,
18 };
19 
20 class State {
21  public:
22 							State();
23 	virtual					~State();
24 
25 			void			Init(rgb_color color, drawing_mode mode,
26 								 bool fill, float penSize);
27 
28 			void			MouseDown(BPoint where);
29 			void			MouseUp();
30 			void			MouseMoved(BPoint where);
31 			bool			IsTracking() const
32 								{ return fTracking; }
33 
34 			void			SetColor(rgb_color color);
35 			void			SetDrawingMode(drawing_mode mode);
36 			void			SetFill(bool fill);
37 			void			SetPenSize(float penSize);
38 
39 			void			SetEditing(bool editing);
40 
41 			BRect			Bounds() const;
42 	virtual	void			Draw(BView* view) const;
43 	virtual	bool			SupportsFill() const
44 								{ return true; }
45 
46 	static	State*			StateFor(int32 objectType,
47 									 rgb_color color, drawing_mode mode,
48 									 bool fill, float penSize);
49 
50  protected:
51 			BRect			_ValidRect() const;
52 			void			_RenderDot(BView* view, BPoint where) const;
53 			void			_AdjustViewState(BView* view) const;
54 
55 			bool			_HitTest(BPoint where, BPoint point) const;
56 
57 			bool			fValid;
58 
59 			bool			fEditing;
60 
61 			enum {
62 				TRACKING_NONE = 0,
63 				TRACKING_START,
64 				TRACKING_END
65 			};
66 
67 			uint32			fTracking;
68 			BPoint			fClickOffset;
69 
70 			BPoint			fStartPoint;
71 			BPoint			fEndPoint;
72 
73 			rgb_color		fColor;
74 			drawing_mode	fDrawingMode;
75 			bool			fFill;
76 			float			fPenSize;
77 };
78 
79 #endif // STATES_H
80