-
Notifications
You must be signed in to change notification settings - Fork 5
/
r_aspect.pas
260 lines (233 loc) · 7.18 KB
/
r_aspect.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
//------------------------------------------------------------------------------
//
// FPCDoom - Port of Doom to Free Pascal Compiler
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 2004-2007 by Jim Valavanis
// Copyright (C) 2017-2022 by Jim Valavanis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//------------------------------------------------------------------------------
// E-Mail: [email protected]
// Site : https://sourceforge.net/projects/fpcdoom/
//------------------------------------------------------------------------------
{$I FPCDoom.inc}
unit r_aspect;
interface
//==============================================================================
//
// R_InitAspect
//
//==============================================================================
procedure R_InitAspect;
//==============================================================================
//
// R_ForcedAspect
//
//==============================================================================
function R_ForcedAspect: Double;
//==============================================================================
//
// R_GetRelativeAspect
//
//==============================================================================
function R_GetRelativeAspect: double;
var
widescreensupport: Boolean = true;
excludewidescreenplayersprites: Boolean = true;
forcedaspectstr: string = '0.00';
const
MINRELATIVEASPECT = 0.5;
MAXRELATIVEASPECT = 2.5;
implementation
uses
Windows,
d_fpc,
doomdef,
m_misc,
c_cmds,
r_main;
var
relative_aspect_fs: Double = 1.0;
//==============================================================================
//
// R_CmdWideScreen
//
//==============================================================================
procedure R_CmdWideScreen(const parm: string);
var
neww: boolean;
begin
if parm = '' then
begin
printf('Current setting: widescreensupport = %s.'#13#10, [truefalseStrings[widescreensupport]]);
exit;
end;
neww := C_BoolEval(parm, widescreensupport);
if neww <> widescreensupport then
begin
widescreensupport := neww;
setsizeneeded := true;
end;
R_CmdWideScreen('');
end;
//==============================================================================
//
// R_CmdExcludeWideScreenPlayerSprites
//
//==============================================================================
procedure R_CmdExcludeWideScreenPlayerSprites(const parm: string);
var
neww: boolean;
begin
if parm = '' then
begin
printf('Current setting: excludewidescreenplayersprites = %s.'#13#10, [truefalseStrings[excludewidescreenplayersprites]]);
exit;
end;
neww := C_BoolEval(parm, excludewidescreenplayersprites);
if neww <> excludewidescreenplayersprites then
begin
excludewidescreenplayersprites := neww;
setsizeneeded := true;
end;
R_CmdExcludeWideScreenPlayerSprites('');
end;
//==============================================================================
//
// R_ForcedAspect
//
//==============================================================================
function R_ForcedAspect: Double;
var
ar, par: string;
nar, npar: float;
begin
splitstring(forcedaspectstr, ar, par, [':', '/']);
if par <> '' then
begin
nar := atof(strtrim(ar));
npar := atof(strtrim(par));
if npar > 0 then
result := nar / npar
else
result := 0.0;
end
else
result := atof(forcedaspectstr);
if result < MINRELATIVEASPECT then
result := 0.0
else if result > MAXRELATIVEASPECT then
result := MAXRELATIVEASPECT;
forcedaspectstr := ftoa(result);
end;
//==============================================================================
//
// R_CmdForcedAspect
//
//==============================================================================
procedure R_CmdForcedAspect(const parm: string);
begin
if parm = '' then
begin
R_ForcedAspect;
printf('Current setting: forcedaspect = %s.'#13#10, [forcedaspectstr]);
exit;
end;
forcedaspectstr := parm;
setsizeneeded := true;
R_CmdForcedAspect('');
end;
//==============================================================================
//
// R_InitAspect
//
//==============================================================================
procedure R_InitAspect;
var
dm: TDevMode;
i: integer;
widths, heights: TDNumberList;
maxwidth, maxheight: integer;
begin
widths := TDNumberList.Create;
maxwidth := 640;
widths.Add(maxwidth);
heights := TDNumberList.Create;
maxheight := 480;
heights.Add(maxheight);
i := 0;
while EnumDisplaySettings(nil, i, dm) do
begin
if (dm.dmPelsWidth > 640) and (dm.dmPelsHeight > 480) and (dm.dmBitsPerPel = 32) then
begin
widths.Add(dm.dmPelsWidth);
heights.Add(dm.dmPelsHeight);
end;
inc(i);
end;
for i := 1 to widths.Count - 1 do
if (widths.Numbers[i] >= maxwidth) and (heights.Numbers[i] >= maxheight) then
begin
maxwidth := widths.Numbers[i];
maxheight := heights.Numbers[i];
end;
if maxheight > 0 then
begin
relative_aspect_fs := maxwidth / maxheight / (4 / 3);
if relative_aspect_fs < MINRELATIVEASPECT then
relative_aspect_fs := MINRELATIVEASPECT
else if relative_aspect_fs > MAXRELATIVEASPECT then
relative_aspect_fs := MAXRELATIVEASPECT;
end;
widths.Free;
heights.Free;
C_AddCmd('widescreen,widescreensupport', @R_CmdWideScreen);
C_AddCmd('excludewidescreenplayersprites', @R_CmdExcludeWideScreenPlayerSprites);
C_AddCmd('forcedaspect', @R_CmdForcedAspect);
end;
//==============================================================================
//
// R_GetRelativeAspect
//
//==============================================================================
function R_GetRelativeAspect: double;
var
asp: Double;
begin
if widescreensupport then
begin
asp := R_ForcedAspect;
if asp < MINRELATIVEASPECT then
begin
if fullscreen and fullscreenexclusive then
result := (SCREENWIDTH / SCREENHEIGHT) / (4 / 3)
else if fullscreen then
result := relative_aspect_fs
else
result := (WINDOWWIDTH / WINDOWHEIGHT) / (4 / 3);
end
else
result := asp / (4 / 3);
if result < MINRELATIVEASPECT then
result := MINRELATIVEASPECT
else if result > MAXRELATIVEASPECT then
result := MAXRELATIVEASPECT;
end
else
result := 1.0;
end;
end.