xref: /haiku/src/libs/icon/shape/Shape.h (revision 6dcd0ccf238263a3e5eb2e2a44e2ed0da1617a42)
1 /*
2  * Copyright 2006-2007, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 #ifndef SHAPE_H
9 #define SHAPE_H
10 
11 
12 #ifdef ICON_O_MATIC
13 #	include "IconObject.h"
14 #	include "Observer.h"
15 #endif
16 #include "PathContainer.h"
17 #include "PathSource.h"
18 #include "Transformable.h"
19 #include "VectorPath.h"
20 
21 #include <List.h>
22 #include <Rect.h>
23 
24 
25 namespace BPrivate {
26 namespace Icon {
27 
28 class Style;
29 
30 #ifdef ICON_O_MATIC
31 // TODO: merge Observer and ShapeListener interface
32 // ie add "AppearanceChanged(Shape* shape)"
33 class ShapeListener {
34  public:
35 								ShapeListener();
36 	virtual						~ShapeListener();
37 
38 	virtual	void				TransformerAdded(Transformer* t,
39 												 int32 index) = 0;
40 	virtual	void				TransformerRemoved(Transformer* t) = 0;
41 
42 	virtual	void				StyleChanged(::Style* oldStyle,
43 											 ::Style* newStyle) = 0;
44 };
45 #endif // ICON_O_MATIC
46 
47 #ifdef ICON_O_MATIC
48 class Shape : public IconObject,
49 			  public BPrivate::Icon::Transformable,
50 			  public Observer,	// observing all the paths and the style
51 			  public PathContainerListener,
52 			  public PathListener {
53 #else
54 class Shape : public BPrivate::Icon::Transformable {
55 #endif
56 
57  public:
58 								Shape(::Style* style);
59 								Shape(const Shape& other);
60 	virtual						~Shape();
61 
62 #ifdef ICON_O_MATIC
63 	// IconObject interface
64 	virtual	status_t			Unarchive(const BMessage* archive);
65 	virtual	status_t			Archive(BMessage* into,
66 										bool deep = true) const;
67 
68 	virtual	PropertyObject*		MakePropertyObject() const;
69 	virtual	bool				SetToPropertyObject(
70 									const PropertyObject* object);
71 
72 	// Transformable interface
73 	virtual	void				TransformationChanged();
74 
75 	// Observer interface
76 	virtual	void				ObjectChanged(const Observable* object);
77 
78 	// PathContainerListener interface
79 	virtual	void				PathAdded(VectorPath* path, int32 index);
80 	virtual	void				PathRemoved(VectorPath* path);
81 
82 	// PathListener interface
83 	virtual	void				PointAdded(int32 index);
84 	virtual	void				PointRemoved(int32 index);
85 	virtual	void				PointChanged(int32 index);
86 	virtual	void				PathChanged();
87 	virtual	void				PathClosedChanged();
88 	virtual	void				PathReversed();
89 #else
90 	inline	void				Notify() {}
91 #endif // ICON_O_MATIC
92 
93 	// Shape
94 			status_t			InitCheck() const;
95 
96 	inline	PathContainer*		Paths() const
97 									{ return fPaths; }
98 
99 			void				SetStyle(::Style* style);
100 	inline	::Style*			Style() const
101 									{ return fStyle; }
102 
103 	inline	BRect				LastBounds() const
104 									{ return fLastBounds; }
105 			BRect				Bounds(bool updateLast = false) const;
106 
107 			::VertexSource&		VertexSource();
108 
109 			bool				AddTransformer(Transformer* transformer);
110 			bool				AddTransformer(Transformer* transformer,
111 											   int32 index);
112 			bool				RemoveTransformer(Transformer* transformer);
113 
114 			int32				CountTransformers() const;
115 
116 			bool				HasTransformer(Transformer* transformer) const;
117 			int32				IndexOf(Transformer* transformer) const;
118 
119 			Transformer*		TransformerAt(int32 index) const;
120 			Transformer*		TransformerAtFast(int32 index) const;
121 
122 			void				SetHinting(bool hinting);
123 			bool				Hinting() const
124 									{ return fHinting; }
125 			void				SetMinVisibilityScale(float scale);
126 			float				MinVisibilityScale() const
127 									{ return fMinVisibilityScale; }
128 			void				SetMaxVisibilityScale(float scale);
129 			float				MaxVisibilityScale() const
130 									{ return fMaxVisibilityScale; }
131 
132 #ifdef ICON_O_MATIC
133 			bool				AddListener(ShapeListener* listener);
134 			bool				RemoveListener(ShapeListener* listener);
135 
136  private:
137 			void				_NotifyTransformerAdded(Transformer* t,
138 														int32 index) const;
139 			void				_NotifyTransformerRemoved(Transformer* t) const;
140 
141 			void				_NotifyStyleChanged(::Style* oldStyle,
142 													::Style* newStyle) const;
143 
144 			void				_NotifyRerender() const;
145 #endif // ICON_O_MATIC
146 
147  private:
148 			PathContainer*		fPaths;
149 			::Style*			fStyle;
150 
151 			PathSource			fPathSource;
152 			BList				fTransformers;
153 	mutable	bool				fNeedsUpdate;
154 
155 	mutable	BRect				fLastBounds;
156 
157 			bool				fHinting;
158 			float				fMinVisibilityScale;
159 			float				fMaxVisibilityScale;
160 
161 #ifdef ICON_O_MATIC
162 			BList				fListeners;
163 #endif
164 };
165 
166 }	// namespace Icon
167 }	// namespace BPrivate
168 
169 #endif	// SHAPE_H
170