xref: /haiku/src/libs/icon/shape/Shape.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
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 	// IconObject interface
63 	virtual	status_t			Unarchive(const BMessage* archive);
64 #ifdef ICON_O_MATIC
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 			void				SetGlobalScale(double scale);
109 
110 			bool				AddTransformer(Transformer* transformer);
111 			bool				AddTransformer(Transformer* transformer,
112 											   int32 index);
113 			bool				RemoveTransformer(Transformer* transformer);
114 
115 			int32				CountTransformers() const;
116 
117 			bool				HasTransformer(Transformer* transformer) const;
118 			int32				IndexOf(Transformer* transformer) const;
119 
120 			Transformer*		TransformerAt(int32 index) const;
121 			Transformer*		TransformerAtFast(int32 index) const;
122 
123 			void				SetHinting(bool hinting);
124 			bool				Hinting() const
125 									{ return fHinting; }
126 			void				SetMinVisibilityScale(float scale);
127 			float				MinVisibilityScale() const
128 									{ return fMinVisibilityScale; }
129 			void				SetMaxVisibilityScale(float scale);
130 			float				MaxVisibilityScale() const
131 									{ return fMaxVisibilityScale; }
132 
133 #ifdef ICON_O_MATIC
134 			bool				AddListener(ShapeListener* listener);
135 			bool				RemoveListener(ShapeListener* listener);
136 
137  private:
138 			void				_NotifyTransformerAdded(Transformer* t,
139 														int32 index) const;
140 			void				_NotifyTransformerRemoved(Transformer* t) const;
141 
142 			void				_NotifyStyleChanged(::Style* oldStyle,
143 													::Style* newStyle) const;
144 
145 			void				_NotifyRerender() const;
146 #endif // ICON_O_MATIC
147 
148  private:
149 			PathContainer*		fPaths;
150 			::Style*			fStyle;
151 
152 			PathSource			fPathSource;
153 			BList				fTransformers;
154 	mutable	bool				fNeedsUpdate;
155 
156 	mutable	BRect				fLastBounds;
157 
158 			bool				fHinting;
159 			float				fMinVisibilityScale;
160 			float				fMaxVisibilityScale;
161 
162 #ifdef ICON_O_MATIC
163 			BList				fListeners;
164 #endif
165 };
166 
167 }	// namespace Icon
168 }	// namespace BPrivate
169 
170 #endif	// SHAPE_H
171