Download Now

    Reference TColorSwatchGrid

    Declared in Codebot.Forms.ColorDialog.pas on line 32

    TColorSwatchGrid shows a grid of colors which can be clicked to select one. Transparent colors are drawn over a checkerboard.
      TColorSwatchGrid = class(TSurfaceGraphicControl)
      protected
        procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
        procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
        procedure MouseLeave; override;
        procedure Draw; override;
      public
        { Create an empty swatch grid }
        constructor Create(AOwner: TComponent); override;
        { Replace all colors in the grid }
        procedure SetColors(const Colors: array of TColorB);
        { Set the size of each cell and the space between cells }
        procedure SetCellSize(CellWidth, CellHeight, Spacing: Integer);
        { Return the index of the cell at a point or -1 if there is none }
        function IndexAt(X, Y: Integer): Integer;
        { Return the bounds of a cell }
        function CellRect(Index: Integer): TRectI;
        { The number of colors }
        property Count: Integer read GetCount write SetCount;
        { The colors indexed by cell }
        property Colors[Index: Integer]: TColorB read GetColor write SetColor; default;
        { The number of cells in each row }
        property Columns: Integer read FColumns write SetColumns;
        { When above zero the grid is this wide, and the space between columns is
          adjusted to fill the width }
        property FitWidth: Integer read FFitWidth write SetFitWidth;
        { The selected cell or -1 }
        property Selected: Integer read FSelected write SetSelected;
        { When false cells cannot be selected or hot tracked }
        property Selectable: Boolean read FSelectable write FSelectable;
        { OnSelect is invoked when a cell is clicked with the left mouse button }
        property OnSelect: TNotifyIndexEvent read FOnSelect write FOnSelect;
        { OnSwatchRightClick is invoked when a cell is clicked with the right mouse
          button }
        property OnSwatchRightClick: TNotifyIndexEvent read FOnSwatchRightClick write FOnSwatchRightClick;
      end;

    See also

    TColorB in Codebot.Graphics.Types.pas
    TNotifyIndexEvent in Codebot.Graphics.pas
    TRectI in Codebot.Graphics.Types.pas
    TSurfaceGraphicControl in Codebot.Controls.pas