| 1 | unit ButtonB;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | ButtonBase, Classes, LCLIntf, LCLType, SysUtils,
|
|---|
| 7 | {$IFDEF DPI}Dpi.Graphics{$ELSE}Graphics{$ENDIF};
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 |
|
|---|
| 11 | { TButtonB }
|
|---|
| 12 |
|
|---|
| 13 | TButtonB = class(TButtonBase)
|
|---|
| 14 | private
|
|---|
| 15 | FMask: TBitmap;
|
|---|
| 16 | FIndex: Integer;
|
|---|
| 17 | FBuffer: TBitmap;
|
|---|
| 18 | procedure SetIndex(Text: Integer);
|
|---|
| 19 | protected
|
|---|
| 20 | procedure Paint; override;
|
|---|
| 21 | public
|
|---|
| 22 | constructor Create(AOwner: TComponent); override;
|
|---|
| 23 | destructor Destroy; override;
|
|---|
| 24 | property Mask: TBitmap read FMask write FMask;
|
|---|
| 25 | published
|
|---|
| 26 | property Visible;
|
|---|
| 27 | property ButtonIndex: Integer read FIndex write SetIndex;
|
|---|
| 28 | property OnClick;
|
|---|
| 29 | end;
|
|---|
| 30 |
|
|---|
| 31 | procedure Register;
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | implementation
|
|---|
| 35 |
|
|---|
| 36 | uses
|
|---|
| 37 | ScreenTools;
|
|---|
| 38 |
|
|---|
| 39 | procedure Register;
|
|---|
| 40 | begin
|
|---|
| 41 | RegisterComponents('C-evo', [TButtonB]);
|
|---|
| 42 | end;
|
|---|
| 43 |
|
|---|
| 44 | constructor TButtonB.Create;
|
|---|
| 45 | begin
|
|---|
| 46 | inherited;
|
|---|
| 47 | ShowHint := True;
|
|---|
| 48 | SetBounds(0, 0, 25, 25);
|
|---|
| 49 | FBuffer := TBitmap.Create;
|
|---|
| 50 | FBuffer.PixelFormat := TPixelFormat.pf24bit;
|
|---|
| 51 | FBuffer.SetSize(Width, Height);
|
|---|
| 52 | FBuffer.Canvas.FillRect(0, 0, FBuffer.Width, FBuffer.Height);
|
|---|
| 53 | end;
|
|---|
| 54 |
|
|---|
| 55 | destructor TButtonB.Destroy;
|
|---|
| 56 | begin
|
|---|
| 57 | FreeAndNil(FBuffer);
|
|---|
| 58 | inherited;
|
|---|
| 59 | end;
|
|---|
| 60 |
|
|---|
| 61 | procedure TButtonB.Paint;
|
|---|
| 62 | begin
|
|---|
| 63 | with Canvas do
|
|---|
| 64 | if FGraphic <> nil then begin
|
|---|
| 65 | UnshareBitmap(FBuffer);
|
|---|
| 66 | BitBltBitmap(FBuffer, 0, 0, Width, Height, FGraphic, 169,
|
|---|
| 67 | 243 + 26 * Byte(FDown));
|
|---|
| 68 | if FIndex >= 0 then begin
|
|---|
| 69 | BitBltBitmap(FBuffer, 0, 0, Width, Height, FMask,
|
|---|
| 70 | 1 + FIndex mod 12 * 26, 337 + FIndex div 12 * 26, SRCAND);
|
|---|
| 71 | BitBltBitmap(FBuffer, 0, 0, Width, Height, FGraphic,
|
|---|
| 72 | 1 + FIndex mod 12 * 26, 337 + FIndex div 12 * 26, SRCPAINT);
|
|---|
| 73 | end;
|
|---|
| 74 | BitBltCanvas(Canvas, 0, 0, Width, Height, FBuffer.Canvas, 0, 0);
|
|---|
| 75 | end else begin
|
|---|
| 76 | Brush.Color := $0000FF;
|
|---|
| 77 | FrameRect(Rect(0, 0, Width, Height));
|
|---|
| 78 | end;
|
|---|
| 79 | inherited;
|
|---|
| 80 | end;
|
|---|
| 81 |
|
|---|
| 82 | procedure TButtonB.SetIndex(Text: Integer);
|
|---|
| 83 | begin
|
|---|
| 84 | if Text <> FIndex then begin
|
|---|
| 85 | FIndex := Text;
|
|---|
| 86 | Invalidate;
|
|---|
| 87 | end;
|
|---|
| 88 | end;
|
|---|
| 89 |
|
|---|
| 90 | end.
|
|---|