• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A categorical programming language


Commit MetaInfo

修訂ae1a5286be825e690fa13ca4fa35676d11109f4d (tree)
時間2022-11-01 05:00:12
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Allow pausing and unpausing videos.

Change Summary

差異

--- a/honey/static/honey.js
+++ b/honey/static/honey.js
@@ -176,23 +176,31 @@ function CammyImage({ drawer }) {
176176
177177 class CammyAnimation extends Component {
178178 #frameRequest;
179- state = null;
179+ state = { frames: 0, isPlaying: false };
180180
181- componentDidMount() {
182- // Reset frame count and timestamp to keep FPS accurate.
183- this.setState({ frames: 0 });
181+ componentDidMount() { this.play(); }
182+ componentWillUnmount() { this.pause(); }
183+
184+ play() {
185+ this.setState({ isPlaying: true });
184186 this.#frameRequest = window.requestAnimationFrame(this.stepFrame.bind(this));
185187 }
186188
187- componentWillUnmount() {
189+ pause() {
190+ // Reset frame count and timestamp to keep FPS accurate.
191+ this.setState({ start: null, frames: 0, isPlaying: false });
188192 window.cancelAnimationFrame(this.#frameRequest);
189193 this.#frameRequest = null;
190194 }
191195
196+ playPause() {
197+ if (this.state.isPlaying) { this.pause(); } else { this.play(); }
198+ }
199+
192200 stepFrame(timestamp) {
193201 const start = this.state.start || timestamp;
194202 this.setState({ start, timestamp, frames: this.state.frames + 1 });
195- setTimeout(() => window.requestAnimationFrame(this.stepFrame.bind(this)), 50);
203+ this.#frameRequest = window.requestAnimationFrame(this.stepFrame.bind(this));
196204 }
197205
198206 render({ drawer }) {
@@ -207,6 +215,9 @@ class CammyAnimation extends Component {
207215
208216 return h("div", {},
209217 h("canvas", { ref: canvas, width: 100, height: 100 }),
218+ h("label", {},
219+ h("input", { type: "checkbox", checked: this.state.isPlaying, onClick: this.playPause.bind(this) }),
220+ "Play/Pause"),
210221 h("p", {}, `${fps} frames/s`),
211222 );
212223 }