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