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