xref: /haiku/docs/user/interface/ColorControl.dox (revision 579f1dbca962a2a03df54f69fdc6e9423f91f20e)
1/*
2 * Copyright 2011 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		John Scipione, jscipione@gmail.com
7 *
8 * Corresponds to:
9 *		headers/os/interface/ColorControl.h	 rev 42794
10 *		src/kits/interface/ColorControl.cpp	 rev 42794
11 */
12
13
14/*!
15	\file ColorControl.h
16	\ingroup interface
17	\ingroup libbe
18	\brief BColorControl class definition and support enums.
19*/
20
21
22/*!
23	\enum color_control_layout
24	\ingroup interface
25
26	Enumeration of the color control layout options.
27*/
28
29/*!
30	\var color_control_layout B_CELLS_4x64
31
32	Cells are arranged in 4 columns, 64 rows.
33*/
34
35/*!
36	\var color_control_layout B_CELLS_8x32
37
38	Cells are arranged in 8 columns, 32 rows.
39*/
40
41/*!
42	\var color_control_layout B_CELLS_16x16
43
44	Cells are arranged in 16 columns, 16 rows.
45*/
46
47/*!
48	\var color_control_layout B_CELLS_32x8
49
50	Cells are arranged in 32 columns, 8 rows.
51*/
52
53/*!
54	\var color_control_layout B_CELLS_64x4
55
56	Cells are arranged in 64 columns, 4 rows.
57*/
58
59
60/*!
61	\class BColorControl
62	\ingroup interface
63	\ingroup libbe
64
65	\brief BColorControl displays an on-screen color picker.
66
67	The value of the color control is a rgb_color data structure
68	containing a 32-bit color. If a message is specified in the
69	constructor then the message is sent to a target in response to
70	changes in the color value.
71
72	The color value is initially set to 0 which corresponds to black.
73	To set the color of the color control use the SetValue() method.
74
75	An example of creating a color control looks like this:
76\code
77colorControl = new BColorControl(BPoint(0, 0), B_CELLS_32x8, 7.0,
78    "ColorControl", new BMessage(kValueChanged));
79colorControl->SetValue(0x336698);
80\endcode
81
82	A BColorControl contains four color ramps to set the red, green,
83	and blue components of the color control value. A greyscale slider
84	is provided to easily select black, white, and shades of grey. The color
85	control also contains three child BTextControl objects used to set the
86	color by typing in a number between 0 and 255 for the red, green, and
87	blue components of the color value.
88
89	\image html BColorControl_example.png
90
91	If the screen is set to 8-bit (256) colors then the color ramps are
92	replaced with a palette of color cells.
93
94	\image html BColorControl_example_256_colors.png
95
96	You can set the size of these cells by calling the SetCellSize() method.
97*/
98
99
100/*!
101	\fn BColorControl::BColorControl(BPoint leftTop,
102		color_control_layout layout, float cellSize, const char *name,
103		BMessage *message = NULL, bool bufferedDrawing = false)
104	\brief Constructs a new color control object.
105
106	\param leftTop location of the left top corner of the frame rectangle
107		relative to the parent view.
108	\param layout The \a layout of the BColorControl. See the
109		#color_control_layout enum for more information. Color control
110		layout options include:
111			- \c B_CELLS_4x64
112			- \c B_CELLS_8x32
113			- \c B_CELLS_16x16
114			- \c B_CELLS_32x8
115			- \c B_CELLS_32x8
116	\param cellSize The size of the sides of the color cell.
117	\param name The name of the color control.
118	\param message The optional \a message to send to a target in response
119		to a change in color value.
120	\param bufferedDrawing If \c true, all on-screen changes are first
121		made to an off-screen bitmap and then copied to the screen
122		making the drawing smoother, but requiring more memory
123		(currently unused).
124*/
125
126
127/*!
128	\fn BColorControl::BColorControl(BMessage* archive)
129	\brief Constructs a BColorControl object from an \a archive message.
130
131	This method is usually not called directly. If you want to build a
132	color control from a message you should call Instantiate() which can
133	handle errors properly.
134
135	If the \a archive deep, the BColorControl object will also unarchive
136	each of its child views recursively.
137
138	\param archive The \a archive message to restore from.
139*/
140
141
142/*!
143	\fn BColorControl::~BColorControl()
144	\brief Destructor method.
145*/
146
147
148/*!
149	\fn void BColorControl::SetLayout(BLayout* layout)
150	\brief Set the layout of the BColorControl object to \a layout.
151
152	\param layout The \a layout to set.
153
154	\sa BView::SetLayout()
155*/
156
157
158/*!
159	\fn void BColorControl::SetLayout(color_control_layout layout)
160	\brief Set the layout of the color control.
161
162	Color control layout options include:
163		- \c B_CELLS_4x64
164		- \c B_CELLS_8x32
165		- \c B_CELLS_16x16
166		- \c B_CELLS_32x8
167		- \c B_CELLS_32x8
168
169	\param layout The color control layout to set.
170*/
171
172
173
174/*!
175	\fn void BColorControl::SetValue(int32 value)
176	\brief Set the color of the BColorControl to \a value.
177
178	\param value The 32-bit color value to set.
179*/
180
181
182/*!
183	\fn inline void BColorControl::SetValue(rgb_color color)
184	\brief Set the color of the BColorControl to \a color.
185
186	\param color The rgb_color to set.
187*/
188
189
190/*!
191	\fn rgb_color BColorControl::ValueAsColor()
192	\brief Return the current color value as an rgb_color.
193
194	\returns The current color as an rgb_color.
195*/
196
197
198/*!
199	\fn void BColorControl::SetEnabled(bool enabled)
200	\brief Enable and disable the color control.
201
202	\param enabled Whether to enable or disable the color control.
203*/
204
205
206/*!
207	\fn void BColorControl::AttachedToWindow()
208	\brief Hook method that is called when the object is attached to a
209		window.
210
211	This method also sets the view color and low color of the color control
212	to be the same as its parent's view color and sets the red, green, and
213	blue BTextControl color values.
214
215	\sa BControl::AttachedToWindow()
216	\sa BView::SetViewColor()
217*/
218
219
220/*!
221	\fn void BColorControl::Draw(BRect updateRect)
222	\brief Draws the area of the color control that intersects \a updateRect.
223
224	\note This is an hook method called by the Interface Kit, you don't
225	have to call it yourself. If you need to forcefully redraw the color
226	control consider calling Invalidate() instead.
227
228	\param updateRect The area to be drawn.
229
230	\sa BView::Draw()
231*/
232
233
234/*!
235	\fn void BColorControl::SetCellSize(float cellSide)
236	\brief Set the size of the color cell in the color control.
237
238	\param cellSide The cell size to set.
239*/
240
241
242/*!
243	\fn float BColorControl::CellSize() const
244	\brief Get the current color cell size.
245
246	\returns the current color cell size as a float.
247*/
248
249
250/*!
251	\fn color_control_layout BColorControl::Layout() const
252	\brief Get the current color control layout.
253
254	\returns The current color_control_layout
255*/
256
257
258/*!
259	\fn void BColorControl::DetachedFromWindow()
260	\brief Hook method that is called when the object is detached from a
261		window.
262
263	\sa BView::DetachedFromWindow()
264*/
265
266
267/*!
268	\fn void BColorControl::GetPreferredSize(float *_width, float *_height)
269	\brief Fill out the preferred width and height of the checkbox
270		into the \a _width and \a _height parameters.
271
272	\param _width Pointer to a \c float to hold the width of the checkbox.
273	\param _height Pointer to a \c float to hold the height of the checkbox.
274
275	\sa BView::GetPreferredSize()
276*/
277
278
279/*!
280	\fn void BColorControl::ResizeToPreferred()
281	\brief Resize the color control to its preferred size.
282
283	\sa BView::ResizeToPreferred()
284*/
285
286
287/*!
288	\fn status_t BColorControl::Invoke(BMessage *msg)
289	\brief Tells the messenger to send a message.
290
291	\param msg The message to send.
292
293	\sa BControl::Invoke()
294*/
295
296
297/*!
298	\fn void BColorControl::FrameMoved(BPoint new_position)
299	\brief Hook method that gets called when the color control is moved.
300
301	\param new_position The point that the top left corner of the frame
302		is moved to.
303
304	\sa BView::FrameMoved()
305*/
306
307
308/*!
309	\fn void BColorControl::FrameResized(float new_width, float new_height)
310	\brief Hook method that gets called when the checkbox is resized.
311
312	\param new_width The new width of the checkbox.
313	\param new_height The new height of the checkbox.
314
315	\sa BView::FrameResized()
316*/
317
318
319/*!
320	\fn void BColorControl::MakeFocus(bool state)
321	\brief Gives focus to or removes focus from the color control.
322
323	\param state \a true to set focus, \a false to remove it.
324
325	\sa BControl::MakeFocus()
326
327*/
328