/* * encantar.js * GPU-accelerated Augmented Reality for the web * Copyright (C) 2022-2024 Alexandre Martins * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 3 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * fullscreen-button.ts * A built-in fullscreen button introduced as a convenience */ import { Viewport } from '../core/viewport'; /** Button icon to be displayed when the fullscreen mode is disabled */ const BUTTON_ICON_OFF = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAbUlEQVRYR+2WOQ4AIAgE5f+PVhobDZANBZAsraAwXMoqFil+f9GBj8BW8dIiKt45at/XgShStHgvmfdekwAdIIEyAmh1Z/U5ikmABPoRsLZWtt+5DUlgHgGr6qM1Pf9XnO131L7fJEQjyOqXEzjP1YAhNmUTrgAAAABJRU5ErkJggg=='; /** Button icon to be displayed when the fullscreen mode is enabled */ const BUTTON_ICON_ON = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAZElEQVRYR+2WwRIAEAhE9f8fTQ5OhtkLxbzOyc5rJSvBYcH3FwTIBKpHb5d57Nqm5o0aCIBAPgLDxSunq69APT8RCBdwezTLHjglDAEQgEC+QZR2EqqbjprHRgSB9wjwHX9LoAHP1YAhXF4Z/QAAAABJRU5ErkJggg=='; /** Button size, in pixels */ const BUTTON_SIZE = 64; /** Button margin, in pixels */ const BUTTON_MARGIN = 24; /** * Built-in fullscreen button */ export class FullscreenButton { /** The viewport associated to this panel */ private readonly _viewport: Viewport; /** The HTML element of the button */ private readonly _button: HTMLButtonElement; /** Bound event handler */ private readonly _boundEventHandler: EventListener; /** * Constructor * @param viewport Viewport */ constructor(viewport: Viewport) { this._viewport = viewport; this._button = this._createButton(); this._boundEventHandler = this._handleFullscreenEvent.bind(this); } /** * Initialize * @param parent parent node * @param isVisible */ init(parent: Node, isVisible: boolean): void { parent.appendChild(this._button); this._button.hidden = !isVisible; this._viewport.addEventListener('fullscreenchange', this._boundEventHandler); } /** * Release */ release(): void { this._viewport.removeEventListener('fullscreenchange', this._boundEventHandler); this._button.remove(); } /** * Create the