source: tags/1.3.1/Packages/CevoComponents/EOTButton.pas

Last change on this file was 330, checked in by chronos, 3 years ago
  • Modified: Reworker IsoEngine unit to support multiple iso maps with different tile sizes.
  • Modified: Changing tile size in main windows map doesn't affect other tile drawing on panel and in other windows like help window.
  • Modified: Optimized tile size switching. Graphic assets needed for given tile size is prepared only once. Then switching between them is just about changing references to objects and redrawing.
  • Modified: Code cleanup.
File size: 2.5 KB
Line 
1unit EOTButton;
2
3interface
4
5uses
6 ButtonBase, Classes, SysUtils, Graphics, LCLIntf, LCLType;
7
8const
9 eotBlinkOff = -1;
10 eotCancel = 0;
11 eotGray = 1;
12 eotBlinkOn = 2;
13 eotBackToNego = 3;
14
15type
16 // EndOfTurn button
17 TEOTButton = class(TButtonBase)
18 public
19 constructor Create(aOwner: TComponent); override;
20 destructor Destroy; override;
21 procedure SetButtonIndexFast(x: integer);
22 procedure SetBack(ca: TCanvas; x, y: integer);
23 private
24 FTemplate: TBitmap;
25 FIndex: integer;
26 procedure SetIndex(x: integer);
27 public
28 property Template: TBitmap read FTemplate write FTemplate;
29 published
30 property Visible;
31 property ButtonIndex: integer read FIndex write SetIndex;
32 property OnClick;
33 protected
34 Buffer, Back: TBitmap;
35 procedure Paint; override;
36 end;
37
38procedure Register;
39
40
41implementation
42
43uses
44 ScreenTools;
45
46procedure Register;
47begin
48 RegisterComponents('C-evo', [TEOTButton]);
49end;
50
51constructor TEOTButton.Create;
52begin
53 inherited;
54 Buffer := TBitmap.Create;
55 Buffer.PixelFormat := pf24bit;
56 Buffer.SetSize(48, 48);
57 Buffer.Canvas.FillRect(0, 0, Buffer.Width, Buffer.Height);
58 Back := TBitmap.Create;
59 Back.PixelFormat := pf24bit;
60 Back.SetSize(48, 48);
61 Back.Canvas.FillRect(0, 0, Back.Width, Back.Height);
62 ShowHint := true;
63 SetBounds(0, 0, 48, 48);
64end;
65
66destructor TEOTButton.Destroy;
67begin
68 FreeAndNil(Buffer);
69 FreeAndNil(Back);
70 inherited;
71end;
72
73procedure TEOTButton.Paint;
74begin
75 with Canvas do
76 if FGraphic <> nil then begin
77 UnshareBitmap(Buffer);
78 BitBltCanvas(Buffer.Canvas, 0, 0, 48, 48, Back.Canvas, 0, 0);
79 ImageOp_CBC(Buffer, Template, 0, 0, 133, 149 + 48 * Byte(FDown), 48, 48,
80 $000000, $FFFFFF);
81 if FIndex >= 0 then
82 ImageOp_CBC(Buffer, Template, 8, 8, 1 + 32 * Byte(FIndex), 246, 32, 32,
83 $000000, $FFFFFF);
84 BitBltCanvas(Canvas, 0, 0, 48, 48, Buffer.Canvas, 0, 0);
85 end else begin
86 Brush.Color := $0000FF;
87 FrameRect(Rect(0, 0, 48, 48))
88 end;
89end;
90
91procedure TEOTButton.SetIndex(x: integer);
92begin
93 if x <> FIndex then begin
94 FIndex := x;
95 Invalidate;
96 end;
97end;
98
99procedure TEOTButton.SetButtonIndexFast(x: integer);
100begin
101 if Visible and (x <> FIndex) then begin
102 FIndex := x;
103 try
104 Paint;
105 except
106 end;
107 end;
108end;
109
110procedure TEOTButton.SetBack(ca: TCanvas; x, y: integer);
111begin
112 BitBltCanvas(Back.Canvas, 0, 0, 48, 48, ca, x, y);
113end;
114
115end.
Note: See TracBrowser for help on using the repository browser.