-
Notifications
You must be signed in to change notification settings - Fork 41
/
PicoGK_ViewerKeyboard.cs
211 lines (198 loc) · 6.47 KB
/
PicoGK_ViewerKeyboard.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//
// SPDX-License-Identifier: Apache-2.0
//
// PicoGK ("peacock") is a compact software kernel for computational geometry,
// specifically for use in Computational Engineering Models (CEM).
//
// For more information, please visit https://picogk.org
//
// PicoGK is developed and maintained by LEAP 71 - © 2023-2024 by LEAP 71
// https://leap71.com
//
// Computational Engineering will profoundly change our physical world in the
// years ahead. Thank you for being part of the journey.
//
// We have developed this library to be used widely, for both commercial and
// non-commercial projects alike. Therefore, we have released it under a
// permissive open-source license.
//
// The foundation of PicoGK is a thin layer on top of the powerful open-source
// OpenVDB project, which in turn uses many other Free and Open Source Software
// libraries. We are grateful to be able to stand on the shoulders of giants.
//
// LEAP 71 licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, THE SOFTWARE IS
// PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace PicoGK
{
public partial class Viewer
{
LinkedList<IKeyHandler> m_oKeyHandlers = new();
KeyHandler m_oHandler = new();
public void AddKeyHandler(IKeyHandler xKeyHandler)
{
// Add to the beginning, so the last added is processed first
m_oKeyHandlers.AddFirst(xKeyHandler);
}
public interface IKeyHandler
{
bool bHandleEvent( Viewer oViewer,
EKeys eKey,
bool bPressed,
bool bShift,
bool bCtrl,
bool bAlt,
bool bCmd);
}
public enum EKeys
{
Key_Space = 32,
Key_0 = 48,
Key_1,
Key_2,
Key_3,
Key_4,
Key_5,
Key_6,
Key_7,
Key_8,
Key_9,
Key_A = 65,
Key_B,
Key_C,
Key_D,
Key_E,
Key_F,
Key_G,
Key_H,
Key_I,
Key_J,
Key_K,
Key_L,
Key_M,
Key_N,
Key_O,
Key_P,
Key_Q,
Key_R,
Key_S,
Key_T,
Key_U,
Key_V,
Key_W,
Key_X,
Key_Y,
Key_Z = 90,
Key_ESC = 256,
Key_Enter,
Key_Tab,
Key_Backspace,
Key_Insert,
Key_Delete,
Key_Right,
Key_Left,
Key_Down,
Key_Up,
Key_PgUp,
Key_PgDn,
Key_Home,
Key_End = 269,
Key_F1 = 290,
Key_F2,
Key_F3,
Key_F4,
Key_F5,
Key_F6,
Key_F7,
Key_F8,
Key_F9,
Key_F10,
Key_F11,
Key_F12
};
public class KeyAction
{
public KeyAction( IViewerAction xAction,
EKeys eKey,
bool bPressed = false, // Handle on release by default
bool bShift = false,
bool bCtrl = false,
bool bAlt = false,
bool bCmd = false)
{
m_xAction = xAction;
m_eKey = eKey;
m_bPressed = bPressed;
m_bShift = bShift;
m_bCtrl = bCtrl;
m_bAlt = bAlt;
m_bCmd = bCmd;
}
public bool bKeyEquals( EKeys eKey,
bool bPressed,
bool bShift,
bool bCtrl,
bool bAlt,
bool bCmd)
{
return ( (m_eKey == eKey) &&
(m_bPressed == bPressed) &&
(m_bShift == bShift) &&
(m_bCtrl == bCtrl) &&
(m_bAlt == bAlt) &&
(m_bCmd == bCmd));
}
public void Do(Viewer oViewer)
{
m_xAction.Do(oViewer);
}
IViewerAction m_xAction;
EKeys m_eKey;
bool m_bPressed;
bool m_bShift;
bool m_bCtrl;
bool m_bAlt;
bool m_bCmd;
}
public class KeyHandler : IKeyHandler
{
public void AddAction(KeyAction oAction)
{
m_oKeyActions.AddFirst(oAction);
}
LinkedList<KeyAction> m_oKeyActions = new();
public bool bHandleEvent( Viewer oViewer,
EKeys eKey,
bool bPressed,
bool bShift,
bool bCtrl,
bool bAlt,
bool bCmd)
{
foreach (KeyAction oAction in m_oKeyActions)
{
if (oAction.bKeyEquals( eKey,
bPressed,
bShift,
bCtrl,
bAlt,
bCmd))
{
oAction.Do(oViewer);
return true;
}
}
return false;
}
}
}
}