-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathd2dFrames.pas
223 lines (198 loc) · 6.26 KB
/
d2dFrames.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
unit d2dFrames;
interface
uses
d2dTypes,
d2dInterfaces;
type
Td2dHorizontalFrameParts = (hfpLeft, hfpMiddle, hfpRight);
Td2dVerticalFrameParts = (vfpTop, vfpMiddle, vfpBottom);
Td2dHorizFrame = class
private
f_Height : Integer;
f_Quad : array [Td2dHorizontalFrameParts] of Td2dQuad;
f_Width : array [Td2dHorizontalFrameParts] of Integer;
f_MinWidth : Integer;
function pm_GetLeftWidth: Integer;
function pm_GetRightWidth: Integer;
public
constructor Create(const aTex: Id2dTexture; aLeft, aTop, aRight, aBottom, aLeftWidth, aMidWidth: Integer);
procedure CorrectWidth(var theWidth: Integer; aToGreater: Boolean = True);
procedure Render(aX, aY: Single; aWidth: Integer);
function GetMidWidth(const aWidth: Integer): Integer;
property Height: Integer read f_Height;
property LeftWidth: Integer read pm_GetLeftWidth;
property MinWidth: Integer read f_MinWidth;
property RightWidth: Integer read pm_GetRightWidth;
end;
Td2dFrame = class
private
f_Quad : array [Td2dHorizontalFrameParts, Td2dVerticalFrameParts] of Td2dQuad;
f_Width : array [Td2dHorizontalFrameParts] of Integer;
f_Height : array [Td2dVerticalFrameParts] of Integer;
f_MinWidth : Integer;
f_MinHeight: Integer;
public
constructor Create(aTex: Id2dTexture; aLeft, aTop, aRight, aBottom,
aLeftWidth, aMidWidth, aTopHeight, aMidHeight: Integer);
end;
implementation
uses
Direct3D8,
d2dCore;
constructor Td2dHorizFrame.Create(const aTex: Id2dTexture; aLeft, aTop, aRight, aBottom, aLeftWidth, aMidWidth: Integer);
var
l_TexWidth: Single;
l_TexHeight: Single;
l_TY, l_BY: Single;
l_LCX, l_LMX, l_RMX, l_RCX: Single;
l_DXTex : IDirect3DTexture8;
begin
inherited Create;
f_Width[hfpLeft] := aLeftWidth;
f_Width[hfpMiddle] := aMidWidth;
f_MinWidth := aRight - aLeft;
f_Width[hfpRight] := f_MinWidth - f_Width[hfpMiddle] - f_Width[hfpLeft];
f_Height := aBottom - aTop;
if aTex <> nil then
begin
l_TexWidth := gD2DE.Texture_GetWidth(aTex);
l_TexHeight := gD2DE.Texture_GetHeight(aTex);
l_DXTex := aTex.DirectXTexture;
end
else
begin
l_TexWidth := 1.0;
l_TexHeight := 1.0;
l_DXTex := nil;
end;
// y-coords
l_TY := aTop / l_TexHeight; // top
l_BY := aBottom / l_TexHeight; // bottom
// x-coords
l_LCX := aLeft / l_TexWidth; // left cap x
l_RCX := aRight / l_TexWidth; // right cap x
l_LMX := (aLeft + aLeftWidth) / l_TexWidth; // left middle x
l_RMX := (aLeft + aLeftWidth + aMidWidth) / l_TexWidth; // right middle x
// left cap quad
with f_Quad[hfpLeft] do
begin
V[0].TX := l_LCX; V[0].TY := l_TY; V[0].Z := 0.5; V[0].Col := $FFFFFFFF;
V[1].TX := l_LMX; V[1].TY := l_TY; V[1].Z := 0.5; V[1].Col := $FFFFFFFF;
V[2].TX := l_LMX; V[2].TY := l_BY; V[2].Z := 0.5; V[2].Col := $FFFFFFFF;
V[3].TX := l_LCX; V[3].TY := l_BY; V[3].Z := 0.5; V[3].Col := $FFFFFFFF;
Blend := BLEND_DEFAULT;
Tex := l_DXTex;
end;
// right cap quad
with f_Quad[hfpRight] do
begin
V[0].TX := l_RMX; V[0].TY := l_TY; V[0].Z := 0.5; V[0].Col := $FFFFFFFF;
V[1].TX := l_RCX; V[1].TY := l_TY; V[1].Z := 0.5; V[1].Col := $FFFFFFFF;
V[2].TX := l_RCX; V[2].TY := l_BY; V[2].Z := 0.5; V[2].Col := $FFFFFFFF;
V[3].TX := l_RMX; V[3].TY := l_BY; V[3].Z := 0.5; V[3].Col := $FFFFFFFF;
Blend := BLEND_DEFAULT;
Tex := l_DXTex;
end;
// middle quad
with f_Quad[hfpMiddle] do
begin
V[0].TX := l_LMX; V[0].TY := l_TY; V[0].Z := 0.5; V[0].Col := $FFFFFFFF;
V[1].TX := l_RMX; V[1].TY := l_TY; V[1].Z := 0.5; V[1].Col := $FFFFFFFF;
V[2].TX := l_RMX; V[2].TY := l_BY; V[2].Z := 0.5; V[2].Col := $FFFFFFFF;
V[3].TX := l_LMX; V[3].TY := l_BY; V[3].Z := 0.5; V[3].Col := $FFFFFFFF;
Blend := BLEND_DEFAULT;
Tex := l_DXTex;
end;
end;
procedure Td2dHorizFrame.CorrectWidth(var theWidth: Integer; aToGreater: Boolean = True);
var
l_MW: Integer;
l_Frac: Integer;
begin
l_MW := theWidth - f_Width[hfpLeft] - f_Width[hfpRight];
if l_MW < f_Width[hfpMiddle] then
begin
theWidth := f_MinWidth;
Exit;
end;
l_Frac := l_MW mod f_Width[hfpMiddle];
if l_Frac > 0 then
begin
if aToGreater then
theWidth := theWidth - l_Frac + f_Width[hfpMiddle]
else
theWidth := theWidth - l_Frac;
end;
end;
function Td2dHorizFrame.GetMidWidth(const aWidth: Integer): Integer;
begin
Result := aWidth - f_Width[hfpLeft] - f_Width[hfpRight];
end;
function Td2dHorizFrame.pm_GetLeftWidth: Integer;
begin
Result := f_Width[hfpLeft];
end;
function Td2dHorizFrame.pm_GetRightWidth: Integer;
begin
Result := f_Width[hfpRight];
end;
procedure Td2dHorizFrame.Render(aX, aY: Single; aWidth: Integer);
var
l_BottomY: Single;
l_LeftM, l_RightM: Single;
l_MiddlesCount: Integer;
I: Integer;
begin
CorrectWidth(aWidth);
l_BottomY := aY + f_Height;
l_LeftM := aX + f_Width[hfpLeft];
// render left cap
with f_Quad[hfpLeft] do
begin
V[0].X := aX; V[0].Y := aY;
V[1].X := l_LeftM; V[1].Y := aY;
V[2].X := l_LeftM; V[2].Y := l_BottomY;
V[3].X := aX; V[3].Y := l_BottomY;
end;
gD2DE.Gfx_RenderQuad(f_Quad[hfpLeft]);
// render middle part
l_MiddlesCount := (aWidth - f_Width[hfpLeft] - f_Width[hfpRight]) div f_Width[hfpMiddle];
for I := 1 to l_MiddlesCount do
begin
l_RightM := l_LeftM + f_Width[hfpMiddle];
with f_Quad[hfpMiddle] do
begin
V[0].X := l_LeftM; V[0].Y := aY;
V[1].X := l_RightM; V[1].Y := aY;
V[2].X := l_RightM; V[2].Y := l_BottomY;
V[3].X := l_LeftM; V[3].Y := l_BottomY;
end;
gD2DE.Gfx_RenderQuad(f_Quad[hfpMiddle]);
l_LeftM := l_RightM;
end;
// render right cap
l_RightM := l_LeftM + f_Width[hfpRight];
with f_Quad[hfpRight] do
begin
V[0].X := l_LeftM; V[0].Y := aY;
V[1].X := l_RightM; V[1].Y := aY;
V[2].X := l_RightM; V[2].Y := l_BottomY;
V[3].X := l_LeftM; V[3].Y := l_BottomY;
end;
gD2DE.Gfx_RenderQuad(f_Quad[hfpRight]);
end;
constructor Td2dFrame.Create(aTex: Id2dTexture;
aLeft, aTop, aRight, aBottom, aLeftWidth,
aMidWidth, aTopHeight, aMidHeight: Integer);
begin
inherited Create;
f_Width[hfpLeft] := aLeftWidth;
f_Width[hfpMiddle] := aMidWidth;
f_MinWidth := (aRight - aLeft);
f_Width[hfpRight] := f_MinWidth - f_Width[hfpLeft] - f_Width[hfpMiddle];
f_Height[vfpTop] := aTopHeight;
f_Height[vfpMiddle] := aMidHeight;
f_MinHeight := (aBottom - aTop);
f_Height[vfpBottom] := f_MinHeight - f_Height[vfpTop] - f_Height[vfpMiddle];
end;
end.