1 /* 2 * Copyright 2006-2007, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 #ifndef GRADIENT_TRANSFORMABLE_H 9 #define GRADIENT_TRANSFORMABLE_H 10 11 12 #ifdef ICON_O_MATIC 13 # include <Archivable.h> 14 # include <Referenceable.h> 15 16 # include "Observable.h" 17 #endif // ICON_O_MATIC 18 19 #include "IconBuild.h" 20 #include "Transformable.h" 21 22 #include <GraphicsDefs.h> 23 #include <Gradient.h> 24 #include <List.h> 25 26 class BMessage; 27 28 enum gradients_type { 29 GRADIENT_LINEAR = 0, 30 GRADIENT_CIRCULAR, 31 GRADIENT_DIAMOND, 32 GRADIENT_CONIC, 33 GRADIENT_XY, 34 GRADIENT_SQRT_XY 35 }; 36 37 enum interpolation_type { 38 INTERPOLATION_LINEAR = 0, 39 INTERPOLATION_SMOOTH 40 }; 41 42 43 _BEGIN_ICON_NAMESPACE 44 45 46 #ifdef ICON_O_MATIC 47 class Gradient : public BArchivable, 48 public Observable, 49 public BReferenceable, 50 public Transformable { 51 #else 52 class Gradient : public Transformable { 53 #endif 54 55 public: 56 Gradient(bool empty = false); 57 Gradient(BMessage* archive); 58 Gradient(const Gradient& other); 59 virtual ~Gradient(); 60 61 #ifdef ICON_O_MATIC 62 status_t Archive(BMessage* into, bool deep = true) const; 63 #else 64 inline void Notify() {} 65 #endif 66 67 Gradient& operator=(const Gradient& other); 68 69 bool operator==(const Gradient& other) const; 70 bool operator!=(const Gradient& other) const; 71 bool ColorStepsAreEqual( 72 const Gradient& other) const; 73 74 void SetColors(const Gradient& other); 75 76 77 int32 AddColor(const rgb_color& color, float offset); 78 bool AddColor(const BGradient::ColorStop& color, 79 int32 index); 80 81 bool RemoveColor(int32 index); 82 83 bool SetColor(int32 index, 84 const BGradient::ColorStop& step); 85 bool SetColor(int32 index, const rgb_color& color); 86 bool SetOffset(int32 index, float offset); 87 88 int32 CountColors() const; 89 BGradient::ColorStop* ColorAt(int32 index) const; 90 BGradient::ColorStop* ColorAtFast(int32 index) const; 91 92 void SetType(gradients_type type); 93 gradients_type Type() const 94 { return fType; } 95 96 void SetInterpolation(interpolation_type type); 97 interpolation_type Interpolation() const 98 { return fInterpolation; } 99 100 void SetInheritTransformation(bool inherit); 101 bool InheritTransformation() const 102 { return fInheritTransformation; } 103 104 void MakeGradient(uint32* colors, 105 int32 count) const; 106 107 void FitToBounds(const BRect& bounds); 108 BRect GradientArea() const; 109 virtual void TransformationChanged(); 110 111 void PrintToStream() const; 112 113 private: 114 void _MakeEmpty(); 115 116 BList fColors; 117 gradients_type fType; 118 interpolation_type fInterpolation; 119 bool fInheritTransformation; 120 }; 121 122 123 _END_ICON_NAMESPACE 124 125 126 #endif // GRADIENT_TRANSFORMABLE_H 127