xref: /haiku/src/libs/icon/style/Style.h (revision c6c2c0428420c1a7a9b16a843b41ab26903bc5fb)
1fb07ece0SStephan Aßmus /*
2098eaec6SZardshard  * Copyright 2006-2007, 2023, Haiku.
3fb07ece0SStephan Aßmus  * Distributed under the terms of the MIT License.
4fb07ece0SStephan Aßmus  *
5fb07ece0SStephan Aßmus  * Authors:
6fb07ece0SStephan Aßmus  *		Stephan Aßmus <superstippi@gmx.de>
7098eaec6SZardshard  *		Zardshard
8fb07ece0SStephan Aßmus  */
9fb07ece0SStephan Aßmus #ifndef STYLE_H
10fb07ece0SStephan Aßmus #define STYLE_H
11fb07ece0SStephan Aßmus 
12fb07ece0SStephan Aßmus 
13fb07ece0SStephan Aßmus #ifdef ICON_O_MATIC
14fb07ece0SStephan Aßmus #	include "IconObject.h"
15fb07ece0SStephan Aßmus #	include "Observer.h"
16fb07ece0SStephan Aßmus #endif
17fb07ece0SStephan Aßmus 
1825dc253dSIngo Weinhold #include "IconBuild.h"
19fb07ece0SStephan Aßmus #include "IconRenderer.h"
20fb07ece0SStephan Aßmus 	// TODO: put GammaTable into its own file
21fb07ece0SStephan Aßmus 
22325a6253SAxel Dörfler #include <GraphicsDefs.h>
23325a6253SAxel Dörfler 
24325a6253SAxel Dörfler #include <agg_color_rgba.h>
25325a6253SAxel Dörfler 
26325a6253SAxel Dörfler 
278b8d44bfSMichael Lotz class BMessage;
288b8d44bfSMichael Lotz 
2925dc253dSIngo Weinhold 
3025dc253dSIngo Weinhold _BEGIN_ICON_NAMESPACE
3125dc253dSIngo Weinhold 
32325a6253SAxel Dörfler 
33fb07ece0SStephan Aßmus class Gradient;
34098eaec6SZardshard class Shape;
35fb07ece0SStephan Aßmus 
36098eaec6SZardshard // TODO: This class can represent solid colors, gradients, and bitmaps. It
37098eaec6SZardshard // should probably be split into subclasses.
38fb07ece0SStephan Aßmus #ifdef ICON_O_MATIC
39fb07ece0SStephan Aßmus class Style : public IconObject,
40fb07ece0SStephan Aßmus 			  public Observer {
41fb07ece0SStephan Aßmus #else
42fb07ece0SStephan Aßmus class Style {
43fb07ece0SStephan Aßmus #endif
44fb07ece0SStephan Aßmus  public:
45fb07ece0SStephan Aßmus 								Style();
46fb07ece0SStephan Aßmus 								Style(const Style& other);
47fb07ece0SStephan Aßmus 								Style(const rgb_color& color);
48098eaec6SZardshard #ifdef ICON_O_MATIC
49098eaec6SZardshard 								Style(BBitmap* image);
50098eaec6SZardshard 									// transfers ownership of the image
51098eaec6SZardshard #endif
52fb07ece0SStephan Aßmus 								Style(BMessage* archive);
538b8d44bfSMichael Lotz 
54fb07ece0SStephan Aßmus 	virtual						~Style();
55fb07ece0SStephan Aßmus 
56fb07ece0SStephan Aßmus #ifdef ICON_O_MATIC
57fb07ece0SStephan Aßmus 	// Observer interface
58fb07ece0SStephan Aßmus 	virtual	void				ObjectChanged(const Observable* object);
59fb07ece0SStephan Aßmus 
60fb07ece0SStephan Aßmus 	// Style
61fb07ece0SStephan Aßmus 			status_t			Archive(BMessage* into,
62fb07ece0SStephan Aßmus 										bool deep = true) const;
636e3b3b09SStephan Aßmus 
646e3b3b09SStephan Aßmus 			bool				operator==(const Style& other) const;
65fb07ece0SStephan Aßmus #else
Notify()66fb07ece0SStephan Aßmus 	inline	void				Notify() {}
67fb07ece0SStephan Aßmus #endif // ICON_O_MATIC
68fb07ece0SStephan Aßmus 
69112d6155SStephan Aßmus 			bool				HasTransparency() const;
70112d6155SStephan Aßmus 
71fb07ece0SStephan Aßmus 			void				SetColor(const rgb_color& color);
Color()72fb07ece0SStephan Aßmus 	inline	rgb_color			Color() const
73fb07ece0SStephan Aßmus 									{ return fColor; }
74fb07ece0SStephan Aßmus 
7525dc253dSIngo Weinhold 			void				SetGradient(const _ICON_NAMESPACE Gradient*
76325a6253SAxel Dörfler 											gradient);
Gradient()7725dc253dSIngo Weinhold 			_ICON_NAMESPACE Gradient* Gradient() const
78fb07ece0SStephan Aßmus 									{ return fGradient; }
79fb07ece0SStephan Aßmus 
80098eaec6SZardshard #ifdef ICON_O_MATIC
81098eaec6SZardshard 			void				SetBitmap(BBitmap* image);
82098eaec6SZardshard 									// transfers ownership of the image
Bitmap()83098eaec6SZardshard 			BBitmap*			Bitmap() const
84098eaec6SZardshard 									{ return fImage; }
85098eaec6SZardshard 
86098eaec6SZardshard 		// alpha only applies to bitmaps
SetAlpha(uint8 alpha)87098eaec6SZardshard 			void				SetAlpha(uint8 alpha)
88098eaec6SZardshard 									{ fAlpha = alpha; Notify(); }
Alpha()89*c6c2c042SZardshard 			uint8				Alpha() const
90098eaec6SZardshard 									{ return fAlpha; }
91098eaec6SZardshard #endif // ICON_O_MATIC
92098eaec6SZardshard 
Colors()93fb07ece0SStephan Aßmus 			const agg::rgba8*	Colors() const
94fb07ece0SStephan Aßmus 									{ return fColors; }
95fb07ece0SStephan Aßmus 
96fb07ece0SStephan Aßmus 			const agg::rgba8*	GammaCorrectedColors(
97fb07ece0SStephan Aßmus 									const GammaTable& table) const;
98fb07ece0SStephan Aßmus 
99fb07ece0SStephan Aßmus  private:
100fb07ece0SStephan Aßmus 			rgb_color			fColor;
101098eaec6SZardshard 
10225dc253dSIngo Weinhold 			_ICON_NAMESPACE Gradient* fGradient;
103fb07ece0SStephan Aßmus 
104fb07ece0SStephan Aßmus 			// hold gradient color array
105fb07ece0SStephan Aßmus 			agg::rgba8*			fColors;
106fb07ece0SStephan Aßmus 
107098eaec6SZardshard #ifdef ICON_O_MATIC
108098eaec6SZardshard 			BBitmap*			fImage;
109098eaec6SZardshard 			uint8				fAlpha;
110098eaec6SZardshard #endif
111098eaec6SZardshard 
112fb07ece0SStephan Aßmus 			// for caching gamma corrected gradient color array
113fb07ece0SStephan Aßmus 	mutable	agg::rgba8*			fGammaCorrectedColors;
114fb07ece0SStephan Aßmus 	mutable	bool				fGammaCorrectedColorsValid;
115fb07ece0SStephan Aßmus };
116fb07ece0SStephan Aßmus 
117325a6253SAxel Dörfler 
11825dc253dSIngo Weinhold _END_ICON_NAMESPACE
11925dc253dSIngo Weinhold 
12025dc253dSIngo Weinhold 
12125dc253dSIngo Weinhold _USING_ICON_NAMESPACE
12225dc253dSIngo Weinhold 
123325a6253SAxel Dörfler 
124fb07ece0SStephan Aßmus #endif	// STYLE_H
125