Skip to content

Commit deb6484

Browse files
committed
Allow floating-point window scale factors.
1 parent 8dad627 commit deb6484

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

d2dx-defaults.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77

88
[window]
9-
scale=1 # range 1-3, an integer scale factor for the window
9+
scale=1.0 # range 1.0-3.0, a scale factor for the window
1010
position=[-1,-1] # if [-1,-1] the window will be centered, otherwise placed at the explicit position given here
1111
frameless=false # if true, the window frame (caption bar etc) will be removed
1212

src/d2dx/Options.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ void Options::ApplyCfg(
116116

117117
if (window)
118118
{
119-
auto windowScale = toml_int_in(window, "scale");
119+
auto windowScale = toml_double_in(window, "scale");
120120
if (windowScale.ok)
121121
{
122-
SetWindowScale((int32_t)windowScale.u.i);
122+
SetWindowScale((float)windowScale.u.d);
123123
}
124124

125125
auto windowPosition = toml_array_in(window, "position");
@@ -178,8 +178,21 @@ void Options::ApplyCommandLine(
178178
static_cast<unsigned int>(upscale[11]) - static_cast<unsigned int>('0')));
179179
}
180180

181-
if (strstr(cmdLine, "-dxscale3")) SetWindowScale(3);
182-
else if (strstr(cmdLine, "-dxscale2")) SetWindowScale(2);
181+
char const* scale = strstr(cmdLine, "-dxscale=");
182+
if (scale)
183+
{
184+
scale = scale + 9;
185+
auto end = const_cast<char*>(scale);
186+
while (*end != 0 && *end != ' ' && *end != '\t')
187+
{
188+
++end;
189+
}
190+
float s = strtof(scale, &end);
191+
if (scale != end)
192+
{
193+
SetWindowScale(s);
194+
}
195+
}
183196

184197
if (strstr(cmdLine, "-dxdbg_dump_textures")) SetFlag(OptionsFlag::DbgDumpTextures, true);
185198
}
@@ -204,13 +217,13 @@ void Options::SetFlag(
204217
}
205218
}
206219

207-
int32_t Options::GetWindowScale() const
220+
float Options::GetWindowScale() const
208221
{
209222
return _windowScale;
210223
}
211224

212225
void Options::SetWindowScale(
213-
_In_ int32_t windowScale)
226+
_In_ float windowScale)
214227
{
215228
_windowScale = min(3, max(1, windowScale));
216229
}

src/d2dx/Options.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ namespace d2dx
7171
_In_ OptionsFlag flag,
7272
_In_ bool value);
7373

74-
int32_t GetWindowScale() const;
74+
float GetWindowScale() const;
7575

7676
void SetWindowScale(
77-
_In_ int32_t zoomLevel);
77+
_In_ float zoomLevel);
7878

7979
Offset GetWindowPosition() const;
8080

@@ -98,7 +98,7 @@ namespace d2dx
9898

9999
private:
100100
uint32_t _flags = 1 << (int)OptionsFlag::NoVSync;
101-
int32_t _windowScale = 1;
101+
float _windowScale = 1;
102102
Offset _windowPosition{ -1, -1 };
103103
Size _userSpecifiedGameSize{ -1, -1 };
104104
UpscaleMethod _upscaleMethod{ UpscaleMethod::HighQuality };

src/d2dx/Types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ namespace d2dx
247247
return { width * (int32_t)value, height * (int32_t)value };
248248
}
249249

250+
Size operator*(float value) noexcept
251+
{
252+
return { static_cast<int32_t>(static_cast<float>(width) * value),
253+
static_cast<int32_t>(static_cast<float>(height) * value) };
254+
}
255+
250256
bool operator==(const Size& rhs) const noexcept
251257
{
252258
return width == rhs.width && height == rhs.height;

0 commit comments

Comments
 (0)