Add Wacom eraser support on OS X

This commit is contained in:
David Capello 2016-04-21 13:13:15 -03:00
parent 119c87873f
commit 9b05d2e8ef
2 changed files with 37 additions and 2 deletions

View File

@ -1,5 +1,5 @@
// SHE library
// Copyright (C) 2015 David Capello
// Copyright (C) 2015-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -8,6 +8,8 @@
#define SHE_OSX_VIEW_H_INCLUDED
#pragma once
#include "she/pointer_type.h"
#include <Cocoa/Cocoa.h>
@interface OSXView : NSView {
@ -15,6 +17,7 @@
NSTrackingArea* m_trackingArea;
NSCursor* m_nsCursor;
bool m_visibleMouse;
she::PointerType m_pointerType;
}
- (id)initWithFrame:(NSRect)frameRect;
- (BOOL)acceptsFirstResponder;

View File

@ -92,6 +92,7 @@ bool is_key_pressed(KeyScancode scancode)
{
m_nsCursor = [NSCursor arrowCursor];
m_visibleMouse = true;
m_pointerType = she::PointerType::Unknown;
self = [super initWithFrame:frameRect];
if (self != nil) {
@ -307,6 +308,10 @@ bool is_key_pressed(KeyScancode scancode)
ev.setPosition(get_local_mouse_pos(self, event));
ev.setButton(get_mouse_buttons(event));
ev.setModifiers(get_modifiers_from_nsevent(event));
if (m_pointerType != she::PointerType::Unknown)
ev.setPointerType(m_pointerType);
queue_event(ev);
}
@ -317,6 +322,10 @@ bool is_key_pressed(KeyScancode scancode)
ev.setPosition(get_local_mouse_pos(self, event));
ev.setButton(get_mouse_buttons(event));
ev.setModifiers(get_modifiers_from_nsevent(event));
if (m_pointerType != she::PointerType::Unknown)
ev.setPointerType(m_pointerType);
queue_event(ev);
}
@ -327,6 +336,10 @@ bool is_key_pressed(KeyScancode scancode)
ev.setPosition(get_local_mouse_pos(self, event));
ev.setButton(get_mouse_buttons(event));
ev.setModifiers(get_modifiers_from_nsevent(event));
if (m_pointerType != she::PointerType::Unknown)
ev.setPointerType(m_pointerType);
queue_event(ev);
}
@ -360,11 +373,13 @@ bool is_key_pressed(KeyScancode scancode)
scale = [(OSXWindow*)self.window scale];
if (event.hasPreciseScrollingDeltas) {
ev.setPointerType(she::PointerType::Multitouch);
ev.setWheelDelta(gfx::Point(-event.scrollingDeltaX / scale,
-event.scrollingDeltaY / scale));
ev.setPreciseWheel(true);
}
else {
ev.setPointerType(she::PointerType::Mouse);
ev.setWheelDelta(gfx::Point(-event.scrollingDeltaX,
-event.scrollingDeltaY));
}
@ -379,10 +394,27 @@ bool is_key_pressed(KeyScancode scancode)
ev.setMagnification(event.magnification);
ev.setPosition(get_local_mouse_pos(self, event));
ev.setModifiers(get_modifiers_from_nsevent(event));
ev.setPointerType(she::PointerType::Multitouch);
queue_event(ev);
}
- (void)tabletProximity:(NSEvent*)event
{
if (event.isEnteringProximity == YES) {
switch (event.pointingDeviceType) {
case NSPenPointingDevice: m_pointerType = she::PointerType::Pen; break;
case NSCursorPointingDevice: m_pointerType = she::PointerType::Cursor; break;
case NSEraserPointingDevice: m_pointerType = she::PointerType::Eraser; break;
default:
m_pointerType = she::PointerType::Unknown;
break;
}
}
else {
m_pointerType = she::PointerType::Unknown;
}
}
- (void)cursorUpdate:(NSEvent*)event
{
[self updateCurrentCursor];