comparison Applications/Generic/GuiAdapter.h @ 858:e3c56d4f863f

GuiAdapter : mouse event routing in SDL + split the undo stack from the ViewportController for multi-canvas apps + adapted the samples to this change
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 24 Jun 2019 10:31:04 +0200
parents df0c73ee7afa
children f0bf971a1e31 12b591d5d63c
comparison
equal deleted inserted replaced
855:41d22389a7d2 858:e3c56d4f863f
15 * Affero General Public License for more details. 15 * Affero General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU Affero General Public License 17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/ 19 **/
20 #pragma once
21
20 #include <string> 22 #include <string>
21 23
22 #if ORTHANC_ENABLE_WASM != 1 24 #if ORTHANC_ENABLE_WASM != 1
23 # ifdef __EMSCRIPTEN__ 25 # ifdef __EMSCRIPTEN__
24 # error __EMSCRIPTEN__ is defined and ORTHANC_ENABLE_WASM != 1 26 # error __EMSCRIPTEN__ is defined and ORTHANC_ENABLE_WASM != 1
60 */ 62 */
61 class IGuiAdapterWidget 63 class IGuiAdapterWidget
62 { 64 {
63 public: 65 public:
64 virtual ~IGuiAdapterWidget() {} 66 virtual ~IGuiAdapterWidget() {}
67
65 }; 68 };
66 69
67 enum GuiAdapterMouseEventType 70 enum GuiAdapterMouseEventType
68 { 71 {
69 GUIADAPTER_EVENT_MOUSEDOWN = 1973, 72 GUIADAPTER_EVENT_MOUSEDOWN = 1973,
82 struct GuiAdapterKeyboardEvent; 85 struct GuiAdapterKeyboardEvent;
83 86
84 class LockingEmitter; 87 class LockingEmitter;
85 88
86 #if 1 89 #if 1
87 typedef bool (*OnMouseEventFunc)(const GuiAdapterMouseEvent* mouseEvent, void* userData); 90 typedef bool (*OnMouseEventFunc)(std::string canvasId, const GuiAdapterMouseEvent* mouseEvent, void* userData);
88 typedef bool (*OnMouseWheelFunc)(const GuiAdapterWheelEvent* wheelEvent, void* userData); 91 typedef bool (*OnMouseWheelFunc)(std::string canvasId, const GuiAdapterWheelEvent* wheelEvent, void* userData);
89 typedef bool (*OnKeyDownFunc) (const GuiAdapterKeyboardEvent* keyEvent, void* userData); 92 typedef bool (*OnKeyDownFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData);
90 typedef bool (*OnKeyUpFunc) (const GuiAdapterKeyboardEvent* keyEvent, void* userData); 93 typedef bool (*OnKeyUpFunc) (std::string canvasId, const GuiAdapterKeyboardEvent* keyEvent, void* userData);
91 94
92 typedef bool (*OnAnimationFrameFunc)(double time, void* userData); 95 typedef bool (*OnAnimationFrameFunc)(double time, void* userData);
93 typedef bool (*OnWindowResizeFunc)(const GuiAdapterUiEvent* uiEvent, void* userData); 96 typedef bool (*OnWindowResizeFunc)(std::string canvasId, const GuiAdapterUiEvent* uiEvent, void* userData);
94 97
95 #else 98 #else
96 99
97 #if ORTHANC_ENABLE_WASM == 1 100 #if ORTHANC_ENABLE_WASM == 1
98 typedef EM_BOOL (*OnMouseEventFunc)(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData); 101 typedef EM_BOOL (*OnMouseEventFunc)(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData);
152 bool ctrlKey; 155 bool ctrlKey;
153 bool shiftKey; 156 bool shiftKey;
154 bool altKey; 157 bool altKey;
155 }; 158 };
156 159
160 std::ostream& operator<<(std::ostream& os, const GuiAdapterKeyboardEvent& event);
161
157 /* 162 /*
158 Mousedown event trigger when either the left or right (or middle) mouse is pressed 163 Mousedown event trigger when either the left or right (or middle) mouse is pressed
159 on the object; 164 on the object;
160 165
161 Mouseup event trigger when either the left or right (or middle) mouse is released 166 Mouseup event trigger when either the left or right (or middle) mouse is released
196 # if ORTHANC_ENABLE_SDL == 1 201 # if ORTHANC_ENABLE_SDL == 1
197 void ConvertFromPlatform( 202 void ConvertFromPlatform(
198 GuiAdapterMouseEvent& dest, 203 GuiAdapterMouseEvent& dest,
199 bool ctrlPressed, bool shiftPressed, bool altPressed, 204 bool ctrlPressed, bool shiftPressed, bool altPressed,
200 const SDL_Event& source); 205 const SDL_Event& source);
206
207 void ConvertFromPlatform(
208 GuiAdapterWheelEvent& dest,
209 bool ctrlPressed, bool shiftPressed, bool altPressed,
210 const SDL_Event& source);
211
201 # endif 212 # endif
202 213
203 #endif 214 #endif
204 215
205 class GuiAdapter 216 class GuiAdapter
219 void RegisterWidget(boost::shared_ptr<IGuiAdapterWidget> widget); 230 void RegisterWidget(boost::shared_ptr<IGuiAdapterWidget> widget);
220 231
221 /** 232 /**
222 emscripten_set_resize_callback("#window", NULL, false, OnWindowResize); 233 emscripten_set_resize_callback("#window", NULL, false, OnWindowResize);
223 234
224 emscripten_set_wheel_callback("mycanvas1", widget1_.get(), false, OnMouseWheel); 235 emscripten_set_wheel_callback("mycanvas1", widget1_.get(), false, OnXXXMouseWheel);
225 emscripten_set_wheel_callback("mycanvas2", widget2_.get(), false, OnMouseWheel); 236 emscripten_set_wheel_callback("mycanvas2", widget2_.get(), false, OnXXXMouseWheel);
226 emscripten_set_wheel_callback("mycanvas3", widget3_.get(), false, OnMouseWheel); 237 emscripten_set_wheel_callback("mycanvas3", widget3_.get(), false, OnXXXMouseWheel);
227 238
228 emscripten_set_keydown_callback("#window", NULL, false, OnKeyDown); 239 emscripten_set_keydown_callback("#window", NULL, false, OnKeyDown);
229 emscripten_set_keyup_callback("#window", NULL, false, OnKeyUp); 240 emscripten_set_keyup_callback("#window", NULL, false, OnKeyUp);
230 241
231 emscripten_request_animation_frame_loop(OnAnimationFrame, NULL); 242 emscripten_request_animation_frame_loop(OnAnimationFrame, NULL);
293 std::vector<std::pair<OnAnimationFrameFunc, void*> > 304 std::vector<std::pair<OnAnimationFrameFunc, void*> >
294 animationFrameHandlers_; 305 animationFrameHandlers_;
295 306
296 void OnResize(); 307 void OnResize();
297 308
298 std::vector<std::pair<OnWindowResizeFunc, void*> >
299 resizeHandlers_;
300
301
302 #if ORTHANC_ENABLE_SDL == 1 309 #if ORTHANC_ENABLE_SDL == 1
310 template<typename Func>
311 struct EventHandlerData
312 {
313 EventHandlerData(std::string canvasName, Func func, void* userData)
314 : canvasName(canvasName)
315 , func(func)
316 , userData(userData)
317 {
318 }
319
320 std::string canvasName;
321 Func func;
322 void* userData;
323 };
324 std::vector<EventHandlerData<OnWindowResizeFunc> > resizeHandlers_;
325 std::vector<EventHandlerData<OnMouseEventFunc > > mouseDownHandlers_;
326 std::vector<EventHandlerData<OnMouseEventFunc > > mouseMoveHandlers_;
327 std::vector<EventHandlerData<OnMouseEventFunc > > mouseUpHandlers_;
328 std::vector<EventHandlerData<OnMouseWheelFunc > > mouseWheelHandlers_;
329
303 330
304 /** 331 /**
305 This executes all the registered headers if needed (in wasm, the browser 332 This executes all the registered headers if needed (in wasm, the browser
306 deals with this) 333 deals with this)
307 */ 334 */
308 void OnMouseEvent(uint32_t windowID, const GuiAdapterMouseEvent& event); 335 void OnMouseEvent(uint32_t windowID, const GuiAdapterMouseEvent& event);
336
337 /**
338 Same remark as OnMouseEvent
339 */
340 void OnMouseWheelEvent(uint32_t windowID, const GuiAdapterWheelEvent& event);
341
342 boost::shared_ptr<IGuiAdapterWidget> GetWidgetFromWindowId();
343
309 #endif 344 #endif
310 345
311 /** 346 /**
312 This executes all the registered headers if needed (in wasm, the browser 347 This executes all the registered headers if needed (in wasm, the browser
313 deals with this) 348 deals with this)