0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / samples / webgl / WasmVKeys.h
CommitLineData
565baee6 1// Copyright (c) 2019 OPEN CASCADE SAS
2//
3// This file is part of the examples of the Open CASCADE Technology software library.
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
21
22#ifndef _WasmVKeys_HeaderFile
23#define _WasmVKeys_HeaderFile
24
25#include <Aspect_VKey.hxx>
26
27#include <emscripten/key_codes.h>
28
29//! Convert Emscripten mouse buttons into Aspect_VKeyMouse.
30inline Aspect_VKeyMouse WasmVKeys_MouseButtonsFromNative (unsigned short theButtons)
31{
32 Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
33 if ((theButtons & 0x1) != 0)
34 {
35 aButtons |= Aspect_VKeyMouse_LeftButton;
36 }
37 if ((theButtons & 0x2) != 0)
38 {
39 aButtons |= Aspect_VKeyMouse_RightButton;
40 }
41 if ((theButtons & 0x4) != 0)
42 {
43 aButtons |= Aspect_VKeyMouse_MiddleButton;
44 }
45 return aButtons;
46}
47
48//! Convert DOM virtual key into Aspect_VKey.
49inline Aspect_VKey WasmVKeys_VirtualKeyFromNative (Standard_Integer theKey)
50{
51 if (theKey >= DOM_VK_0
52 && theKey <= DOM_VK_9)
53 {
54 // numpad keys
55 return Aspect_VKey((theKey - DOM_VK_0) + Aspect_VKey_0);
56 }
57 if (theKey >= DOM_VK_A
58 && theKey <= DOM_VK_Z)
59 {
60 // main latin alphabet keys
61 return Aspect_VKey((theKey - DOM_VK_A) + Aspect_VKey_A);
62 }
63 if (theKey >= DOM_VK_F1
64 && theKey <= DOM_VK_F24)
65 {
66 // special keys
67 if (theKey <= DOM_VK_F12)
68 {
69 return Aspect_VKey((theKey - DOM_VK_F1) + Aspect_VKey_F1);
70 }
71 return Aspect_VKey_UNKNOWN;
72 }
73 if (theKey >= DOM_VK_NUMPAD0
74 && theKey <= DOM_VK_NUMPAD9)
75 {
76 // numpad keys
77 return Aspect_VKey((theKey - DOM_VK_NUMPAD0) + Aspect_VKey_Numpad0);
78 }
79
80 switch (theKey)
81 {
82 case DOM_VK_CANCEL:
83 case DOM_VK_HELP:
84 return Aspect_VKey_UNKNOWN;
85 case DOM_VK_BACK_SPACE:
86 return Aspect_VKey_Backspace;
87 case DOM_VK_TAB:
88 return Aspect_VKey_Tab;
89 case DOM_VK_CLEAR:
90 return Aspect_VKey_UNKNOWN;
91 case DOM_VK_RETURN:
92 case DOM_VK_ENTER:
93 return Aspect_VKey_Enter;
94 case DOM_VK_SHIFT:
95 return Aspect_VKey_Shift;
96 case DOM_VK_CONTROL:
97 return Aspect_VKey_Control;
98 case DOM_VK_ALT:
99 return Aspect_VKey_Alt;
100 case DOM_VK_PAUSE:
101 case DOM_VK_CAPS_LOCK:
102 case DOM_VK_KANA:
103 //case DOM_VK_HANGUL:
104 case DOM_VK_EISU:
105 case DOM_VK_JUNJA:
106 case DOM_VK_FINAL:
107 case DOM_VK_HANJA:
108 //case DOM_VK_KANJI:
109 return Aspect_VKey_UNKNOWN;
110 case DOM_VK_ESCAPE:
111 return Aspect_VKey_Escape;
112 case DOM_VK_CONVERT:
113 case DOM_VK_NONCONVERT:
114 case DOM_VK_ACCEPT:
115 case DOM_VK_MODECHANGE:
116 return Aspect_VKey_UNKNOWN;
117 case DOM_VK_SPACE:
118 return Aspect_VKey_Space;
119 case DOM_VK_PAGE_UP:
120 return Aspect_VKey_PageUp;
121 case DOM_VK_PAGE_DOWN:
122 return Aspect_VKey_PageDown;
123 case DOM_VK_END:
124 return Aspect_VKey_End;
125 case DOM_VK_HOME:
126 return Aspect_VKey_Home;
127 case DOM_VK_LEFT:
128 return Aspect_VKey_Left;
129 case DOM_VK_UP:
130 return Aspect_VKey_Up;
131 case DOM_VK_RIGHT:
132 return Aspect_VKey_Right;
133 case DOM_VK_DOWN:
134 return Aspect_VKey_Down;
135 case DOM_VK_SELECT:
136 case DOM_VK_PRINT:
137 case DOM_VK_EXECUTE:
138 case DOM_VK_PRINTSCREEN:
139 case DOM_VK_INSERT:
140 return Aspect_VKey_UNKNOWN;
141 case DOM_VK_DELETE:
142 return Aspect_VKey_Delete;
143 case DOM_VK_COLON:
144 return Aspect_VKey_Comma;
145 case DOM_VK_SEMICOLON:
146 return Aspect_VKey_Semicolon;
147 case DOM_VK_LESS_THAN:
148 return Aspect_VKey_UNKNOWN;
149 case DOM_VK_EQUALS:
150 return Aspect_VKey_Equal;
151 case DOM_VK_GREATER_THAN:
152 return Aspect_VKey_UNKNOWN;
153 case DOM_VK_QUESTION_MARK:
154 return Aspect_VKey_Slash;
155 case DOM_VK_AT: // @ key
156 return Aspect_VKey_UNKNOWN;
157 case DOM_VK_WIN:
158 return Aspect_VKey_Meta;
159 case DOM_VK_CONTEXT_MENU:
160 case DOM_VK_SLEEP:
161 return Aspect_VKey_UNKNOWN;
162 case DOM_VK_MULTIPLY:
163 return Aspect_VKey_NumpadMultiply;
164 case DOM_VK_ADD:
165 return Aspect_VKey_NumpadAdd;
166 case DOM_VK_SEPARATOR:
167 return Aspect_VKey_UNKNOWN;
168 case DOM_VK_SUBTRACT:
169 return Aspect_VKey_NumpadSubtract;
170 case DOM_VK_DECIMAL:
171 return Aspect_VKey_UNKNOWN;
172 case DOM_VK_DIVIDE:
173 return Aspect_VKey_NumpadDivide;
174 case DOM_VK_NUM_LOCK:
175 return Aspect_VKey_Numlock;
176 case DOM_VK_SCROLL_LOCK:
177 return Aspect_VKey_Scroll;
178 case DOM_VK_WIN_OEM_FJ_JISHO:
179 case DOM_VK_WIN_OEM_FJ_MASSHOU:
180 case DOM_VK_WIN_OEM_FJ_TOUROKU:
181 case DOM_VK_WIN_OEM_FJ_LOYA:
182 case DOM_VK_WIN_OEM_FJ_ROYA:
183 case DOM_VK_CIRCUMFLEX:
184 return Aspect_VKey_UNKNOWN;
185 case DOM_VK_EXCLAMATION:
186 case DOM_VK_DOUBLE_QUOTE:
187 //case DOM_VK_HASH:
188 case DOM_VK_DOLLAR:
189 case DOM_VK_PERCENT:
190 case DOM_VK_AMPERSAND:
191 case DOM_VK_UNDERSCORE:
192 case DOM_VK_OPEN_PAREN:
193 case DOM_VK_CLOSE_PAREN:
194 case DOM_VK_ASTERISK:
195 return Aspect_VKey_UNKNOWN;
196 case DOM_VK_PLUS:
197 return Aspect_VKey_Plus;
198 case DOM_VK_PIPE:
199 case DOM_VK_HYPHEN_MINUS:
200 return Aspect_VKey_UNKNOWN;
201 case DOM_VK_OPEN_CURLY_BRACKET:
202 return Aspect_VKey_BracketLeft;
203 case DOM_VK_CLOSE_CURLY_BRACKET:
204 return Aspect_VKey_BracketRight;
205 case DOM_VK_TILDE:
206 return Aspect_VKey_Tilde;
207 case DOM_VK_VOLUME_MUTE:
208 return Aspect_VKey_VolumeMute;
209 case DOM_VK_VOLUME_DOWN:
210 return Aspect_VKey_VolumeDown;
211 case DOM_VK_VOLUME_UP:
212 return Aspect_VKey_VolumeUp;
213 case DOM_VK_COMMA:
214 return Aspect_VKey_Comma;
215 case DOM_VK_PERIOD:
216 return Aspect_VKey_Period;
217 case DOM_VK_SLASH:
218 return Aspect_VKey_Slash;
219 case DOM_VK_BACK_QUOTE:
220 return Aspect_VKey_UNKNOWN;
221 case DOM_VK_OPEN_BRACKET:
222 return Aspect_VKey_BracketLeft;
223 case DOM_VK_BACK_SLASH:
224 return Aspect_VKey_Backslash;
225 case DOM_VK_CLOSE_BRACKET:
226 return Aspect_VKey_BracketRight;
227 case DOM_VK_QUOTE:
228 return Aspect_VKey_UNKNOWN;
229 case DOM_VK_META:
230 return Aspect_VKey_Meta;
231 case DOM_VK_ALTGR:
232 return Aspect_VKey_Alt;
233 case DOM_VK_WIN_ICO_HELP:
234 case DOM_VK_WIN_ICO_00:
235 case DOM_VK_WIN_ICO_CLEAR:
236 case DOM_VK_WIN_OEM_RESET:
237 case DOM_VK_WIN_OEM_JUMP:
238 case DOM_VK_WIN_OEM_PA1:
239 case DOM_VK_WIN_OEM_PA2:
240 case DOM_VK_WIN_OEM_PA3:
241 case DOM_VK_WIN_OEM_WSCTRL:
242 case DOM_VK_WIN_OEM_CUSEL:
243 case DOM_VK_WIN_OEM_ATTN:
244 case DOM_VK_WIN_OEM_FINISH:
245 case DOM_VK_WIN_OEM_COPY:
246 case DOM_VK_WIN_OEM_AUTO:
247 case DOM_VK_WIN_OEM_ENLW:
248 case DOM_VK_WIN_OEM_BACKTAB:
249 case DOM_VK_ATTN:
250 case DOM_VK_CRSEL:
251 case DOM_VK_EXSEL:
252 case DOM_VK_EREOF:
253 return Aspect_VKey_UNKNOWN;
254 case DOM_VK_PLAY:
255 return Aspect_VKey_MediaPlayPause;
256 case DOM_VK_ZOOM:
257 case DOM_VK_PA1:
258 case DOM_VK_WIN_OEM_CLEAR:
259 return Aspect_VKey_UNKNOWN;
260 }
261 return Aspect_VKey_UNKNOWN;
262}
263
264#endif // _WasmVKeys_HeaderFile