Unify she::InputDevice and ui::PointerType

This commit is contained in:
David Capello 2016-04-20 22:49:03 -03:00
parent a58cbfbc1c
commit 7b4511a5df
5 changed files with 55 additions and 55 deletions

View File

@ -11,6 +11,7 @@
#include "gfx/point.h" #include "gfx/point.h"
#include "gfx/size.h" #include "gfx/size.h"
#include "she/keys.h" #include "she/keys.h"
#include "she/pointer_type.h"
#include <string> #include <string>
#include <vector> #include <vector>
@ -41,14 +42,6 @@ namespace she {
TouchMagnify, TouchMagnify,
}; };
enum InputDevice {
UnknownDevice,
MouseDevice,
MultitouchDevice, // Multitouch device with finger gestures
StylusDevice, // Pen/stylus device
EraserDevice, // Inverted-stylus device
};
enum MouseButton { enum MouseButton {
NoneButton, NoneButton,
LeftButton, LeftButton,
@ -65,7 +58,7 @@ namespace she {
m_unicodeChar(0), m_unicodeChar(0),
m_repeat(0), m_repeat(0),
m_preciseWheel(false), m_preciseWheel(false),
m_device(UnknownDevice), m_pointerType(PointerType::Unknown),
m_button(NoneButton), m_button(NoneButton),
m_magnification(0.0), m_magnification(0.0),
m_pressure(0.0) { m_pressure(0.0) {
@ -84,10 +77,10 @@ namespace she {
// We suppose that if we are receiving precise scrolling deltas, // We suppose that if we are receiving precise scrolling deltas,
// it means that the user is using a touch-like surface (trackpad, // it means that the user is using a touch-like surface (trackpad,
// magic mouse scrolling, touch wacom tablet, etc.) // 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; } bool preciseWheel() const { return m_preciseWheel; }
InputDevice device() const { return m_device; } PointerType pointerType() const { return m_pointerType; }
MouseButton button() const { return m_button; } MouseButton button() const { return m_button; }
double magnification() const { return m_magnification; } double magnification() const { return m_magnification; }
double pressure() const { return m_pressure; } double pressure() const { return m_pressure; }
@ -103,7 +96,7 @@ namespace she {
void setPosition(const gfx::Point& pos) { m_position = pos; } void setPosition(const gfx::Point& pos) { m_position = pos; }
void setWheelDelta(const gfx::Point& delta) { m_wheelDelta = delta; } void setWheelDelta(const gfx::Point& delta) { m_wheelDelta = delta; }
void setPreciseWheel(bool precise) { m_preciseWheel = precise; } 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 setButton(MouseButton button) { m_button = button; }
void setMagnification(double magnification) { m_magnification = magnification; } void setMagnification(double magnification) { m_magnification = magnification; }
void setPressure(double pressure) { m_pressure = pressure; } void setPressure(double pressure) { m_pressure = pressure; }
@ -119,7 +112,7 @@ namespace she {
gfx::Point m_position; gfx::Point m_position;
gfx::Point m_wheelDelta; gfx::Point m_wheelDelta;
bool m_preciseWheel; bool m_preciseWheel;
InputDevice m_device; PointerType m_pointerType;
MouseButton m_button; MouseButton m_button;
// For TouchMagnify event // For TouchMagnify event

23
src/she/pointer_type.h Normal file
View File

@ -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

View File

@ -43,7 +43,7 @@ namespace she {
, m_hasMouse(false) , m_hasMouse(false)
, m_captureMouse(false) , m_captureMouse(false)
, m_hpenctx(nullptr) , m_hpenctx(nullptr)
, m_device(Event::UnknownDevice) , m_pointerType(PointerType::Unknown)
, m_pressure(0.0) { , m_pressure(0.0) {
registerClass(); registerClass();
m_hwnd = createHwnd(this, width, height); m_hwnd = createHwnd(this, width, height);
@ -325,8 +325,8 @@ namespace she {
_TrackMouseEvent(&tme); _TrackMouseEvent(&tme);
} }
if (m_device != Event::UnknownDevice) { if (m_pointerType != PointerType::Unknown) {
ev.setDevice(m_device); ev.setPointerType(m_pointerType);
ev.setPressure(m_pressure); ev.setPressure(m_pressure);
} }
@ -361,8 +361,8 @@ namespace she {
msg == WM_RBUTTONDOWN ? Event::RightButton: msg == WM_RBUTTONDOWN ? Event::RightButton:
msg == WM_MBUTTONDOWN ? Event::MiddleButton: Event::NoneButton); msg == WM_MBUTTONDOWN ? Event::MiddleButton: Event::NoneButton);
if (m_device != Event::UnknownDevice) { if (m_pointerType != PointerType::Unknown) {
ev.setDevice(m_device); ev.setPointerType(m_pointerType);
ev.setPressure(m_pressure); ev.setPressure(m_pressure);
} }
@ -384,8 +384,8 @@ namespace she {
msg == WM_RBUTTONUP ? Event::RightButton: msg == WM_RBUTTONUP ? Event::RightButton:
msg == WM_MBUTTONUP ? Event::MiddleButton: Event::NoneButton); msg == WM_MBUTTONUP ? Event::MiddleButton: Event::NoneButton);
if (m_device != Event::UnknownDevice) { if (m_pointerType != PointerType::Unknown) {
ev.setDevice(m_device); ev.setPointerType(m_pointerType);
ev.setPressure(m_pressure); ev.setPressure(m_pressure);
} }
@ -412,8 +412,8 @@ namespace she {
msg == WM_RBUTTONDBLCLK ? Event::RightButton: msg == WM_RBUTTONDBLCLK ? Event::RightButton:
msg == WM_MBUTTONDBLCLK ? Event::MiddleButton: Event::NoneButton); msg == WM_MBUTTONDBLCLK ? Event::MiddleButton: Event::NoneButton);
if (m_device != Event::UnknownDevice) { if (m_pointerType != PointerType::Unknown) {
ev.setDevice(m_device); ev.setPointerType(m_pointerType);
ev.setPressure(m_pressure); ev.setPressure(m_pressure);
} }
@ -613,7 +613,7 @@ namespace she {
case WT_PROXIMITY: { case WT_PROXIMITY: {
bool entering_ctx = (LOWORD(lparam) ? true: false); bool entering_ctx = (LOWORD(lparam) ? true: false);
if (!entering_ctx) if (!entering_ctx)
m_device = Event::UnknownDevice; m_pointerType = PointerType::Unknown;
break; break;
} }
@ -625,12 +625,12 @@ namespace she {
if (api.packet(ctx, serial, &packet)) { if (api.packet(ctx, serial, &packet)) {
if (packet.pkCursor == 2 || packet.pkCursor == 5) if (packet.pkCursor == 2 || packet.pkCursor == 5)
m_device = Event::EraserDevice; m_pointerType = PointerType::Eraser;
else else
m_device = Event::StylusDevice; m_pointerType = PointerType::Pen;
} }
else else
m_device = Event::UnknownDevice; m_pointerType = PointerType::Unknown;
} }
case WT_PACKET: { case WT_PACKET: {
@ -643,12 +643,12 @@ namespace she {
m_pressure = packet.pkNormalPressure / 1000.0; // TODO get the maximum value m_pressure = packet.pkNormalPressure / 1000.0; // TODO get the maximum value
if (packet.pkCursor == 2 || packet.pkCursor == 5) if (packet.pkCursor == 2 || packet.pkCursor == 5)
m_device = Event::EraserDevice; m_pointerType = PointerType::Eraser;
else else
m_device = Event::StylusDevice; m_pointerType = PointerType::Pen;
} }
else else
m_device = Event::UnknownDevice; m_pointerType = PointerType::Unknown;
break; break;
} }
@ -755,7 +755,7 @@ namespace she {
// Wintab API data // Wintab API data
HCTX m_hpenctx; HCTX m_hpenctx;
Event::InputDevice m_device; PointerType m_pointerType;
double m_pressure; double m_pressure;
}; };

View File

@ -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() void Manager::generateMessagesFromSheEvents()
{ {
she::Event lastMouseMoveEvent; she::Event lastMouseMoveEvent;
@ -365,7 +353,7 @@ void Manager::generateMessagesFromSheEvents()
sheEvent.position(), sheEvent.position(),
m_mouseButtons, m_mouseButtons,
sheEvent.modifiers(), sheEvent.modifiers(),
pointer_type_from_she_event(sheEvent)); sheEvent.pointerType());
lastMouseMoveEvent = sheEvent; lastMouseMoveEvent = sheEvent;
break; break;
} }
@ -379,7 +367,7 @@ void Manager::generateMessagesFromSheEvents()
sheEvent.position(), sheEvent.position(),
pressedButton, pressedButton,
sheEvent.modifiers(), sheEvent.modifiers(),
pointer_type_from_she_event(sheEvent)); sheEvent.pointerType());
break; break;
} }
@ -392,7 +380,7 @@ void Manager::generateMessagesFromSheEvents()
sheEvent.position(), sheEvent.position(),
releasedButton, releasedButton,
sheEvent.modifiers(), sheEvent.modifiers(),
pointer_type_from_she_event(sheEvent)); sheEvent.pointerType());
break; break;
} }
@ -402,14 +390,14 @@ void Manager::generateMessagesFromSheEvents()
sheEvent.position(), sheEvent.position(),
clickedButton, clickedButton,
sheEvent.modifiers(), sheEvent.modifiers(),
pointer_type_from_she_event(sheEvent)); sheEvent.pointerType());
break; break;
} }
case she::Event::MouseWheel: { case she::Event::MouseWheel: {
handleMouseWheel(sheEvent.position(), m_mouseButtons, handleMouseWheel(sheEvent.position(), m_mouseButtons,
sheEvent.modifiers(), sheEvent.modifiers(),
pointer_type_from_she_event(sheEvent), sheEvent.pointerType(),
sheEvent.wheelDelta(), sheEvent.wheelDelta(),
sheEvent.preciseWheel()); sheEvent.preciseWheel());
break; break;
@ -432,7 +420,7 @@ void Manager::generateMessagesFromSheEvents()
sheEvent = lastMouseMoveEvent; sheEvent = lastMouseMoveEvent;
generateSetCursorMessage(sheEvent.position(), generateSetCursorMessage(sheEvent.position(),
sheEvent.modifiers(), sheEvent.modifiers(),
pointer_type_from_she_event(sheEvent)); sheEvent.pointerType());
} }
} }

View File

@ -8,15 +8,11 @@
#define UI_POINTER_TYPE_H_INCLUDED #define UI_POINTER_TYPE_H_INCLUDED
#pragma once #pragma once
#include "she/pointer_type.h"
namespace ui { namespace ui {
enum class PointerType { typedef she::PointerType PointerType;
Unknown,
Mouse,
Multitouch,
Pen,
Eraser
};
} // namespace ui } // namespace ui