Skip to content

TTMSFNCBitmapSelector / TTMSFNCBitmapPicker

TTMSFNCUIPack41

The TTMSFNCBitmapSelector and TTMSFNCBitmapPicker are components that support displaying a collection of images to select from either directly in a selector or through a popup in a picker variant. Selecting a bitmap is as easy as implementing the OnBitmapSelect event and/or programmatically retrieve the selected Bitmap with the TMSFNCColorSelector.SelectedBitmap / TMSFNCColorSelector.SelectedItemIndex or TMSFNCColorPicker.SelectedBitmap property. The picker variant displays the selector in a popup.

The TTMSFNCBitmapSelector and TTMSFNCBitmapPicker inherit from a base that allows a high level of customization. Each base supports an item collection that can be displayed in a column and row structure. Each item can be optionally hidden and/or disabled, stretched over a column and / or row span and can also be optionally configured as a seperator. The TTMSFNCBitmapSelector component overrides and adds a Bitmap property to the base collection item class.

The base selector and picker classes support custom drawing on three levels: the background, the content and the text. Below is a sample that demonstrates this.

procedure TForm1.FormCreate(Sender: TObject);
var
 I: Integer;
begin
 TMSFNCBitmapSelector1.BeginUpdate;
 TMSFNCBitmapSelector1.Items.Clear;
 TMSFNCBitmapSelector1.Columns := 3;
 TMSFNCBitmapSelector1.Rows := 1;
 for I := 0 to 2 do
 TMSFNCBitmapSelector1.Items.Add;
 TMSFNCBitmapSelector1.EndUpdate;
end;
procedure TForm1.TMSFNCBitmapSelector1ItemAfterDrawContent(Sender: TObject;
 AGraphics: TTMSFNCGraphics; ARect: TRectF; AItemIndex: Integer);
var
 pt: TTMSFNCGraphicsPath;
begin
 case TMSFNCBitmapSelector1.Items[AItemIndex].State of
 isHover: InflateRect(ARect,-4, -4);
 isDown,isSelected:
 begin
 InflateRectEx(ARect,-4, -4);
 AGraphics.Stroke.Width := 2;
 AGraphics.Stroke.Color := gcBlack;
 end;
 isNormal: InflateRectEx(ARect, -8, -8);
 end;
 ARect := RectF(Int(ARect.Left)+ 0.5, Int(ARect.Top) + 0.5,
Int(ARect.Right) +0.5, Int(ARect.Bottom) + 0.5);
 case AItemIndex of
 0:
 begin
 AGraphics.Fill.Color := gcBlue;
 AGraphics.DrawEllipse(ARect);
 end;
 1:
 begin
 AGraphics.Fill.Color := gcGreen;
 AGraphics.DrawRectangle(ARect);
 end;
 2:
 begin
 pt := TTMSFNCGraphicsPath.Create;
 pt.MoveTo(PointF(ARect.Left + ARect.Width / 2, ARect.Top));
 pt.LineTo(PointF(ARect.Left + ARect.Width , ARect.Bottom));
 pt.LineTo(PointF(ARect.Left , ARect.Bottom));
 pt.ClosePath;
 AGraphics.Fill.Color := gcRed;
 AGraphics.DrawPath(pt);
 pt.Free;
 end;
 end;
end; 

TTMSFNCUIPack42