Add pressure normalization

Add (x, y) coordinates of the point location of the pen
Code comments cleanup
This commit is contained in:
Raja 2017-11-06 21:25:44 -05:00
parent 59721ebfef
commit a089df00cb
5 changed files with 22 additions and 32 deletions

View File

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

View File

@ -1279,21 +1279,23 @@ typedef void (* GLFWframebuffersizefun)(GLFWwindow*,int,int);
*/
typedef void (* GLFWmousebuttonfun)(GLFWwindow*,int,int,int);
/*! @brief The function signature for pen --pressure-- callbacks.
/*! @brief The function signature for pen callbacks.
*
* This is the function signature for pen --pressure-- callback functions.
* 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_button
* @sa @ref input_pen_pressure
* @sa @ref glfwSetPenPressureCallback
*
* @ingroup input
*/
typedef void(*GLFWpenpressurefun)(GLFWwindow*, int, int, int);
typedef void(*GLFWpenpressurefun)(GLFWwindow*, double, int, int);
/*! @brief The function signature for cursor position callbacks.
*
@ -4144,17 +4146,11 @@ GLFWAPI GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* window, GLFWcharmods
* @ingroup input
*/
GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun cbfun);
/*! @brief Sets the pen --button-- callback.
*
* This function sets the pen --button-- callback of the specified window, which
* is called when a pen --button-- is pressed or released.
*
* When a window loses input focus, it will generate synthetic pen --button--
* release events for all pressed pen buttons. You can tell these events
* from user-generated events by the fact that the synthetic ones are generated
* after the focus loss event has been processed, i.e. after the
* [window focus callback](@ref glfwSetWindowFocusCallback) has been called.
/*! @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.
@ -4165,10 +4161,8 @@ GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmo
*
* @thread_safety This function must only be called from the main thread.
*
* @sa @ref input_pen_button
* @sa @ref input_pen_pressure
*
* @since Added in version 1.0.
* @glfw3 Added window handle parameter and return value.
*
* @ingroup input
*/

View File

@ -232,8 +232,7 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
window->callbacks.mouseButton((GLFWwindow*) window, button, action, mods);
}
/*************************PEN**************************************************/
void _glfwInputPenPressure(_GLFWwindow* window, int pressure, int x, int y)
void _glfwInputPenPressure(_GLFWwindow* window, double pressure, int x, int y)
{
window->penPressure = pressure;
window->penXposition = x;
@ -242,7 +241,6 @@ void _glfwInputPenPressure(_GLFWwindow* window, int pressure, int x, int y)
if (window->callbacks.penPressure)
window->callbacks.penPressure((GLFWwindow*)window, pressure, x, y);
}
/***********************************PEN*************************************/
void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos)
{
@ -733,7 +731,6 @@ GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* handle,
return cbfun;
}
/*********PEN************************************/
GLFWAPI GLFWpenpressurefun glfwSetPenPressureCallback(GLFWwindow* handle,
GLFWpenpressurefun cbfun)
{
@ -744,7 +741,6 @@ GLFWAPI GLFWpenpressurefun glfwSetPenPressureCallback(GLFWwindow* handle,
_GLFW_SWAP_POINTERS(window->callbacks.penPressure, cbfun);
return cbfun;
}
/************************************************/
GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* handle,
GLFWcursorposfun cbfun)

View File

@ -417,7 +417,7 @@ struct _GLFWwindow
GLFWbool stickyKeys;
GLFWbool stickyMouseButtons;
int penPressure;
double penPressure;
int penXposition;
int penYposition;
int cursorMode;
@ -820,14 +820,14 @@ void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset);
*/
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods);
/*! @brief Notifies shared code of a pen button click event.
/*! @brief Notifies shared code of a pen click event.
* @param[in] window The window that received the event.
* @param[in] button The button that was pressed or released.
* @param[in] action @ref GLFW_PRESS or @ref GLFW_RELEASE.
* @param[in] mods The modifiers pressed when the event was generated.
* @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, int pressure, int x, int y);
void _glfwInputPenPressure(_GLFWwindow* window, double pressure, int x, int y);
/*! @brief Notifies shared code of a cursor motion event.
* @param[in] window The window that received the event.

View File

@ -597,8 +597,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
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]
// 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);