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