1/*
2 * Copyright 2005, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _COLOR_CONTROL_H
6#define _COLOR_CONTROL_H
7
8
9#include <Control.h>
10
11class BBitmap;
12
13
14enum color_control_layout {
15	B_CELLS_4x64	= 4,
16	B_CELLS_8x32	= 8,
17	B_CELLS_16x16	= 16,
18	B_CELLS_32x8	= 32,
19	B_CELLS_64x4	= 64,
20};
21
22class BTextControl;
23
24
25class BColorControl : public BControl {
26public:
27								BColorControl(BPoint start,
28									color_control_layout layout,
29									float cellSize, const char* name,
30									BMessage* message = NULL,
31									bool useOffscreen = false);
32								BColorControl(BMessage* archive);
33	virtual						~BColorControl();
34
35	static	BArchivable*		Instantiate(BMessage* archive);
36	virtual	status_t			Archive(BMessage* archive,
37									bool deep = true) const;
38
39	virtual	void				SetLayout(BLayout* layout);
40
41	virtual	void				SetValue(int32 color_value);
42			void				SetValue(rgb_color color);
43			rgb_color			ValueAsColor();
44
45	virtual	void				SetEnabled(bool state);
46
47	virtual	void				AttachedToWindow();
48	virtual	void				MessageReceived(BMessage* message);
49	virtual	void				Draw(BRect updateRect);
50	virtual	void				MouseDown(BPoint where);
51	virtual	void				KeyDown(const char* bytes, int32 numBytes);
52
53	virtual	void				SetCellSize(float size);
54			float				CellSize() const;
55	virtual	void				SetLayout(color_control_layout layout);
56			color_control_layout Layout() const;
57
58	virtual	void				WindowActivated(bool state);
59	virtual	void				MouseUp(BPoint point);
60	virtual	void				MouseMoved(BPoint point, uint32 code,
61									const BMessage* dragMessage);
62	virtual	void				DetachedFromWindow();
63	virtual	void				GetPreferredSize(float* _width,
64									float* _height);
65	virtual	void				ResizeToPreferred();
66	virtual	status_t			Invoke(BMessage* message = NULL);
67	virtual	void				FrameMoved(BPoint newPosition);
68	virtual	void				FrameResized(float newWidth, float newHeight);
69
70	virtual	BHandler*			ResolveSpecifier(BMessage* message,
71									int32 index, BMessage* specifier,
72									int32 what, const char* property);
73	virtual	status_t			GetSupportedSuites(BMessage* data);
74
75	virtual	void				MakeFocus(bool state = true);
76	virtual	void				AllAttached();
77	virtual	void				AllDetached();
78
79private:
80	virtual	status_t			Perform(perform_code d, void *arg);
81		// this can be made public again if needed
82
83	virtual	void				_ReservedColorControl1();
84	virtual	void				_ReservedColorControl2();
85	virtual	void				_ReservedColorControl3();
86	virtual	void				_ReservedColorControl4();
87
88			BColorControl&		operator=(const BColorControl &other);
89
90			void				_InitData(color_control_layout layout,
91									float size, bool useOffscreen,
92									BMessage* archive = NULL);
93			void				_LayoutView();
94			void				_InitOffscreen();
95			void				_DrawColorArea(BView* target, BRect update);
96			void				_DrawSelectors(BView* target);
97			void				_ColorRamp(BRect rect, BView* target,
98									rgb_color baseColor, rgb_color compColor,
99									int16 flag, bool focused, BRect update);
100			BPoint				_SelectorPosition(const BRect& rampRect,
101									uint8 shade) const;
102			BRect				_PaletteSelectorFrame(uint8 colorIndex) const;
103			BRect				_RampFrame(uint8 rampIndex) const;
104
105	private:
106			BRect				fPaletteFrame;
107			int16				fSelectedPaletteColorIndex;
108			int16				fPreviousSelectedPaletteColorIndex;
109
110			float				fCellSize;
111			int32				fRows;
112			int32				fColumns;
113			bool				fPaletteMode;
114			bool				_unused[3];
115
116			BTextControl*		fRedText;
117			BTextControl*		fGreenText;
118			BTextControl*		fBlueText;
119
120			BBitmap*			fBitmap;
121			BView*				fOffscreenView;
122
123			int32				fFocusedComponent;
124			uint32				_reserved[2];
125};
126
127inline void
128BColorControl::SetValue(rgb_color color)
129{
130	int32 c = (color.red << 24) + (color.green << 16) + (color.blue << 8);
131	SetValue(c);
132}
133
134#endif // _COLOR_CONTROL_H
135