Download Now

    Reference TCanvasTheme

    Declared in Codebot.Render.Widgets.Themes.pas on line 28

    TCanvasTheme is the base class of the themes, which draw widgets on a canvas. It draws what the themes share and leaves the look of each widget to its descendants.
      TCanvasTheme = class(TTheme)
      protected
        function MeasureText(Font: IFont; const Text: string): TPointF;
        function MeasureMemo(Font: IFont; const Text: string; Width: Float): Float;
        procedure DrawText(Font: IFont; const Text: string; X, Y: Float);
        procedure DrawTextMemo(Font: IFont; const Text: string; X, Y, Width: Float);
        procedure DrawCaption(Widget: TWidget; const Rect: TRectF; Text: string = ''); virtual;
        { Draw the text, selection, and caret of an edit inside Rect }
        procedure DrawEditText(Edit: TEdit; const Rect: TRectF; const TextColor, SelectColor, SelectTextColor: TColorF);
        procedure DrawEdit(Edit: TEdit); virtual; abstract;
        procedure DrawMemo(Memo: TMemo); virtual; abstract;
        { Draw a scroll bar given the rectangle of the bar and of its thumb }
        procedure DrawScrollBar(Widget: TWidget; const Track, Thumb: TRectF; Horizontal: Boolean); virtual; abstract;
        { Draw the rows, selection, caret, and scroll bars of a memo }
        procedure DrawMemoText(Memo: TMemo; const TextColor, SelectColor, SelectTextColor: TColorF);
        procedure DrawButton(Button: TPushButton); virtual; abstract;
        procedure DrawGlyphButton(GlyphButton: TGlyphButton); virtual; abstract;
        procedure DrawGlyphImage(Widget: TGlyphImage); virtual; abstract;
        procedure DrawCheckBox(CheckBox: TCheckBox); virtual; abstract;
        procedure DrawSlider(Widget: TSlider); virtual; abstract;
        procedure DrawSpinBox(Widget: TSpinBox); virtual; abstract;
        { Draw the frame and background shared by a list box and a scroll grid,
          which themes draw the same as a memo. The colors of text, of the
          selection, and of text in the selection are returned for drawing what is
          inside the frame. }
        procedure DrawListFrame(Widget: TWidget; out TextColor, SelectColor, SelectTextColor: TColorF); virtual; abstract;
        { Draw a list box, which is its frame followed by its items }
        procedure DrawListBox(Widget: TListBox);
        { Draw the items, selection, and scroll bar of a list box. The item under
          the mouse is shaded with a fainter selection color. }
        procedure DrawListBoxItems(ListBox: TListBox; const TextColor, SelectColor, SelectTextColor: TColorF);
        { Draw a scroll grid. The frame and background are those of a list box, each
          cell which can be seen is drawn by the grid, and the scroll bars are drawn
          last. The theme draws nothing in a cell, selected or not, other than the
          lines between cells when the grid has GridLines set. }
        procedure DrawScrollGrid(Grid: TScrollGrid); virtual;
        { Draw the header of a scroll grid over the top of its cells, which is one
          header cell for each column which can be seen }
        procedure DrawGridHeader(Grid: TScrollGrid);
        { Draw one header cell of a scroll grid. Rect is on whole pixels. Hot is
          true while the mouse is over the cell and Pressed while it is held down on
          it. Col is -1 for the part of the header past the last column, which has
          no title and is never hot or pressed. The default is a flat cell shaded
          with the active color. Themes draw the cell to match their own look, then
          its title with DrawHeaderText. }
        procedure DrawHeaderCell(Grid: TScrollGrid; const Rect: TRectF; Col: Integer; Hot, Pressed: Boolean); virtual;
        { Draw the title of a header cell where the column aligns it, and the sort
          arrow at the right of the cell if the grid is sorted by the column.
          Nothing is drawn when Col is -1. }
        procedure DrawHeaderText(Grid: TScrollGrid; const Rect: TRectF; Col: Integer; const Color: TColorF);
        { Draw a line down the right and along the bottom of a header cell }
        procedure DrawHeaderLines(const Rect: TRectF; const Color: TColorF);
        procedure PostDrawSpinBox(Widget: TSpinBox); virtual; abstract;
        { The colors of the scrolling list of a spin box: its frame, its background,
          the item under the mouse, text, and text in the item under the mouse }
        procedure DropColors(Widget: TSpinBox; out Frame, Back, Hot, Text, HotText: TColorF); virtual;
        { Draw the scrolling list of a spin box of the spinDropScroll kind, with the
          scroll bar of the theme. The chosen item is shaded with a fainter color
          than the item under the mouse. }
        procedure DrawDropScroll(Widget: TSpinBox); virtual;
        procedure DrawLabel(ALabel: TLabel); virtual; abstract;
        procedure DrawWindow(Window: TWindow); virtual; abstract;
        { Draw the close button of a window in Rect, which is CalcCloseRect moved to
          where the window is. The default is a cross on a red circle when the mouse
          is over it. }
        procedure DrawClose(Window: TWindow; const Rect: TRectF; Hot, Pressed: Boolean); virtual;
        { Draw two crossing lines inside a rectangle }
        procedure DrawCross(const Rect: TRectF; const Color: TColorF; Width, Inset: Float);
        { A $RRGGBB color faded by the opacity of the widget }
        function Tint(Widget: TWidget; RGB: LongWord; Alpha: Float = 1): TColorF;
        procedure DrawContainer(Widget: TContainerWidget); virtual; abstract;
        function FontSize: Float; virtual; abstract;
        function GlyphSize: Float; virtual; abstract;
        function TitleSize: Float; virtual; abstract;
        procedure Init(Canvas: ICanvas); virtual;
        procedure Fixup;
        property Pen: IPen read FPen;
      public
        procedure Render(Widget: TWidget; Stage: TPaintStage); override;
        procedure RenderHint(Widget: TWidget; Opacity: Float); override;
        function CalcTextHeight: Float; override;
        function CalcTextWidth(Widget: TWidget; const Text: string): Float; override;
        { By default the close button is a square at the right of the title bar }
        function CalcCloseRect(Window: TWindow): TRectF; override;
        procedure PushMatrix(Matrix: IMatrix); override;
        procedure PopMatrix; override;
        { The canvas the theme draws on }
        property Canvas: ICanvas read FCanvas;
        { The height of a line of text in the theme font }
        property FontHeight: Float read FFontHeight;
        { The font for text }
        property Font: IFont read FFont write FFont;
        { The icon font for glyphs }
        property Glyph: IFont read FGlyph write FGlyph;
        { The font for window titles }
        property Title: IFont read FTitle write FTitle;
      end;

    See also

    Float in Codebot.System.pas
    ICanvas in Codebot.Render.Graphics.pas
    IFont in Codebot.Render.Graphics.pas
    IMatrix in Codebot.Render.Graphics.pas
    IPen in Codebot.Render.Graphics.pas
    TCheckBox in Codebot.Render.Widgets.pas
    TColorF in Codebot.Graphics.Types.pas
    TContainerWidget in Codebot.Render.Widgets.pas
    TEdit in Codebot.Render.Widgets.pas
    TGlyphButton in Codebot.Render.Widgets.pas
    TGlyphImage in Codebot.Render.Widgets.pas
    TLabel in Codebot.Render.Widgets.pas
    TListBox in Codebot.Render.Widgets.pas
    TMemo in Codebot.Render.Widgets.pas
    TPaintStage in Codebot.Render.Widgets.pas
    TPointF in Codebot.Graphics.Types.pas
    TPushButton in Codebot.Render.Widgets.pas
    TRectF in Codebot.Graphics.Types.pas
    TScrollGrid in Codebot.Render.Widgets.pas
    TSlider in Codebot.Render.Widgets.pas
    TSpinBox in Codebot.Render.Widgets.pas
    TTheme in Codebot.Render.Widgets.pas
    TWidget in Codebot.Render.Widgets.pas
    TWindow in Codebot.Render.Widgets.pas