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