VrDesign.pas
上传用户:hbszzs
上传日期:2008-08-20
资源大小:628k
文件大小:48k
- {*****************************************************}
- { }
- { Varian Component Workshop }
- { }
- { Varian Software NL (c) 1996-2000 }
- { All Rights Reserved }
- { }
- {*****************************************************}
- unit VrDesign;
- {$I VRLIB.INC}
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- VrTypes, VrClasses, VrControls, VrSystem, VrSysUtils;
- type
- TVrBitmapButton = class(TVrGraphicImageControl)
- private
- FAutoSize: Boolean;
- FGlyph: TBitmap;
- FMask: TBitmap;
- FNumGlyphs: TVrNumGlyphs;
- FImageWidth: Integer;
- FImageHeight: Integer;
- FVIndent: Integer;
- FHIndent: Integer;
- FHasMouse: Boolean;
- FTransparentMode: TVrTransparentMode;
- Down: Boolean;
- Pressed: Boolean;
- function InControl(X, Y: Integer): Boolean;
- procedure SetGlyph(Value: TBitmap);
- procedure SetNumGlyphs(Value: TVrNumGlyphs);
- procedure SetVIndent(Value: Integer);
- procedure SetHIndent(Value: Integer);
- procedure SetAutoSize(Value: Boolean);
- procedure SetTransparentMode(Value: TVrTransparentMode);
- procedure GlyphChanged(Sender: TObject);
- procedure DoMouseDown(XPos, YPos: Integer);
- procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LButtonDown;
- procedure WMMouseMove(var Message: TWMMouseMove); message WM_MouseMove;
- procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LButtonUp;
- procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
- procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
- procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
- protected
- function GetPalette: HPalette; override;
- procedure Loaded; override;
- procedure Paint; override;
- procedure AdjustBounds;
- procedure AdjustImageSize;
- function DestRect: TRect;
- function GetImageRect(Index: Integer): TRect;
- function GetTransparentColor: TColor;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- published
- property Glyph: TBitmap read FGlyph write SetGlyph;
- property NumGlyphs: TVrNumGlyphs read FNumGlyphs write SetNumGlyphs default 1;
- property VIndent: Integer read FVIndent write SetVIndent default 2;
- property HIndent: Integer read FHIndent write SetHIndent default 2;
- property AutoSize: Boolean read FAutoSize write SetAutoSize default false;
- property TransparentMode: TVrTransparentMode read FTransparentMode write SetTransparentMode default tmColor;
- property Transparent default false;
- property Align;
- {$IFDEF VER110}
- property Anchors;
- property Constraints;
- {$ENDIF}
- property Color default clBtnFace;
- property DragCursor;
- {$IFDEF VER110}
- property DragKind;
- {$ENDIF}
- property DragMode;
- property Enabled;
- property Hint;
- property ParentColor default false;
- property ParentShowHint;
- property PopupMenu;
- property ShowHint;
- property Visible;
- property OnClick;
- {$IFDEF VER130}
- property OnContextPopup;
- {$ENDIF}
- property OnDragDrop;
- property OnDragOver;
- {$IFDEF VER110}
- property OnEndDock;
- {$ENDIF}
- property OnEndDrag;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- {$IFDEF VER110}
- property OnStartDock;
- {$ENDIF}
- property OnStartDrag;
- end;
- TVrBitmapImage = class(TVrGraphicImageControl)
- private
- FAutoSize: Boolean;
- FCenter: Boolean;
- FStretch: Boolean;
- FBitmapIndex: Integer;
- FBitmap: TBitmap;
- FBitmapList: TVrBitmapList;
- FBitmapListLink: TVrChangeLink;
- function GetBitmap: TBitmap;
- procedure SetAutoSize(Value: Boolean);
- procedure SetCenter(Value: Boolean);
- procedure SetStretch(Value: Boolean);
- procedure SetBitmapIndex(Value: Integer);
- procedure SetBitmapList(Value: TVrBitmapList);
- procedure BitmapListChanged(Sender: TObject);
- protected
- function GetPalette: HPALETTE; override;
- function DestRect: TRect;
- procedure AdjustBounds;
- procedure Paint; override;
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- published
- property AutoSize: Boolean read FAutoSize write SetAutoSize default false;
- property Center: Boolean read FCenter write SetCenter default True;
- property Stretch: Boolean read FStretch write SetStretch default false;
- property BitmapIndex: Integer read FBitmapIndex write SetBitmapIndex default -1;
- property BitmapList: TVrBitmapList read FBitmapList write SetBitmapList;
- property Transparent default false;
- property Align;
- {$IFDEF VER110}
- property Anchors;
- property Constraints;
- {$ENDIF}
- property Color default clBlack;
- property DragCursor;
- {$IFDEF VER110}
- property DragKind;
- {$ENDIF}
- property DragMode;
- property Hint;
- property ParentColor default false;
- property ParentShowHint;
- property PopupMenu;
- property ShowHint;
- property Visible;
- property OnClick;
- {$IFDEF VER130}
- property OnContextPopup;
- {$ENDIF}
- property OnDblClick;
- property OnDragDrop;
- property OnDragOver;
- {$IFDEF VER110}
- property OnEndDock;
- {$ENDIF}
- property OnEndDrag;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- {$IFDEF VER110}
- property OnStartDock;
- {$ENDIF}
- property OnStartDrag;
- end;
- TVrCounterDigits = 1..10;
- TVrCounterValue = 0..MaxInt;
- TVrCounter = class(TVrGraphicImageControl)
- private
- FValue: TVrCounterValue;
- FDigits: TVrCounterDigits;
- FAutoSize: Boolean;
- FBitmap: TBitmap;
- FSpacing: Integer;
- FDigitSize: TPoint;
- FStretch: Boolean;
- FOnChange: TNotifyEvent;
- FImage: TBitmap;
- procedure SetValue(Value: TVrCounterValue);
- procedure SetDigits(Value: TVrCounterDigits);
- procedure SetAutoSize(Value: Boolean);
- procedure SetBitmap(Value: TBitmap);
- procedure SetSpacing(Value: Integer);
- procedure SetStretch(Value: Boolean);
- procedure BitmapChanged(Sender: TObject);
- protected
- function GetPalette: HPalette; override;
- procedure CalcPaintParams;
- procedure Paint; override;
- procedure Changed; virtual;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- published
- property Value: TVrCounterValue read FValue write SetValue default 0;
- property Digits: TVrCounterDigits read FDigits write SetDigits default 8;
- property AutoSize: Boolean read FAutoSize write SetAutoSize default True;
- property Bitmap: TBitmap read FBitmap write SetBitmap;
- property Spacing: Integer read FSpacing write SetSpacing default 0;
- property Stretch: Boolean read FStretch write SetStretch default false;
- property OnChange: TNotifyEvent read FOnChange write FOnChange;
- property Transparent default false;
- {$IFDEF VER110}
- property Anchors;
- property Constraints;
- {$ENDIF}
- property Color default clBlack;
- property DragCursor;
- {$IFDEF VER110}
- property DragKind;
- {$ENDIF}
- property DragMode;
- property Hint;
- property ParentColor default false;
- property ParentShowHint;
- property PopupMenu;
- property ShowHint;
- property Visible;
- property OnClick;
- {$IFDEF VER130}
- property OnContextPopup;
- {$ENDIF}
- property OnDblClick;
- property OnDragDrop;
- property OnDragOver;
- {$IFDEF VER110}
- property OnEndDock;
- {$ENDIF}
- property OnEndDrag;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- {$IFDEF VER110}
- property OnStartDock;
- {$ENDIF}
- property OnStartDrag;
- end;
- TVrCheckBoxState = (vcbUnchecked, vcbChecked, vcbGrayed);
- TVrCheckBoxGlyphs = 1..3;
- TVrCheckBoxTexture = (cbtTile, cbtStretch);
- TVrBitmapCheckBox = class(TVrCustomImageControl)
- private
- FSpacing: Integer;
- FMargin: Integer;
- FLayout: TVrImageTextLayout;
- FState: TVrCheckBoxState;
- FNumGlyphs: TVrCheckBoxGlyphs;
- FEnabledGlyphs: TBitmap;
- FEnabledGlyphIndex: Integer;
- FDisabledGlyphs: TBitmap;
- FDisabledGlyphIndex: Integer;
- FTransparentColor: TColor;
- FTextureIndex: Integer;
- FTextureStyle: TVrCheckBoxTexture;
- FAllowGrayed: Boolean;
- FFont3D: TVrFont3D;
- FFocusColor: TColor;
- FFocusOffset: Integer;
- FFocused: Boolean;
- FSize: TPoint;
- FImageRect: TRect;
- FTextBounds: TRect;
- FBitmapList: TVrBitmapList;
- FBitmapListLink: TVrChangeLink;
- FButtonDown: Boolean;
- FOnChange: TNotifyEvent;
- function GetChecked: Boolean;
- function GetBitmap(Index: Integer): TBitmap;
- procedure SetLayout(Value: TVrImageTextLayout);
- procedure SetMargin(Value: Integer);
- procedure SetSpacing(Value: Integer);
- procedure SetState(Value: TVrCheckBoxState);
- procedure SetEnabledGlyphIndex(Value: Integer);
- procedure SetDisabledGlyphIndex(Value: Integer);
- procedure SetNumGlyphs(Value: TVrCheckBoxGlyphs);
- procedure SetTransparentColor(Value: TColor);
- procedure SetTextureIndex(Value: Integer);
- procedure SetTextureStyle(Value: TVrCheckBoxTexture);
- procedure SetFont3D(Value: TVrFont3D);
- procedure SetBitmapList(Value: TVrBitmapList);
- procedure SetChecked(Value: Boolean);
- procedure SetFocusColor(Value: TColor);
- procedure SetFocusOffset(Value: Integer);
- procedure Font3DChanged(Sender: TObject);
- procedure BitmapListChanged(Sender: TObject);
- procedure WMSize(var Message: TMessage); message WM_SIZE;
- procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
- procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
- procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
- procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
- procedure CMFocusChanged(var Message: TCMFocusChanged); message CM_FOCUSCHANGED;
- protected
- procedure CreateParams(var Params: TCreateParams); override;
- procedure UpdateGlyphs;
- procedure CalcPaintParams(Repaint: Boolean);
- procedure Paint; override;
- procedure Changed; dynamic;
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
- procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
- procedure Keypress(var Key: Char); override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure Toggle;
- published
- property Layout: TVrImageTextLayout read FLayout write SetLayout default ImageLeft;
- property Margin: Integer read FMargin write SetMargin default -1;
- property Spacing: Integer read FSpacing write SetSpacing default 5;
- property State: TVrCheckBoxState read FState write SetState default vcbUnchecked;
- property EnabledGlyphIndex: Integer read FEnabledGlyphIndex write SetEnabledGlyphIndex default -1;
- property DisabledGlyphIndex: Integer read FDisabledGlyphIndex write SetDisabledGlyphIndex default -1;
- property NumGlyphs: TVrCheckBoxGlyphs read FNumGlyphs write SetNumGlyphs default 3;
- property TransparentColor: TColor read FTransparentColor write SetTransparentColor default clOlive;
- property Font3D: TVrFont3D read FFont3D write SetFont3D;
- property BitmapList: TVrBitmapList read FBitmapList write SetBitmapList;
- property TextureIndex: Integer read FTextureIndex write SetTextureIndex default -1;
- property TextureStyle: TVrCheckBoxTexture read FTextureStyle write SetTextureStyle default cbtTile;
- property Checked: Boolean read GetChecked write SetChecked;
- property AllowGrayed: Boolean read FAllowGrayed write FAllowGrayed default false;
- property FocusColor: TColor read FFocusColor write SetFocusColor default clBlue;
- property FocusOffset: Integer read FFocusOffset write SetFocusOffset default 0;
- property OnChange: TNotifyEvent read FOnChange write FOnChange;
- {$IFDEF VER110}
- property Anchors;
- property Constraints;
- {$ENDIF}
- property Caption;
- property Color;
- property DragCursor;
- {$IFDEF VER110}
- property DragKind;
- {$ENDIF}
- property DragMode;
- property Enabled;
- property Font;
- property ParentFont;
- property ParentColor;
- property ParentShowHint;
- property PopupMenu;
- property ShowHint;
- property TabOrder;
- property TabStop default false;
- property Visible;
- property OnClick;
- {$IFDEF VER130}
- property OnContextPopup;
- {$ENDIF}
- property OnDragDrop;
- property OnDragOver;
- {$IFDEF VER110}
- property OnEndDock;
- {$ENDIF}
- property OnEndDrag;
- property OnEnter;
- property OnExit;
- property OnKeyDown;
- property OnKeyPress;
- property OnKeyUp;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- {$IFDEF VER110}
- property OnStartDock;
- {$ENDIF}
- property OnStartDrag;
- end;
- TVrRadioButtonState = (vrbUnchecked, vrbChecked);
- TVrRadioButtonGlyphs = 1..2;
- TVrRadioButtonTexture = (rbtTile, rbtStretch);
- TVrBitmapRadioButton = class(TVrCustomImageControl)
- private
- FChecked: Boolean;
- FSpacing: Integer;
- FMargin: Integer;
- FLayout: TVrImageTextLayout;
- FNumGlyphs: TVrRadioButtonGlyphs;
- FEnabledGlyphs: TBitmap;
- FEnabledGlyphIndex: Integer;
- FDisabledGlyphs: TBitmap;
- FDisabledGlyphIndex: Integer;
- FTransparentColor: TColor;
- FTextureIndex: Integer;
- FTextureStyle: TVrRadioButtonTexture;
- FFont3D: TVrFont3D;
- FFocusColor: TColor;
- FFocusOffset: Integer;
- FFocused: Boolean;
- FSize: TPoint;
- FImageRect: TRect;
- FTextBounds: TRect;
- FBitmapList: TVrBitmapList;
- FBitmapListLink: TVrChangeLink;
- FButtonDown: Boolean;
- FOnChange: TNotifyEvent;
- function GetBitmap(Index: Integer): TBitmap;
- procedure SetLayout(Value: TVrImageTextLayout);
- procedure SetMargin(Value: Integer);
- procedure SetSpacing(Value: Integer);
- procedure SetEnabledGlyphIndex(Value: Integer);
- procedure SetDisabledGlyphIndex(Value: Integer);
- procedure SetNumGlyphs(Value: TVrRadioButtonGlyphs);
- procedure SetTransparentColor(Value: TColor);
- procedure SetTextureIndex(Value: Integer);
- procedure SetTextureStyle(Value: TVrRadioButtonTexture);
- procedure SetFont3D(Value: TVrFont3D);
- procedure SetBitmapList(Value: TVrBitmapList);
- procedure SetChecked(Value: Boolean);
- procedure SetFocusColor(Value: TColor);
- procedure SetFocusOffset(Value: Integer);
- procedure Font3DChanged(Sender: TObject);
- procedure BitmapListChanged(Sender: TObject);
- procedure WMSize(var Message: TMessage); message WM_SIZE;
- procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
- procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
- procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
- procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
- procedure CMFocusChanged(var Message: TCMFocusChanged); message CM_FOCUSCHANGED;
- protected
- procedure CreateParams(var Params: TCreateParams); override;
- procedure UpdateGlyphs;
- procedure CalcPaintParams(Repaint: Boolean);
- procedure Paint; override;
- procedure Changed; dynamic;
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
- procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
- procedure Keypress(var Key: Char); override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- published
- property Layout: TVrImageTextLayout read FLayout write SetLayout default ImageLeft;
- property Margin: Integer read FMargin write SetMargin default -1;
- property Spacing: Integer read FSpacing write SetSpacing default 5;
- property EnabledGlyphIndex: Integer read FEnabledGlyphIndex write SetEnabledGlyphIndex default -1;
- property DisabledGlyphIndex: Integer read FDisabledGlyphIndex write SetDisabledGlyphIndex default -1;
- property NumGlyphs: TVrRadioButtonGlyphs read FNumGlyphs write SetNumGlyphs default 2;
- property TransparentColor: TColor read FTransparentColor write SetTransparentColor default clOlive;
- property Font3D: TVrFont3D read FFont3D write SetFont3D;
- property BitmapList: TVrBitmapList read FBitmapList write SetBitmapList;
- property TextureIndex: Integer read FTextureIndex write SetTextureIndex default -1;
- property TextureStyle: TVrRadioButtonTexture read FTextureStyle write SetTextureStyle default rbtTile;
- property Checked: Boolean read FChecked write SetChecked default false;
- property FocusColor: TColor read FFocusColor write SetFocusColor default clBlue;
- property FocusOffset: Integer read FFocusOffset write SetFocusOffset default 0;
- property OnChange: TNotifyEvent read FOnChange write FOnChange;
- {$IFDEF VER110}
- property Anchors;
- property Constraints;
- {$ENDIF}
- property Caption;
- property Color;
- property DragCursor;
- {$IFDEF VER110}
- property DragKind;
- {$ENDIF}
- property DragMode;
- property Enabled;
- property Font;
- property ParentFont;
- property ParentColor;
- property ParentShowHint;
- property PopupMenu;
- property ShowHint;
- property TabOrder;
- property TabStop default false;
- property Visible;
- property OnClick;
- {$IFDEF VER130}
- property OnContextPopup;
- {$ENDIF}
- property OnDragDrop;
- property OnDragOver;
- {$IFDEF VER110}
- property OnEndDock;
- {$ENDIF}
- property OnEndDrag;
- property OnEnter;
- property OnExit;
- property OnKeyDown;
- property OnKeyPress;
- property OnKeyUp;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- {$IFDEF VER110}
- property OnStartDock;
- {$ENDIF}
- property OnStartDrag;
- end;
- implementation
- { TVrBitmapButton }
- constructor TVrBitmapButton.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- ControlStyle := ControlStyle + [csOpaque, csReplicatable] -
- [csDoubleClicks, csSetCaption];
- Width := 50;
- Height := 50;
- Color := clBtnFace;
- ParentColor := false;
- FGlyph := TBitmap.Create;
- FGlyph.OnChange := GlyphChanged;
- FMask := TBitmap.Create;
- FNumGlyphs := 1;
- FAutoSize := false;
- FVIndent := 2;
- FHIndent := 2;
- FTransparentMode := tmColor;
- end;
- destructor TVrBitmapButton.Destroy;
- begin
- FMask.Free;
- FGlyph.Free;
- inherited Destroy;
- end;
- procedure TVrBitmapButton.Loaded;
- begin
- inherited Loaded;
- AdjustImageSize;
- FMask.Assign(Glyph);
- FMask.Mask(Self.Color);
- end;
- procedure TVrBitmapButton.Paint;
- var
- Index: Integer;
- begin
- AdjustBounds;
- ClearBitmapCanvas;
- Index := 0;
- if FHasMouse then Index := 1;
- if Down then Index := 2;
- if not Enabled then Index := 3;
- if Succ(Index) > NumGlyphs then Index := 0;
- if not Glyph.Empty then
- with BitmapCanvas do
- begin
- if Transparent then Brush.Style := bsClear
- else Brush.Style := bsSolid;
- BrushCopy(DestRect, FGlyph, GetImageRect(Index), GetTransparentColor);
- end;
- ShowDesignFrame(BitmapCanvas);
- inherited Paint;
- end;
- function TVrBitmapButton.GetTransparentColor: TColor;
- begin
- Result := Self.Color;
- if (not Glyph.Empty) and (TransparentMode = tmPixel) then
- Result := Glyph.Canvas.Pixels[0,0];
- end;
- function TVrBitmapButton.GetPalette: HPALETTE;
- begin
- Result := 0;
- if not Glyph.Empty then
- Result := Glyph.Palette;
- end;
- procedure TVrBitmapButton.AdjustImageSize;
- begin
- FImageWidth := 0;
- FImageHeight := 0;
- if not Glyph.Empty then
- begin
- FImageWidth := Glyph.Width div NumGlyphs;
- FImageHeight := Glyph.Height;
- end;
- end;
- function TVrBitmapButton.GetImageRect(Index: Integer): TRect;
- begin
- Result := Bounds(Index * FImageWidth, 0, FImageWidth, FImageHeight)
- end;
- procedure TVrBitmapButton.AdjustBounds;
- begin
- if (AutoSize) and (Align = alNone) then
- if (FImageWidth > 0) and (FImageHeight > 0) then
- SetBounds(Left, Top, FImageWidth + HIndent + 1, FImageHeight + VIndent + 1);
- end;
- function TVrBitmapButton.DestRect: TRect;
- var
- MidX, MidY: Integer;
- begin
- MidX := (ClientWidth - FImageWidth) div 2;
- MidY := (ClientHeight - FImageHeight) div 2;
- Result := Bounds(MidX, MidY, FImageWidth, FImageHeight);
- if Down then OffsetRect(Result, HIndent, VIndent);
- end;
- procedure TVrBitmapButton.GlyphChanged(Sender: TObject);
- begin
- AdjustImageSize;
- UpdateControlCanvas;
- end;
- procedure TVrBitmapButton.SetGlyph(Value: TBitmap);
- begin
- FGlyph.Assign(Value);
- FMask.Assign(Value);
- FMask.Mask(Self.Color);
- end;
- procedure TVrBitmapButton.SetNumGlyphs(Value: TVrNumGlyphs);
- begin
- if (FNumGlyphs <> Value) then
- begin
- FNumGlyphs := Value;
- AdjustImageSize;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapButton.SetVIndent(Value: Integer);
- begin
- if (FVIndent <> Value) and (Value >= 0) then
- begin
- FVIndent := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapButton.SetHIndent(Value: Integer);
- begin
- if (FHIndent <> Value) and (Value >= 0) then
- begin
- FHIndent := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapButton.SetAutoSize(Value: Boolean);
- begin
- if FAutoSize <> Value then
- begin
- FAutoSize := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapButton.SetTransparentMode(Value: TVrTransparentMode);
- begin
- if FTransparentMode <> Value then
- begin
- FTransparentMode := Value;
- UpdateControlCanvas;
- end;
- end;
- function TVrBitmapButton.InControl(X, Y: Integer): Boolean;
- var
- R: TRect;
- begin
- R := ClientRect;
- Result := (PtInRect(R, Point(X, Y))) and
- (FMask.Canvas.Pixels[X, Y] = clBlack);
- end;
- procedure TVrBitmapButton.DoMouseDown(XPos, YPos: Integer);
- begin
- if InControl(XPos, YPos) then
- begin
- Pressed := True;
- Down := True;
- MouseCapture := true;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapButton.WMLButtonDown(var Message: TWMLButtonDown);
- begin
- inherited;
- DoMouseDown(Message.XPos, Message.YPos);
- end;
- procedure TVrBitmapButton.WMMouseMove(var Message: TWMMouseMove);
- var
- P: TPoint;
- begin
- inherited;
- if Pressed then
- begin
- P := Point(Message.XPos, Message.YPos);
- if InControl(P.X, P.Y) <> Down then
- begin
- Down := not Down;
- UpdateControlCanvas;
- end;
- end;
- end;
- procedure TVrBitmapButton.WMLButtonUp(var Message: TWMLButtonUp);
- var
- DoClick: Boolean;
- begin
- MouseCapture := false;
- DoClick := Pressed and Down;
- Down := false;
- Pressed := false;
- if DoClick then
- begin
- UpdateControlCanvas;
- inherited; // Click;
- end;
- end;
- procedure TVrBitmapButton.CMMouseEnter(var Message: TMessage);
- begin
- inherited;
- FHasMouse := True;
- UpdateControlCanvas;
- end;
- procedure TVrBitmapButton.CMMouseLeave(var Message: TMessage);
- begin
- inherited;
- FHasMouse := false;
- UpdateControlCanvas;
- end;
- procedure TVrBitmapButton.CMEnabledChanged(var Message: TMessage);
- begin
- inherited;
- UpdateControlCanvas;
- end;
- { TVrBitmapImage }
- constructor TVrBitmapImage.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- ControlStyle := ControlStyle + [csOpaque, csReplicatable];
- Width := 105;
- Height := 105;
- Color := clBtnFace;
- ParentColor := false;
- FAutoSize := false;
- FCenter := True;
- FStretch := false;
- FBitmapIndex := -1;
- FBitmapListLink := TVrChangeLink.Create;
- FBitmapListLink.OnChange := BitmapListChanged;
- end;
- destructor TVrBitmapImage.Destroy;
- begin
- FBitmapListLink.Free;
- inherited Destroy;
- end;
- function TVrBitmapImage.GetBitmap: TBitmap;
- begin
- Result := nil;
- if Assigned(FBitmapList) then
- Result := FBitmapList.GetBitmap(BitmapIndex);
- end;
- procedure TVrBitmapImage.SetBitmapList(Value: TVrBitmapList);
- begin
- if FBitmapList <> nil then
- FBitmapList.RemoveLink(FBitmapListLink);
- FBitmapList := Value;
- if FBitmapList <> nil then
- FBitmapList.InsertLink(FBitmapListLink);
- UpdateControlCanvas;
- end;
- procedure TVrBitmapImage.BitmapListChanged(Sender: TObject);
- begin
- UpdateControlCanvas;
- end;
- function TVrBitmapImage.GetPalette: HPALETTE;
- begin
- Result := 0;
- if GetBitmap <> nil then
- Result := GetBitmap.Palette;
- end;
- procedure TVrBitmapImage.Notification(AComponent: TComponent;
- Operation: TOperation);
- begin
- inherited Notification(AComponent, Operation);
- if (Operation = opRemove) then
- if AComponent = BitmapList then BitmapList := nil;
- end;
- function TVrBitmapImage.DestRect: TRect;
- begin
- if Stretch then
- Result := ClientRect
- else if Center then
- Result := Bounds((Width - FBitmap.Width) div 2, (Height - FBitmap.Height) div 2,
- FBitmap.Width, FBitmap.Height)
- else
- Result := Rect(0, 0, FBitmap.Width, FBitmap.Height);
- end;
- procedure TVrBitmapImage.AdjustBounds;
- begin
- if (AutoSize) and (Align = alNone) then
- if (FBitmap.Width > 0) and (FBitmap.Height > 0) then
- SetBounds(Left, Top, FBitmap.Width, FBitmap.Height);
- end;
- procedure TVrBitmapImage.Paint;
- begin
- FBitmap := GetBitmap;
- if FBitmap <> nil then AdjustBounds;
- ClearBitmapCanvas;
- if FBitmap <> nil then
- with BitmapCanvas do
- begin
- if Transparent then Brush.Style := bsClear
- else Brush.Style := bsSolid;
- BrushCopy(DestRect, FBitmap, BitmapRect(FBitmap), Self.Color);
- end;
- ShowDesignFrame(BitmapCanvas);
- inherited Paint;
- end;
- procedure TVrBitmapImage.SetAutoSize(Value: Boolean);
- begin
- if FAutoSize <> Value then
- begin
- FAutoSize := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapImage.SetCenter(Value: Boolean);
- begin
- if FCenter <> Value then
- begin
- FCenter := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapImage.SetStretch(Value: Boolean);
- begin
- if FStretch <> Value then
- begin
- FStretch := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapImage.SetBitmapIndex(Value: Integer);
- begin
- if FBitmapIndex <> Value then
- begin
- FBitmapIndex := Value;
- UpdateControlCanvas;
- end;
- end;
- { TVrCounter }
- constructor TVrCounter.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- ControlStyle := ControlStyle + [csOpaque];
- Width := 150;
- Height := 25;
- Color := clBtnFace;
- ParentColor := false;
- Transparent := false;
- FValue := 0;
- FDigits := 8;
- FAutoSize := True;
- FSpacing := 0;
- FStretch := false;
- FBitmap := TBitmap.Create;
- FBitmap.OnChange := BitmapChanged;
- FImage := TBitmap.Create;
- end;
- destructor TVrCounter.Destroy;
- begin
- FImage.Free;
- FBitmap.Free;
- inherited Destroy;
- end;
- procedure TVrCounter.Changed;
- begin
- if Assigned(FOnChange) then FOnChange(Self);
- end;
- procedure TVrCounter.BitmapChanged(Sender: TObject);
- begin
- UpdateControlCanvas;
- end;
- procedure TVrCounter.Paint;
- var
- str: string;
- I, V, MidX, MidY: Integer;
- begin
- CalcPaintParams;
- ClearBitmapCanvas;
- with FImage, FImage.Canvas do
- begin
- Brush.Color := Self.Color;
- Brush.Style := bsSolid;
- FillRect(Bounds(0, 0, Width, Height));
- end;
- MidX := 0;
- MidY := 0;
- if not Bitmap.Empty then
- begin
- str := Format('%.' + IntToStr(Digits) + 'd', [Value]);
- for I := 1 to Length(str) do
- begin
- V := StrToInt(str[I]);
- FImage.Canvas.BrushCopy(Bounds(MidX, MidY, FDigitSize.X, FDigitSize.Y),
- Bitmap, Bounds(V * FDigitSize.X, 0, FDigitSize.X, FDigitSize.Y),
- Self.Color);
- Inc(MidX, FSpacing + FDigitSize.X);
- end;
- end;
- if Transparent then BitmapCanvas.Brush.Style := bsClear
- else BitmapCanvas.Brush.Style := bsSolid;
- if (Stretch) and (not AutoSize) then
- BitmapCanvas.BrushCopy(ClientRect, FImage,
- BitmapRect(FImage), Self.Color)
- else
- begin
- MidX := (ClientWidth - FImage.Width) div 2;
- MidY := (ClientHeight - FImage.Height) div 2;
- BitmapCanvas.BrushCopy(Bounds(MidX, MidY, FImage.Width, FImage.Height),
- FImage, BitmapRect(FImage), Self.Color);
- end;
- ShowDesignFrame(BitmapCanvas);
- inherited Paint;
- end;
- procedure TVrCounter.CalcPaintParams;
- begin
- if not Bitmap.Empty then
- begin
- FDigitSize.X := Bitmap.Width div 10;
- FDigitSize.Y := Bitmap.Height;
- FImage.Width := (Spacing * Pred(Digits)) + (FDigitSize.X * Digits);
- FImage.Height := Bitmap.Height;
- if AutoSize then
- BoundsRect := Bounds(Left, Top, FImage.Width, FImage.Height);
- end;
- end;
- function TVrCounter.GetPalette: HPalette;
- begin
- if FBitmap.Empty then Result := inherited GetPalette
- else Result := FBitmap.Palette;
- end;
- procedure TVrCounter.SetValue(Value: TVrCounterValue);
- begin
- if FValue <> Value then
- begin
- FValue := Value;
- UpdateControlCanvas;
- Changed;
- end;
- end;
- procedure TVrCounter.SetDigits(Value: TVrCounterDigits);
- begin
- if FDigits <> Value then
- begin
- FDigits := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrCounter.SetAutoSize(Value: Boolean);
- begin
- if FAutoSize <> Value then
- begin
- FAutoSize := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrCounter.SetBitmap(Value: TBitmap);
- begin
- FBitmap.Assign(Value);
- end;
- procedure TVrCounter.SetSpacing(Value: Integer);
- begin
- if FSpacing <> Value then
- begin
- FSpacing := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrCounter.SetStretch(Value: Boolean);
- begin
- if FStretch <> Value then
- begin
- FStretch := Value;
- UpdateControlCanvas;
- end;
- end;
- { TVrBitmapCheckBox }
- constructor TVrBitmapCheckBox.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- ControlStyle := ControlStyle + [csOpaque, csSetCaption] - [csDoubleClicks];
- Width := 140;
- Height := 17;
- TabStop := false;
- FSpacing := 5;
- FMargin := -1;
- FLayout := ImageLeft;
- FState := vcbUnchecked;
- FTransparentColor := clOlive;
- FTextureIndex := -1;
- FTextureStyle := cbtTile;
- FAllowGrayed := false;
- FFocusColor := clBlue;
- FFocusOffset := 0;
- FNumGlyphs := 3;
- FFont3D := TVrFont3D.Create;
- FFont3D.OnChange := Font3DChanged;
- FEnabledGlyphIndex := -1;
- FDisabledGlyphIndex := -1;
- FBitmapListLink := TVrChangeLink.Create;
- FBitmapListLink.OnChange := BitmapListChanged;
- end;
- destructor TVrBitmapCheckBox.Destroy;
- begin
- FFont3D.Free;
- FBitmapListLink.Free;
- inherited Destroy;
- end;
- procedure TVrBitmapCheckBox.CreateParams(var Params: TCreateParams);
- begin
- inherited CreateParams(Params);
- with Params do
- WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
- end;
- procedure TVrBitmapCheckBox.UpdateGlyphs;
- var
- NewX, NewY: Integer;
- begin
- FEnabledGlyphs := GetBitmap(FEnabledGlyphIndex);
- FDisabledGlyphs := GetBitmap(FDisabledGlyphIndex);
- NewX := -1;
- NewY := -1;
- FSize.X := 0;
- FSize.Y := 0;
- if FEnabledGlyphs <> nil then
- begin
- FSize.X := FEnabledGlyphs.Width div NumGlyphs;
- FSize.Y := FEnabledGlyphs.Height;
- end;
- if FDisabledGlyphs <> nil then
- begin
- NewX := FDisabledGlyphs.Width div NumGlyphs;
- NewY := FDisabledGlyphs.Height;
- end;
- if NewX > FSize.X then FSize.X := NewX;
- if NewY > FSize.Y then FSize.Y := NewY;
- end;
- procedure TVrBitmapCheckBox.Paint;
- var
- Index, X, Y: Integer;
- iWidth, iHeight: Integer;
- R: TRect;
- BackImage, Glyphs: TBitmap;
- begin
- BackImage := GetBitmap(FTextureIndex);
- if BackImage = nil then ClearBitmapCanvas
- else
- begin
- if TextureStyle = cbtTile then
- DrawTiledBitmap(BitmapCanvas, ClientRect, BackImage)
- else BitmapCanvas.CopyRect(ClientRect, BackImage.Canvas, BitmapRect(BackImage));
- end;
- if (Enabled) or (FDisabledGlyphs = nil) then
- Glyphs := FEnabledGlyphs
- else Glyphs := FDisabledGlyphs;
- with BitmapCanvas do
- begin
- Index := Ord(State); //0, 1 or 2
- if (Glyphs <> nil) and (Index < NumGlyphs) then
- begin
- iWidth := Glyphs.Width div NumGlyphs;
- iHeight := Glyphs.Height;
- X := (WidthOf(FImageRect) - iWidth) div 2;
- Y := (HeightOf(FImageRect) - iHeight) div 2;
- R := Bounds(FImageRect.Left + X, FImageRect.Top + Y, iWidth, iHeight);
- Brush.Style := bsClear;
- BrushCopy(R, Glyphs,
- Bounds(Index * iWidth, 0, iWidth, iHeight), TransparentColor);
- end;
- Font := Self.Font;
- FFont3D.Paint(BitmapCanvas, FTextBounds, Caption,
- DT_LEFT or DT_VCENTER or DT_SINGLELINE);
- if (Focused) and (FocusOffset > -1) then
- begin
- R := ClientRect;
- InflateRect(R, -FocusOffset, -FocusOffset);
- Brush.Color := FocusColor;
- FrameRect(R);
- end;
- end;
- inherited Paint;
- end;
- procedure TVrBitmapCheckBox.CalcPaintParams(Repaint: Boolean);
- var
- ImagePos: TPoint;
- begin
- UpdateGlyphs;
- Canvas.Font.Assign(Self.Font);
- CalcImageTextLayout(Canvas, ClientRect, Point(1, 1), Caption, FLayout,
- FMargin, FSpacing, Point(FSize.X, FSize.Y), ImagePos, FTextBounds);
- FImageRect := Bounds(ImagePos.X, ImagePos.Y, FSize.X, FSize.Y);
- if Repaint then UpdateControlCanvas;
- end;
- procedure TVrBitmapCheckBox.WMSize(var Message: TMessage);
- begin
- inherited;
- CalcPaintParams(True);
- end;
- procedure TVrBitmapCheckBox.CMFontChanged(var Message: TMessage);
- begin
- inherited;
- CalcPaintParams(True);
- end;
- procedure TVrBitmapCheckBox.CMTextChanged(var Message: TMessage);
- begin
- inherited;
- if HandleAllocated then
- CalcPaintParams(True);
- end;
- procedure TVrBitmapCheckBox.CMEnabledChanged(var Message: TMessage);
- begin
- inherited;
- UpdateControlCanvas;
- end;
- procedure TVrBitmapCheckBox.CMDialogChar(var Message: TCMDialogChar);
- begin
- with Message do
- if IsAccel(CharCode, Caption) and CanFocus then
- begin
- SetFocus;
- if Focused then Toggle;
- Result := 1;
- end else inherited;
- end;
- procedure TVrBitmapCheckBox.CMFocusChanged(var Message: TCMFocusChanged);
- var
- Active: Boolean;
- begin
- with Message do Active := (Sender = Self);
- if Active <> FFocused then
- begin
- FFocused := Active;
- UpdateControlCanvas;
- end;
- inherited;
- end;
- procedure TVrBitmapCheckBox.Notification(AComponent: TComponent;
- Operation: TOperation);
- begin
- inherited Notification(AComponent, Operation);
- if (Operation = opRemove) then
- if AComponent = BitmapList then BitmapList := nil;
- end;
- function TVrBitmapCheckBox.GetBitmap(Index: Integer): TBitmap;
- begin
- Result := nil;
- if Assigned(FBitmapList) then
- Result := FBitmapList.GetBitmap(Index);
- end;
- procedure TVrBitmapCheckBox.SetBitmapList(Value: TVrBitmapList);
- begin
- if FBitmapList <> nil then
- FBitmapList.RemoveLink(FBitmapListLink);
- FBitmapList := Value;
- if FBitmapList <> nil then
- FBitmapList.InsertLink(FBitmapListLink);
- CalcPaintParams(True);
- end;
- procedure TVrBitmapCheckBox.BitmapListChanged(Sender: TObject);
- begin
- CalcPaintParams(True);
- end;
- procedure TVrBitmapCheckBox.SetEnabledGlyphIndex(Value: Integer);
- begin
- if FEnabledGlyphIndex <> Value then
- begin
- FEnabledGlyphIndex := Value;
- CalcPaintParams(True);
- end;
- end;
- procedure TVrBitmapCheckBox.SetDisabledGlyphIndex(Value: Integer);
- begin
- if FDisabledGlyphIndex <> Value then
- begin
- FDisabledGlyphIndex := Value;
- CalcPaintParams(True);
- end;
- end;
- procedure TVrBitmapCheckBox.Font3DChanged(Sender: TObject);
- begin
- UpdateControlCanvas;
- end;
- procedure TVrBitmapCheckBox.SetFont3D(Value: TVrFont3D);
- begin
- FFont3D.Assign(Value);
- end;
- procedure TVrBitmapCheckBox.SetLayout(Value: TVrImageTextLayout);
- begin
- if FLayout <> Value then
- begin
- FLayout := Value;
- CalcPaintParams(True);
- end;
- end;
- procedure TVrBitmapCheckBox.SetMargin(Value: Integer);
- begin
- if FMargin <> Value then
- begin
- FMargin := Value;
- CalcPaintParams(True);
- end;
- end;
- procedure TVrBitmapCheckBox.SetSpacing(Value: Integer);
- begin
- if FSpacing <> Value then
- begin
- FSpacing := Value;
- CalcPaintParams(True);
- end;
- end;
- procedure TVrBitmapCheckBox.SetState(Value: TVrCheckBoxState);
- begin
- if FState <> Value then
- begin
- FState := Value;
- UpdateControlCanvas;
- Changed;
- end;
- end;
- procedure TVrBitmapCheckBox.SetNumGlyphs(Value: TVrCheckBoxGlyphs);
- begin
- if FNumGlyphs <> Value then
- begin
- FNumGlyphs := Value;
- CalcPaintParams(True);
- end;
- end;
- procedure TVrBitmapCheckBox.SetTransparentColor(Value: TColor);
- begin
- if FTransparentColor <> Value then
- begin
- FTransparentColor := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapCheckBox.SetTextureIndex(Value: Integer);
- begin
- if FTextureIndex <> Value then
- begin
- FTextureIndex := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapCheckBox.SetTextureStyle(Value: TVrCheckBoxTexture);
- begin
- if FTextureStyle <> Value then
- begin
- FTextureStyle := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapCheckBox.SetFocusColor(Value: TColor);
- begin
- if FFocusColor <> Value then
- begin
- FFocusColor := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapCheckBox.SetFocusOffset(Value: Integer);
- begin
- if FFocusOffset <> Value then
- begin
- FFocusOffset := Value;
- UpdateControlCanvas;
- end;
- end;
- function TVrBitmapCheckBox.GetChecked: Boolean;
- begin
- Result := State = vcbChecked;
- end;
- procedure TVrBitmapCheckBox.SetChecked(Value: Boolean);
- begin
- if Value then State := vcbChecked else State := vcbUnchecked;
- end;
- procedure TVrBitmapCheckBox.Changed;
- begin
- if Assigned(FOnChange) then FOnChange(Self);
- end;
- procedure TVrBitmapCheckBox.Toggle;
- begin
- case State of
- vcbUnchecked:
- if AllowGrayed then State := vcbGrayed else State := vcbChecked;
- vcbChecked: State := vcbUnchecked;
- vcbGrayed: State := vcbChecked;
- end;
- end;
- procedure TVrBitmapCheckBox.MouseDown(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer);
- begin
- inherited MouseDown(Button, Shift, X, Y);
- if Button = mbLeft then
- begin
- if TabStop then SetFocus;
- FButtonDown := True;
- end;
- end;
- procedure TVrBitmapCheckBox.MouseUp(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer);
- begin
- if FButtonDown then
- begin
- FButtonDown := false;
- if PtInRect(ClientRect, Point(X, Y)) then
- Toggle;
- end;
- inherited MouseUp(Button, Shift, X, Y);
- end;
- procedure TVrBitmapCheckBox.Keypress(var Key: Char);
- begin
- if Key = #32 then Toggle;
- inherited;
- end;
- { TVrBitmapRadioButton }
- constructor TVrBitmapRadioButton.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- ControlStyle := ControlStyle + [csOpaque, csSetCaption] - [csDoubleClicks];
- Width := 140;
- Height := 17;
- FSpacing := 5;
- FMargin := -1;
- FLayout := ImageLeft;
- FChecked := false;
- FTransparentColor := clOlive;
- FTextureIndex := -1;
- FTextureStyle := rbtTile;
- FFocusColor := clBlue;
- FFocusOffset := 0;
- FNumGlyphs := 2;
- FFont3D := TVrFont3D.Create;
- FFont3D.OnChange := Font3DChanged;
- FEnabledGlyphIndex := -1;
- FDisabledGlyphIndex := -1;
- FBitmapListLink := TVrChangeLink.Create;
- FBitmapListLink.OnChange := BitmapListChanged;
- end;
- destructor TVrBitmapRadioButton.Destroy;
- begin
- FFont3D.Free;
- FBitmapListLink.Free;
- inherited Destroy;
- end;
- procedure TVrBitmapRadioButton.CreateParams(var Params: TCreateParams);
- begin
- inherited CreateParams(Params);
- with Params do
- WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
- end;
- procedure TVrBitmapRadioButton.UpdateGlyphs;
- var
- NewX, NewY: Integer;
- begin
- FEnabledGlyphs := GetBitmap(FEnabledGlyphIndex);
- FDisabledGlyphs := GetBitmap(FDisabledGlyphIndex);
- NewX := -1;
- NewY := -1;
- FSize.X := 0;
- FSize.Y := 0;
- if FEnabledGlyphs <> nil then
- begin
- FSize.X := FEnabledGlyphs.Width div NumGlyphs;
- FSize.Y := FEnabledGlyphs.Height;
- end;
- if FDisabledGlyphs <> nil then
- begin
- NewX := FDisabledGlyphs.Width div NumGlyphs;
- NewY := FDisabledGlyphs.Height;
- end;
- if NewX > FSize.X then FSize.X := NewX;
- if NewY > FSize.Y then FSize.Y := NewY;
- end;
- procedure TVrBitmapRadioButton.Paint;
- var
- Index, X, Y: Integer;
- iWidth, iHeight: Integer;
- R: TRect;
- BackImage, Glyphs: TBitmap;
- begin
- BackImage := GetBitmap(FTextureIndex);
- if BackImage = nil then ClearBitmapCanvas
- else
- begin
- if TextureStyle = rbtTile then
- DrawTiledBitmap(BitmapCanvas, ClientRect, BackImage)
- else BitmapCanvas.CopyRect(ClientRect, BackImage.Canvas, BitmapRect(BackImage));
- end;
- if (Enabled) or (FDisabledGlyphs = nil) then
- Glyphs := FEnabledGlyphs
- else Glyphs := FDisabledGlyphs;
- with BitmapCanvas do
- begin
- Index := Ord(FChecked); //0 or 1
- if (Glyphs <> nil) and (Index < NumGlyphs) then
- begin
- iWidth := Glyphs.Width div NumGlyphs;
- iHeight := Glyphs.Height;
- X := (WidthOf(FImageRect) - iWidth) div 2;
- Y := (HeightOf(FImageRect) - iHeight) div 2;
- R := Bounds(FImageRect.Left + X, FImageRect.Top + Y, iWidth, iHeight);
- Brush.Style := bsClear;
- BrushCopy(R, Glyphs,
- Bounds(Index * iWidth, 0, iWidth, iHeight), TransparentColor);
- end;
- Font := Self.Font;
- FFont3D.Paint(BitmapCanvas, FTextBounds, Caption,
- DT_LEFT or DT_VCENTER or DT_SINGLELINE);
- if (Focused) and (FocusOffset > -1) then
- begin
- R := ClientRect;
- InflateRect(R, -FocusOffset, -FocusOffset);
- Brush.Color := FocusColor;
- FrameRect(R);
- end;
- end;
- inherited Paint;
- end;
- procedure TVrBitmapRadioButton.CalcPaintParams(Repaint: Boolean);
- var
- ImagePos: TPoint;
- begin
- UpdateGlyphs;
- Canvas.Font.Assign(Self.Font);
- CalcImageTextLayout(Canvas, ClientRect, Point(1, 1), Caption, FLayout,
- FMargin, FSpacing, Point(FSize.X, FSize.Y), ImagePos, FTextBounds);
- FImageRect := Bounds(ImagePos.X, ImagePos.Y, FSize.X, FSize.Y);
- if Repaint then UpdateControlCanvas;
- end;
- procedure TVrBitmapRadioButton.WMSize(var Message: TMessage);
- begin
- inherited;
- CalcPaintParams(True);
- end;
- procedure TVrBitmapRadioButton.CMFontChanged(var Message: TMessage);
- begin
- inherited;
- CalcPaintParams(True);
- end;
- procedure TVrBitmapRadioButton.CMTextChanged(var Message: TMessage);
- begin
- inherited;
- if HandleAllocated then
- CalcPaintParams(True);
- end;
- procedure TVrBitmapRadioButton.CMEnabledChanged(var Message: TMessage);
- begin
- inherited;
- UpdateControlCanvas;
- end;
- procedure TVrBitmapRadioButton.CMDialogChar(var Message: TCMDialogChar);
- begin
- with Message do
- if IsAccel(CharCode, Caption) and CanFocus then
- begin
- SetFocus;
- Result := 1;
- end else inherited;
- end;
- procedure TVrBitmapRadioButton.CMFocusChanged(var Message: TCMFocusChanged);
- var
- Active: Boolean;
- begin
- with Message do Active := (Sender = Self);
- if Active <> FFocused then
- begin
- FFocused := Active;
- UpdateControlCanvas;
- end;
- inherited;
- end;
- procedure TVrBitmapRadioButton.Notification(AComponent: TComponent;
- Operation: TOperation);
- begin
- inherited Notification(AComponent, Operation);
- if (Operation = opRemove) then
- if AComponent = BitmapList then BitmapList := nil;
- end;
- function TVrBitmapRadioButton.GetBitmap(Index: Integer): TBitmap;
- begin
- Result := nil;
- if Assigned(FBitmapList) then
- Result := FBitmapList.GetBitmap(Index);
- end;
- procedure TVrBitmapRadioButton.SetBitmapList(Value: TVrBitmapList);
- begin
- if FBitmapList <> nil then
- FBitmapList.RemoveLink(FBitmapListLink);
- FBitmapList := Value;
- if FBitmapList <> nil then
- FBitmapList.InsertLink(FBitmapListLink);
- CalcPaintParams(True);
- end;
- procedure TVrBitmapRadioButton.BitmapListChanged(Sender: TObject);
- begin
- CalcPaintParams(True);
- end;
- procedure TVrBitmapRadioButton.SetEnabledGlyphIndex(Value: Integer);
- begin
- if FEnabledGlyphIndex <> Value then
- begin
- FEnabledGlyphIndex := Value;
- CalcPaintParams(True);
- end;
- end;
- procedure TVrBitmapRadioButton.SetDisabledGlyphIndex(Value: Integer);
- begin
- if FDisabledGlyphIndex <> Value then
- begin
- FDisabledGlyphIndex := Value;
- CalcPaintParams(True);
- end;
- end;
- procedure TVrBitmapRadioButton.Font3DChanged(Sender: TObject);
- begin
- UpdateControlCanvas;
- end;
- procedure TVrBitmapRadioButton.SetFont3D(Value: TVrFont3D);
- begin
- FFont3D.Assign(Value);
- end;
- procedure TVrBitmapRadioButton.SetLayout(Value: TVrImageTextLayout);
- begin
- if FLayout <> Value then
- begin
- FLayout := Value;
- CalcPaintParams(True);
- end;
- end;
- procedure TVrBitmapRadioButton.SetMargin(Value: Integer);
- begin
- if FMargin <> Value then
- begin
- FMargin := Value;
- CalcPaintParams(True);
- end;
- end;
- procedure TVrBitmapRadioButton.SetSpacing(Value: Integer);
- begin
- if FSpacing <> Value then
- begin
- FSpacing := Value;
- CalcPaintParams(True);
- end;
- end;
- procedure TVrBitmapRadioButton.SetNumGlyphs(Value: TVrRadioButtonGlyphs);
- begin
- if FNumGlyphs <> Value then
- begin
- FNumGlyphs := Value;
- CalcPaintParams(True);
- end;
- end;
- procedure TVrBitmapRadioButton.SetTransparentColor(Value: TColor);
- begin
- if FTransparentColor <> Value then
- begin
- FTransparentColor := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapRadioButton.SetTextureIndex(Value: Integer);
- begin
- if FTextureIndex <> Value then
- begin
- FTextureIndex := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapRadioButton.SetTextureStyle(Value: TVrRadioButtonTexture);
- begin
- if FTextureStyle <> Value then
- begin
- FTextureStyle := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapRadioButton.SetFocusColor(Value: TColor);
- begin
- if FFocusColor <> Value then
- begin
- FFocusColor := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapRadioButton.SetFocusOffset(Value: Integer);
- begin
- if FFocusOffset <> Value then
- begin
- FFocusOffset := Value;
- UpdateControlCanvas;
- end;
- end;
- procedure TVrBitmapRadioButton.SetChecked(Value: Boolean);
- procedure TurnSiblingsOff;
- var
- I: Integer;
- Sibling: TControl;
- begin
- if Parent <> nil then
- with Parent do
- for I := 0 to ControlCount - 1 do
- begin
- Sibling := Controls[I];
- if (Sibling <> Self) and (Sibling is TVrBitmapRadioButton) then
- TVrBitmapRadioButton(Sibling).SetChecked(False);
- end;
- end;
- begin
- if FChecked <> Value then
- begin
- FChecked := Value;
- TabStop := Value;
- if Value then TurnSiblingsOff;
- UpdateControlCanvas;
- Changed;
- end;
- end;
- procedure TVrBitmapRadioButton.Changed;
- begin
- if Assigned(FOnChange) then FOnChange(Self);
- end;
- procedure TVrBitmapRadioButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer);
- begin
- inherited MouseDown(Button, Shift, X, Y);
- if Button = mbLeft then
- begin
- if CanFocus then SetFocus;
- FButtonDown := True;
- end;
- end;
- procedure TVrBitmapRadioButton.MouseUp(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer);
- begin
- if FButtonDown then
- begin
- FButtonDown := false;
- if PtInRect(ClientRect, Point(X, Y)) then
- Checked := True;
- end;
- inherited MouseUp(Button, Shift, X, Y);
- end;
- procedure TVrBitmapRadioButton.Keypress(var Key: Char);
- begin
- if Key = #32 then Checked := True;
- inherited;
- end;
- end.