From 7b4511a5df0cee641088085a19486b6f884a2277 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 20 Apr 2016 22:49:03 -0300 Subject: [PATCH] Unify she::InputDevice and ui::PointerType --- src/she/event.h | 19 ++++++------------- src/she/pointer_type.h | 23 +++++++++++++++++++++++ src/she/win/window.h | 34 +++++++++++++++++----------------- src/ui/manager.cpp | 24 ++++++------------------ src/ui/pointer_type.h | 10 +++------- 5 files changed, 55 insertions(+), 55 deletions(-) create mode 100644 src/she/pointer_type.h diff --git a/src/she/event.h b/src/she/event.h index 8d280cc4c..ed9415e1d 100644 --- a/src/she/event.h +++ b/src/she/event.h @@ -11,6 +11,7 @@ #include "gfx/point.h" #include "gfx/size.h" #include "she/keys.h" +#include "she/pointer_type.h" #include #include @@ -41,14 +42,6 @@ namespace she { TouchMagnify, }; - enum InputDevice { - UnknownDevice, - MouseDevice, - MultitouchDevice, // Multitouch device with finger gestures - StylusDevice, // Pen/stylus device - EraserDevice, // Inverted-stylus device - }; - enum MouseButton { NoneButton, LeftButton, @@ -65,7 +58,7 @@ namespace she { m_unicodeChar(0), m_repeat(0), m_preciseWheel(false), - m_device(UnknownDevice), + m_pointerType(PointerType::Unknown), m_button(NoneButton), m_magnification(0.0), m_pressure(0.0) { @@ -84,10 +77,10 @@ namespace she { // We suppose that if we are receiving precise scrolling deltas, // it means that the user is using a touch-like surface (trackpad, // magic mouse scrolling, touch wacom tablet, etc.) - // TODO change this with the new InputDevice::MultitouchDevice + // TODO change this with the new PointerType::Multitouch bool preciseWheel() const { return m_preciseWheel; } - InputDevice device() const { return m_device; } + PointerType pointerType() const { return m_pointerType; } MouseButton button() const { return m_button; } double magnification() const { return m_magnification; } double pressure() const { return m_pressure; } @@ -103,7 +96,7 @@ namespace she { void setPosition(const gfx::Point& pos) { m_position = pos; } void setWheelDelta(const gfx::Point& delta) { m_wheelDelta = delta; } void setPreciseWheel(bool precise) { m_preciseWheel = precise; } - void setDevice(InputDevice device) { m_device = device; } + void setPointerType(PointerType pointerType) { m_pointerType = pointerType; } void setButton(MouseButton button) { m_button = button; } void setMagnification(double magnification) { m_magnification = magnification; } void setPressure(double pressure) { m_pressure = pressure; } @@ -119,7 +112,7 @@ namespace she { gfx::Point m_position; gfx::Point m_wheelDelta; bool m_preciseWheel; - InputDevice m_device; + PointerType m_pointerType; MouseButton m_button; // For TouchMagnify event diff --git a/src/she/pointer_type.h b/src/she/pointer_type.h new file mode 100644 index 000000000..7e4f2c780 --- /dev/null +++ b/src/she/pointer_type.h @@ -0,0 +1,23 @@ +// SHE library +// Copyright (C) 2016 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. + +#ifndef SHE_POINTER_TYPE_H_INCLUDED +#define SHE_POINTER_TYPE_H_INCLUDED +#pragma once + +namespace she { + + enum class PointerType { + Unknown, + Mouse, + Multitouch, + Pen, + Eraser + }; + +} // namespace she + +#endif diff --git a/src/she/win/window.h b/src/she/win/window.h index e58f804e0..00c0096e7 100644 --- a/src/she/win/window.h +++ b/src/she/win/window.h @@ -43,7 +43,7 @@ namespace she { , m_hasMouse(false) , m_captureMouse(false) , m_hpenctx(nullptr) - , m_device(Event::UnknownDevice) + , m_pointerType(PointerType::Unknown) , m_pressure(0.0) { registerClass(); m_hwnd = createHwnd(this, width, height); @@ -325,8 +325,8 @@ namespace she { _TrackMouseEvent(&tme); } - if (m_device != Event::UnknownDevice) { - ev.setDevice(m_device); + if (m_pointerType != PointerType::Unknown) { + ev.setPointerType(m_pointerType); ev.setPressure(m_pressure); } @@ -361,8 +361,8 @@ namespace she { msg == WM_RBUTTONDOWN ? Event::RightButton: msg == WM_MBUTTONDOWN ? Event::MiddleButton: Event::NoneButton); - if (m_device != Event::UnknownDevice) { - ev.setDevice(m_device); + if (m_pointerType != PointerType::Unknown) { + ev.setPointerType(m_pointerType); ev.setPressure(m_pressure); } @@ -384,8 +384,8 @@ namespace she { msg == WM_RBUTTONUP ? Event::RightButton: msg == WM_MBUTTONUP ? Event::MiddleButton: Event::NoneButton); - if (m_device != Event::UnknownDevice) { - ev.setDevice(m_device); + if (m_pointerType != PointerType::Unknown) { + ev.setPointerType(m_pointerType); ev.setPressure(m_pressure); } @@ -412,8 +412,8 @@ namespace she { msg == WM_RBUTTONDBLCLK ? Event::RightButton: msg == WM_MBUTTONDBLCLK ? Event::MiddleButton: Event::NoneButton); - if (m_device != Event::UnknownDevice) { - ev.setDevice(m_device); + if (m_pointerType != PointerType::Unknown) { + ev.setPointerType(m_pointerType); ev.setPressure(m_pressure); } @@ -613,7 +613,7 @@ namespace she { case WT_PROXIMITY: { bool entering_ctx = (LOWORD(lparam) ? true: false); if (!entering_ctx) - m_device = Event::UnknownDevice; + m_pointerType = PointerType::Unknown; break; } @@ -625,12 +625,12 @@ namespace she { if (api.packet(ctx, serial, &packet)) { if (packet.pkCursor == 2 || packet.pkCursor == 5) - m_device = Event::EraserDevice; + m_pointerType = PointerType::Eraser; else - m_device = Event::StylusDevice; + m_pointerType = PointerType::Pen; } else - m_device = Event::UnknownDevice; + m_pointerType = PointerType::Unknown; } case WT_PACKET: { @@ -643,12 +643,12 @@ namespace she { m_pressure = packet.pkNormalPressure / 1000.0; // TODO get the maximum value if (packet.pkCursor == 2 || packet.pkCursor == 5) - m_device = Event::EraserDevice; + m_pointerType = PointerType::Eraser; else - m_device = Event::StylusDevice; + m_pointerType = PointerType::Pen; } else - m_device = Event::UnknownDevice; + m_pointerType = PointerType::Unknown; break; } @@ -755,7 +755,7 @@ namespace she { // Wintab API data HCTX m_hpenctx; - Event::InputDevice m_device; + PointerType m_pointerType; double m_pressure; }; diff --git a/src/ui/manager.cpp b/src/ui/manager.cpp index 3d0b9bff6..7f3ea7abc 100644 --- a/src/ui/manager.cpp +++ b/src/ui/manager.cpp @@ -276,18 +276,6 @@ static MouseButtons mouse_buttons_from_she_to_ui(const she::Event& sheEvent) } } -static PointerType pointer_type_from_she_event(const she::Event& sheEvent) -{ - switch (sheEvent.device()) { - case she::Event::MouseDevice: return PointerType::Mouse; break; - case she::Event::MultitouchDevice: return PointerType::Multitouch; break; - case she::Event::StylusDevice: return PointerType::Pen; break; - case she::Event::EraserDevice: return PointerType::Eraser; break; - default: - return PointerType::Unknown; - } -} - void Manager::generateMessagesFromSheEvents() { she::Event lastMouseMoveEvent; @@ -365,7 +353,7 @@ void Manager::generateMessagesFromSheEvents() sheEvent.position(), m_mouseButtons, sheEvent.modifiers(), - pointer_type_from_she_event(sheEvent)); + sheEvent.pointerType()); lastMouseMoveEvent = sheEvent; break; } @@ -379,7 +367,7 @@ void Manager::generateMessagesFromSheEvents() sheEvent.position(), pressedButton, sheEvent.modifiers(), - pointer_type_from_she_event(sheEvent)); + sheEvent.pointerType()); break; } @@ -392,7 +380,7 @@ void Manager::generateMessagesFromSheEvents() sheEvent.position(), releasedButton, sheEvent.modifiers(), - pointer_type_from_she_event(sheEvent)); + sheEvent.pointerType()); break; } @@ -402,14 +390,14 @@ void Manager::generateMessagesFromSheEvents() sheEvent.position(), clickedButton, sheEvent.modifiers(), - pointer_type_from_she_event(sheEvent)); + sheEvent.pointerType()); break; } case she::Event::MouseWheel: { handleMouseWheel(sheEvent.position(), m_mouseButtons, sheEvent.modifiers(), - pointer_type_from_she_event(sheEvent), + sheEvent.pointerType(), sheEvent.wheelDelta(), sheEvent.preciseWheel()); break; @@ -432,7 +420,7 @@ void Manager::generateMessagesFromSheEvents() sheEvent = lastMouseMoveEvent; generateSetCursorMessage(sheEvent.position(), sheEvent.modifiers(), - pointer_type_from_she_event(sheEvent)); + sheEvent.pointerType()); } } diff --git a/src/ui/pointer_type.h b/src/ui/pointer_type.h index 8a179288a..09740e559 100644 --- a/src/ui/pointer_type.h +++ b/src/ui/pointer_type.h @@ -8,15 +8,11 @@ #define UI_POINTER_TYPE_H_INCLUDED #pragma once +#include "she/pointer_type.h" + namespace ui { - enum class PointerType { - Unknown, - Mouse, - Multitouch, - Pen, - Eraser - }; + typedef she::PointerType PointerType; } // namespace ui