From 9a940935af5a2d35a110e4bec263f1199ced4da7 Mon Sep 17 00:00:00 2001 From: Will Scullin Date: Sun, 15 May 2022 14:57:21 -0700 Subject: [PATCH] Refactor some controls (#114) * Refactor some controls * Feedback --- css/apple2.css | 10 ++++- js/components/Apple2.tsx | 2 +- js/components/AudioControl.tsx | 51 +++++++++++++++++++++++ js/components/ControlButton.tsx | 5 ++- js/components/ControlStrip.tsx | 71 +++++++-------------------------- js/components/PauseControl.tsx | 51 +++++++++++++++++++++++ 6 files changed, 129 insertions(+), 61 deletions(-) create mode 100644 js/components/AudioControl.tsx create mode 100644 js/components/PauseControl.tsx diff --git a/css/apple2.css b/css/apple2.css index a60881c..4bc42a6 100644 --- a/css/apple2.css +++ b/css/apple2.css @@ -606,6 +606,9 @@ button:focus { padding: 0; margin-left: 10px; width: 42px; + display: flex; + justify-content: center; + align-items: center; } #reset:hover { @@ -614,8 +617,11 @@ button:focus { } #reset:active { - background: #22150A; - border: 5px outset #44372C; + background-color: #22150A; + border-left: 3px solid #44372C; + border-top: 3px solid #44372C; + border-right: 3px solid #000000; + border-bottom: 3px solid #000000; } #keyboard .key-OPEN_APPLE.active div { diff --git a/js/components/Apple2.tsx b/js/components/Apple2.tsx index f26343a..ad92b31 100644 --- a/js/components/Apple2.tsx +++ b/js/components/Apple2.tsx @@ -49,8 +49,8 @@ export const Apple2 = (props: Apple2Props) => { ...props, }; const apple2 = new Apple2Impl(options); - setApple2(apple2); apple2.ready.then(() => { + setApple2(apple2); const io = apple2.getIO(); const cpu = apple2.getCPU(); setIO(io); diff --git a/js/components/AudioControl.tsx b/js/components/AudioControl.tsx new file mode 100644 index 0000000..6663378 --- /dev/null +++ b/js/components/AudioControl.tsx @@ -0,0 +1,51 @@ +import { h } from 'preact'; +import { useCallback, useContext, useEffect, useState } from 'preact/hooks'; +import { ControlButton } from './ControlButton'; +import { OptionsContext } from './OptionsContext'; +import { Audio, SOUND_ENABLED_OPTION } from '../ui/audio'; +import { Apple2 as Apple2Impl } from '../apple2'; + +/** + * AudioControl component properties. + */ +export interface AudioControlProps { + apple2: Apple2Impl | undefined; +} + +/** + * Control that instantiates the Audio object and provides + * a control to mute and unmute audio. + * + * @param apple2 The Apple2 object + * @returns AudioControl component + */ +export const AudioControl = ({ apple2 }: AudioControlProps) => { + const [audioEnabled, setAudioEnabled] = useState(false); + const [audio, setAudio] = useState