This commit is contained in:
Raja Lehtihet 2018-01-10 02:12:02 +00:00 committed by GitHub
commit fb87fda026
11 changed files with 1019 additions and 746 deletions

1
.gitignore vendored
View File

@ -82,3 +82,4 @@ tests/title
tests/vulkan tests/vulkan
tests/windows tests/windows
/build

View File

@ -1318,6 +1318,24 @@ typedef void (* GLFWwindowcontentscalefun)(GLFWwindow*,float,float);
*/ */
typedef void (* GLFWmousebuttonfun)(GLFWwindow*,int,int,int); typedef void (* GLFWmousebuttonfun)(GLFWwindow*,int,int,int);
/*! @brief The function signature for pen callbacks.
*
* This is the function signature for pen callback functions.
*
* @param[in] window The window that received the event.
* @param[in] pressure The [pen pressure](@ref pressure) that was pressed or
* released.
* @param[in] the x (horizontal point) coordinate of the point location of the pen.
* @param[in] the y (vertical point) coordinate of the point location of the pen.
* *
* @sa @ref input_pen_pressure
* @sa @ref glfwSetPenPressureCallback
*
* @ingroup input
*/
typedef void(*GLFWpenpressurefun)(GLFWwindow*, double, int, int);
/*! @brief The function signature for cursor position callbacks. /*! @brief The function signature for cursor position callbacks.
* *
* This is the function signature for cursor position callback functions. * This is the function signature for cursor position callback functions.
@ -1390,6 +1408,7 @@ typedef void (* GLFWscrollfun)(GLFWwindow*,double,double);
* *
* @ingroup input * @ingroup input
*/ */
typedef void (* GLFWkeyfun)(GLFWwindow*,int,int,int,int); typedef void (* GLFWkeyfun)(GLFWwindow*,int,int,int,int);
/*! @brief The function signature for Unicode character callbacks. /*! @brief The function signature for Unicode character callbacks.
@ -4014,7 +4033,32 @@ GLFWAPI int glfwGetKey(GLFWwindow* window, int key);
* *
* @ingroup input * @ingroup input
*/ */
GLFWAPI int glfwGetMouseButton(GLFWwindow* window, int button); GLFWAPI int glfwGetMouseButton(GLFWwindow* handle, int button);
/*! @brief Returns the last reported state of a pen button for the specified
* window.
*
* This function returns the last state reported for the specified pen button
* to the specified window. The returned state is one of `GLFW_PRESS` or
* `GLFW_RELEASE`.
*
* @param[in] window The desired window.
* @param[in] button The desired [pen button](@ref pen buttons).
* @return One of `GLFW_PRESS` or `GLFW_RELEASE`.
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_INVALID_ENUM.
*
* @thread_safety This function must only be called from the main thread.
*
* @sa @ref input_pen_button
*
* @since Added in version 1.0.
* @glfw3 Added window handle parameter.
*
* @ingroup input
*/
GLFWAPI double glfwGetPenPressure(GLFWwindow* handle);
/*! @brief Retrieves the position of the cursor relative to the client area of /*! @brief Retrieves the position of the cursor relative to the client area of
* the window. * the window.
@ -4354,6 +4398,27 @@ GLFWAPI GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* window, GLFWcharmods
* @ingroup input * @ingroup input
*/ */
GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun cbfun); GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun cbfun);
/*! @brief Sets the pen callback.
*
* This function sets the pen callback of the specified window, which
* is called when a pen is pressed or released.
**
* @param[in] window The window whose callback to set.
* @param[in] cbfun The new callback, or `NULL` to remove the currently set
* callback.
* @return The previously set callback, or `NULL` if no callback was set or the
* library had not been [initialized](@ref intro_init).
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
*
* @thread_safety This function must only be called from the main thread.
*
* @sa @ref input_pen_pressure
*
*
* @ingroup input
*/
GLFWAPI GLFWpenpressurefun glfwSetPenPressureCallback(GLFWwindow* window, GLFWpenpressurefun cbfun);
/*! @brief Sets the cursor position callback. /*! @brief Sets the cursor position callback.
* *

View File

@ -293,6 +293,16 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
window->callbacks.mouseButton((GLFWwindow*) window, button, action, mods); window->callbacks.mouseButton((GLFWwindow*) window, button, action, mods);
} }
void _glfwInputPenPressure(_GLFWwindow* window, double pressure, int x, int y)
{
window->penPressure = pressure;
window->penXposition = x;
window->penYposition = y;
if (window->callbacks.penPressure)
window->callbacks.penPressure((GLFWwindow*)window, pressure, x, y);
}
void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos) void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos)
{ {
if (window->virtualCursorPosX == xpos && window->virtualCursorPosY == ypos) if (window->virtualCursorPosX == xpos && window->virtualCursorPosY == ypos)
@ -578,6 +588,19 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow* handle, int button)
return (int) window->mouseButtons[button]; return (int) window->mouseButtons[button];
} }
/***************************PEN**************************************************/
GLFWAPI double glfwGetPenPressure(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*)handle;
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(0);
return window->penPressure;
}
/**************************PEN***************************************************/
GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, double* xpos, double* ypos) GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, double* xpos, double* ypos)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
@ -773,6 +796,17 @@ GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* handle,
return cbfun; return cbfun;
} }
GLFWAPI GLFWpenpressurefun glfwSetPenPressureCallback(GLFWwindow* handle,
GLFWpenpressurefun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*)handle;
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.penPressure, cbfun);
return cbfun;
}
GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* handle, GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* handle,
GLFWcursorposfun cbfun) GLFWcursorposfun cbfun)
{ {

View File

@ -419,7 +419,13 @@ struct _GLFWwindow
GLFWbool stickyKeys; GLFWbool stickyKeys;
GLFWbool stickyMouseButtons; GLFWbool stickyMouseButtons;
double penPressure;
int penXposition;
int penYposition;
GLFWbool lockKeyMods; GLFWbool lockKeyMods;
int cursorMode; int cursorMode;
char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1]; char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
char keys[GLFW_KEY_LAST + 1]; char keys[GLFW_KEY_LAST + 1];
@ -439,6 +445,7 @@ struct _GLFWwindow
GLFWframebuffersizefun fbsize; GLFWframebuffersizefun fbsize;
GLFWwindowcontentscalefun scale; GLFWwindowcontentscalefun scale;
GLFWmousebuttonfun mouseButton; GLFWmousebuttonfun mouseButton;
GLFWpenpressurefun penPressure;
GLFWcursorposfun cursorPos; GLFWcursorposfun cursorPos;
GLFWcursorenterfun cursorEnter; GLFWcursorenterfun cursorEnter;
GLFWscrollfun scroll; GLFWscrollfun scroll;
@ -835,6 +842,15 @@ void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset);
*/ */
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods); void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods);
/*! @brief Notifies shared code of a pen click event.
* @param[in] window The window that received the event.
* @param[in] pressure when the pen was pressed.
* @param[in] x (horizontal point) coordinate of the point location of the pen.
* @param[in] y (vertical point) coordinate of the point location of the pen.
* @ingroup event
*/
void _glfwInputPenPressure(_GLFWwindow* window, double pressure, int x, int y);
/*! @brief Notifies shared code of a cursor motion event. /*! @brief Notifies shared code of a cursor motion event.
* @param[in] window The window that received the event. * @param[in] window The window that received the event.
* @param[in] xpos The new x-coordinate of the cursor, relative to the left * @param[in] xpos The new x-coordinate of the cursor, relative to the left

View File

@ -104,6 +104,89 @@
#define _WIN32_WINNT_WINBLUE 0x0602 #define _WIN32_WINNT_WINBLUE 0x0602
#endif #endif
#if WINVER < 0x0604
#define WM_POINTERUPDATE 0x0245
#define WM_POINTERDOWN 0x0246
#define WM_POINTERUP 0x0247
#define POINTER_MESSAGE_FLAG_INCONTACT 0x00000004 // Pointer is in contact
#define GET_POINTERID_WPARAM(wParam) (LOWORD(wParam))
#define IS_POINTER_INCONTACT_WPARAM(wParam) IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_INCONTACT)
#define IS_POINTER_FLAG_SET_WPARAM(wParam, flag) (((DWORD)HIWORD(wParam) & (flag)) == (flag))
typedef enum
{
POINTER_CHANGE_NONE,
POINTER_CHANGE_FIRSTBUTTON_DOWN,
POINTER_CHANGE_FIRSTBUTTON_UP,
POINTER_CHANGE_SECONDBUTTON_DOWN,
POINTER_CHANGE_SECONDBUTTON_UP,
POINTER_CHANGE_THIRDBUTTON_DOWN,
POINTER_CHANGE_THIRDBUTTON_UP,
POINTER_CHANGE_FOURTHBUTTON_DOWN,
POINTER_CHANGE_FOURTHBUTTON_UP,
POINTER_CHANGE_FIFTHBUTTON_DOWN,
POINTER_CHANGE_FIFTHBUTTON_UP,
} POINTER_BUTTON_CHANGE_TYPE;
typedef struct
{
DWORD pointerType;
UINT32 pointerId;
UINT32 frameId;
UINT32 pointerFlags;
HANDLE sourceDevice;
HWND hwndTarget;
POINT ptPixelLocation;
POINT ptHimetricLocation;
POINT ptPixelLocationRaw;
POINT ptHimetricLocationRaw;
DWORD dwTime;
UINT32 historyCount;
INT32 InputData;
DWORD dwKeyStates;
UINT64 PerformanceCount;
POINTER_BUTTON_CHANGE_TYPE ButtonChangeType;
} POINTER_INFO;
typedef struct
{
POINTER_INFO pointerInfo;
UINT32 penFlags;
UINT32 penMask;
UINT32 pressure;
UINT32 rotation;
INT32 tiltX;
INT32 tiltY;
} POINTER_PEN_INFO;
typedef struct
{
POINTER_INFO pointerInfo;
UINT32 touchFlags;
UINT32 touchMask;
RECT rcContact;
RECT rcContactRaw;
UINT32 orientation;
UINT32 pressure;
} POINTER_TOUCH_INFO;
enum {
PT_POINTER = 0x00000001, // Generic pointer
PT_TOUCH = 0x00000002, // Touch
PT_PEN = 0x00000003, // Pen
PT_MOUSE = 0x00000004, // Mouse
#if WINVER >= 0x0603
PT_TOUCHPAD = 0x00000005, // Touchpad
#endif /* WINVER >= 0x0603 */
};
WINUSERAPI BOOL WINAPI GetPointerType(UINT32,DWORD*);
WINUSERAPI BOOL WINAPI GetPointerPenInfo(UINT32,POINTER_PEN_INFO*);
WINUSERAPI BOOL WINAPI GetPointerInfo(UINT32,POINTER_INFO*);
#endif /*Windows 8 and above*/
#if WINVER < 0x0601 #if WINVER < 0x0601
typedef struct typedef struct
{ {

View File

@ -31,8 +31,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
#include <WinUser.h>
#include <windowsx.h> #include <windowsx.h>
#include <shellapi.h> #include <shellapi.h>
#include <stdio.h>
#define _GLFW_KEY_INVALID -2 #define _GLFW_KEY_INVALID -2
@ -124,11 +126,11 @@ static HICON createIcon(const GLFWimage* image,
dc = GetDC(NULL); dc = GetDC(NULL);
color = CreateDIBSection(dc, color = CreateDIBSection(dc,
(BITMAPINFO*) &bi, (BITMAPINFO*)&bi,
DIB_RGB_COLORS, DIB_RGB_COLORS,
(void**) &target, (void**)&target,
NULL, NULL,
(DWORD) 0); (DWORD)0);
ReleaseDC(NULL, dc); ReleaseDC(NULL, dc);
if (!color) if (!color)
@ -203,7 +205,7 @@ static void getFullWindowSize(DWORD style, DWORD exStyle,
static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area) static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area)
{ {
int xoff, yoff; int xoff, yoff;
const float ratio = (float) window->numer / (float) window->denom; const float ratio = (float)window->numer / (float)window->denom;
getFullWindowSize(getWindowStyle(window), getWindowExStyle(window), getFullWindowSize(getWindowStyle(window), getWindowExStyle(window),
0, 0, &xoff, &yoff); 0, 0, &xoff, &yoff);
@ -212,17 +214,17 @@ static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area)
edge == WMSZ_RIGHT || edge == WMSZ_BOTTOMRIGHT) edge == WMSZ_RIGHT || edge == WMSZ_BOTTOMRIGHT)
{ {
area->bottom = area->top + yoff + area->bottom = area->top + yoff +
(int) ((area->right - area->left - xoff) / ratio); (int)((area->right - area->left - xoff) / ratio);
} }
else if (edge == WMSZ_TOPLEFT || edge == WMSZ_TOPRIGHT) else if (edge == WMSZ_TOPLEFT || edge == WMSZ_TOPRIGHT)
{ {
area->top = area->bottom - yoff - area->top = area->bottom - yoff -
(int) ((area->right - area->left - xoff) / ratio); (int)((area->right - area->left - xoff) / ratio);
} }
else if (edge == WMSZ_TOP || edge == WMSZ_BOTTOM) else if (edge == WMSZ_TOP || edge == WMSZ_BOTTOM)
{ {
area->right = area->left + xoff + area->right = area->left + xoff +
(int) ((area->bottom - area->top - yoff) * ratio); (int)((area->bottom - area->top - yoff) * ratio);
} }
} }
@ -249,8 +251,8 @@ static GLFWbool cursorInClientArea(_GLFWwindow* window)
return GLFW_FALSE; return GLFW_FALSE;
GetClientRect(window->win32.handle, &area); GetClientRect(window->win32.handle, &area);
ClientToScreen(window->win32.handle, (POINT*) &area.left); ClientToScreen(window->win32.handle, (POINT*)&area.left);
ClientToScreen(window->win32.handle, (POINT*) &area.right); ClientToScreen(window->win32.handle, (POINT*)&area.right);
return PtInRect(&area, pos); return PtInRect(&area, pos);
} }
@ -278,8 +280,8 @@ static void updateClipRect(_GLFWwindow* window)
{ {
RECT clipRect; RECT clipRect;
GetClientRect(window->win32.handle, &clipRect); GetClientRect(window->win32.handle, &clipRect);
ClientToScreen(window->win32.handle, (POINT*) &clipRect.left); ClientToScreen(window->win32.handle, (POINT*)&clipRect.left);
ClientToScreen(window->win32.handle, (POINT*) &clipRect.right); ClientToScreen(window->win32.handle, (POINT*)&clipRect.right);
ClipCursor(&clipRect); ClipCursor(&clipRect);
} }
else else
@ -297,8 +299,8 @@ static void updateWindowStyles(const _GLFWwindow* window)
GetClientRect(window->win32.handle, &rect); GetClientRect(window->win32.handle, &rect);
AdjustWindowRectEx(&rect, style, FALSE, getWindowExStyle(window)); AdjustWindowRectEx(&rect, style, FALSE, getWindowExStyle(window));
ClientToScreen(window->win32.handle, (POINT*) &rect.left); ClientToScreen(window->win32.handle, (POINT*)&rect.left);
ClientToScreen(window->win32.handle, (POINT*) &rect.right); ClientToScreen(window->win32.handle, (POINT*)&rect.right);
SetWindowLongW(window->win32.handle, GWL_STYLE, style); SetWindowLongW(window->win32.handle, GWL_STYLE, style);
SetWindowPos(window->win32.handle, HWND_TOP, SetWindowPos(window->win32.handle, HWND_TOP,
rect.left, rect.top, rect.left, rect.top,
@ -316,7 +318,7 @@ static void updateFramebufferTransparency(const _GLFWwindow* window)
if (_glfwIsCompositionEnabledWin32()) if (_glfwIsCompositionEnabledWin32())
{ {
HRGN region = CreateRectRgn(0, 0, -1, -1); HRGN region = CreateRectRgn(0, 0, -1, -1);
DWM_BLURBEHIND bb = {0}; DWM_BLURBEHIND bb = { 0 };
bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
bb.hRgnBlur = region; bb.hRgnBlur = region;
bb.fEnable = TRUE; bb.fEnable = TRUE;
@ -532,13 +534,13 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
{ {
if (wParam == DBT_DEVICEARRIVAL) if (wParam == DBT_DEVICEARRIVAL)
{ {
DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam; DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*)lParam;
if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
_glfwDetectJoystickConnectionWin32(); _glfwDetectJoystickConnectionWin32();
} }
else if (wParam == DBT_DEVICEREMOVECOMPLETE) else if (wParam == DBT_DEVICEREMOVECOMPLETE)
{ {
DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam; DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*)lParam;
if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
_glfwDetectJoystickDisconnectionWin32(); _glfwDetectJoystickDisconnectionWin32();
} }
@ -569,6 +571,67 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
break; break;
} }
case WM_POINTERDOWN:
case WM_POINTERUPDATE:
case WM_POINTERUP:
{
POINTER_PEN_INFO penInfo;
POINTER_INFO pointerInfo;
UINT32 pointerId = GET_POINTERID_WPARAM(wParam);
DWORD pointerType = PT_POINTER;
// default to unhandled to enable call to DefWindowProc
BOOL fHandled = FALSE;
// Retrieve common pointer information
if (!GetPointerType(pointerId, &pointerType))
{
// failure, call
GetLastError();
// set PT_POINTER to fall to default case below
pointerType = PT_POINTER;
}
switch (pointerType)
{
case (PT_PEN):
//Retrieve pen information
if (!GetPointerPenInfo(pointerId, &penInfo))
{
// failure, call
GetLastError();
}
else
{
// success, process penInfo
// We change the pen pressure which is given normalized to a range between 0 and 1024
// to a normalized value in [0..1]
double pressure = (double)penInfo.pressure /(double) 1024;
int xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam);
if (IS_POINTER_INCONTACT_WPARAM(wParam))
{
_glfwInputPenPressure(window, pressure, xPos, yPos);
}
// mark as handled to skip call to DefWindowProc
fHandled = TRUE;
}
break;
}
default:
if (!GetPointerInfo(pointerId, &pointerInfo))
{
// failure.
GetLastError();
}
else
{
// success, proceed with pointerInfo.
// fHandled = HandleGenericPointerMessage(&pointerInfo);
}
break;
}
case WM_CAPTURECHANGED: case WM_CAPTURECHANGED:
{ {
// HACK: Disable the cursor once the caption button action has been // HACK: Disable the cursor once the caption button action has been
@ -661,7 +724,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
return TRUE; return TRUE;
} }
_glfwInputChar(window, (unsigned int) wParam, getKeyMods(), plain); _glfwInputChar(window, (unsigned int)wParam, getKeyMods(), plain);
return 0; return 0;
} }
@ -787,7 +850,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_INPUT: case WM_INPUT:
{ {
UINT size; UINT size;
HRAWINPUT ri = (HRAWINPUT) lParam; HRAWINPUT ri = (HRAWINPUT)lParam;
RAWINPUT* data; RAWINPUT* data;
int dx, dy; int dx, dy;
@ -796,7 +859,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
break; break;
GetRawInputData(ri, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)); GetRawInputData(ri, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER));
if (size > (UINT) _glfw.win32.rawInputSize) if (size > (UINT)_glfw.win32.rawInputSize)
{ {
free(_glfw.win32.rawInput); free(_glfw.win32.rawInput);
_glfw.win32.rawInput = calloc(size, 1); _glfw.win32.rawInput = calloc(size, 1);
@ -806,7 +869,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
size = _glfw.win32.rawInputSize; size = _glfw.win32.rawInputSize;
if (GetRawInputData(ri, RID_INPUT, if (GetRawInputData(ri, RID_INPUT,
_glfw.win32.rawInput, &size, _glfw.win32.rawInput, &size,
sizeof(RAWINPUTHEADER)) == (UINT) -1) sizeof(RAWINPUTHEADER)) == (UINT)-1)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to retrieve raw input data"); "Win32: Failed to retrieve raw input data");
@ -843,7 +906,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
{ {
_glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA); _glfwInputScroll(window, 0.0, (SHORT)HIWORD(wParam) / (double)WHEEL_DELTA);
return 0; return 0;
} }
@ -851,7 +914,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
{ {
// This message is only sent on Windows Vista and later // This message is only sent on Windows Vista and later
// NOTE: The X-axis is inverted for consistency with macOS and X11 // NOTE: The X-axis is inverted for consistency with macOS and X11
_glfwInputScroll(window, -((SHORT) HIWORD(wParam) / (double) WHEEL_DELTA), 0.0); _glfwInputScroll(window, -((SHORT)HIWORD(wParam) / (double)WHEEL_DELTA), 0.0);
return 0; return 0;
} }
@ -930,14 +993,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
break; break;
} }
applyAspectRatio(window, (int) wParam, (RECT*) lParam); applyAspectRatio(window, (int)wParam, (RECT*)lParam);
return TRUE; return TRUE;
} }
case WM_GETMINMAXINFO: case WM_GETMINMAXINFO:
{ {
int xoff, yoff; int xoff, yoff;
MINMAXINFO* mmi = (MINMAXINFO*) lParam; MINMAXINFO* mmi = (MINMAXINFO*)lParam;
if (window->monitor) if (window->monitor)
break; break;
@ -1017,7 +1080,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_DROPFILES: case WM_DROPFILES:
{ {
HDROP drop = (HDROP) wParam; HDROP drop = (HDROP)wParam;
POINT pt; POINT pt;
int i; int i;
@ -1039,7 +1102,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
free(buffer); free(buffer);
} }
_glfwInputDrop(window, count, (const char**) paths); _glfwInputDrop(window, count, (const char**)paths);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
free(paths[i]); free(paths[i]);
@ -1150,7 +1213,7 @@ GLFWbool _glfwRegisterWindowClassWin32(void)
ZeroMemory(&wc, sizeof(wc)); ZeroMemory(&wc, sizeof(wc));
wc.cbSize = sizeof(wc); wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) windowProc; wc.lpfnWndProc = (WNDPROC)windowProc;
wc.hInstance = GetModuleHandleW(NULL); wc.hInstance = GetModuleHandleW(NULL);
wc.hCursor = LoadCursorW(NULL, IDC_ARROW); wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
wc.lpszClassName = _GLFW_WNDCLASSNAME; wc.lpszClassName = _GLFW_WNDCLASSNAME;
@ -1304,12 +1367,12 @@ void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
} }
else else
{ {
bigIcon = (HICON) GetClassLongPtrW(window->win32.handle, GCLP_HICON); bigIcon = (HICON)GetClassLongPtrW(window->win32.handle, GCLP_HICON);
smallIcon = (HICON) GetClassLongPtrW(window->win32.handle, GCLP_HICONSM); smallIcon = (HICON)GetClassLongPtrW(window->win32.handle, GCLP_HICONSM);
} }
SendMessage(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM) bigIcon); SendMessage(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM)bigIcon);
SendMessage(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM) smallIcon); SendMessage(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM)smallIcon);
if (window->win32.bigIcon) if (window->win32.bigIcon)
DestroyIcon(window->win32.bigIcon); DestroyIcon(window->win32.bigIcon);
@ -1624,7 +1687,7 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
{ {
if (opacity < 1.f) if (opacity < 1.f)
{ {
const BYTE alpha = (BYTE) (255 * opacity); const BYTE alpha = (BYTE)(255 * opacity);
DWORD style = GetWindowLongW(window->win32.handle, GWL_EXSTYLE); DWORD style = GetWindowLongW(window->win32.handle, GWL_EXSTYLE);
style |= WS_EX_LAYERED; style |= WS_EX_LAYERED;
SetWindowLongW(window->win32.handle, GWL_EXSTYLE, style); SetWindowLongW(window->win32.handle, GWL_EXSTYLE, style);
@ -1719,7 +1782,7 @@ void _glfwPlatformWaitEvents(void)
void _glfwPlatformWaitEventsTimeout(double timeout) void _glfwPlatformWaitEventsTimeout(double timeout)
{ {
MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD) (timeout * 1e3), QS_ALLEVENTS); MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD)(timeout * 1e3), QS_ALLEVENTS);
_glfwPlatformPollEvents(); _glfwPlatformPollEvents();
} }
@ -1746,7 +1809,7 @@ void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos) void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos)
{ {
POINT pos = { (int) xpos, (int) ypos }; POINT pos = { (int)xpos, (int)ypos };
// Store the new position so it can be recognized later // Store the new position so it can be recognized later
window->win32.lastCursorPosX = pos.x; window->win32.lastCursorPosX = pos.x;
@ -1810,7 +1873,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
const GLFWimage* image, const GLFWimage* image,
int xhot, int yhot) int xhot, int yhot)
{ {
cursor->win32.handle = (HCURSOR) createIcon(image, xhot, yhot, GLFW_FALSE); cursor->win32.handle = (HCURSOR)createIcon(image, xhot, yhot, GLFW_FALSE);
if (!cursor->win32.handle) if (!cursor->win32.handle)
return GLFW_FALSE; return GLFW_FALSE;
@ -1834,7 +1897,7 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor) void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
{ {
if (cursor->win32.handle) if (cursor->win32.handle)
DestroyIcon((HICON) cursor->win32.handle); DestroyIcon((HICON)cursor->win32.handle);
} }
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
@ -1993,7 +2056,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle) GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*)handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return window->win32.handle; return window->win32.handle;
} }

View File

@ -27,7 +27,6 @@
//======================================================================== //========================================================================
#include "internal.h" #include "internal.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -354,6 +354,17 @@ static void mouse_button_callback(GLFWwindow* window, int button, int action, in
get_action_name(action)); get_action_name(action));
} }
static void pen_callback(GLFWwindow* window, double pressure, int x, int y)
{
Slot* slot = glfwGetWindowUserPointer(window);
printf("%08x to %i at %0.3f: Pen position: %i %i Pressure: %f\n",
counter++, slot->number, glfwGetTime(), x, y, pressure);
/*
fprintf(stderr, "pressure -- %f --\n", pressure);
fprintf(stderr, "xPosition -- %d --\n", x);
fprintf(stderr, "yPosition -- %d --\n", y);*/
}
static void cursor_position_callback(GLFWwindow* window, double x, double y) static void cursor_position_callback(GLFWwindow* window, double x, double y)
{ {
Slot* slot = glfwGetWindowUserPointer(window); Slot* slot = glfwGetWindowUserPointer(window);
@ -613,6 +624,7 @@ int main(int argc, char** argv)
glfwSetWindowIconifyCallback(slots[i].window, window_iconify_callback); glfwSetWindowIconifyCallback(slots[i].window, window_iconify_callback);
glfwSetWindowMaximizeCallback(slots[i].window, window_maximize_callback); glfwSetWindowMaximizeCallback(slots[i].window, window_maximize_callback);
glfwSetMouseButtonCallback(slots[i].window, mouse_button_callback); glfwSetMouseButtonCallback(slots[i].window, mouse_button_callback);
glfwSetPenPressureCallback(slots[i].window, pen_callback);
glfwSetCursorPosCallback(slots[i].window, cursor_position_callback); glfwSetCursorPosCallback(slots[i].window, cursor_position_callback);
glfwSetCursorEnterCallback(slots[i].window, cursor_enter_callback); glfwSetCursorEnterCallback(slots[i].window, cursor_enter_callback);
glfwSetScrollCallback(slots[i].window, scroll_callback); glfwSetScrollCallback(slots[i].window, scroll_callback);