VrDesign.pas
上传用户:hbszzs
上传日期:2008-08-20
资源大小:628k
文件大小:48k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. {*****************************************************}
  2. {                                                     }
  3. {     Varian Component Workshop                       }
  4. {                                                     }
  5. {     Varian Software NL (c) 1996-2000                }
  6. {     All Rights Reserved                             }
  7. {                                                     }
  8. {*****************************************************}
  9. unit VrDesign;
  10. {$I VRLIB.INC}
  11. interface
  12. uses
  13.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  14.   VrTypes, VrClasses, VrControls, VrSystem, VrSysUtils;
  15. type
  16.   TVrBitmapButton = class(TVrGraphicImageControl)
  17.   private
  18.     FAutoSize: Boolean;
  19.     FGlyph: TBitmap;
  20.     FMask: TBitmap;
  21.     FNumGlyphs: TVrNumGlyphs;
  22.     FImageWidth: Integer;
  23.     FImageHeight: Integer;
  24.     FVIndent: Integer;
  25.     FHIndent: Integer;
  26.     FHasMouse: Boolean;
  27.     FTransparentMode: TVrTransparentMode;
  28.     Down: Boolean;
  29.     Pressed: Boolean;
  30.     function InControl(X, Y: Integer): Boolean;
  31.     procedure SetGlyph(Value: TBitmap);
  32.     procedure SetNumGlyphs(Value: TVrNumGlyphs);
  33.     procedure SetVIndent(Value: Integer);
  34.     procedure SetHIndent(Value: Integer);
  35.     procedure SetAutoSize(Value: Boolean);
  36.     procedure SetTransparentMode(Value: TVrTransparentMode);
  37.     procedure GlyphChanged(Sender: TObject);
  38.     procedure DoMouseDown(XPos, YPos: Integer);
  39.     procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LButtonDown;
  40.     procedure WMMouseMove(var Message: TWMMouseMove); message WM_MouseMove;
  41.     procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LButtonUp;
  42.     procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  43.     procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  44.     procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  45.   protected
  46.     function GetPalette: HPalette; override;
  47.     procedure Loaded; override;
  48.     procedure Paint; override;
  49.     procedure AdjustBounds;
  50.     procedure AdjustImageSize;
  51.     function DestRect: TRect;
  52.     function GetImageRect(Index: Integer): TRect;
  53.     function GetTransparentColor: TColor;
  54.   public
  55.     constructor Create(AOwner: TComponent); override;
  56.     destructor Destroy; override;
  57.   published
  58.     property Glyph: TBitmap read FGlyph write SetGlyph;
  59.     property NumGlyphs: TVrNumGlyphs read FNumGlyphs write SetNumGlyphs default 1;
  60.     property VIndent: Integer read FVIndent write SetVIndent default 2;
  61.     property HIndent: Integer read FHIndent write SetHIndent default 2;
  62.     property AutoSize: Boolean read FAutoSize write SetAutoSize default false;
  63.     property TransparentMode: TVrTransparentMode read FTransparentMode write SetTransparentMode default tmColor;
  64.     property Transparent default false;
  65.     property Align;
  66. {$IFDEF VER110}
  67.     property Anchors;
  68.     property Constraints;
  69. {$ENDIF}
  70.     property Color default clBtnFace;
  71.     property DragCursor;
  72. {$IFDEF VER110}
  73.     property DragKind;
  74. {$ENDIF}
  75.     property DragMode;
  76.     property Enabled;
  77.     property Hint;
  78.     property ParentColor default false;
  79.     property ParentShowHint;
  80.     property PopupMenu;
  81.     property ShowHint;
  82.     property Visible;
  83.     property OnClick;
  84. {$IFDEF VER130}
  85.     property OnContextPopup;
  86. {$ENDIF}
  87.     property OnDragDrop;
  88.     property OnDragOver;
  89. {$IFDEF VER110}
  90.     property OnEndDock;
  91. {$ENDIF}
  92.     property OnEndDrag;
  93.     property OnMouseDown;
  94.     property OnMouseMove;
  95.     property OnMouseUp;
  96. {$IFDEF VER110}
  97.     property OnStartDock;
  98. {$ENDIF}
  99.     property OnStartDrag;
  100.   end;
  101.   TVrBitmapImage = class(TVrGraphicImageControl)
  102.   private
  103.     FAutoSize: Boolean;
  104.     FCenter: Boolean;
  105.     FStretch: Boolean;
  106.     FBitmapIndex: Integer;
  107.     FBitmap: TBitmap;
  108.     FBitmapList: TVrBitmapList;
  109.     FBitmapListLink: TVrChangeLink;
  110.     function GetBitmap: TBitmap;
  111.     procedure SetAutoSize(Value: Boolean);
  112.     procedure SetCenter(Value: Boolean);
  113.     procedure SetStretch(Value: Boolean);
  114.     procedure SetBitmapIndex(Value: Integer);
  115.     procedure SetBitmapList(Value: TVrBitmapList);
  116.     procedure BitmapListChanged(Sender: TObject);
  117.   protected
  118.     function GetPalette: HPALETTE; override;
  119.     function DestRect: TRect;
  120.     procedure AdjustBounds;
  121.     procedure Paint; override;
  122.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  123.   public
  124.     constructor Create(AOwner: TComponent); override;
  125.     destructor Destroy; override;
  126.   published
  127.     property AutoSize: Boolean read FAutoSize write SetAutoSize default false;
  128.     property Center: Boolean read FCenter write SetCenter default True;
  129.     property Stretch: Boolean read FStretch write SetStretch default false;
  130.     property BitmapIndex: Integer read FBitmapIndex write SetBitmapIndex default -1;
  131.     property BitmapList: TVrBitmapList read FBitmapList write SetBitmapList;
  132.     property Transparent default false;
  133.     property Align;
  134. {$IFDEF VER110}
  135.     property Anchors;
  136.     property Constraints;
  137. {$ENDIF}
  138.     property Color default clBlack;
  139.     property DragCursor;
  140. {$IFDEF VER110}
  141.     property DragKind;
  142. {$ENDIF}
  143.     property DragMode;
  144.     property Hint;
  145.     property ParentColor default false;
  146.     property ParentShowHint;
  147.     property PopupMenu;
  148.     property ShowHint;
  149.     property Visible;
  150.     property OnClick;
  151. {$IFDEF VER130}
  152.     property OnContextPopup;
  153. {$ENDIF}    
  154.     property OnDblClick;    
  155.     property OnDragDrop;
  156.     property OnDragOver;
  157. {$IFDEF VER110}
  158.     property OnEndDock;
  159. {$ENDIF}
  160.     property OnEndDrag;
  161.     property OnMouseDown;
  162.     property OnMouseMove;
  163.     property OnMouseUp;
  164. {$IFDEF VER110}
  165.     property OnStartDock;
  166. {$ENDIF}
  167.     property OnStartDrag;
  168.   end;
  169.   TVrCounterDigits = 1..10;
  170.   TVrCounterValue = 0..MaxInt;
  171.   TVrCounter = class(TVrGraphicImageControl)
  172.   private
  173.     FValue: TVrCounterValue;
  174.     FDigits: TVrCounterDigits;
  175.     FAutoSize: Boolean;
  176.     FBitmap: TBitmap;
  177.     FSpacing: Integer;
  178.     FDigitSize: TPoint;
  179.     FStretch: Boolean;
  180.     FOnChange: TNotifyEvent;
  181.     FImage: TBitmap;
  182.     procedure SetValue(Value: TVrCounterValue);
  183.     procedure SetDigits(Value: TVrCounterDigits);
  184.     procedure SetAutoSize(Value: Boolean);
  185.     procedure SetBitmap(Value: TBitmap);
  186.     procedure SetSpacing(Value: Integer);
  187.     procedure SetStretch(Value: Boolean);
  188.     procedure BitmapChanged(Sender: TObject);
  189.   protected
  190.     function GetPalette: HPalette; override;
  191.     procedure CalcPaintParams;
  192.     procedure Paint; override;
  193.     procedure Changed; virtual;
  194.   public
  195.     constructor Create(AOwner: TComponent); override;
  196.     destructor Destroy; override;
  197.   published
  198.     property Value: TVrCounterValue read FValue write SetValue default 0;
  199.     property Digits: TVrCounterDigits read FDigits write SetDigits default 8;
  200.     property AutoSize: Boolean read FAutoSize write SetAutoSize default True;
  201.     property Bitmap: TBitmap read FBitmap write SetBitmap;
  202.     property Spacing: Integer read FSpacing write SetSpacing default 0;
  203.     property Stretch: Boolean read FStretch write SetStretch default false;
  204.     property OnChange: TNotifyEvent read FOnChange write FOnChange;
  205.     property Transparent default false;
  206. {$IFDEF VER110}
  207.     property Anchors;
  208.     property Constraints;
  209. {$ENDIF}
  210.     property Color default clBlack;
  211.     property DragCursor;
  212. {$IFDEF VER110}
  213.     property DragKind;
  214. {$ENDIF}
  215.     property DragMode;
  216.     property Hint;
  217.     property ParentColor default false;
  218.     property ParentShowHint;
  219.     property PopupMenu;
  220.     property ShowHint;
  221.     property Visible;
  222.     property OnClick;
  223. {$IFDEF VER130}
  224.     property OnContextPopup;
  225. {$ENDIF}
  226.     property OnDblClick;    
  227.     property OnDragDrop;
  228.     property OnDragOver;
  229. {$IFDEF VER110}
  230.     property OnEndDock;
  231. {$ENDIF}
  232.     property OnEndDrag;
  233.     property OnMouseDown;
  234.     property OnMouseMove;
  235.     property OnMouseUp;
  236. {$IFDEF VER110}
  237.     property OnStartDock;
  238. {$ENDIF}
  239.     property OnStartDrag;
  240.   end;
  241.   TVrCheckBoxState = (vcbUnchecked, vcbChecked, vcbGrayed);
  242.   TVrCheckBoxGlyphs = 1..3;
  243.   TVrCheckBoxTexture = (cbtTile, cbtStretch);
  244.   TVrBitmapCheckBox = class(TVrCustomImageControl)
  245.   private
  246.     FSpacing: Integer;
  247.     FMargin: Integer;
  248.     FLayout: TVrImageTextLayout;
  249.     FState: TVrCheckBoxState;
  250.     FNumGlyphs: TVrCheckBoxGlyphs;
  251.     FEnabledGlyphs: TBitmap;
  252.     FEnabledGlyphIndex: Integer;
  253.     FDisabledGlyphs: TBitmap;
  254.     FDisabledGlyphIndex: Integer;
  255.     FTransparentColor: TColor;
  256.     FTextureIndex: Integer;
  257.     FTextureStyle: TVrCheckBoxTexture;
  258.     FAllowGrayed: Boolean;
  259.     FFont3D: TVrFont3D;
  260.     FFocusColor: TColor;
  261.     FFocusOffset: Integer;
  262.     FFocused: Boolean;
  263.     FSize: TPoint;
  264.     FImageRect: TRect;
  265.     FTextBounds: TRect;
  266.     FBitmapList: TVrBitmapList;
  267.     FBitmapListLink: TVrChangeLink;
  268.     FButtonDown: Boolean;
  269.     FOnChange: TNotifyEvent;
  270.     function GetChecked: Boolean;
  271.     function GetBitmap(Index: Integer): TBitmap;
  272.     procedure SetLayout(Value: TVrImageTextLayout);
  273.     procedure SetMargin(Value: Integer);
  274.     procedure SetSpacing(Value: Integer);
  275.     procedure SetState(Value: TVrCheckBoxState);
  276.     procedure SetEnabledGlyphIndex(Value: Integer);
  277.     procedure SetDisabledGlyphIndex(Value: Integer);
  278.     procedure SetNumGlyphs(Value: TVrCheckBoxGlyphs);
  279.     procedure SetTransparentColor(Value: TColor);
  280.     procedure SetTextureIndex(Value: Integer);
  281.     procedure SetTextureStyle(Value: TVrCheckBoxTexture);
  282.     procedure SetFont3D(Value: TVrFont3D);
  283.     procedure SetBitmapList(Value: TVrBitmapList);
  284.     procedure SetChecked(Value: Boolean);
  285.     procedure SetFocusColor(Value: TColor);
  286.     procedure SetFocusOffset(Value: Integer);
  287.     procedure Font3DChanged(Sender: TObject);
  288.     procedure BitmapListChanged(Sender: TObject);
  289.     procedure WMSize(var Message: TMessage); message WM_SIZE;
  290.     procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  291.     procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  292.     procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  293.     procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
  294.     procedure CMFocusChanged(var Message: TCMFocusChanged); message CM_FOCUSCHANGED;
  295.   protected
  296.     procedure CreateParams(var Params: TCreateParams); override;
  297.     procedure UpdateGlyphs;
  298.     procedure CalcPaintParams(Repaint: Boolean);
  299.     procedure Paint; override;
  300.     procedure Changed; dynamic;
  301.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  302.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  303.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  304.     procedure Keypress(var Key: Char); override;
  305.   public
  306.     constructor Create(AOwner: TComponent); override;
  307.     destructor Destroy; override;
  308.     procedure Toggle;
  309.   published
  310.     property Layout: TVrImageTextLayout read FLayout write SetLayout default ImageLeft;
  311.     property Margin: Integer read FMargin write SetMargin default -1;
  312.     property Spacing: Integer read FSpacing write SetSpacing default 5;
  313.     property State: TVrCheckBoxState read FState write SetState default vcbUnchecked;
  314.     property EnabledGlyphIndex: Integer read FEnabledGlyphIndex write SetEnabledGlyphIndex default -1;
  315.     property DisabledGlyphIndex: Integer read FDisabledGlyphIndex write SetDisabledGlyphIndex default -1;
  316.     property NumGlyphs: TVrCheckBoxGlyphs read FNumGlyphs write SetNumGlyphs default 3;
  317.     property TransparentColor: TColor read FTransparentColor write SetTransparentColor default clOlive;
  318.     property Font3D: TVrFont3D read FFont3D write SetFont3D;
  319.     property BitmapList: TVrBitmapList read FBitmapList write SetBitmapList;
  320.     property TextureIndex: Integer read FTextureIndex write SetTextureIndex default -1;
  321.     property TextureStyle: TVrCheckBoxTexture read FTextureStyle write SetTextureStyle default cbtTile;
  322.     property Checked: Boolean read GetChecked write SetChecked;
  323.     property AllowGrayed: Boolean read FAllowGrayed write FAllowGrayed default false;
  324.     property FocusColor: TColor read FFocusColor write SetFocusColor default clBlue;
  325.     property FocusOffset: Integer read FFocusOffset write SetFocusOffset default 0;
  326.     property OnChange: TNotifyEvent read FOnChange write FOnChange;
  327. {$IFDEF VER110}
  328.     property Anchors;
  329.     property Constraints;
  330. {$ENDIF}
  331.     property Caption;
  332.     property Color;
  333.     property DragCursor;
  334. {$IFDEF VER110}
  335.     property DragKind;
  336. {$ENDIF}
  337.     property DragMode;
  338.     property Enabled;
  339.     property Font;
  340.     property ParentFont;
  341.     property ParentColor;
  342.     property ParentShowHint;
  343.     property PopupMenu;
  344.     property ShowHint;
  345.     property TabOrder;
  346.     property TabStop default false;
  347.     property Visible;
  348.     property OnClick;
  349. {$IFDEF VER130}
  350.     property OnContextPopup;
  351. {$ENDIF}
  352.     property OnDragDrop;
  353.     property OnDragOver;
  354. {$IFDEF VER110}
  355.     property OnEndDock;
  356. {$ENDIF}
  357.     property OnEndDrag;
  358.     property OnEnter;
  359.     property OnExit;
  360.     property OnKeyDown;
  361.     property OnKeyPress;
  362.     property OnKeyUp;
  363.     property OnMouseDown;
  364.     property OnMouseMove;
  365.     property OnMouseUp;
  366. {$IFDEF VER110}
  367.     property OnStartDock;
  368. {$ENDIF}
  369.     property OnStartDrag;
  370.   end;
  371.   TVrRadioButtonState = (vrbUnchecked, vrbChecked);
  372.   TVrRadioButtonGlyphs = 1..2;
  373.   TVrRadioButtonTexture = (rbtTile, rbtStretch);
  374.   TVrBitmapRadioButton = class(TVrCustomImageControl)
  375.   private
  376.     FChecked: Boolean;
  377.     FSpacing: Integer;
  378.     FMargin: Integer;
  379.     FLayout: TVrImageTextLayout;
  380.     FNumGlyphs: TVrRadioButtonGlyphs;
  381.     FEnabledGlyphs: TBitmap;
  382.     FEnabledGlyphIndex: Integer;
  383.     FDisabledGlyphs: TBitmap;
  384.     FDisabledGlyphIndex: Integer;
  385.     FTransparentColor: TColor;
  386.     FTextureIndex: Integer;
  387.     FTextureStyle: TVrRadioButtonTexture;
  388.     FFont3D: TVrFont3D;
  389.     FFocusColor: TColor;
  390.     FFocusOffset: Integer;
  391.     FFocused: Boolean;
  392.     FSize: TPoint;
  393.     FImageRect: TRect;
  394.     FTextBounds: TRect;
  395.     FBitmapList: TVrBitmapList;
  396.     FBitmapListLink: TVrChangeLink;
  397.     FButtonDown: Boolean;
  398.     FOnChange: TNotifyEvent;
  399.     function GetBitmap(Index: Integer): TBitmap;
  400.     procedure SetLayout(Value: TVrImageTextLayout);
  401.     procedure SetMargin(Value: Integer);
  402.     procedure SetSpacing(Value: Integer);
  403.     procedure SetEnabledGlyphIndex(Value: Integer);
  404.     procedure SetDisabledGlyphIndex(Value: Integer);
  405.     procedure SetNumGlyphs(Value: TVrRadioButtonGlyphs);
  406.     procedure SetTransparentColor(Value: TColor);
  407.     procedure SetTextureIndex(Value: Integer);
  408.     procedure SetTextureStyle(Value: TVrRadioButtonTexture);
  409.     procedure SetFont3D(Value: TVrFont3D);
  410.     procedure SetBitmapList(Value: TVrBitmapList);
  411.     procedure SetChecked(Value: Boolean);
  412.     procedure SetFocusColor(Value: TColor);
  413.     procedure SetFocusOffset(Value: Integer);
  414.     procedure Font3DChanged(Sender: TObject);
  415.     procedure BitmapListChanged(Sender: TObject);
  416.     procedure WMSize(var Message: TMessage); message WM_SIZE;
  417.     procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  418.     procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  419.     procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  420.     procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
  421.     procedure CMFocusChanged(var Message: TCMFocusChanged); message CM_FOCUSCHANGED;
  422.   protected
  423.     procedure CreateParams(var Params: TCreateParams); override;
  424.     procedure UpdateGlyphs;
  425.     procedure CalcPaintParams(Repaint: Boolean);
  426.     procedure Paint; override;
  427.     procedure Changed; dynamic;
  428.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  429.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  430.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  431.     procedure Keypress(var Key: Char); override;
  432.   public
  433.     constructor Create(AOwner: TComponent); override;
  434.     destructor Destroy; override;
  435.   published
  436.     property Layout: TVrImageTextLayout read FLayout write SetLayout default ImageLeft;
  437.     property Margin: Integer read FMargin write SetMargin default -1;
  438.     property Spacing: Integer read FSpacing write SetSpacing default 5;
  439.     property EnabledGlyphIndex: Integer read FEnabledGlyphIndex write SetEnabledGlyphIndex default -1;
  440.     property DisabledGlyphIndex: Integer read FDisabledGlyphIndex write SetDisabledGlyphIndex default -1;
  441.     property NumGlyphs: TVrRadioButtonGlyphs read FNumGlyphs write SetNumGlyphs default 2;
  442.     property TransparentColor: TColor read FTransparentColor write SetTransparentColor default clOlive;
  443.     property Font3D: TVrFont3D read FFont3D write SetFont3D;
  444.     property BitmapList: TVrBitmapList read FBitmapList write SetBitmapList;
  445.     property TextureIndex: Integer read FTextureIndex write SetTextureIndex default -1;
  446.     property TextureStyle: TVrRadioButtonTexture read FTextureStyle write SetTextureStyle default rbtTile;
  447.     property Checked: Boolean read FChecked write SetChecked default false;
  448.     property FocusColor: TColor read FFocusColor write SetFocusColor default clBlue;
  449.     property FocusOffset: Integer read FFocusOffset write SetFocusOffset default 0;    
  450.     property OnChange: TNotifyEvent read FOnChange write FOnChange;
  451. {$IFDEF VER110}
  452.     property Anchors;
  453.     property Constraints;
  454. {$ENDIF}
  455.     property Caption;
  456.     property Color;
  457.     property DragCursor;
  458. {$IFDEF VER110}
  459.     property DragKind;
  460. {$ENDIF}
  461.     property DragMode;
  462.     property Enabled;
  463.     property Font;
  464.     property ParentFont;
  465.     property ParentColor;
  466.     property ParentShowHint;
  467.     property PopupMenu;
  468.     property ShowHint;
  469.     property TabOrder;
  470.     property TabStop default false;
  471.     property Visible;
  472.     property OnClick;
  473. {$IFDEF VER130}
  474.     property OnContextPopup;
  475. {$ENDIF}
  476.     property OnDragDrop;
  477.     property OnDragOver;
  478. {$IFDEF VER110}
  479.     property OnEndDock;
  480. {$ENDIF}
  481.     property OnEndDrag;
  482.     property OnEnter;
  483.     property OnExit;
  484.     property OnKeyDown;
  485.     property OnKeyPress;
  486.     property OnKeyUp;
  487.     property OnMouseDown;
  488.     property OnMouseMove;
  489.     property OnMouseUp;
  490. {$IFDEF VER110}
  491.     property OnStartDock;
  492. {$ENDIF}
  493.     property OnStartDrag;
  494.   end;
  495. implementation
  496. { TVrBitmapButton }
  497. constructor TVrBitmapButton.Create(AOwner: TComponent);
  498. begin
  499.   inherited Create(AOwner);
  500.   ControlStyle := ControlStyle + [csOpaque, csReplicatable] -
  501.     [csDoubleClicks, csSetCaption];
  502.   Width := 50;
  503.   Height := 50;
  504.   Color := clBtnFace;
  505.   ParentColor := false;
  506.   FGlyph := TBitmap.Create;
  507.   FGlyph.OnChange := GlyphChanged;
  508.   FMask := TBitmap.Create;
  509.   FNumGlyphs := 1;
  510.   FAutoSize := false;
  511.   FVIndent := 2;
  512.   FHIndent := 2;
  513.   FTransparentMode := tmColor;
  514. end;
  515. destructor TVrBitmapButton.Destroy;
  516. begin
  517.   FMask.Free;
  518.   FGlyph.Free;
  519.   inherited Destroy;
  520. end;
  521. procedure TVrBitmapButton.Loaded;
  522. begin
  523.   inherited Loaded;
  524.   AdjustImageSize;
  525.   FMask.Assign(Glyph);
  526.   FMask.Mask(Self.Color);
  527. end;
  528. procedure TVrBitmapButton.Paint;
  529. var
  530.   Index: Integer;
  531. begin
  532.   AdjustBounds;
  533.   ClearBitmapCanvas;
  534.   Index := 0;
  535.   if FHasMouse then Index := 1;
  536.   if Down then Index := 2;
  537.   if not Enabled then Index := 3;
  538.   if Succ(Index) > NumGlyphs then Index := 0;
  539.   if not Glyph.Empty then
  540.     with BitmapCanvas do
  541.     begin
  542.       if Transparent then Brush.Style := bsClear
  543.       else Brush.Style := bsSolid;
  544.       BrushCopy(DestRect, FGlyph, GetImageRect(Index), GetTransparentColor);
  545.     end;
  546.   ShowDesignFrame(BitmapCanvas);
  547.   inherited Paint;
  548. end;
  549. function TVrBitmapButton.GetTransparentColor: TColor;
  550. begin
  551.   Result := Self.Color;
  552.   if (not Glyph.Empty) and (TransparentMode = tmPixel) then
  553.     Result := Glyph.Canvas.Pixels[0,0];
  554. end;
  555. function TVrBitmapButton.GetPalette: HPALETTE;
  556. begin
  557.   Result := 0;
  558.   if not Glyph.Empty then
  559.     Result := Glyph.Palette;
  560. end;
  561. procedure TVrBitmapButton.AdjustImageSize;
  562. begin
  563.   FImageWidth := 0;
  564.   FImageHeight := 0;
  565.   if not Glyph.Empty then
  566.   begin
  567.     FImageWidth := Glyph.Width div NumGlyphs;
  568.     FImageHeight := Glyph.Height;
  569.   end;
  570. end;
  571. function TVrBitmapButton.GetImageRect(Index: Integer): TRect;
  572. begin
  573.   Result := Bounds(Index * FImageWidth, 0, FImageWidth, FImageHeight)
  574. end;
  575. procedure TVrBitmapButton.AdjustBounds;
  576. begin
  577.   if (AutoSize) and (Align = alNone) then
  578.     if (FImageWidth > 0) and (FImageHeight > 0) then
  579.       SetBounds(Left, Top, FImageWidth + HIndent + 1, FImageHeight + VIndent + 1);
  580. end;
  581. function TVrBitmapButton.DestRect: TRect;
  582. var
  583.   MidX, MidY: Integer;
  584. begin
  585.   MidX := (ClientWidth - FImageWidth) div 2;
  586.   MidY := (ClientHeight - FImageHeight) div 2;
  587.   Result := Bounds(MidX, MidY, FImageWidth, FImageHeight);
  588.   if Down then OffsetRect(Result, HIndent, VIndent);
  589. end;
  590. procedure TVrBitmapButton.GlyphChanged(Sender: TObject);
  591. begin
  592.   AdjustImageSize;
  593.   UpdateControlCanvas;
  594. end;
  595. procedure TVrBitmapButton.SetGlyph(Value: TBitmap);
  596. begin
  597.   FGlyph.Assign(Value);
  598.   FMask.Assign(Value);
  599.   FMask.Mask(Self.Color);
  600. end;
  601. procedure TVrBitmapButton.SetNumGlyphs(Value: TVrNumGlyphs);
  602. begin
  603.   if (FNumGlyphs <> Value) then
  604.   begin
  605.     FNumGlyphs := Value;
  606.     AdjustImageSize;
  607.     UpdateControlCanvas;
  608.   end;
  609. end;
  610. procedure TVrBitmapButton.SetVIndent(Value: Integer);
  611. begin
  612.   if (FVIndent <> Value) and (Value >= 0) then
  613.   begin
  614.     FVIndent := Value;
  615.     UpdateControlCanvas;
  616.   end;
  617. end;
  618. procedure TVrBitmapButton.SetHIndent(Value: Integer);
  619. begin
  620.   if (FHIndent <> Value) and (Value >= 0) then
  621.   begin
  622.     FHIndent := Value;
  623.     UpdateControlCanvas;
  624.   end;
  625. end;
  626. procedure TVrBitmapButton.SetAutoSize(Value: Boolean);
  627. begin
  628.   if FAutoSize <> Value then
  629.   begin
  630.     FAutoSize := Value;
  631.     UpdateControlCanvas;
  632.   end;
  633. end;
  634. procedure TVrBitmapButton.SetTransparentMode(Value: TVrTransparentMode);
  635. begin
  636.   if FTransparentMode <> Value then
  637.   begin
  638.     FTransparentMode := Value;
  639.     UpdateControlCanvas;
  640.   end;
  641. end;
  642. function TVrBitmapButton.InControl(X, Y: Integer): Boolean;
  643. var
  644.   R: TRect;
  645. begin
  646.   R := ClientRect;
  647.   Result := (PtInRect(R, Point(X, Y))) and
  648.             (FMask.Canvas.Pixels[X, Y] = clBlack);
  649. end;
  650. procedure TVrBitmapButton.DoMouseDown(XPos, YPos: Integer);
  651. begin
  652.   if InControl(XPos, YPos) then
  653.   begin
  654.     Pressed := True;
  655.     Down := True;
  656.     MouseCapture := true;
  657.     UpdateControlCanvas;
  658.   end;
  659. end;
  660. procedure TVrBitmapButton.WMLButtonDown(var Message: TWMLButtonDown);
  661. begin
  662.   inherited;
  663.   DoMouseDown(Message.XPos, Message.YPos);
  664. end;
  665. procedure TVrBitmapButton.WMMouseMove(var Message: TWMMouseMove);
  666. var
  667.   P: TPoint;
  668. begin
  669.   inherited;
  670.   if Pressed then
  671.   begin
  672.     P := Point(Message.XPos, Message.YPos);
  673.     if InControl(P.X, P.Y) <> Down then
  674.     begin
  675.       Down := not Down;
  676.       UpdateControlCanvas;
  677.     end;
  678.   end;
  679. end;
  680. procedure TVrBitmapButton.WMLButtonUp(var Message: TWMLButtonUp);
  681. var
  682.   DoClick: Boolean;
  683. begin
  684.   MouseCapture := false;
  685.   DoClick := Pressed and Down;
  686.   Down := false;
  687.   Pressed := false;
  688.   if DoClick then
  689.   begin
  690.     UpdateControlCanvas;
  691.     inherited; // Click;
  692.   end;
  693. end;
  694. procedure TVrBitmapButton.CMMouseEnter(var Message: TMessage);
  695. begin
  696.   inherited;
  697.   FHasMouse := True;
  698.   UpdateControlCanvas;
  699. end;
  700. procedure TVrBitmapButton.CMMouseLeave(var Message: TMessage);
  701. begin
  702.   inherited;
  703.   FHasMouse := false;
  704.   UpdateControlCanvas;
  705. end;
  706. procedure TVrBitmapButton.CMEnabledChanged(var Message: TMessage);
  707. begin
  708.   inherited;
  709.   UpdateControlCanvas;
  710. end;
  711. { TVrBitmapImage }
  712. constructor TVrBitmapImage.Create(AOwner: TComponent);
  713. begin
  714.   inherited Create(AOwner);
  715.   ControlStyle := ControlStyle + [csOpaque, csReplicatable];
  716.   Width := 105;
  717.   Height := 105;
  718.   Color := clBtnFace;
  719.   ParentColor := false;
  720.   FAutoSize := false;
  721.   FCenter := True;
  722.   FStretch := false;
  723.   FBitmapIndex := -1;
  724.   FBitmapListLink := TVrChangeLink.Create;
  725.   FBitmapListLink.OnChange := BitmapListChanged;
  726. end;
  727. destructor TVrBitmapImage.Destroy;
  728. begin
  729.   FBitmapListLink.Free;
  730.   inherited Destroy;
  731. end;
  732. function TVrBitmapImage.GetBitmap: TBitmap;
  733. begin
  734.   Result := nil;
  735.   if Assigned(FBitmapList) then
  736.     Result := FBitmapList.GetBitmap(BitmapIndex);
  737. end;
  738. procedure TVrBitmapImage.SetBitmapList(Value: TVrBitmapList);
  739. begin
  740.   if FBitmapList <> nil then
  741.     FBitmapList.RemoveLink(FBitmapListLink);
  742.   FBitmapList := Value;
  743.   if FBitmapList <> nil then
  744.     FBitmapList.InsertLink(FBitmapListLink);
  745.   UpdateControlCanvas;
  746. end;
  747. procedure TVrBitmapImage.BitmapListChanged(Sender: TObject);
  748. begin
  749.   UpdateControlCanvas;
  750. end;
  751. function TVrBitmapImage.GetPalette: HPALETTE;
  752. begin
  753.   Result := 0;
  754.   if GetBitmap <> nil then
  755.     Result := GetBitmap.Palette;
  756. end;
  757. procedure TVrBitmapImage.Notification(AComponent: TComponent;
  758.   Operation: TOperation);
  759. begin
  760.   inherited Notification(AComponent, Operation);
  761.   if (Operation = opRemove) then
  762.     if AComponent = BitmapList then BitmapList := nil;
  763. end;
  764. function TVrBitmapImage.DestRect: TRect;
  765. begin
  766.   if Stretch then
  767.     Result := ClientRect
  768.   else if Center then
  769.     Result := Bounds((Width - FBitmap.Width) div 2, (Height - FBitmap.Height) div 2,
  770.       FBitmap.Width, FBitmap.Height)
  771.   else
  772.     Result := Rect(0, 0, FBitmap.Width, FBitmap.Height);
  773. end;
  774. procedure TVrBitmapImage.AdjustBounds;
  775. begin
  776.   if (AutoSize) and (Align = alNone) then
  777.     if (FBitmap.Width > 0) and (FBitmap.Height > 0) then
  778.       SetBounds(Left, Top, FBitmap.Width, FBitmap.Height);
  779. end;
  780. procedure TVrBitmapImage.Paint;
  781. begin
  782.   FBitmap := GetBitmap;
  783.   if FBitmap <> nil then AdjustBounds;
  784.   ClearBitmapCanvas;
  785.   if FBitmap <> nil then
  786.     with BitmapCanvas do
  787.     begin
  788.       if Transparent then Brush.Style := bsClear
  789.         else Brush.Style := bsSolid;
  790.       BrushCopy(DestRect, FBitmap, BitmapRect(FBitmap), Self.Color);
  791.     end;
  792.   ShowDesignFrame(BitmapCanvas);
  793.   inherited Paint;
  794. end;
  795. procedure TVrBitmapImage.SetAutoSize(Value: Boolean);
  796. begin
  797.   if FAutoSize <> Value then
  798.   begin
  799.     FAutoSize := Value;
  800.     UpdateControlCanvas;
  801.   end;
  802. end;
  803. procedure TVrBitmapImage.SetCenter(Value: Boolean);
  804. begin
  805.   if FCenter <> Value then
  806.   begin
  807.     FCenter := Value;
  808.     UpdateControlCanvas;
  809.   end;
  810. end;
  811. procedure TVrBitmapImage.SetStretch(Value: Boolean);
  812. begin
  813.   if FStretch <> Value then
  814.   begin
  815.     FStretch := Value;
  816.     UpdateControlCanvas;
  817.   end;
  818. end;
  819. procedure TVrBitmapImage.SetBitmapIndex(Value: Integer);
  820. begin
  821.   if FBitmapIndex <> Value then
  822.   begin
  823.     FBitmapIndex := Value;
  824.     UpdateControlCanvas;
  825.   end;
  826. end;
  827. { TVrCounter }
  828. constructor TVrCounter.Create(AOwner: TComponent);
  829. begin
  830.   inherited Create(AOwner);
  831.   ControlStyle := ControlStyle + [csOpaque];
  832.   Width := 150;
  833.   Height := 25;
  834.   Color := clBtnFace;
  835.   ParentColor := false;
  836.   Transparent := false;
  837.   FValue := 0;
  838.   FDigits := 8;
  839.   FAutoSize := True;
  840.   FSpacing := 0;
  841.   FStretch := false;
  842.   FBitmap := TBitmap.Create;
  843.   FBitmap.OnChange := BitmapChanged;
  844.   FImage := TBitmap.Create;
  845. end;
  846. destructor TVrCounter.Destroy;
  847. begin
  848.   FImage.Free;
  849.   FBitmap.Free;
  850.   inherited Destroy;
  851. end;
  852. procedure TVrCounter.Changed;
  853. begin
  854.   if Assigned(FOnChange) then FOnChange(Self);
  855. end;
  856. procedure TVrCounter.BitmapChanged(Sender: TObject);
  857. begin
  858.   UpdateControlCanvas;
  859. end;
  860. procedure TVrCounter.Paint;
  861. var
  862.   str: string;
  863.   I, V, MidX, MidY: Integer;
  864. begin
  865.   CalcPaintParams;
  866.   ClearBitmapCanvas;
  867.   with FImage, FImage.Canvas do
  868.   begin
  869.     Brush.Color := Self.Color;
  870.     Brush.Style := bsSolid;
  871.     FillRect(Bounds(0, 0, Width, Height));
  872.   end;
  873.   MidX := 0;
  874.   MidY := 0;
  875.   if not Bitmap.Empty then
  876.   begin
  877.     str := Format('%.' + IntToStr(Digits) + 'd', [Value]);
  878.     for I := 1 to Length(str) do
  879.     begin
  880.       V := StrToInt(str[I]);
  881.       FImage.Canvas.BrushCopy(Bounds(MidX, MidY, FDigitSize.X, FDigitSize.Y),
  882.         Bitmap, Bounds(V * FDigitSize.X, 0, FDigitSize.X, FDigitSize.Y),
  883.         Self.Color);
  884.       Inc(MidX, FSpacing + FDigitSize.X);
  885.     end;
  886.   end;
  887.   if Transparent then BitmapCanvas.Brush.Style := bsClear
  888.     else BitmapCanvas.Brush.Style := bsSolid;
  889.   if (Stretch) and (not AutoSize) then
  890.     BitmapCanvas.BrushCopy(ClientRect, FImage,
  891.       BitmapRect(FImage), Self.Color)
  892.   else
  893.   begin
  894.     MidX := (ClientWidth - FImage.Width) div 2;
  895.     MidY := (ClientHeight - FImage.Height) div 2;
  896.     BitmapCanvas.BrushCopy(Bounds(MidX, MidY, FImage.Width, FImage.Height),
  897.       FImage, BitmapRect(FImage), Self.Color);
  898.   end;
  899.   ShowDesignFrame(BitmapCanvas);
  900.   inherited Paint;
  901. end;
  902. procedure TVrCounter.CalcPaintParams;
  903. begin
  904.   if not Bitmap.Empty then
  905.   begin
  906.     FDigitSize.X := Bitmap.Width div 10;
  907.     FDigitSize.Y := Bitmap.Height;
  908.     FImage.Width := (Spacing * Pred(Digits)) + (FDigitSize.X * Digits);
  909.     FImage.Height := Bitmap.Height;
  910.     if AutoSize then
  911.       BoundsRect := Bounds(Left, Top, FImage.Width, FImage.Height);
  912.   end;
  913. end;
  914. function TVrCounter.GetPalette: HPalette;
  915. begin
  916.   if FBitmap.Empty then Result := inherited GetPalette
  917.   else Result := FBitmap.Palette;
  918. end;
  919. procedure TVrCounter.SetValue(Value: TVrCounterValue);
  920. begin
  921.   if FValue <> Value then
  922.   begin
  923.     FValue := Value;
  924.     UpdateControlCanvas;
  925.     Changed;
  926.   end;
  927. end;
  928. procedure TVrCounter.SetDigits(Value: TVrCounterDigits);
  929. begin
  930.   if FDigits <> Value then
  931.   begin
  932.     FDigits := Value;
  933.     UpdateControlCanvas;
  934.   end;
  935. end;
  936. procedure TVrCounter.SetAutoSize(Value: Boolean);
  937. begin
  938.   if FAutoSize <> Value then
  939.   begin
  940.     FAutoSize := Value;
  941.     UpdateControlCanvas;
  942.   end;
  943. end;
  944. procedure TVrCounter.SetBitmap(Value: TBitmap);
  945. begin
  946.   FBitmap.Assign(Value);
  947. end;
  948. procedure TVrCounter.SetSpacing(Value: Integer);
  949. begin
  950.   if FSpacing <> Value then
  951.   begin
  952.     FSpacing := Value;
  953.     UpdateControlCanvas;
  954.   end;
  955. end;
  956. procedure TVrCounter.SetStretch(Value: Boolean);
  957. begin
  958.   if FStretch <> Value then
  959.   begin
  960.     FStretch := Value;
  961.     UpdateControlCanvas;
  962.   end;
  963. end;
  964. { TVrBitmapCheckBox }
  965. constructor TVrBitmapCheckBox.Create(AOwner: TComponent);
  966. begin
  967.   inherited Create(AOwner);
  968.   ControlStyle := ControlStyle + [csOpaque, csSetCaption] - [csDoubleClicks];
  969.   Width := 140;
  970.   Height := 17;
  971.   TabStop := false;
  972.   FSpacing := 5;
  973.   FMargin := -1;
  974.   FLayout := ImageLeft;
  975.   FState := vcbUnchecked;
  976.   FTransparentColor := clOlive;
  977.   FTextureIndex := -1;
  978.   FTextureStyle := cbtTile;
  979.   FAllowGrayed := false;
  980.   FFocusColor := clBlue;
  981.   FFocusOffset := 0;
  982.   FNumGlyphs := 3;
  983.   FFont3D := TVrFont3D.Create;
  984.   FFont3D.OnChange := Font3DChanged;
  985.   FEnabledGlyphIndex := -1;
  986.   FDisabledGlyphIndex := -1;
  987.   FBitmapListLink := TVrChangeLink.Create;
  988.   FBitmapListLink.OnChange := BitmapListChanged;
  989. end;
  990. destructor TVrBitmapCheckBox.Destroy;
  991. begin
  992.   FFont3D.Free;
  993.   FBitmapListLink.Free;
  994.   inherited Destroy;
  995. end;
  996. procedure TVrBitmapCheckBox.CreateParams(var Params: TCreateParams);
  997. begin
  998.   inherited CreateParams(Params);
  999.   with Params do
  1000.     WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
  1001. end;
  1002. procedure TVrBitmapCheckBox.UpdateGlyphs;
  1003. var
  1004.   NewX, NewY: Integer;
  1005. begin
  1006.   FEnabledGlyphs := GetBitmap(FEnabledGlyphIndex);
  1007.   FDisabledGlyphs := GetBitmap(FDisabledGlyphIndex);
  1008.   NewX := -1;
  1009.   NewY := -1;
  1010.   FSize.X := 0;
  1011.   FSize.Y := 0;
  1012.   if FEnabledGlyphs <> nil then
  1013.   begin
  1014.     FSize.X := FEnabledGlyphs.Width div NumGlyphs;
  1015.     FSize.Y := FEnabledGlyphs.Height;
  1016.   end;
  1017.   if FDisabledGlyphs <> nil then
  1018.   begin
  1019.     NewX := FDisabledGlyphs.Width div NumGlyphs;
  1020.     NewY := FDisabledGlyphs.Height;
  1021.   end;
  1022.   if NewX > FSize.X then FSize.X := NewX;
  1023.   if NewY > FSize.Y then FSize.Y := NewY;
  1024. end;
  1025. procedure TVrBitmapCheckBox.Paint;
  1026. var
  1027.   Index, X, Y: Integer;
  1028.   iWidth, iHeight: Integer;
  1029.   R: TRect;
  1030.   BackImage, Glyphs: TBitmap;
  1031. begin
  1032.   BackImage := GetBitmap(FTextureIndex);
  1033.   if BackImage = nil then ClearBitmapCanvas
  1034.   else
  1035.   begin
  1036.     if TextureStyle = cbtTile then
  1037.       DrawTiledBitmap(BitmapCanvas, ClientRect, BackImage)
  1038.     else BitmapCanvas.CopyRect(ClientRect, BackImage.Canvas, BitmapRect(BackImage));
  1039.   end;
  1040.   if (Enabled) or (FDisabledGlyphs = nil) then
  1041.     Glyphs := FEnabledGlyphs
  1042.   else Glyphs := FDisabledGlyphs;
  1043.   with BitmapCanvas do
  1044.   begin
  1045.     Index := Ord(State); //0, 1 or 2
  1046.     if (Glyphs <> nil) and (Index < NumGlyphs) then
  1047.     begin
  1048.       iWidth := Glyphs.Width div NumGlyphs;
  1049.       iHeight := Glyphs.Height;
  1050.       X := (WidthOf(FImageRect) - iWidth) div 2;
  1051.       Y := (HeightOf(FImageRect) - iHeight) div 2;
  1052.       R := Bounds(FImageRect.Left + X, FImageRect.Top + Y, iWidth, iHeight);
  1053.       Brush.Style := bsClear;
  1054.       BrushCopy(R, Glyphs,
  1055.         Bounds(Index * iWidth, 0, iWidth, iHeight), TransparentColor);
  1056.     end;
  1057.     Font := Self.Font;
  1058.     FFont3D.Paint(BitmapCanvas, FTextBounds, Caption,
  1059.       DT_LEFT or DT_VCENTER or DT_SINGLELINE);
  1060.     if (Focused) and (FocusOffset > -1) then
  1061.     begin
  1062.       R := ClientRect;
  1063.       InflateRect(R, -FocusOffset, -FocusOffset);
  1064.       Brush.Color := FocusColor;
  1065.       FrameRect(R);
  1066.     end;
  1067.   end;
  1068.   inherited Paint;
  1069. end;
  1070. procedure TVrBitmapCheckBox.CalcPaintParams(Repaint: Boolean);
  1071. var
  1072.   ImagePos: TPoint;
  1073. begin
  1074.   UpdateGlyphs;
  1075.   Canvas.Font.Assign(Self.Font);
  1076.   CalcImageTextLayout(Canvas, ClientRect, Point(1, 1), Caption, FLayout,
  1077.     FMargin, FSpacing, Point(FSize.X, FSize.Y), ImagePos, FTextBounds);
  1078.   FImageRect := Bounds(ImagePos.X, ImagePos.Y, FSize.X, FSize.Y);
  1079.   if Repaint then UpdateControlCanvas;
  1080. end;
  1081. procedure TVrBitmapCheckBox.WMSize(var Message: TMessage);
  1082. begin
  1083.   inherited;
  1084.   CalcPaintParams(True);
  1085. end;
  1086. procedure TVrBitmapCheckBox.CMFontChanged(var Message: TMessage);
  1087. begin
  1088.   inherited;
  1089.   CalcPaintParams(True);
  1090. end;
  1091. procedure TVrBitmapCheckBox.CMTextChanged(var Message: TMessage);
  1092. begin
  1093.   inherited;
  1094.   if HandleAllocated then
  1095.     CalcPaintParams(True);
  1096. end;
  1097. procedure TVrBitmapCheckBox.CMEnabledChanged(var Message: TMessage);
  1098. begin
  1099.   inherited;
  1100.   UpdateControlCanvas;
  1101. end;
  1102. procedure TVrBitmapCheckBox.CMDialogChar(var Message: TCMDialogChar);
  1103. begin
  1104.   with Message do
  1105.     if IsAccel(CharCode, Caption) and CanFocus then
  1106.     begin
  1107.       SetFocus;
  1108.       if Focused then Toggle;
  1109.       Result := 1;
  1110.     end else inherited;
  1111. end;
  1112. procedure TVrBitmapCheckBox.CMFocusChanged(var Message: TCMFocusChanged);
  1113. var
  1114.   Active: Boolean;
  1115. begin
  1116.   with Message do Active := (Sender = Self);
  1117.   if Active <> FFocused then
  1118.   begin
  1119.     FFocused := Active;
  1120.     UpdateControlCanvas;
  1121.   end;
  1122.   inherited;
  1123. end;
  1124. procedure TVrBitmapCheckBox.Notification(AComponent: TComponent;
  1125.   Operation: TOperation);
  1126. begin
  1127.   inherited Notification(AComponent, Operation);
  1128.   if (Operation = opRemove) then
  1129.     if AComponent = BitmapList then BitmapList := nil;
  1130. end;
  1131. function TVrBitmapCheckBox.GetBitmap(Index: Integer): TBitmap;
  1132. begin
  1133.   Result := nil;
  1134.   if Assigned(FBitmapList) then
  1135.     Result := FBitmapList.GetBitmap(Index);
  1136. end;
  1137. procedure TVrBitmapCheckBox.SetBitmapList(Value: TVrBitmapList);
  1138. begin
  1139.   if FBitmapList <> nil then
  1140.     FBitmapList.RemoveLink(FBitmapListLink);
  1141.   FBitmapList := Value;
  1142.   if FBitmapList <> nil then
  1143.     FBitmapList.InsertLink(FBitmapListLink);
  1144.   CalcPaintParams(True);
  1145. end;
  1146. procedure TVrBitmapCheckBox.BitmapListChanged(Sender: TObject);
  1147. begin
  1148.   CalcPaintParams(True);
  1149. end;
  1150. procedure TVrBitmapCheckBox.SetEnabledGlyphIndex(Value: Integer);
  1151. begin
  1152.   if FEnabledGlyphIndex <> Value then
  1153.   begin
  1154.     FEnabledGlyphIndex := Value;
  1155.     CalcPaintParams(True);
  1156.   end;
  1157. end;
  1158. procedure TVrBitmapCheckBox.SetDisabledGlyphIndex(Value: Integer);
  1159. begin
  1160.   if FDisabledGlyphIndex <> Value then
  1161.   begin
  1162.     FDisabledGlyphIndex := Value;
  1163.     CalcPaintParams(True);
  1164.   end;
  1165. end;
  1166. procedure TVrBitmapCheckBox.Font3DChanged(Sender: TObject);
  1167. begin
  1168.   UpdateControlCanvas;
  1169. end;
  1170. procedure TVrBitmapCheckBox.SetFont3D(Value: TVrFont3D);
  1171. begin
  1172.   FFont3D.Assign(Value);
  1173. end;
  1174. procedure TVrBitmapCheckBox.SetLayout(Value: TVrImageTextLayout);
  1175. begin
  1176.   if FLayout <> Value then
  1177.   begin
  1178.     FLayout := Value;
  1179.     CalcPaintParams(True);
  1180.   end;
  1181. end;
  1182. procedure TVrBitmapCheckBox.SetMargin(Value: Integer);
  1183. begin
  1184.   if FMargin <> Value then
  1185.   begin
  1186.     FMargin := Value;
  1187.     CalcPaintParams(True);
  1188.   end;
  1189. end;
  1190. procedure TVrBitmapCheckBox.SetSpacing(Value: Integer);
  1191. begin
  1192.   if FSpacing <> Value then
  1193.   begin
  1194.     FSpacing := Value;
  1195.     CalcPaintParams(True);
  1196.   end;
  1197. end;
  1198. procedure TVrBitmapCheckBox.SetState(Value: TVrCheckBoxState);
  1199. begin
  1200.   if FState <> Value then
  1201.   begin
  1202.     FState := Value;
  1203.     UpdateControlCanvas;
  1204.     Changed;
  1205.   end;
  1206. end;
  1207. procedure TVrBitmapCheckBox.SetNumGlyphs(Value: TVrCheckBoxGlyphs);
  1208. begin
  1209.   if FNumGlyphs <> Value then
  1210.   begin
  1211.     FNumGlyphs := Value;
  1212.     CalcPaintParams(True);
  1213.   end;
  1214. end;
  1215. procedure TVrBitmapCheckBox.SetTransparentColor(Value: TColor);
  1216. begin
  1217.   if FTransparentColor <> Value then
  1218.   begin
  1219.     FTransparentColor := Value;
  1220.     UpdateControlCanvas;
  1221.   end;
  1222. end;
  1223. procedure TVrBitmapCheckBox.SetTextureIndex(Value: Integer);
  1224. begin
  1225.   if FTextureIndex <> Value then
  1226.   begin
  1227.     FTextureIndex := Value;
  1228.     UpdateControlCanvas;
  1229.   end;
  1230. end;
  1231. procedure TVrBitmapCheckBox.SetTextureStyle(Value: TVrCheckBoxTexture);
  1232. begin
  1233.   if FTextureStyle <> Value then
  1234.   begin
  1235.     FTextureStyle := Value;
  1236.     UpdateControlCanvas;
  1237.   end;
  1238. end;
  1239. procedure TVrBitmapCheckBox.SetFocusColor(Value: TColor);
  1240. begin
  1241.   if FFocusColor <> Value then
  1242.   begin
  1243.     FFocusColor := Value;
  1244.     UpdateControlCanvas;
  1245.   end;
  1246. end;
  1247. procedure TVrBitmapCheckBox.SetFocusOffset(Value: Integer);
  1248. begin
  1249.   if FFocusOffset <> Value then
  1250.   begin
  1251.     FFocusOffset := Value;
  1252.     UpdateControlCanvas;
  1253.   end;
  1254. end;
  1255. function TVrBitmapCheckBox.GetChecked: Boolean;
  1256. begin
  1257.   Result := State = vcbChecked;
  1258. end;
  1259. procedure TVrBitmapCheckBox.SetChecked(Value: Boolean);
  1260. begin
  1261.   if Value then State := vcbChecked else State := vcbUnchecked;
  1262. end;
  1263. procedure TVrBitmapCheckBox.Changed;
  1264. begin
  1265.   if Assigned(FOnChange) then FOnChange(Self);
  1266. end;
  1267. procedure TVrBitmapCheckBox.Toggle;
  1268. begin
  1269.   case State of
  1270.     vcbUnchecked:
  1271.       if AllowGrayed then State := vcbGrayed else State := vcbChecked;
  1272.     vcbChecked: State := vcbUnchecked;
  1273.     vcbGrayed: State := vcbChecked;
  1274.   end;
  1275. end;
  1276. procedure TVrBitmapCheckBox.MouseDown(Button: TMouseButton; Shift: TShiftState;
  1277.   X, Y: Integer);
  1278. begin
  1279.   inherited MouseDown(Button, Shift, X, Y);
  1280.   if Button = mbLeft then
  1281.   begin
  1282.     if TabStop then SetFocus;
  1283.     FButtonDown := True;
  1284.   end;
  1285. end;
  1286. procedure TVrBitmapCheckBox.MouseUp(Button: TMouseButton; Shift: TShiftState;
  1287.   X, Y: Integer);
  1288. begin
  1289.   if FButtonDown then
  1290.   begin
  1291.     FButtonDown := false;
  1292.     if PtInRect(ClientRect, Point(X, Y)) then
  1293.       Toggle;
  1294.   end;
  1295.   inherited MouseUp(Button, Shift, X, Y);
  1296. end;
  1297. procedure TVrBitmapCheckBox.Keypress(var Key: Char);
  1298. begin
  1299.   if Key = #32 then Toggle;
  1300.   inherited;
  1301. end;
  1302. { TVrBitmapRadioButton }
  1303. constructor TVrBitmapRadioButton.Create(AOwner: TComponent);
  1304. begin
  1305.   inherited Create(AOwner);
  1306.   ControlStyle := ControlStyle + [csOpaque, csSetCaption] - [csDoubleClicks];
  1307.   Width := 140;
  1308.   Height := 17;
  1309.   FSpacing := 5;
  1310.   FMargin := -1;
  1311.   FLayout := ImageLeft;
  1312.   FChecked := false;
  1313.   FTransparentColor := clOlive;
  1314.   FTextureIndex := -1;
  1315.   FTextureStyle := rbtTile;
  1316.   FFocusColor := clBlue;
  1317.   FFocusOffset := 0;
  1318.   FNumGlyphs := 2;
  1319.   FFont3D := TVrFont3D.Create;
  1320.   FFont3D.OnChange := Font3DChanged;
  1321.   FEnabledGlyphIndex := -1;
  1322.   FDisabledGlyphIndex := -1;
  1323.   FBitmapListLink := TVrChangeLink.Create;
  1324.   FBitmapListLink.OnChange := BitmapListChanged;
  1325. end;
  1326. destructor TVrBitmapRadioButton.Destroy;
  1327. begin
  1328.   FFont3D.Free;
  1329.   FBitmapListLink.Free;
  1330.   inherited Destroy;
  1331. end;
  1332. procedure TVrBitmapRadioButton.CreateParams(var Params: TCreateParams);
  1333. begin
  1334.   inherited CreateParams(Params);
  1335.   with Params do
  1336.     WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
  1337. end;
  1338. procedure TVrBitmapRadioButton.UpdateGlyphs;
  1339. var
  1340.   NewX, NewY: Integer;
  1341. begin
  1342.   FEnabledGlyphs := GetBitmap(FEnabledGlyphIndex);
  1343.   FDisabledGlyphs := GetBitmap(FDisabledGlyphIndex);
  1344.   NewX := -1;
  1345.   NewY := -1;
  1346.   FSize.X := 0;
  1347.   FSize.Y := 0;
  1348.   if FEnabledGlyphs <> nil then
  1349.   begin
  1350.     FSize.X := FEnabledGlyphs.Width div NumGlyphs;
  1351.     FSize.Y := FEnabledGlyphs.Height;
  1352.   end;
  1353.   if FDisabledGlyphs <> nil then
  1354.   begin
  1355.     NewX := FDisabledGlyphs.Width div NumGlyphs;
  1356.     NewY := FDisabledGlyphs.Height;
  1357.   end;
  1358.   if NewX > FSize.X then FSize.X := NewX;
  1359.   if NewY > FSize.Y then FSize.Y := NewY;
  1360. end;
  1361. procedure TVrBitmapRadioButton.Paint;
  1362. var
  1363.   Index, X, Y: Integer;
  1364.   iWidth, iHeight: Integer;
  1365.   R: TRect;
  1366.   BackImage, Glyphs: TBitmap;
  1367. begin
  1368.   BackImage := GetBitmap(FTextureIndex);
  1369.   if BackImage = nil then ClearBitmapCanvas
  1370.   else
  1371.   begin
  1372.     if TextureStyle = rbtTile then
  1373.       DrawTiledBitmap(BitmapCanvas, ClientRect, BackImage)
  1374.     else BitmapCanvas.CopyRect(ClientRect, BackImage.Canvas, BitmapRect(BackImage));
  1375.   end;
  1376.   if (Enabled) or (FDisabledGlyphs = nil) then
  1377.     Glyphs := FEnabledGlyphs
  1378.   else Glyphs := FDisabledGlyphs;
  1379.   with BitmapCanvas do
  1380.   begin
  1381.     Index := Ord(FChecked); //0 or 1
  1382.     if (Glyphs <> nil) and (Index < NumGlyphs) then
  1383.     begin
  1384.       iWidth := Glyphs.Width div NumGlyphs;
  1385.       iHeight := Glyphs.Height;
  1386.       X := (WidthOf(FImageRect) - iWidth) div 2;
  1387.       Y := (HeightOf(FImageRect) - iHeight) div 2;
  1388.       R := Bounds(FImageRect.Left + X, FImageRect.Top + Y, iWidth, iHeight);
  1389.       Brush.Style := bsClear;
  1390.       BrushCopy(R, Glyphs,
  1391.         Bounds(Index * iWidth, 0, iWidth, iHeight), TransparentColor);
  1392.     end;
  1393.     Font := Self.Font;
  1394.     FFont3D.Paint(BitmapCanvas, FTextBounds, Caption,
  1395.       DT_LEFT or DT_VCENTER or DT_SINGLELINE);
  1396.     if (Focused) and (FocusOffset > -1) then
  1397.     begin
  1398.       R := ClientRect;
  1399.       InflateRect(R, -FocusOffset, -FocusOffset);
  1400.       Brush.Color := FocusColor;
  1401.       FrameRect(R);
  1402.     end;
  1403.   end;
  1404.   inherited Paint;
  1405. end;
  1406. procedure TVrBitmapRadioButton.CalcPaintParams(Repaint: Boolean);
  1407. var
  1408.   ImagePos: TPoint;
  1409. begin
  1410.   UpdateGlyphs;
  1411.   Canvas.Font.Assign(Self.Font);
  1412.   CalcImageTextLayout(Canvas, ClientRect, Point(1, 1), Caption, FLayout,
  1413.     FMargin, FSpacing, Point(FSize.X, FSize.Y), ImagePos, FTextBounds);
  1414.   FImageRect := Bounds(ImagePos.X, ImagePos.Y, FSize.X, FSize.Y);
  1415.   if Repaint then UpdateControlCanvas;
  1416. end;
  1417. procedure TVrBitmapRadioButton.WMSize(var Message: TMessage);
  1418. begin
  1419.   inherited;
  1420.   CalcPaintParams(True);
  1421. end;
  1422. procedure TVrBitmapRadioButton.CMFontChanged(var Message: TMessage);
  1423. begin
  1424.   inherited;
  1425.   CalcPaintParams(True);
  1426. end;
  1427. procedure TVrBitmapRadioButton.CMTextChanged(var Message: TMessage);
  1428. begin
  1429.   inherited;
  1430.   if HandleAllocated then
  1431.     CalcPaintParams(True);
  1432. end;
  1433. procedure TVrBitmapRadioButton.CMEnabledChanged(var Message: TMessage);
  1434. begin
  1435.   inherited;
  1436.   UpdateControlCanvas;
  1437. end;
  1438. procedure TVrBitmapRadioButton.CMDialogChar(var Message: TCMDialogChar);
  1439. begin
  1440.   with Message do
  1441.     if IsAccel(CharCode, Caption) and CanFocus then
  1442.     begin
  1443.       SetFocus;
  1444.       Result := 1;
  1445.     end else inherited;
  1446. end;
  1447. procedure TVrBitmapRadioButton.CMFocusChanged(var Message: TCMFocusChanged);
  1448. var
  1449.   Active: Boolean;
  1450. begin
  1451.   with Message do Active := (Sender = Self);
  1452.   if Active <> FFocused then
  1453.   begin
  1454.     FFocused := Active;
  1455.     UpdateControlCanvas;
  1456.   end;
  1457.   inherited;
  1458. end;
  1459. procedure TVrBitmapRadioButton.Notification(AComponent: TComponent;
  1460.   Operation: TOperation);
  1461. begin
  1462.   inherited Notification(AComponent, Operation);
  1463.   if (Operation = opRemove) then
  1464.     if AComponent = BitmapList then BitmapList := nil;
  1465. end;
  1466. function TVrBitmapRadioButton.GetBitmap(Index: Integer): TBitmap;
  1467. begin
  1468.   Result := nil;
  1469.   if Assigned(FBitmapList) then
  1470.     Result := FBitmapList.GetBitmap(Index);
  1471. end;
  1472. procedure TVrBitmapRadioButton.SetBitmapList(Value: TVrBitmapList);
  1473. begin
  1474.   if FBitmapList <> nil then
  1475.     FBitmapList.RemoveLink(FBitmapListLink);
  1476.   FBitmapList := Value;
  1477.   if FBitmapList <> nil then
  1478.     FBitmapList.InsertLink(FBitmapListLink);
  1479.   CalcPaintParams(True);
  1480. end;
  1481. procedure TVrBitmapRadioButton.BitmapListChanged(Sender: TObject);
  1482. begin
  1483.   CalcPaintParams(True);
  1484. end;
  1485. procedure TVrBitmapRadioButton.SetEnabledGlyphIndex(Value: Integer);
  1486. begin
  1487.   if FEnabledGlyphIndex <> Value then
  1488.   begin
  1489.     FEnabledGlyphIndex := Value;
  1490.     CalcPaintParams(True);
  1491.   end;
  1492. end;
  1493. procedure TVrBitmapRadioButton.SetDisabledGlyphIndex(Value: Integer);
  1494. begin
  1495.   if FDisabledGlyphIndex <> Value then
  1496.   begin
  1497.     FDisabledGlyphIndex := Value;
  1498.     CalcPaintParams(True);
  1499.   end;
  1500. end;
  1501. procedure TVrBitmapRadioButton.Font3DChanged(Sender: TObject);
  1502. begin
  1503.   UpdateControlCanvas;
  1504. end;
  1505. procedure TVrBitmapRadioButton.SetFont3D(Value: TVrFont3D);
  1506. begin
  1507.   FFont3D.Assign(Value);
  1508. end;
  1509. procedure TVrBitmapRadioButton.SetLayout(Value: TVrImageTextLayout);
  1510. begin
  1511.   if FLayout <> Value then
  1512.   begin
  1513.     FLayout := Value;
  1514.     CalcPaintParams(True);
  1515.   end;
  1516. end;
  1517. procedure TVrBitmapRadioButton.SetMargin(Value: Integer);
  1518. begin
  1519.   if FMargin <> Value then
  1520.   begin
  1521.     FMargin := Value;
  1522.     CalcPaintParams(True);
  1523.   end;
  1524. end;
  1525. procedure TVrBitmapRadioButton.SetSpacing(Value: Integer);
  1526. begin
  1527.   if FSpacing <> Value then
  1528.   begin
  1529.     FSpacing := Value;
  1530.     CalcPaintParams(True);
  1531.   end;
  1532. end;
  1533. procedure TVrBitmapRadioButton.SetNumGlyphs(Value: TVrRadioButtonGlyphs);
  1534. begin
  1535.   if FNumGlyphs <> Value then
  1536.   begin
  1537.     FNumGlyphs := Value;
  1538.     CalcPaintParams(True);
  1539.   end;
  1540. end;
  1541. procedure TVrBitmapRadioButton.SetTransparentColor(Value: TColor);
  1542. begin
  1543.   if FTransparentColor <> Value then
  1544.   begin
  1545.     FTransparentColor := Value;
  1546.     UpdateControlCanvas;
  1547.   end;
  1548. end;
  1549. procedure TVrBitmapRadioButton.SetTextureIndex(Value: Integer);
  1550. begin
  1551.   if FTextureIndex <> Value then
  1552.   begin
  1553.     FTextureIndex := Value;
  1554.     UpdateControlCanvas;
  1555.   end;
  1556. end;
  1557. procedure TVrBitmapRadioButton.SetTextureStyle(Value: TVrRadioButtonTexture);
  1558. begin
  1559.   if FTextureStyle <> Value then
  1560.   begin
  1561.     FTextureStyle := Value;
  1562.     UpdateControlCanvas;
  1563.   end;
  1564. end;
  1565. procedure TVrBitmapRadioButton.SetFocusColor(Value: TColor);
  1566. begin
  1567.   if FFocusColor <> Value then
  1568.   begin
  1569.     FFocusColor := Value;
  1570.     UpdateControlCanvas;
  1571.   end;
  1572. end;
  1573. procedure TVrBitmapRadioButton.SetFocusOffset(Value: Integer);
  1574. begin
  1575.   if FFocusOffset <> Value then
  1576.   begin
  1577.     FFocusOffset := Value;
  1578.     UpdateControlCanvas;
  1579.   end;
  1580. end;
  1581. procedure TVrBitmapRadioButton.SetChecked(Value: Boolean);
  1582.   procedure TurnSiblingsOff;
  1583.   var
  1584.     I: Integer;
  1585.     Sibling: TControl;
  1586.   begin
  1587.     if Parent <> nil then
  1588.       with Parent do
  1589.         for I := 0 to ControlCount - 1 do
  1590.         begin
  1591.           Sibling := Controls[I];
  1592.           if (Sibling <> Self) and (Sibling is TVrBitmapRadioButton) then
  1593.             TVrBitmapRadioButton(Sibling).SetChecked(False);
  1594.         end;
  1595.   end;
  1596. begin
  1597.   if FChecked <> Value then
  1598.   begin
  1599.     FChecked := Value;
  1600.     TabStop := Value;
  1601.     if Value then TurnSiblingsOff;
  1602.     UpdateControlCanvas;
  1603.     Changed;
  1604.   end;
  1605. end;
  1606. procedure TVrBitmapRadioButton.Changed;
  1607. begin
  1608.   if Assigned(FOnChange) then FOnChange(Self);
  1609. end;
  1610. procedure TVrBitmapRadioButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
  1611.   X, Y: Integer);
  1612. begin
  1613.   inherited MouseDown(Button, Shift, X, Y);
  1614.   if Button = mbLeft then
  1615.   begin
  1616.     if CanFocus then SetFocus;
  1617.     FButtonDown := True;
  1618.   end;
  1619. end;
  1620. procedure TVrBitmapRadioButton.MouseUp(Button: TMouseButton; Shift: TShiftState;
  1621.   X, Y: Integer);
  1622. begin
  1623.   if FButtonDown then
  1624.   begin
  1625.     FButtonDown := false;
  1626.     if PtInRect(ClientRect, Point(X, Y)) then
  1627.       Checked := True;
  1628.   end;
  1629.   inherited MouseUp(Button, Shift, X, Y);
  1630. end;
  1631. procedure TVrBitmapRadioButton.Keypress(var Key: Char);
  1632. begin
  1633.   if Key = #32 then Checked := True;
  1634.   inherited;
  1635. end;
  1636. end.