ColorControl.h revision 1f424632
1/*
2 * Copyright 2005-2013 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
11
12enum color_control_layout {
13	B_CELLS_4x64	= 4,
14	B_CELLS_8x32	= 8,
15	B_CELLS_16x16	= 16,
16	B_CELLS_32x8	= 32,
17	B_CELLS_64x4	= 64,
18};
19
20
21class BBitmap;
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* data);
33	virtual						~BColorControl();
34
35	static	BArchivable*		Instantiate(BMessage* data);
36	virtual	status_t			Archive(BMessage* data,
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 focused = true);
76	virtual	void				AllAttached();
77	virtual	void				AllDetached();
78
79	virtual	status_t			SetIcon(const BBitmap* icon, uint32 flags = 0);
80
81private:
82	virtual	status_t			Perform(perform_code d, void *arg);
83		// this can be made public again if needed
84
85	virtual	void				_ReservedColorControl1();
86	virtual	void				_ReservedColorControl2();
87	virtual	void				_ReservedColorControl3();
88	virtual	void				_ReservedColorControl4();
89
90			BColorControl&		operator=(const BColorControl &other);
91
92			void				_InitData(color_control_layout layout,
93									float size, bool useOffscreen,
94									BMessage* data = NULL);
95			void				_LayoutView();
96			void				_InitOffscreen();
97			void				_InvalidateSelector(int16 ramp,
98									rgb_color color, bool focused);
99			void				_DrawColorArea(BView* target, BRect update);
100			void				_DrawSelectors(BView* target);
101			void				_DrawColorRamp(BRect rect, BView* target,
102									rgb_color baseColor, rgb_color compColor,
103									int16 flag, bool focused,
104									BRect updateRect);
105			BPoint				_SelectorPosition(const BRect& rampRect,
106									uint8 shade) const;
107			BRect				_PaletteFrame() const;
108			BRect				_PaletteSelectorFrame(uint8 colorIndex) const;
109			BRect				_RampFrame(uint8 rampIndex) const;
110			void				_SetCellSize(float size);
111			float				_TextRectOffset();
112
113	private:
114			BRect				fPaletteFrame;
115			int16				fSelectedPaletteColorIndex;
116			int16				fPreviousSelectedPaletteColorIndex;
117
118			float				fCellSize;
119			int32				fRows;
120			int32				fColumns;
121			bool				fPaletteMode;
122			bool				_unused[3];
123
124			BTextControl*		fRedText;
125			BTextControl*		fGreenText;
126			BTextControl*		fBlueText;
127
128			BBitmap*			fBitmap;
129			BView*				fOffscreenView;
130
131			int16				fFocusedRamp;
132			int16				fClickedRamp;
133			uint32				_reserved[2];
134};
135
136inline void
137BColorControl::SetValue(rgb_color color)
138{
139	int32 c = (color.red << 24) + (color.green << 16) + (color.blue << 8);
140	SetValue(c);
141}
142
143#endif // _COLOR_CONTROL_H
144