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