Add x any pen position

pen pressure normalization in [0..1]
This commit is contained in:
Raja 2017-11-06 14:45:22 -05:00
parent 07053602a5
commit 59721ebfef
5 changed files with 20 additions and 17 deletions

View File

@ -74,9 +74,11 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
glfwSetWindowShouldClose(window, GLFW_TRUE); glfwSetWindowShouldClose(window, GLFW_TRUE);
} }
static void pen_callback(GLFWwindow* window, int pressure) static void pen_callback(GLFWwindow* window, int pressure, int x, int y)
{ {
fprintf(stderr, "pressure -- %d --\n", pressure); fprintf(stderr, "pressure -- %d --\n", pressure);
fprintf (stderr, "xPosition -- %d --\n", x);
fprintf(stderr, "yPosition -- %d --\n", y);
} }
int main(void) int main(void)

View File

@ -1279,27 +1279,21 @@ typedef void (* GLFWframebuffersizefun)(GLFWwindow*,int,int);
*/ */
typedef void (* GLFWmousebuttonfun)(GLFWwindow*,int,int,int); typedef void (* GLFWmousebuttonfun)(GLFWwindow*,int,int,int);
/*! @brief The function signature for pen --button-- callbacks. /*! @brief The function signature for pen --pressure-- callbacks.
* *
* This is the function signature for pen --button-- callback functions. * This is the function signature for pen --pressure-- callback functions.
* *
* @param[in] window The window that received the event. * @param[in] window The window that received the event.
* @param[in] button The [pen button](@ref buttons) that was pressed or * @param[in] pressure The [pen pressure](@ref pressure) that was pressed or
* released. * released.
* @param[in] action One of `GLFW_PRESS` or `GLFW_RELEASE`. * *
* @param[in] mods Bit field describing which [modifier keys](@ref mods) were
* held down.
*
* @sa @ref input_pen_button * @sa @ref input_pen_button
* @sa @ref glfwSetPenButtonCallback * @sa @ref glfwSetPenPressureCallback
*
* ---- @since Added in version 1.0.
* @glfw3 Added window handle and modifier mask parameters.------
* *
* @ingroup input * @ingroup input
*/ */
typedef void(*GLFWpenpressurefun)(GLFWwindow*, int); typedef void(*GLFWpenpressurefun)(GLFWwindow*, int, int, int);
/*! @brief The function signature for cursor position callbacks. /*! @brief The function signature for cursor position callbacks.
* *

View File

@ -233,12 +233,14 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
} }
/*************************PEN**************************************************/ /*************************PEN**************************************************/
void _glfwInputPenPressure(_GLFWwindow* window, int pressure) void _glfwInputPenPressure(_GLFWwindow* window, int pressure, int x, int y)
{ {
window->penPressure = pressure; window->penPressure = pressure;
window->penXposition = x;
window->penYposition = y;
if (window->callbacks.penPressure) if (window->callbacks.penPressure)
window->callbacks.penPressure((GLFWwindow*)window, pressure); window->callbacks.penPressure((GLFWwindow*)window, pressure, x, y);
} }
/***********************************PEN*************************************/ /***********************************PEN*************************************/

View File

@ -418,6 +418,8 @@ struct _GLFWwindow
GLFWbool stickyKeys; GLFWbool stickyKeys;
GLFWbool stickyMouseButtons; GLFWbool stickyMouseButtons;
int penPressure; int penPressure;
int penXposition;
int penYposition;
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];
@ -825,7 +827,7 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
* @param[in] mods The modifiers pressed when the event was generated. * @param[in] mods The modifiers pressed when the event was generated.
* @ingroup event * @ingroup event
*/ */
void _glfwInputPenPressure(_GLFWwindow* window, int pressure); void _glfwInputPenPressure(_GLFWwindow* window, int 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.

View File

@ -597,11 +597,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
else else
{ {
// success, process penInfo // 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 xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam); int yPos = GET_Y_LPARAM(lParam);
if (IS_POINTER_INCONTACT_WPARAM(wParam)) if (IS_POINTER_INCONTACT_WPARAM(wParam))
{ {
_glfwInputPenPressure(window, penInfo.pressure); _glfwInputPenPressure(window, pressure, xPos, yPos);
} }
// mark as handled to skip call to DefWindowProc // mark as handled to skip call to DefWindowProc
fHandled = TRUE; fHandled = TRUE;