xref: /haiku/headers/os/interface/ColorControl.h (revision 89755088d790ff4fe36f8aa77dacb2bd15507108)
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		SetLayout(BLayout* layout);
37 
38 		virtual void		SetValue(int32 color_value);
39 		void				SetValue(rgb_color color);
40 		rgb_color			ValueAsColor();
41 
42 		virtual void		SetEnabled(bool state);
43 
44 		virtual void		AttachedToWindow();
45 		virtual void		MessageReceived(BMessage* message);
46 		virtual void		Draw(BRect updateRect);
47 		virtual void		MouseDown(BPoint where);
48 		virtual void		KeyDown(const char* bytes, int32 numBytes);
49 
50 		virtual void		SetCellSize(float size);
51 		float				CellSize() const;
52 		virtual void		SetLayout(color_control_layout layout);
53 		color_control_layout Layout() const;
54 
55 		virtual void		WindowActivated(bool state);
56 		virtual void		MouseUp(BPoint point);
57 		virtual void		MouseMoved(BPoint point, uint32 code,
58 								const BMessage* dragMessage);
59 		virtual void		DetachedFromWindow();
60 		virtual void		GetPreferredSize(float* _width, float* _height);
61 		virtual void		ResizeToPreferred();
62 		virtual status_t	Invoke(BMessage* message = NULL);
63 		virtual void		FrameMoved(BPoint newPosition);
64 		virtual void		FrameResized(float newWidth, float newHeight);
65 
66 		virtual BHandler*	ResolveSpecifier(BMessage* message, int32 index,
67 								BMessage* specifier, int32 what,
68 								const char* property);
69 		virtual status_t	GetSupportedSuites(BMessage* data);
70 
71 		virtual void		MakeFocus(bool state = true);
72 		virtual void		AllAttached();
73 		virtual void		AllDetached();
74 
75 	private:
76 		virtual status_t	Perform(perform_code d, void *arg);
77 			// this can be made public again if needed
78 
79 		virtual void		_ReservedColorControl1();
80 		virtual void		_ReservedColorControl2();
81 		virtual void		_ReservedColorControl3();
82 		virtual void		_ReservedColorControl4();
83 
84 		BColorControl&		operator=(const BColorControl &other);
85 
86 		void				_InitData(color_control_layout layout,
87 								float size, bool useOffscreen,
88 								BMessage* archive = NULL);
89 		void				_LayoutView();
90 		void				_InitOffscreen();
91 		void				_DrawColorArea(BView* target, BRect update);
92 		void				_DrawSelectors(BView* target);
93 		void				_ColorRamp(BRect rect, BView* target,
94 								rgb_color baseColor, int16 flag,
95 								bool focused, BRect update);
96 		BPoint				_SelectorPosition(const BRect& rampRect, uint8 shade) const;
97 		BRect				_PaletteSelectorFrame(uint8 colorIndex) const;
98 		BRect				_RampFrame(uint8 rampIndex) const;
99 
100 	private:
101 		BRect				fPaletteFrame;
102 		int16				fSelectedPaletteColorIndex;
103 		int16				fPreviousSelectedPaletteColorIndex;
104 
105 		float				fCellSize;
106 		int32				fRows;
107 		int32				fColumns;
108 		bool				fPaletteMode;
109 		bool				_unused[3];
110 
111 		BTextControl*		fRedText;
112 		BTextControl*		fGreenText;
113 		BTextControl*		fBlueText;
114 
115 		BBitmap*			fBitmap;
116 		BView*				fOffscreenView;
117 
118 		int32				fFocusedComponent;
119 		uint32				_reserved[2];
120 };
121 
122 inline void
123 BColorControl::SetValue(rgb_color color)
124 {
125 	int32 c = (color.red << 24) + (color.green << 16) + (color.blue << 8);
126 	SetValue(c);
127 }
128 
129 #endif /* _COLOR_CONTROL_H */
130