浏览代码

Add support widget

customisations
alemart 5 个月前
父节点
当前提交
c84d6402e2
共有 2 个文件被更改,包括 132 次插入0 次删除
  1. 7
    0
      src/core/hud.ts
  2. 125
    0
      src/ui/support-widget.ts

+ 7
- 0
src/core/hud.ts 查看文件

@@ -23,6 +23,7 @@
23 23
 import { Viewport } from './viewport';
24 24
 import { StatsPanel } from '../ui/stats-panel';
25 25
 import { FullscreenButton } from '../ui/fullscreen-button';
26
+import { SupportWidget } from '../ui/support-widget';
26 27
 import { Nullable, Utils } from '../utils/utils';
27 28
 
28 29
 /** HUD container */
@@ -48,6 +49,9 @@ export class HUD
48 49
     /** Fullscreen button */
49 50
     #fullscreenButton: FullscreenButton;
50 51
 
52
+    /** Support widget */
53
+    #supportWidget: SupportWidget;
54
+
51 55
 
52 56
 
53 57
     /**
@@ -80,6 +84,7 @@ export class HUD
80 84
         // create internal components
81 85
         this.#statsPanel = new StatsPanel();
82 86
         this.#fullscreenButton = new FullscreenButton(viewport);
87
+        this.#supportWidget = new SupportWidget();
83 88
     }
84 89
 
85 90
     /**
@@ -129,6 +134,7 @@ export class HUD
129 134
         const parent = this._internalContainer;
130 135
         this.#statsPanel.init(parent, wantStatsPanel);
131 136
         this.#fullscreenButton.init(parent, wantFullscreenButton);
137
+        this.#supportWidget.init(parent);
132 138
 
133 139
         const container = this._container;
134 140
         container.style.position = 'absolute';
@@ -149,6 +155,7 @@ export class HUD
149 155
     {
150 156
         this._visible = false;
151 157
 
158
+        this.#supportWidget.release();
152 159
         this.#fullscreenButton.release();
153 160
         this.#statsPanel.release();
154 161
 

+ 125
- 0
src/ui/support-widget.ts 查看文件

@@ -0,0 +1,125 @@
1
+/*
2
+ * encantar.js
3
+ * GPU-accelerated Augmented Reality for the web
4
+ * Copyright (C) 2022-2024 Alexandre Martins <alemartf(at)gmail.com>
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Lesser General Public License as published
8
+ * by the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public License
17
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
+ *
19
+ * support-widget.ts
20
+ * Support widget
21
+ */
22
+
23
+/*
24
+
25
+This widget is intended to ask users to support the project
26
+
27
+You are asked to support the project!
28
+
29
+https://encantar.dev/supporter
30
+
31
+*/
32
+
33
+declare const __AR_FLAGS__: number;
34
+
35
+/**
36
+ * Support widget
37
+ */
38
+export class SupportWidget
39
+{
40
+    /** The element of the widget */
41
+    private readonly _element: HTMLElement;
42
+
43
+
44
+
45
+    /**
46
+     * Constructor
47
+     */
48
+    constructor()
49
+    {
50
+        this._element = this._createElement();
51
+    }
52
+
53
+    /**
54
+     * Initialize
55
+     * @param parent parent node
56
+     */
57
+    init(parent: Node): void
58
+    {
59
+        parent.appendChild(this._element);
60
+    }
61
+
62
+    /**
63
+     * Release
64
+     */
65
+    release(): void
66
+    {
67
+        this._element.remove();
68
+    }
69
+
70
+    /**
71
+     * Create the element of the widget
72
+     */
73
+    private _createElement(): HTMLElement
74
+    {
75
+        const button = document.createElement('button');
76
+
77
+        button.innerText = 'Support encantar.js';
78
+        button.style.font = 'bold small-caps 1.25rem sans-serif';
79
+        button.style.color = 'white';
80
+        button.style.padding = '0.5rem';
81
+        button.style.maxWidth = '40%';
82
+
83
+        button.style.position = 'absolute';
84
+        button.style.bottom = '0';
85
+        button.style.right = '50%';
86
+        button.style.transform = 'translateX(50%)';
87
+
88
+        button.style.opacity = '0.75';
89
+        button.style.zIndex = '1000000';
90
+        button.style.cursor = 'pointer';
91
+        button.style.outline = 'none';
92
+        (button.style as any)['-webkit-tap-highlight-color'] = 'transparent';
93
+        button.draggable = false;
94
+        button.hidden = !!(__AR_FLAGS__ & 1);
95
+
96
+        button.style.backgroundColor = 'rgba(0,0,0,0.25)';
97
+        button.style.borderColor = 'white';
98
+        button.style.borderStyle = 'solid';
99
+        button.style.borderWidth = '2px';
100
+        button.style.borderTopLeftRadius = '8px';
101
+        button.style.borderTopRightRadius = '8px';
102
+        button.style.borderBottomStyle = 'none';
103
+
104
+        const highlight = () => {
105
+            button.style.backgroundColor = '#ffd500';
106
+            button.style.borderColor = '#ffd500';
107
+            button.style.opacity = '1.0';
108
+        };
109
+
110
+        const dehighlight = () => {
111
+            button.style.backgroundColor = 'rgba(0,0,0,0.25)';
112
+            button.style.borderColor = 'white';
113
+            button.style.opacity = '0.75';
114
+        };
115
+
116
+        button.addEventListener('pointerdown', highlight);
117
+        button.addEventListener('pointerup', dehighlight);
118
+        button.addEventListener('pointerleave', dehighlight);
119
+        button.addEventListener('click', () => {
120
+            location.href = 'https://encantar.dev/supporter';
121
+        });
122
+
123
+        return button;
124
+    }
125
+}

正在加载...
取消
保存