xref: /haiku/src/tests/servers/app/playground/States.h (revision ed24eb5ff12640d052171c6a7feba37fab8a75d1)
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 			rgb_color		Color() const
36 								{ return fColor; }
37 			void			SetDrawingMode(drawing_mode mode);
38 			void			SetFill(bool fill);
39 			void			SetPenSize(float penSize);
40 
41 			void			SetEditing(bool editing);
42 
43 			BRect			Bounds() const;
44 	virtual	void			Draw(BView* view) const;
45 	virtual	bool			SupportsFill() const
46 								{ return true; }
47 
48 	static	State*			StateFor(int32 objectType,
49 									 rgb_color color, drawing_mode mode,
50 									 bool fill, float penSize);
51 
52  protected:
53 			BRect			_ValidRect() const;
54 			void			_RenderDot(BView* view, BPoint where) const;
55 			void			_AdjustViewState(BView* view) const;
56 
57 			bool			_HitTest(BPoint where, BPoint point) const;
58 
59 			bool			fValid;
60 
61 			bool			fEditing;
62 
63 			enum {
64 				TRACKING_NONE = 0,
65 				TRACKING_START,
66 				TRACKING_END
67 			};
68 
69 			uint32			fTracking;
70 			BPoint			fClickOffset;
71 
72 			BPoint			fStartPoint;
73 			BPoint			fEndPoint;
74 
75 			rgb_color		fColor;
76 			drawing_mode	fDrawingMode;
77 			bool			fFill;
78 			float			fPenSize;
79 };
80 
81 #endif // STATES_H
82