1 | {$INCLUDE switches}
|
---|
2 | unit TechTree;
|
---|
3 |
|
---|
4 | interface
|
---|
5 |
|
---|
6 | uses
|
---|
7 | ScreenTools, Messg,
|
---|
8 |
|
---|
9 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
|
---|
10 | ButtonBase, ButtonB;
|
---|
11 |
|
---|
12 | type
|
---|
13 | TTechTreeDlg = class(TDrawDlg)
|
---|
14 | CloseBtn: TButtonB;
|
---|
15 | procedure FormCreate(Sender: TObject);
|
---|
16 | procedure FormPaint(Sender: TObject);
|
---|
17 | procedure FormShow(Sender: TObject);
|
---|
18 | procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
19 | Shift: TShiftState; X, Y: Integer);
|
---|
20 | procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
21 | Shift: TShiftState; X, Y: Integer);
|
---|
22 | procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
---|
23 | procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
---|
24 | procedure CloseBtnClick(Sender: TObject);
|
---|
25 | private
|
---|
26 | xOffset, yOffset, xDown, yDown: Integer;
|
---|
27 | Image: TBitmap;
|
---|
28 | dragging: boolean;
|
---|
29 | end;
|
---|
30 |
|
---|
31 | var
|
---|
32 | TechTreeDlg: TTechTreeDlg;
|
---|
33 |
|
---|
34 | implementation
|
---|
35 |
|
---|
36 | uses
|
---|
37 | Directories;
|
---|
38 |
|
---|
39 | {$R *.DFM}
|
---|
40 |
|
---|
41 | const
|
---|
42 | BlackBorder = 4;
|
---|
43 | LeftBorder = 72;
|
---|
44 | RightBorder = 45;
|
---|
45 | TopBorder = 16;
|
---|
46 | BottomBorder = 48;
|
---|
47 | xStart = 0;
|
---|
48 | yStart = 40;
|
---|
49 | xPitch = 160;
|
---|
50 | yPitch = 90;
|
---|
51 | xLegend = 44;
|
---|
52 | yLegend = 79;
|
---|
53 | yLegendPitch = 32;
|
---|
54 |
|
---|
55 | function min(a, b: Integer): Integer;
|
---|
56 | begin
|
---|
57 | if a < b then
|
---|
58 | result := a
|
---|
59 | else
|
---|
60 | result := b;
|
---|
61 | end;
|
---|
62 |
|
---|
63 | function max(a, b: Integer): Integer;
|
---|
64 | begin
|
---|
65 | if a > b then
|
---|
66 | result := a
|
---|
67 | else
|
---|
68 | result := b;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | procedure TTechTreeDlg.FormCreate(Sender: TObject);
|
---|
72 | begin
|
---|
73 | InitButtons;
|
---|
74 | Image := nil;
|
---|
75 | end;
|
---|
76 |
|
---|
77 | procedure TTechTreeDlg.FormPaint(Sender: TObject);
|
---|
78 | var
|
---|
79 | X, w: Integer;
|
---|
80 | begin
|
---|
81 | with Canvas do
|
---|
82 | begin
|
---|
83 | // black border
|
---|
84 | brush.color := $000000;
|
---|
85 | fillrect(rect(0, 0, BlackBorder, ClientHeight));
|
---|
86 | fillrect(rect(BlackBorder, 0, ClientWidth - BlackBorder, BlackBorder));
|
---|
87 | fillrect(rect(ClientWidth - BlackBorder, 0, ClientWidth, ClientHeight));
|
---|
88 | fillrect(rect(BlackBorder, ClientHeight - BlackBorder,
|
---|
89 | ClientWidth - BlackBorder, ClientHeight));
|
---|
90 |
|
---|
91 | // texturize empty space
|
---|
92 | brush.color := $FFFFFF;
|
---|
93 | if xOffset > 0 then
|
---|
94 | FillRectSeamless(Canvas, BlackBorder, BlackBorder, BlackBorder + xOffset,
|
---|
95 | ClientHeight - BlackBorder, -BlackBorder - xOffset,
|
---|
96 | -BlackBorder - yOffset, Paper);
|
---|
97 | if xOffset + Image.width < ClientWidth - 2 * BlackBorder then
|
---|
98 | FillRectSeamless(Canvas, BlackBorder + xOffset + Image.width, BlackBorder,
|
---|
99 | ClientWidth - BlackBorder, ClientHeight - BlackBorder,
|
---|
100 | -BlackBorder - xOffset, -BlackBorder - yOffset, Paper);
|
---|
101 | X := max(BlackBorder, BlackBorder + xOffset);
|
---|
102 | w := min(BlackBorder + xOffset + Image.width, ClientWidth - BlackBorder);
|
---|
103 | if yOffset > 0 then
|
---|
104 | FillRectSeamless(Canvas, X, BlackBorder, w, BlackBorder + yOffset,
|
---|
105 | -BlackBorder - xOffset, -BlackBorder - yOffset, Paper);
|
---|
106 | if yOffset + Image.height < ClientHeight - 2 * BlackBorder then
|
---|
107 | FillRectSeamless(Canvas, X, BlackBorder + yOffset + Image.height, w,
|
---|
108 | ClientHeight - BlackBorder, -BlackBorder - xOffset,
|
---|
109 | -BlackBorder - yOffset, Paper);
|
---|
110 | end;
|
---|
111 | BitBlt(Canvas.Handle, max(BlackBorder, BlackBorder + xOffset),
|
---|
112 | max(BlackBorder, BlackBorder + yOffset),
|
---|
113 | min(Image.width, min(Image.width + xOffset,
|
---|
114 | min(ClientWidth - 2 * BlackBorder, ClientWidth - 2 * BlackBorder - xOffset))
|
---|
115 | ), min(Image.height, min(Image.height + yOffset,
|
---|
116 | min(ClientHeight - 2 * BlackBorder, ClientHeight - 2 * BlackBorder -
|
---|
117 | yOffset))), Image.Canvas.Handle, max(0, -xOffset),
|
---|
118 | max(0, -yOffset), SRCCOPY);
|
---|
119 | end;
|
---|
120 |
|
---|
121 | procedure TTechTreeDlg.FormShow(Sender: TObject);
|
---|
122 | type
|
---|
123 | TLine = array [0 .. 9999, 0 .. 2] of Byte;
|
---|
124 | var
|
---|
125 | X, Y, ad, TexWidth, TexHeight: Integer;
|
---|
126 | s: string;
|
---|
127 | SrcLine, DstLine: ^TLine;
|
---|
128 | begin
|
---|
129 | if Image = nil then
|
---|
130 | begin
|
---|
131 | Image := TBitmap.Create;
|
---|
132 | LoadGraphicFile(Image, HomeDir + 'Help\AdvTree', gfNoGamma);
|
---|
133 | Image.PixelFormat := pf24bit;
|
---|
134 |
|
---|
135 | with Image.Canvas do
|
---|
136 | begin
|
---|
137 | // write advance names
|
---|
138 | Font.Assign(UniFont[ftSmall]);
|
---|
139 | Font.color := clBlack;
|
---|
140 | brush.Style := bsClear;
|
---|
141 | for X := 0 to (Image.width - xStart) div xPitch do
|
---|
142 | for Y := 0 to (Image.height - yStart) div yPitch do
|
---|
143 | begin
|
---|
144 | ad := Pixels[xStart + X * xPitch + 10, yStart + Y * yPitch - 1];
|
---|
145 | if ad and $FFFF00 = 0 then
|
---|
146 | begin
|
---|
147 | s := Phrases.Lookup('ADVANCES', ad);
|
---|
148 | while TextWidth(s) > 112 do
|
---|
149 | Delete(s, Length(s), 1);
|
---|
150 | TextOut(xStart + X * xPitch + 2, yStart + Y * yPitch, s);
|
---|
151 | Pixels[xStart + X * xPitch + 10, yStart + Y * yPitch - 1]
|
---|
152 | := $7F007F;
|
---|
153 | end
|
---|
154 | end;
|
---|
155 |
|
---|
156 | // write legend
|
---|
157 | TextOut(xLegend, yLegend, Phrases2.Lookup('ADVTREE_UP0'));
|
---|
158 | TextOut(xLegend, yLegend + yLegendPitch, Phrases2.Lookup('ADVTREE_UP1'));
|
---|
159 | TextOut(xLegend, yLegend + 2 * yLegendPitch,
|
---|
160 | Phrases2.Lookup('ADVTREE_UP2'));
|
---|
161 | TextOut(xLegend, yLegend + 3 * yLegendPitch,
|
---|
162 | Phrases2.Lookup('ADVTREE_GOV'));
|
---|
163 | TextOut(xLegend, yLegend + 4 * yLegendPitch,
|
---|
164 | Phrases2.Lookup('ADVTREE_OTHER'));
|
---|
165 | end;
|
---|
166 |
|
---|
167 | // texturize background
|
---|
168 | TexWidth := Paper.width;
|
---|
169 | TexHeight := Paper.height;
|
---|
170 | for Y := 0 to Image.height - 1 do
|
---|
171 | begin
|
---|
172 | SrcLine := Paper.ScanLine[Y mod TexHeight];
|
---|
173 | DstLine := Image.ScanLine[Y];
|
---|
174 | for X := 0 to Image.width - 1 do
|
---|
175 | begin
|
---|
176 | if Cardinal((@DstLine[X])^) and $FFFFFF = $7F007F then // transparent
|
---|
177 | DstLine[X] := SrcLine[X mod TexWidth];
|
---|
178 | end
|
---|
179 | end
|
---|
180 | end;
|
---|
181 |
|
---|
182 | // fit window to image, center image in window, center window to screen
|
---|
183 | width := min(Screen.width - 40, Image.width + LeftBorder + RightBorder + 2 *
|
---|
184 | BlackBorder);
|
---|
185 | height := min(Screen.height - 40, Image.height + TopBorder + BottomBorder + 2
|
---|
186 | * BlackBorder);
|
---|
187 | Left := (Screen.width - width) div 2;
|
---|
188 | Top := (Screen.height - height) div 2;
|
---|
189 | CloseBtn.Left := width - CloseBtn.width - BlackBorder - 8;
|
---|
190 | CloseBtn.Top := BlackBorder + 8;
|
---|
191 | xOffset := (ClientWidth - Image.width + LeftBorder - RightBorder) div 2 -
|
---|
192 | BlackBorder;
|
---|
193 | yOffset := ClientHeight - 2 * BlackBorder - Image.height - BottomBorder;
|
---|
194 | end;
|
---|
195 |
|
---|
196 | procedure TTechTreeDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
197 | Shift: TShiftState; X, Y: Integer);
|
---|
198 | begin
|
---|
199 | if Button = mbLeft then
|
---|
200 | begin
|
---|
201 | dragging := true;
|
---|
202 | xDown := X;
|
---|
203 | yDown := Y;
|
---|
204 | end
|
---|
205 | end;
|
---|
206 |
|
---|
207 | procedure TTechTreeDlg.FormMouseUp(Sender: TObject; Button: TMouseButton;
|
---|
208 | Shift: TShiftState; X, Y: Integer);
|
---|
209 | begin
|
---|
210 | dragging := false;
|
---|
211 | end;
|
---|
212 |
|
---|
213 | procedure TTechTreeDlg.FormMouseMove(Sender: TObject; Shift: TShiftState;
|
---|
214 | X, Y: Integer);
|
---|
215 | begin
|
---|
216 | if dragging then
|
---|
217 | begin
|
---|
218 | xOffset := xOffset + X - xDown;
|
---|
219 | yOffset := yOffset + Y - yDown;
|
---|
220 | xDown := X;
|
---|
221 | yDown := Y;
|
---|
222 |
|
---|
223 | if xOffset > LeftBorder then
|
---|
224 | xOffset := LeftBorder;
|
---|
225 | if xOffset < ClientWidth - 2 * BlackBorder - Image.width - RightBorder then
|
---|
226 | xOffset := ClientWidth - 2 * BlackBorder - Image.width - RightBorder;
|
---|
227 | if yOffset > TopBorder then
|
---|
228 | yOffset := TopBorder;
|
---|
229 | if yOffset < ClientHeight - 2 * BlackBorder - Image.height - BottomBorder
|
---|
230 | then
|
---|
231 | yOffset := ClientHeight - 2 * BlackBorder - Image.height - BottomBorder;
|
---|
232 |
|
---|
233 | SmartInvalidate;
|
---|
234 | end
|
---|
235 | end;
|
---|
236 |
|
---|
237 | procedure TTechTreeDlg.FormKeyDown(Sender: TObject; var Key: Word;
|
---|
238 | Shift: TShiftState);
|
---|
239 | begin
|
---|
240 | if Key = VK_ESCAPE then
|
---|
241 | Close;
|
---|
242 | end;
|
---|
243 |
|
---|
244 | procedure TTechTreeDlg.CloseBtnClick(Sender: TObject);
|
---|
245 | begin
|
---|
246 | Close();
|
---|
247 | end;
|
---|
248 |
|
---|
249 | end.
|
---|