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