The Interface Kit: BColorControl

Derived from: public BControl

Declared in: <interface/ColorControl.h>


Overview

A BColorControl object displays an on-screen device that permits users to pick a color. It reports the color as its current value--an rgb_color data structure stored as a long integer. If a model message is provided, it announces each change in value by sending a copy of the message to a designated target.

When the screen is 8 bits deep, the BColorControl object presents users with a matrix of the 256 available colors. The user chooses a color by pressing the primary mouse button while the cursor is over one of the cells in the matrix. Dragging from cell to cell changes the selected color. The arrow keys can similarly change the selection when the object is the focus view. The BColorControl's value changes each time the selection does.

When the screen is 32 bits deep, the BColorControl object displays ramps for each color component. The user changes the current color by modifying a red, green, or blue component value.


Constructor and Destructor


BColorControl()

      BColorControl(BPoint leftTop, color_control_layout matrix, long cellSide, 
         const char *name, BMessage *message = NULL, 
         bool bufferedDrawing = FALSE)

Initializes the BColorControl so that the left top corner of its frame rectangle will be located at the stated leftTop point in the coordinate system of its parent view. The frame rectangle will be large enough to display 256 color cells arranged in the specified matrix, which can be any of the following constants:

B_CELLS_4x64
B_CELLS_8x32
B_CELLS_16x16
B_CELLS_32x8
B_CELLS_64x4

For example, B_CELLS_4x64 lays out a matrix with four cell columns and 64 rows; B_CELLS_32x8 specifies 32 columns and 8 rows. Each cell is a square cellSide coordinate units on a side.

When the screen is 32 bits deep, the same frame rectangle will display four color ramps, one each for the red, green, and blue components, plus a disabled ramp for the alpha component. You might choose matrix and cellSize values with a view toward how the resulting bounds rectangle would be divided into four horizontal rows.

The name argument assigns a name to the object as a BHandler. It's the same as the argument declared by the BView constructor.

If a model message is supplied, the BColorControl will announce every change in color value by calling Invoke() (defined in the BControl class) to post a copy of the message to a designated target.

If the bufferedDrawing flag is TRUE, all changes to the on-screen display will first be made in an off-screen bitmap and then copied to the screen. This makes the drawing smoother, but it requires more memory.

The initial value of the new object is 0, which when translated to an rgb_color structure, means black.

See also: BHandler::SetName() , BControl::Invoke()


~BColorControl()

      virtual ~BColorControl(void)

Gets rid of the off-screen bitmap, if one was requested when the object was constructed.


Member Functions


AttachedToWindow()

      virtual void AttachedToWindow(void)

Augments the BControl version of this function to set the BColorControl's view color and low color to be the same as its parent's view color.

See also: BControl::AttachedToWindow(), BView::SetViewColor()


Draw()

      virtual void Draw(BRect updateRect)

Overrides the BView version of this function to draw the color control.

See also: BView::Draw()


KeyDown()

      virtual void KeyDown(ulong aChar)

Augments the BControl version of KeyDown() to allow the user to navigate within the color control using the arrow keys.

See also: BControl::KeyDown()


MouseDown()

      virtual void MouseDown(BPoint point)

Overrides the BView version of this function to allow the user to operate the color control with the mouse.

See also: BView::MouseDown()


SetValue(), ValueAsColor()

      virtual void SetValue(long color)
      virtual void SetValue(rgb_color color)

      rgb_color ValueAsColor(void)

These functions set and return the BColorControl's current value-- the last color that the user selected.

The version of SetValue() that takes a long argument is essentially the same as the BControl version of the function, which it augments only to take care of class-internal housekeeping details. The version that takes an rgb_color argument packs the information from that structure into a long integer and passes it to the other version of the function. Like all other objects that derive from BControl, a BColorControl stores its current value as a long; no information is lost in the translation from an rgb_color structure to an integer.

ValueAsColor() is an alternative to the Value() function inherited from the BControl class. It returns the object's current value as an rgb_color; Value() returns it as a long.

See also: BControl::SetValue()






The Be Book, HTML Edition, for Developer Release 8 of the Be Operating System.

Copyright © 1996 Be, Inc. All rights reserved.

Be, the Be logo, BeBox, BeOS, BeWare, and GeekPort are trademarks of Be, Inc.

Last modified September 6, 1996.