mirror of
https://github.com/glfw/glfw.git
synced 2025-10-04 21:56:36 +00:00
Merge ae04c86c42
into 6c421f131d
This commit is contained in:
commit
fb87fda026
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -1 +1 @@
|
|||||||
*.m linguist-language=Objective-C
|
*.m linguist-language=Objective-C
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -82,3 +82,4 @@ tests/title
|
|||||||
tests/vulkan
|
tests/vulkan
|
||||||
tests/windows
|
tests/windows
|
||||||
|
|
||||||
|
/build
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
|
|
||||||
GLFW_ICON ICON "glfw.ico"
|
GLFW_ICON ICON "glfw.ico"
|
||||||
|
|
||||||
|
@ -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.
|
||||||
*
|
*
|
||||||
|
34
src/input.c
34
src/input.c
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -84,8 +84,8 @@ typedef GLFWglproc (* _GLFWgetprocaddressfun)(const char*);
|
|||||||
typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*);
|
typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*);
|
||||||
|
|
||||||
#define GL_VERSION 0x1f02
|
#define GL_VERSION 0x1f02
|
||||||
#define GL_NONE 0
|
#define GL_NONE 0
|
||||||
#define GL_COLOR_BUFFER_BIT 0x00004000
|
#define GL_COLOR_BUFFER_BIT 0x00004000
|
||||||
#define GL_UNSIGNED_BYTE 0x1401
|
#define GL_UNSIGNED_BYTE 0x1401
|
||||||
#define GL_EXTENSIONS 0x1f03
|
#define GL_EXTENSIONS 0x1f03
|
||||||
#define GL_NUM_EXTENSIONS 0x821d
|
#define GL_NUM_EXTENSIONS 0x821d
|
||||||
@ -102,7 +102,7 @@ typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*);
|
|||||||
#define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82fc
|
#define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82fc
|
||||||
#define GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008
|
#define GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008
|
||||||
|
|
||||||
typedef int GLint;
|
typedef int GLint;
|
||||||
typedef unsigned int GLuint;
|
typedef unsigned int GLuint;
|
||||||
typedef unsigned int GLenum;
|
typedef unsigned int GLenum;
|
||||||
typedef unsigned int GLbitfield;
|
typedef unsigned int GLbitfield;
|
||||||
@ -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
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
@ -189,7 +272,7 @@ BOOL IsWindowsVersionOrGreater(WORD major, WORD minor, WORD sp);
|
|||||||
|
|
||||||
// HACK: Define macros that some dinput.h variants don't
|
// HACK: Define macros that some dinput.h variants don't
|
||||||
#ifndef DIDFT_OPTIONAL
|
#ifndef DIDFT_OPTIONAL
|
||||||
#define DIDFT_OPTIONAL 0x80000000
|
#define DIDFT_OPTIONAL 0x80000000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// winmm.dll function pointer typedefs
|
// winmm.dll function pointer typedefs
|
||||||
|
1323
src/win32_window.c
1323
src/win32_window.c
File diff suppressed because it is too large
Load Diff
@ -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>
|
||||||
|
@ -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);
|
||||||
|
212
tests/opacity.c
212
tests/opacity.c
@ -1,106 +1,106 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// Window opacity test program
|
// Window opacity test program
|
||||||
// Copyright (c) Camilla Löwy <elmindreda@glfw.org>
|
// Copyright (c) Camilla Löwy <elmindreda@glfw.org>
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied
|
// This software is provided 'as-is', without any express or implied
|
||||||
// warranty. In no event will the authors be held liable for any damages
|
// warranty. In no event will the authors be held liable for any damages
|
||||||
// arising from the use of this software.
|
// arising from the use of this software.
|
||||||
//
|
//
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
// including commercial applications, and to alter it and redistribute it
|
// including commercial applications, and to alter it and redistribute it
|
||||||
// freely, subject to the following restrictions:
|
// freely, subject to the following restrictions:
|
||||||
//
|
//
|
||||||
// 1. The origin of this software must not be misrepresented; you must not
|
// 1. The origin of this software must not be misrepresented; you must not
|
||||||
// claim that you wrote the original software. If you use this software
|
// claim that you wrote the original software. If you use this software
|
||||||
// in a product, an acknowledgment in the product documentation would
|
// in a product, an acknowledgment in the product documentation would
|
||||||
// be appreciated but is not required.
|
// be appreciated but is not required.
|
||||||
//
|
//
|
||||||
// 2. Altered source versions must be plainly marked as such, and must not
|
// 2. Altered source versions must be plainly marked as such, and must not
|
||||||
// be misrepresented as being the original software.
|
// be misrepresented as being the original software.
|
||||||
//
|
//
|
||||||
// 3. This notice may not be removed or altered from any source
|
// 3. This notice may not be removed or altered from any source
|
||||||
// distribution.
|
// distribution.
|
||||||
//
|
//
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#define NK_IMPLEMENTATION
|
#define NK_IMPLEMENTATION
|
||||||
#define NK_INCLUDE_FIXED_TYPES
|
#define NK_INCLUDE_FIXED_TYPES
|
||||||
#define NK_INCLUDE_FONT_BAKING
|
#define NK_INCLUDE_FONT_BAKING
|
||||||
#define NK_INCLUDE_DEFAULT_FONT
|
#define NK_INCLUDE_DEFAULT_FONT
|
||||||
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
||||||
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
||||||
#define NK_INCLUDE_STANDARD_VARARGS
|
#define NK_INCLUDE_STANDARD_VARARGS
|
||||||
#include <nuklear.h>
|
#include <nuklear.h>
|
||||||
|
|
||||||
#define NK_GLFW_GL2_IMPLEMENTATION
|
#define NK_GLFW_GL2_IMPLEMENTATION
|
||||||
#include <nuklear_glfw_gl2.h>
|
#include <nuklear_glfw_gl2.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static void error_callback(int error, const char* description)
|
static void error_callback(int error, const char* description)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error: %s\n", description);
|
fprintf(stderr, "Error: %s\n", description);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
GLFWmonitor* monitor = NULL;
|
GLFWmonitor* monitor = NULL;
|
||||||
GLFWwindow* window;
|
GLFWwindow* window;
|
||||||
struct nk_context* nk;
|
struct nk_context* nk;
|
||||||
struct nk_font_atlas* atlas;
|
struct nk_font_atlas* atlas;
|
||||||
|
|
||||||
glfwSetErrorCallback(error_callback);
|
glfwSetErrorCallback(error_callback);
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
window = glfwCreateWindow(400, 400, "Opacity", NULL, NULL);
|
window = glfwCreateWindow(400, 400, "Opacity", NULL, NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
nk = nk_glfw3_init(window, NK_GLFW3_INSTALL_CALLBACKS);
|
nk = nk_glfw3_init(window, NK_GLFW3_INSTALL_CALLBACKS);
|
||||||
nk_glfw3_font_stash_begin(&atlas);
|
nk_glfw3_font_stash_begin(&atlas);
|
||||||
nk_glfw3_font_stash_end();
|
nk_glfw3_font_stash_end();
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
int width, height;
|
int width, height;
|
||||||
struct nk_rect area;
|
struct nk_rect area;
|
||||||
|
|
||||||
glfwGetWindowSize(window, &width, &height);
|
glfwGetWindowSize(window, &width, &height);
|
||||||
area = nk_rect(0.f, 0.f, (float) width, (float) height);
|
area = nk_rect(0.f, 0.f, (float) width, (float) height);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
nk_glfw3_new_frame();
|
nk_glfw3_new_frame();
|
||||||
if (nk_begin(nk, "", area, 0))
|
if (nk_begin(nk, "", area, 0))
|
||||||
{
|
{
|
||||||
float opacity = glfwGetWindowOpacity(window);
|
float opacity = glfwGetWindowOpacity(window);
|
||||||
nk_layout_row_dynamic(nk, 30, 2);
|
nk_layout_row_dynamic(nk, 30, 2);
|
||||||
if (nk_slider_float(nk, 0.f, &opacity, 1.f, 0.001f))
|
if (nk_slider_float(nk, 0.f, &opacity, 1.f, 0.001f))
|
||||||
glfwSetWindowOpacity(window, opacity);
|
glfwSetWindowOpacity(window, opacity);
|
||||||
nk_labelf(nk, NK_TEXT_LEFT, "%0.3f", opacity);
|
nk_labelf(nk, NK_TEXT_LEFT, "%0.3f", opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
nk_end(nk);
|
nk_end(nk);
|
||||||
nk_glfw3_render(NK_ANTI_ALIASING_ON);
|
nk_glfw3_render(NK_ANTI_ALIASING_ON);
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwWaitEventsTimeout(1.0);
|
glfwWaitEventsTimeout(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
nk_glfw3_shutdown();
|
nk_glfw3_shutdown();
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user