md
First Lazarus Components - Part 2

Previous: Part 1
Original: 2016-01-27

Two new components have been added to the package discussed in the previous part.

The first, called TSliderPlane, is a two-dimensional version of TSliderBar. It draws vertical and horizontal cursor lines over the owner drawn content. The fields ValueX and ValueY indicate the crossing point of these lines. The lines can be moved by clicking and dragging the mouse over the control or by using the up/down and left/right keys on the keyboard. Demo4 in the downloadable archive illustrates what can be done with the component. It is not necessary to install the package to compile the program.

demo 4 image
Figure 1: Demo 2, Using a colour plane to define a colour

The second component is called TColorPlane. It is very specialized, meant to deal with the RGB colour cube. It draws a plane cut from the cube along one of the colour channels. Not clear? Well, I just mean that it draws a two cool gradient while the third colour remains unchanged. The screen shot from the second demonstration program illustrates what is going on. The vertical colour bar represents the fixed colour, here red. Note how the red radio button is selected. The actual value of the red channel is specified along that bar or using the associated spin edit. All pixels on the colour plane have a red value of 151. Along each horizontal line, the blue channel values start at 0 at the left edge and end at 255 at the right edge. Along each vertical line, the green channel starts at 0 at the bottom edge and ends at 255 at the top edge. According the RGB value at the four corners are

bottom left:RGB = (151, 0, 0)
top left:RGB = (151, 255, 0)
top right:RGB = (151, 255, 255)
bottom right:RGB = (151, 0, 255).

Using this component is actually easier than using three separate colour bars as it handles most everything by itself. On the other hand, it should be used with at least four other components. To create the example shown in the figure, drop a TColorPlane on a form, a TColorBar, three TSpinEdits and three radio buttons corresponding to the three colour channels: red, green and blue.

With the object inspector change the following properties of the colour plane:

MarkerStyle = msBeam (optional but avoid msNone)
BlueEdit = blue spin edit
GreenEdit = green spin edit
RedEdit = red spin edit
AssociateBar = colour bar

As with the colour bar, do not attempt to use the OnChange event of these associated components; the colour plane uses them for its own purpose.

Do make sure that the Red radio button is selected, because that is the default cut channel (fixed colour) of the colour plane. Again with the object inspector, set the tag values of each of the three radio buttons to the following values : red = 0, green = 1, blue = 2. Finally, set the OnChange event of all three radio buttons to the same handler :

procedure TPickerForm.SlicerChange(Sender: TObject);
begin
  ColorPlane.CutChannel := TColorChannel(TRadioButton(Sender).Tag);
end;

There remains one routine to create, the handler for colour plane’s OnChange event :

procedure TPickerForm.ColorPlaneChange(Sender: TObject);
begin
  FSelected.Color := ColorPlane.Color;
  RedrawSelected;
end; 

All it does is update the selected colour and displays it at the bottom of the window.

Upcoming: faster drawing.

Test environment: Lazarus 1.4.4, FPC 2.64, Ubuntu 14.04 LTS 64 bit.

Download the package archive: mdsliderbarslaz-2.zip.