source: trunk/Packages/CevoComponents/EOTButton.pas

Last change on this file was 734, checked in by chronos, 8 hours ago
  • Fixed: Some buttons were not paint correctly with Qt5 widgetset.
File size: 2.6 KB
Line 
1unit EOTButton;
2
3interface
4
5uses
6 ButtonBase, Classes, SysUtils, LCLIntf, LCLType,
7 {$IFDEF DPI}Dpi.Graphics{$ELSE}Graphics{$ENDIF};
8
9const
10 eotBlinkOff = -1;
11 eotCancel = 0;
12 eotGray = 1;
13 eotBlinkOn = 2;
14 eotBackToNego = 3;
15
16type
17 // EndOfTurn button
18 TEOTButton = class(TButtonBase)
19 private
20 FTemplate: TBitmap;
21 FIndex: Integer;
22 procedure SetIndex(X: Integer);
23 protected
24 Buffer: TBitmap;
25 Back: TBitmap;
26 procedure Paint; override;
27 public
28 constructor Create(AOwner: TComponent); override;
29 destructor Destroy; override;
30 procedure SetButtonIndexFast(X: Integer);
31 procedure SetBack(Canvas: TCanvas; X, Y: Integer);
32 property Template: TBitmap read FTemplate write FTemplate;
33 published
34 property Visible;
35 property ButtonIndex: Integer read FIndex write SetIndex;
36 property OnClick;
37 end;
38
39procedure Register;
40
41
42implementation
43
44uses
45 ScreenTools;
46
47procedure Register;
48begin
49 RegisterComponents('C-evo', [TEOTButton]);
50end;
51
52constructor TEOTButton.Create;
53begin
54 inherited;
55 Buffer := TBitmap.Create;
56 Buffer.PixelFormat := TPixelFormat.pf24bit;
57 Buffer.SetSize(48, 48);
58 Buffer.Canvas.FillRect(0, 0, Buffer.Width, Buffer.Height);
59 Back := TBitmap.Create;
60 Back.PixelFormat := TPixelFormat.pf24bit;
61 Back.SetSize(48, 48);
62 Back.Canvas.FillRect(0, 0, Back.Width, Back.Height);
63 ShowHint := True;
64 SetBounds(0, 0, 48, 48);
65end;
66
67destructor TEOTButton.Destroy;
68begin
69 FreeAndNil(Buffer);
70 FreeAndNil(Back);
71 inherited;
72end;
73
74procedure TEOTButton.Paint;
75begin
76 with Canvas do
77 if FGraphic <> nil then begin
78 UnshareBitmap(Buffer);
79 BitBltBitmap(Buffer, 0, 0, 48, 48, Back, 0, 0);
80 ImageOp_CBC(Buffer, Template, 0, 0, 133, 149 + 48 * Byte(FDown), 48, 48,
81 $000000, $FFFFFF);
82 if FIndex >= 0 then
83 ImageOp_CBC(Buffer, Template, 8, 8, 1 + 32 * Byte(FIndex), 246, 32, 32,
84 $000000, $FFFFFF);
85 BitBltCanvas(Canvas, 0, 0, 48, 48, Buffer.Canvas, 0, 0);
86 end else begin
87 Brush.Color := $0000FF;
88 FrameRect(Rect(0, 0, 48, 48));
89 end;
90end;
91
92procedure TEOTButton.SetIndex(X: Integer);
93begin
94 if X <> FIndex then begin
95 FIndex := X;
96 Invalidate;
97 end;
98end;
99
100procedure TEOTButton.SetButtonIndexFast(X: Integer);
101begin
102 if Visible and (X <> FIndex) then begin
103 FIndex := X;
104 try
105 Paint;
106 except
107 end;
108 end;
109end;
110
111procedure TEOTButton.SetBack(Canvas: TCanvas; X, Y: Integer);
112begin
113 BitBltCanvas(Back.Canvas, 0, 0, 48, 48, Canvas, X, Y);
114end;
115
116end.
Note: See TracBrowser for help on using the repository browser.