1/*
2 * Copyright 2006-2007, 2023, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Stephan A��mus <superstippi@gmx.de>
7 *		Zardshard
8 */
9#ifndef STYLE_H
10#define STYLE_H
11
12
13#ifdef ICON_O_MATIC
14#	include "IconObject.h"
15#	include "Observer.h"
16#endif
17
18#include "IconBuild.h"
19#include "IconRenderer.h"
20	// TODO: put GammaTable into its own file
21
22#include <GraphicsDefs.h>
23
24#include <agg_color_rgba.h>
25
26
27class BMessage;
28
29
30_BEGIN_ICON_NAMESPACE
31
32
33class Gradient;
34class Shape;
35
36// TODO: This class can represent solid colors, gradients, and bitmaps. It
37// should probably be split into subclasses.
38#ifdef ICON_O_MATIC
39class Style : public IconObject,
40			  public Observer {
41#else
42class Style {
43#endif
44 public:
45								Style();
46								Style(const Style& other);
47								Style(const rgb_color& color);
48#ifdef ICON_O_MATIC
49								Style(BBitmap* image);
50									// transfers ownership of the image
51#endif
52								Style(BMessage* archive);
53
54	virtual						~Style();
55
56#ifdef ICON_O_MATIC
57	// Observer interface
58	virtual	void				ObjectChanged(const Observable* object);
59
60	// Style
61			status_t			Archive(BMessage* into,
62										bool deep = true) const;
63
64			bool				operator==(const Style& other) const;
65#else
66	inline	void				Notify() {}
67#endif // ICON_O_MATIC
68
69			bool				HasTransparency() const;
70
71			void				SetColor(const rgb_color& color);
72	inline	rgb_color			Color() const
73									{ return fColor; }
74
75			void				SetGradient(const _ICON_NAMESPACE Gradient*
76											gradient);
77			_ICON_NAMESPACE Gradient* Gradient() const
78									{ return fGradient; }
79
80#ifdef ICON_O_MATIC
81			void				SetBitmap(BBitmap* image);
82									// transfers ownership of the image
83			BBitmap*			Bitmap() const
84									{ return fImage; }
85
86		// alpha only applies to bitmaps
87			void				SetAlpha(uint8 alpha)
88									{ fAlpha = alpha; Notify(); }
89			uint8				Alpha() const
90									{ return fAlpha; }
91#endif // ICON_O_MATIC
92
93			const agg::rgba8*	Colors() const
94									{ return fColors; }
95
96			const agg::rgba8*	GammaCorrectedColors(
97									const GammaTable& table) const;
98
99 private:
100			rgb_color			fColor;
101
102			_ICON_NAMESPACE Gradient* fGradient;
103
104			// hold gradient color array
105			agg::rgba8*			fColors;
106
107#ifdef ICON_O_MATIC
108			BBitmap*			fImage;
109			uint8				fAlpha;
110#endif
111
112			// for caching gamma corrected gradient color array
113	mutable	agg::rgba8*			fGammaCorrectedColors;
114	mutable	bool				fGammaCorrectedColorsValid;
115};
116
117
118_END_ICON_NAMESPACE
119
120
121_USING_ICON_NAMESPACE
122
123
124#endif	// STYLE_H
125