xref: /haiku/headers/os/interface/ColorControl.h (revision 5d9e40fe9252c8f9c5e5e41594545bfa4419fcc7)
1 /*******************************************************************************
2 /
3 /	File:			ColorControl.h
4 /
5 /   Description:    BColorControl displays a palette of selectable colors.
6 /
7 /	Copyright 1996-98, Be Incorporated, All Rights Reserved
8 /
9 *******************************************************************************/
10 
11 
12 #ifndef _COLOR_CONTROL_H
13 #define _COLOR_CONTROL_H
14 
15 #include <BeBuild.h>
16 #include <Control.h>
17 
18 class BBitmap;
19 
20 /*------------------------------------------------------------*/
21 /*----- layout options for the color control -----------------*/
22 
23 enum color_control_layout {
24 	B_CELLS_4x64 = 4,
25 	B_CELLS_8x32 = 8,
26 	B_CELLS_16x16 = 16,
27 	B_CELLS_32x8 = 32,
28 	B_CELLS_64x4 = 64
29 };
30 
31 class BTextControl;
32 
33 /*----------------------------------------------------------------*/
34 /*----- BColorControl class --------------------------------------*/
35 
36 class BColorControl : public BControl {
37 public:
38 						BColorControl(	BPoint start,
39 										color_control_layout layout,
40 										float cell_size,
41 										const char *name,
42 										BMessage *message = NULL,
43 										bool use_offscreen = false);
44 virtual					~BColorControl();
45 
46 						BColorControl(BMessage *data);
47 static	BArchivable		*Instantiate(BMessage *data);
48 virtual	status_t		Archive(BMessage *data, bool deep = true) const;
49 
50 virtual	void			SetValue(int32 color_value);
51 		void			SetValue(rgb_color color);
52 		rgb_color		ValueAsColor();
53 
54 virtual	void			SetEnabled(bool state);
55 
56 virtual	void			AttachedToWindow();
57 virtual	void			MessageReceived(BMessage *msg);
58 virtual	void			Draw(BRect updateRect);
59 virtual	void			MouseDown(BPoint where);
60 virtual	void			KeyDown(const char *bytes, int32 numBytes);
61 
62 virtual	void			SetCellSize(float size);
63 		float			CellSize() const;
64 virtual	void			SetLayout(color_control_layout layout);
65 		color_control_layout Layout() const;
66 
67 virtual void			WindowActivated(bool state);
68 virtual	void			MouseUp(BPoint pt);
69 virtual	void			MouseMoved(BPoint pt, uint32 code, const BMessage *msg);
70 virtual	void			DetachedFromWindow();
71 virtual void			GetPreferredSize(float *width, float *height);
72 virtual void			ResizeToPreferred();
73 virtual	status_t		Invoke(BMessage *msg = NULL);
74 virtual	void			FrameMoved(BPoint new_position);
75 virtual	void			FrameResized(float new_width, float new_height);
76 
77 virtual BHandler		*ResolveSpecifier(BMessage *msg,
78 										int32 index,
79 										BMessage *specifier,
80 										int32 form,
81 										const char *property);
82 virtual status_t		GetSupportedSuites(BMessage *data);
83 
84 virtual void			MakeFocus(bool state = true);
85 virtual void			AllAttached();
86 virtual void			AllDetached();
87 
88 
89 /*----- Private or reserved -----------------------------------------*/
90 virtual status_t		Perform(perform_code d, void *arg);
91 
92 private:
93 
94 virtual	void			_ReservedColorControl1();
95 virtual	void			_ReservedColorControl2();
96 virtual	void			_ReservedColorControl3();
97 virtual	void			_ReservedColorControl4();
98 
99 		BColorControl	&operator=(const BColorControl &);
100 
101 		void			LayoutView(bool calc_frame);
102 		void			UpdateOffscreen();
103 		void			UpdateOffscreen(BRect update);
104 		void			DrawColorArea(BView *target, BRect update);
105 		void			ColorRamp(	BRect r,
106 									BRect where,
107 									BView *target,
108 									rgb_color c,
109 									int16 flag,
110 									bool focused);
111 		void			KbAdjustColor(uint32 key);
112 		bool			key_down32(uint32 key);
113 		bool			key_down8(uint32 key);
114 static	BRect			CalcFrame(	BPoint start,
115 									color_control_layout layout,
116 									int32 size);
117 		void			InitData(	color_control_layout layout,
118 									float size,
119 									bool use_offscreen,
120 									BMessage *data = NULL);
121 		void			DoMouseMoved(BPoint pt);
122 		void			DoMouseUp(BPoint pt);
123 
124 		float			fCellSize;
125 		int32			fRows;
126 		int32			fColumns;
127 
128 		struct track_state {
129 			int32		orig_color;
130 			int32		cur_color;
131 			int32		prev_color;
132 			int32		bar_index;
133 			BRect		active_area;
134 			BRect		r;
135 			rgb_color	rgb;
136 			color_space	cspace;
137 		};
138 
139 		BTextControl	*fRedText;
140 		BTextControl	*fGreenText;
141 		BTextControl	*fBlueText;
142 		BBitmap			*fBitmap;
143 		BView			*fOffscreenView;
144 		color_space		fLastMode;
145 		float			fRound;
146 		int32			fFocusedComponent;
147 		int32			fCachedIndex;
148 		uint32			_reserved[3];
149 		track_state		*fTState;
150 		bool			fUnused;	// fTracking;
151 		bool			fFocused;
152 		bool			fRetainCache;
153 		bool			fFastSet;
154 };
155 
156 /*------------------------------------------------------------*/
157 /*----- inline functions -------------------------------------*/
158 
159 inline void BColorControl::SetValue(rgb_color color)
160 {
161 	/* OK, no private parts */
162 	int32 c = (color.red << 24) + (color.green << 16) + (color.blue << 8);
163 	SetValue(c);
164 }
165 
166 /*-------------------------------------------------------------*/
167 /*-------------------------------------------------------------*/
168 
169 #endif /* _COLOR_CONTROL_H */
170