source: tags/1.3.1/LocalPlayer/TechTree.pas

Last change on this file was 426, checked in by chronos, 3 years ago
  • Fixed: Show correctly buttons on task bar with localized captions in windowed mode on Windows.
File size: 7.0 KB
Line 
1{$INCLUDE Switches.inc}
2unit TechTree;
3
4interface
5
6uses
7 ScreenTools, LCLIntf, LCLType, SysUtils, Classes, Graphics,
8 Controls, Forms, ButtonB, DrawDlg;
9
10type
11
12 { TTechTreeDlg }
13
14 TTechTreeDlg = class(TDrawDlg)
15 CloseBtn: TButtonB;
16 procedure FormCreate(Sender: TObject);
17 procedure FormDestroy(Sender: TObject);
18 procedure FormPaint(Sender: TObject);
19 procedure FormShow(Sender: TObject);
20 procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
21 Shift: TShiftState; X, Y: Integer);
22 procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
23 Shift: TShiftState; X, Y: Integer);
24 procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
25 procedure CloseBtnClick(Sender: TObject);
26 private
27 xOffset, yOffset, xDown, yDown: Integer;
28 Image: TBitmap;
29 Dragging: Boolean;
30 end;
31
32var
33 TechTreeDlg: TTechTreeDlg;
34
35
36implementation
37
38uses
39 Directories;
40
41{$R *.lfm}
42
43const
44 BlackBorder = 4;
45 LeftBorder = 72;
46 RightBorder = 45;
47 TopBorder = 16;
48 BottomBorder = 48;
49 xStart = 0;
50 yStart = 40;
51 xPitch = 160;
52 yPitch = 90;
53 xLegend = 44;
54 yLegend = 79;
55 yLegendPitch = 32;
56
57function min(a, b: Integer): Integer;
58begin
59 if a < b then
60 result := a
61 else
62 result := b;
63end;
64
65function max(a, b: Integer): Integer;
66begin
67 if a > b then
68 result := a
69 else
70 result := b;
71end;
72
73procedure TTechTreeDlg.FormCreate(Sender: TObject);
74begin
75 InitButtons;
76 Image := nil;
77end;
78
79procedure TTechTreeDlg.FormDestroy(Sender: TObject);
80begin
81 FreeAndNil(Image);
82end;
83
84procedure TTechTreeDlg.FormPaint(Sender: TObject);
85var
86 X, w: Integer;
87begin
88 with Canvas do begin
89 // black border
90 brush.color := $000000;
91 fillrect(rect(0, 0, BlackBorder, ClientHeight));
92 fillrect(rect(BlackBorder, 0, ClientWidth - BlackBorder, BlackBorder));
93 fillrect(rect(ClientWidth - BlackBorder, 0, ClientWidth, ClientHeight));
94 fillrect(rect(BlackBorder, ClientHeight - BlackBorder,
95 ClientWidth - BlackBorder, ClientHeight));
96
97 // texturize empty space
98 brush.color := $FFFFFF;
99 if xOffset > 0 then
100 FillRectSeamless(Canvas, BlackBorder, BlackBorder, BlackBorder + xOffset,
101 ClientHeight - BlackBorder, -BlackBorder - xOffset,
102 -BlackBorder - yOffset, Paper);
103 if xOffset + Image.width < ClientWidth - 2 * BlackBorder then
104 FillRectSeamless(Canvas, BlackBorder + xOffset + Image.width, BlackBorder,
105 ClientWidth - BlackBorder, ClientHeight - BlackBorder,
106 -BlackBorder - xOffset, -BlackBorder - yOffset, Paper);
107 X := max(BlackBorder, BlackBorder + xOffset);
108 w := min(BlackBorder + xOffset + Image.width, ClientWidth - BlackBorder);
109 if yOffset > 0 then
110 FillRectSeamless(Canvas, X, BlackBorder, w, BlackBorder + yOffset,
111 -BlackBorder - xOffset, -BlackBorder - yOffset, Paper);
112 if yOffset + Image.height < ClientHeight - 2 * BlackBorder then
113 FillRectSeamless(Canvas, X, BlackBorder + yOffset + Image.height, w,
114 ClientHeight - BlackBorder, -BlackBorder - xOffset,
115 -BlackBorder - yOffset, Paper);
116 end;
117 BitBltCanvas(Canvas, max(BlackBorder, BlackBorder + xOffset),
118 max(BlackBorder, BlackBorder + yOffset),
119 min(Image.width, min(Image.width + xOffset,
120 min(ClientWidth - 2 * BlackBorder, ClientWidth - 2 * BlackBorder - xOffset))
121 ), min(Image.height, min(Image.height + yOffset,
122 min(ClientHeight - 2 * BlackBorder, ClientHeight - 2 * BlackBorder -
123 yOffset))), Image.Canvas, max(0, -xOffset),
124 max(0, -yOffset));
125end;
126
127procedure TTechTreeDlg.FormShow(Sender: TObject);
128var
129 X, Y, ad: Integer;
130 s: string;
131 NewWidth: Integer;
132 NewHeight: Integer;
133begin
134 Caption := Phrases2.Lookup('MENU_ADVTREE');
135 if Image = nil then begin
136 Image := TBitmap.Create;
137 Image.PixelFormat := pf24bit;
138 LoadGraphicFile(Image, HomeDir + 'Help' + DirectorySeparator + 'AdvTree.png',
139 [gfNoGamma]);
140
141 with Image.Canvas do begin
142 // write advance names
143 Font.Assign(UniFont[ftSmall]);
144 Font.color := clBlack;
145 brush.Style := bsClear;
146 for X := 0 to (Image.width - xStart) div xPitch do
147 for Y := 0 to (Image.height - yStart) div yPitch do
148 begin
149 ad := Pixels[xStart + X * xPitch + 10, yStart + Y * yPitch - 1];
150 if ad and $FFFF00 = 0 then
151 begin
152 s := Phrases.Lookup('ADVANCES', ad);
153 while TextWidth(s) > 112 do
154 Delete(s, Length(s), 1);
155 TextOut(xStart + X * xPitch + 2, yStart + Y * yPitch, s);
156 Pixels[xStart + X * xPitch + 10, yStart + Y * yPitch - 1]
157 := TransparentColor2;
158 end
159 end;
160
161 // write legend
162 TextOut(xLegend, yLegend, Phrases2.Lookup('ADVTREE_UP0'));
163 TextOut(xLegend, yLegend + yLegendPitch, Phrases2.Lookup('ADVTREE_UP1'));
164 TextOut(xLegend, yLegend + 2 * yLegendPitch,
165 Phrases2.Lookup('ADVTREE_UP2'));
166 TextOut(xLegend, yLegend + 3 * yLegendPitch,
167 Phrases2.Lookup('ADVTREE_GOV'));
168 TextOut(xLegend, yLegend + 4 * yLegendPitch,
169 Phrases2.Lookup('ADVTREE_OTHER'));
170 end;
171
172 Texturize(Image, Paper, TransparentColor2);
173 end;
174
175 // fit window to image, center image in window, center window to screen
176 NewWidth := Min(Screen.Width - 40, Image.Width + LeftBorder + RightBorder + 2 * BlackBorder);
177 NewHeight := Min(Screen.Height - 40, Image.Height + TopBorder + BottomBorder + 2 * BlackBorder);
178 BoundsRect := Bounds((Screen.Width - NewWidth) div 2,
179 (Screen.Height - NewHeight) div 2,
180 NewWidth, NewHeight);
181 CloseBtn.Left := width - CloseBtn.width - BlackBorder - 8;
182 CloseBtn.Top := BlackBorder + 8;
183 xOffset := (ClientWidth - Image.Width + LeftBorder - RightBorder) div 2 -
184 BlackBorder;
185 yOffset := ClientHeight - 2 * BlackBorder - Image.Height - BottomBorder;
186end;
187
188procedure TTechTreeDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
189 Shift: TShiftState; X, Y: Integer);
190begin
191 if Button = mbLeft then
192 begin
193 dragging := true;
194 xDown := X;
195 yDown := Y;
196 end;
197end;
198
199procedure TTechTreeDlg.FormMouseUp(Sender: TObject; Button: TMouseButton;
200 Shift: TShiftState; X, Y: Integer);
201begin
202 dragging := false;
203end;
204
205procedure TTechTreeDlg.FormMouseMove(Sender: TObject; Shift: TShiftState;
206 X, Y: Integer);
207begin
208 if dragging then
209 begin
210 xOffset := xOffset + X - xDown;
211 yOffset := yOffset + Y - yDown;
212 xDown := X;
213 yDown := Y;
214
215 if xOffset > LeftBorder then
216 xOffset := LeftBorder;
217 if xOffset < ClientWidth - 2 * BlackBorder - Image.width - RightBorder then
218 xOffset := ClientWidth - 2 * BlackBorder - Image.width - RightBorder;
219 if yOffset > TopBorder then
220 yOffset := TopBorder;
221 if yOffset < ClientHeight - 2 * BlackBorder - Image.height - BottomBorder
222 then
223 yOffset := ClientHeight - 2 * BlackBorder - Image.height - BottomBorder;
224
225 SmartInvalidate;
226 end;
227end;
228
229procedure TTechTreeDlg.CloseBtnClick(Sender: TObject);
230begin
231 Close;
232end;
233
234end.
Note: See TracBrowser for help on using the repository browser.