1 /* 2 * Copyright 2006-2009, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 * Artur Wyszynski <harakash@gmail.com> 8 */ 9 10 #ifndef _GRADIENT_H 11 #define _GRADIENT_H 12 13 #include <Archivable.h> 14 #include <GraphicsDefs.h> 15 #include <List.h> 16 17 18 class BMessage; 19 class BRect; 20 21 22 class BGradient : public BArchivable { 23 public: 24 enum Type { 25 TYPE_LINEAR = 0, 26 TYPE_RADIAL, 27 TYPE_RADIAL_FOCUS, 28 TYPE_DIAMOND, 29 TYPE_CONIC, 30 TYPE_NONE 31 }; 32 33 struct ColorStop { 34 ColorStop(const rgb_color c, float o); 35 ColorStop(uint8 r, uint8 g, uint8 b, uint8 a, float o); 36 ColorStop(const ColorStop& other); 37 ColorStop(); 38 39 bool operator!=(const ColorStop& other) const; 40 41 rgb_color color; 42 float offset; 43 }; 44 45 public: 46 BGradient(); 47 BGradient(BMessage* archive); 48 virtual ~BGradient(); 49 50 status_t Archive(BMessage* into, bool deep = true) const; 51 52 BGradient& operator=(const BGradient& other); 53 54 bool operator==(const BGradient& other) const; 55 bool operator!=(const BGradient& other) const; 56 bool ColorStopsAreEqual(const BGradient& other) const; 57 58 void SetColorStops(const BGradient& other); 59 60 int32 AddColor(const rgb_color& color, float offset); 61 bool AddColorStop(const ColorStop& colorStop, int32 index); 62 63 bool RemoveColor(int32 index); 64 65 bool SetColorStop(int32 index, const ColorStop& colorStop); 66 bool SetColor(int32 index, const rgb_color& color); 67 bool SetOffset(int32 index, float offset); 68 69 int32 CountColorStops() const; 70 ColorStop* ColorStopAt(int32 index) const; 71 ColorStop* ColorStopAtFast(int32 index) const; 72 ColorStop* ColorStops() const; 73 void SortColorStopsByOffset(); 74 75 Type GetType() const 76 { return fType; } 77 78 void MakeEmpty(); 79 80 private: 81 friend class BGradientLinear; 82 friend class BGradientRadial; 83 friend class BGradientRadialFocus; 84 friend class BGradientDiamond; 85 friend class BGradientConic; 86 87 union { 88 struct { 89 float x1, y1, x2, y2; 90 } linear; 91 struct { 92 float cx, cy, radius; 93 } radial; 94 struct { 95 float cx, cy, fx, fy, radius; 96 } radial_focus; 97 struct { 98 float cx, cy; 99 } diamond; 100 struct { 101 float cx, cy, angle; 102 } conic; 103 } fData; 104 105 BList fColorStops; 106 Type fType; 107 }; 108 109 #endif // _GRADIENT_H 110