xref: /haiku/headers/os/interface/ColorControl.h (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
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 
11 class BBitmap;
12 
13 
14 enum 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 
22 class BTextControl;
23 
24 
25 class BColorControl : public BControl {
26 	public:
27 							BColorControl(BPoint start, color_control_layout layout,
28 								float cellSize, const char* name,
29 								BMessage* message = NULL, bool useOffscreen = false);
30 							BColorControl(BMessage* archive);
31 		virtual				~BColorControl();
32 
33 		static BArchivable*	Instantiate(BMessage* archive);
34 		virtual status_t	Archive(BMessage* archive, bool deep = true) const;
35 
36 		virtual void		SetValue(int32 color_value);
37 		void				SetValue(rgb_color color);
38 		rgb_color			ValueAsColor();
39 
40 		virtual void		SetEnabled(bool state);
41 
42 		virtual void		AttachedToWindow();
43 		virtual void		MessageReceived(BMessage* message);
44 		virtual void		Draw(BRect updateRect);
45 		virtual void		MouseDown(BPoint where);
46 		virtual void		KeyDown(const char* bytes, int32 numBytes);
47 
48 		virtual void		SetCellSize(float size);
49 		float				CellSize() const;
50 		virtual void		SetLayout(color_control_layout layout);
51 		color_control_layout Layout() const;
52 
53 		virtual void		WindowActivated(bool state);
54 		virtual void		MouseUp(BPoint point);
55 		virtual void		MouseMoved(BPoint point, uint32 code,
56 								const BMessage* dragMessage);
57 		virtual void		DetachedFromWindow();
58 		virtual void		GetPreferredSize(float* _width, float* _height);
59 		virtual void		ResizeToPreferred();
60 		virtual status_t	Invoke(BMessage* message = NULL);
61 		virtual void		FrameMoved(BPoint newPosition);
62 		virtual void		FrameResized(float newWidth, float newHeight);
63 
64 		virtual BHandler*	ResolveSpecifier(BMessage* message, int32 index,
65 								BMessage* specifier, int32 what,
66 								const char* property);
67 		virtual status_t	GetSupportedSuites(BMessage* data);
68 
69 		virtual void		MakeFocus(bool state = true);
70 		virtual void		AllAttached();
71 		virtual void		AllDetached();
72 
73 	private:
74 		virtual status_t	Perform(perform_code d, void *arg);
75 			// this can be made public again if needed
76 
77 		virtual void		_ReservedColorControl1();
78 		virtual void		_ReservedColorControl2();
79 		virtual void		_ReservedColorControl3();
80 		virtual void		_ReservedColorControl4();
81 
82 		BColorControl&		operator=(const BColorControl &other);
83 
84 		void				_InitData(color_control_layout layout,
85 								float size, bool useOffscreen,
86 								BMessage* archive = NULL);
87 		void				_LayoutView();
88 		void				_UpdateOffscreen(BRect update);
89 		void				_DrawColorArea(BView* target, BRect update);
90 		void				_ColorRamp(BRect rect, BView* target,
91 								rgb_color baseColor, int16 flag,
92 								bool focused);
93 
94 	private:
95 		float				fCellSize;
96 		int32				fRows;
97 		int32				fColumns;
98 
99 		BTextControl*		fRedText;
100 		BTextControl*		fGreenText;
101 		BTextControl*		fBlueText;
102 
103 		BBitmap*			fBitmap;
104 		BView*				fOffscreenView;
105 
106 		int32				fFocusedComponent;
107 		uint32				_reserved[8];
108 };
109 
110 inline void
111 BColorControl::SetValue(rgb_color color)
112 {
113 	int32 c = (color.red << 24) + (color.green << 16) + (color.blue << 8);
114 	SetValue(c);
115 }
116 
117 #endif /* _COLOR_CONTROL_H */
118