Skip to content

Commit a91251f

Browse files
committed
Add emulator setting to allow more control over screen scaling
Allows explicit control over scaling vs. nearest-neighbor scaling (the current automatic behavior remains the default). Fixes #174
1 parent b1357d8 commit a91251f

3 files changed

Lines changed: 59 additions & 28 deletions

File tree

src/Mac.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,7 @@ export default function Mac({
404404
<div
405405
className={classNames("Mac-Loading", {
406406
"Mac-Loading-Non-Modal": emulatorLoaded,
407-
})}
408-
>
407+
})}>
409408
Loading CD-ROM…
410409
<span className="Mac-Loading-Fraction">
411410
{(emulatorCDROMLoadingProgress * 100).toFixed(0)}%
@@ -557,10 +556,24 @@ export default function Mac({
557556
}
558557

559558
const devicePixelRatio = useDevicePixelRatio();
559+
let smoothScaling;
560+
const {screenScaling = "auto"} = emulatorSettings;
561+
switch (screenScaling) {
562+
case "auto":
563+
smoothScaling =
564+
screenSizeProp === "auto" &&
565+
(fullscreen ||
566+
devicePixelRatio !== Math.floor(devicePixelRatio));
567+
break;
568+
case "pixelated":
569+
smoothScaling = false;
570+
break;
571+
case "smooth":
572+
smoothScaling = true;
573+
break;
574+
}
560575
const screenClassName = classNames("Mac-Screen", {
561-
"Mac-Screen-Smooth-Scaling":
562-
screenSizeProp === "auto" &&
563-
(fullscreen || devicePixelRatio !== Math.floor(devicePixelRatio)),
576+
"Mac-Screen-Smooth-Scaling": smoothScaling,
564577
});
565578

566579
return (
@@ -612,8 +625,7 @@ export default function Mac({
612625
/>
613626
)}
614627
</>
615-
}
616-
>
628+
}>
617629
{progress}
618630
{dragCount > 0 && (
619631
<div
@@ -873,8 +885,7 @@ function MacEthernetStatus({
873885
return (
874886
<div
875887
className="Mac-Ethernet-Status"
876-
onClick={() => setExpanded(!expanded)}
877-
>
888+
onClick={() => setExpanded(!expanded)}>
878889
<div className="ScreenFrame-Bezel-Text">{text}</div>
879890
{details}
880891
</div>
@@ -895,8 +906,7 @@ function MacError({
895906
appearance={appearance}
896907
title="Emulator Error"
897908
onDone={onDone}
898-
doneLabel="Bummer"
899-
>
909+
doneLabel="Bummer">
900910
<p style={{whiteSpace: "pre-line"}}>{text}</p>
901911
</Dialog>
902912
);

src/MacSettings.tsx

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import {useCallback, useEffect, useState} from "react";
2-
import {type EmulatorSettings} from "./emulator/emulator-ui";
2+
import {
3+
type EmulatorScreenScaling,
4+
type EmulatorSettings,
5+
} from "./emulator/emulator-ui";
36
import {
47
type EmulatorSpeed,
58
type EmulatorType,
@@ -65,6 +68,7 @@ export function MacSettings({
6568
const [storageExportVisible, setStorageExportVisible] = useState(false);
6669
const [storageImportVisible, setStorageImportVisible] = useState(false);
6770
const [saveImageVisible, setSaveImageVisible] = useState(false);
71+
const {screenScaling = "auto"} = emulatorSettings;
6872

6973
return (
7074
<Dialog title="Settings" onDone={onDone} appearance={appearance}>
@@ -122,8 +126,7 @@ export function MacSettings({
122126
event.target.value
123127
) as EmulatorSpeed,
124128
})
125-
}
126-
>
129+
}>
127130
{Array.from(
128131
EMULATOR_SPEEDS.entries(),
129132
([speed, label]) => (
@@ -139,15 +142,36 @@ export function MacSettings({
139142
</div>
140143
</label>
141144
)}
145+
<div className="MacSettings-Row">
146+
<div className="MacSettings-Row-Label">Scaling:</div>
147+
<Select
148+
appearance={appearance}
149+
value={screenScaling}
150+
onChange={e => {
151+
const screenScaling = e.target
152+
.value as EmulatorScreenScaling;
153+
setEmulatorSettings({
154+
...emulatorSettings,
155+
screenScaling,
156+
});
157+
}}>
158+
<option value="auto">Auto</option>
159+
<option value="smooth">Smooth</option>
160+
<option value="pixelated">Crisp</option>
161+
</Select>
162+
<div className="Dialog-Description">
163+
Preferred scaling method when displaying the Mac screen at
164+
non-native sizes.
165+
</div>
166+
</div>
142167
{hasSavedHD && (
143168
<>
144169
<h2>Saved HD</h2>
145170
<div className="MacSettings-Row">
146171
<div className="MacSettings-Row-Label">Contents:</div>
147172
<Button
148173
appearance={appearance}
149-
onClick={() => setStorageExportVisible(true)}
150-
>
174+
onClick={() => setStorageExportVisible(true)}>
151175
Export…
152176
</Button>
153177
<StorageConfirmDialog
@@ -163,8 +187,7 @@ export function MacSettings({
163187
/>{" "}
164188
<Button
165189
appearance={appearance}
166-
onClick={() => setStorageImportVisible(true)}
167-
>
190+
onClick={() => setStorageImportVisible(true)}>
168191
Import…
169192
</Button>
170193
<StorageConfirmDialog
@@ -180,8 +203,7 @@ export function MacSettings({
180203
/>{" "}
181204
<Button
182205
appearance={appearance}
183-
onClick={() => setStorageResetVisible(true)}
184-
>
206+
onClick={() => setStorageResetVisible(true)}>
185207
Reset
186208
</Button>
187209
<StorageConfirmDialog
@@ -206,8 +228,7 @@ export function MacSettings({
206228
<div className="MacSettings-Row-Label" />
207229
<Button
208230
appearance={appearance}
209-
onClick={() => setSaveImageVisible(true)}
210-
>
231+
onClick={() => setSaveImageVisible(true)}>
211232
Save Disk Image…
212233
</Button>
213234
<StorageConfirmDialog
@@ -242,8 +263,7 @@ export function MacSettings({
242263
{" "}
243264
<Button
244265
appearance={appearance}
245-
onClick={handleRequestPersistence}
246-
>
266+
onClick={handleRequestPersistence}>
247267
Request Persistence
248268
</Button>
249269
</>
@@ -253,8 +273,7 @@ export function MacSettings({
253273
HD data even when running low on disk space (
254274
<a
255275
href="https://web.dev/persistent-storage/"
256-
target="_blank"
257-
>
276+
target="_blank">
258277
more info
259278
</a>
260279
).
@@ -299,8 +318,7 @@ function StorageConfirmDialog({
299318
onOther={onOther}
300319
otherLabel={otherLabel}
301320
onCancel={() => setVisible(false)}
302-
appearance={appearance}
303-
>
321+
appearance={appearance}>
304322
<div style={{maxWidth: 400}}>{body}</div>
305323
</Dialog>
306324
);

src/emulator/emulator-ui.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,14 @@ export type EmulatorConfig = {
9090
debugTrackpad?: boolean;
9191
};
9292

93+
export type EmulatorScreenScaling = "auto" | "smooth" | "pixelated";
94+
9395
export type EmulatorSettings = {
9496
swapControlAndCommand: boolean;
9597
speed: EmulatorSpeed;
9698
useMouseDeltas: boolean;
9799
trackpadMode: boolean;
100+
screenScaling?: EmulatorScreenScaling;
98101
};
99102

100103
export interface EmulatorEthernetProvider {

0 commit comments

Comments
 (0)