mirror of
https://github.com/glfw/glfw.git
synced 2025-10-03 21:30:57 +00:00
Add pen tablet support for OSX cocoa
This commit is contained in:
parent
fa5882eb54
commit
bd7ce80369
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -439,6 +440,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
|
|||||||
|
|
||||||
- (void)mouseDown:(NSEvent *)event
|
- (void)mouseDown:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
[self handlePenTablet:event];
|
||||||
_glfwInputMouseClick(window,
|
_glfwInputMouseClick(window,
|
||||||
GLFW_MOUSE_BUTTON_LEFT,
|
GLFW_MOUSE_BUTTON_LEFT,
|
||||||
GLFW_PRESS,
|
GLFW_PRESS,
|
||||||
@ -452,14 +454,70 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
|
|||||||
|
|
||||||
- (void)mouseUp:(NSEvent *)event
|
- (void)mouseUp:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
[self handlePenTablet:event];
|
||||||
_glfwInputMouseClick(window,
|
_glfwInputMouseClick(window,
|
||||||
GLFW_MOUSE_BUTTON_LEFT,
|
GLFW_MOUSE_BUTTON_LEFT,
|
||||||
GLFW_RELEASE,
|
GLFW_RELEASE,
|
||||||
translateFlags([event modifierFlags]));
|
translateFlags([event modifierFlags]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)handlePenTablet:(NSEvent *)event
|
||||||
|
{
|
||||||
|
if ([window->ns.object isKeyWindow])
|
||||||
|
{
|
||||||
|
if ([event subtype] == NSTabletPointEventSubtype)
|
||||||
|
{
|
||||||
|
const double pressure = [event pressure];
|
||||||
|
const NSPoint tilt = [event tilt];
|
||||||
|
const NSPoint pos = [NSEvent mouseLocation];
|
||||||
|
const double posz = [event absoluteZ];
|
||||||
|
|
||||||
|
double tx = tilt.x * 1.5707963267949;
|
||||||
|
double ty = tilt.y * 1.5707963267949;
|
||||||
|
|
||||||
|
double sinx = sin(tx);
|
||||||
|
double siny = sin(ty);
|
||||||
|
double cosx = cos(tx);
|
||||||
|
double cosy = cos(ty);
|
||||||
|
/*double matrix[9] = { // full matrix for reference
|
||||||
|
0.0, -cosy, siny,
|
||||||
|
cosx, -sinx*siny, -sinx*cosy,
|
||||||
|
sinx, cosx*siny, cosx*cosy
|
||||||
|
};*/
|
||||||
|
double v[3] = {sinx, cosx*siny, cosx*cosy};
|
||||||
|
double yaw = atan2(v[0], v[1]);
|
||||||
|
double pitch = 3.141592653589793 - acos(v[2]);
|
||||||
|
if (yaw < 0.0) yaw += 6.28318530717959;
|
||||||
|
|
||||||
|
_glfwInputPenTabletData(
|
||||||
|
pos.x,
|
||||||
|
transformY(pos.y),
|
||||||
|
posz / 1024.0,
|
||||||
|
pressure,
|
||||||
|
pitch,
|
||||||
|
yaw,
|
||||||
|
0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([event subtype] == NSTabletProximityEventSubtype)
|
||||||
|
{
|
||||||
|
static unsigned int s_cursor = 0;
|
||||||
|
unsigned int cursor = [event pointingDeviceType];
|
||||||
|
|
||||||
|
_glfwInputPenTabletProximity([event isEnteringProximity]);
|
||||||
|
if (cursor != s_cursor)
|
||||||
|
{
|
||||||
|
_glfwInputPenTabletCursor(cursor);
|
||||||
|
s_cursor = cursor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)mouseMoved:(NSEvent *)event
|
- (void)mouseMoved:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
[self handlePenTablet:event];
|
||||||
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
||||||
{
|
{
|
||||||
const double dx = [event deltaX] - window->ns.cursorWarpDeltaX;
|
const double dx = [event deltaX] - window->ns.cursorWarpDeltaX;
|
||||||
@ -483,6 +541,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
|
|||||||
|
|
||||||
- (void)rightMouseDown:(NSEvent *)event
|
- (void)rightMouseDown:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
[self handlePenTablet:event];
|
||||||
_glfwInputMouseClick(window,
|
_glfwInputMouseClick(window,
|
||||||
GLFW_MOUSE_BUTTON_RIGHT,
|
GLFW_MOUSE_BUTTON_RIGHT,
|
||||||
GLFW_PRESS,
|
GLFW_PRESS,
|
||||||
@ -496,6 +555,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
|
|||||||
|
|
||||||
- (void)rightMouseUp:(NSEvent *)event
|
- (void)rightMouseUp:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
[self handlePenTablet:event];
|
||||||
_glfwInputMouseClick(window,
|
_glfwInputMouseClick(window,
|
||||||
GLFW_MOUSE_BUTTON_RIGHT,
|
GLFW_MOUSE_BUTTON_RIGHT,
|
||||||
GLFW_RELEASE,
|
GLFW_RELEASE,
|
||||||
@ -504,6 +564,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
|
|||||||
|
|
||||||
- (void)otherMouseDown:(NSEvent *)event
|
- (void)otherMouseDown:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
[self handlePenTablet:event];
|
||||||
_glfwInputMouseClick(window,
|
_glfwInputMouseClick(window,
|
||||||
(int) [event buttonNumber],
|
(int) [event buttonNumber],
|
||||||
GLFW_PRESS,
|
GLFW_PRESS,
|
||||||
@ -517,6 +578,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
|
|||||||
|
|
||||||
- (void)otherMouseUp:(NSEvent *)event
|
- (void)otherMouseUp:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
[self handlePenTablet:event];
|
||||||
_glfwInputMouseClick(window,
|
_glfwInputMouseClick(window,
|
||||||
(int) [event buttonNumber],
|
(int) [event buttonNumber],
|
||||||
GLFW_RELEASE,
|
GLFW_RELEASE,
|
||||||
|
Loading…
Reference in New Issue
Block a user