xref: /haiku/src/libs/icon/style/GradientTransformable.h (revision a4ef4a49150f118d47324242917a596a3f8f8bd5)
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 #ifdef ICON_O_MATIC
54 								Gradient(BMessage* archive);
55 #endif
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::color_step& color,
77 									int32 index);
78 
79 			bool				RemoveColor(int32 index);
80 
81 			bool				SetColor(int32 index,
82 									const BGradient::color_step& step);
83 			bool				SetColor(int32 index, const rgb_color& color);
84 			bool				SetOffset(int32 index, float offset);
85 
86 			int32				CountColors() const;
87 			BGradient::color_step* ColorAt(int32 index) const;
88 			BGradient::color_step* 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 }	// namespace Icon
121 }	// namespace BPrivate
122 
123 #endif	// GRADIENT_TRANSFORMABLE_H
124