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/size.h"
#include "she/keys.h"
#include "she/pointer_type.h"
#include <string>
#include <vector>
@ -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

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_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;
};

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()
{
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());
}
}

View File

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