mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 04:54:35 +00:00
Cleanup.
This commit is contained in:
parent
40c04a7565
commit
608de57358
2
.gitignore
vendored
2
.gitignore
vendored
@ -52,6 +52,8 @@ tests/*.app
|
|||||||
tests/*.exe
|
tests/*.exe
|
||||||
tests/accuracy
|
tests/accuracy
|
||||||
tests/clipboard
|
tests/clipboard
|
||||||
|
tests/cursor
|
||||||
|
tests/cursoranim
|
||||||
tests/defaults
|
tests/defaults
|
||||||
tests/empty
|
tests/empty
|
||||||
tests/events
|
tests/events
|
||||||
|
@ -130,7 +130,7 @@ typedef struct _GLFWmonitorNS
|
|||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
typedef struct _GLFWcursorNS
|
typedef struct _GLFWcursorNS
|
||||||
{
|
{
|
||||||
id handle;
|
id object;
|
||||||
} _GLFWcursorNS;
|
} _GLFWcursorNS;
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ static void setModeCursor(_GLFWwindow* window)
|
|||||||
if (window->cursorMode == GLFW_CURSOR_NORMAL)
|
if (window->cursorMode == GLFW_CURSOR_NORMAL)
|
||||||
{
|
{
|
||||||
if (window->cursor)
|
if (window->cursor)
|
||||||
[(NSCursor*) window->cursor->ns.handle set];
|
[(NSCursor*) window->cursor->ns.object set];
|
||||||
else
|
else
|
||||||
[[NSCursor arrowCursor] set];
|
[[NSCursor arrowCursor] set];
|
||||||
}
|
}
|
||||||
@ -1201,7 +1201,7 @@ void _glfwPlatformApplyCursorMode(_GLFWwindow* window)
|
|||||||
CGAssociateMouseAndMouseCursorPosition(true);
|
CGAssociateMouseAndMouseCursorPosition(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int cx, int cy,
|
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int xhot, int yhot,
|
||||||
int format, const void* data)
|
int format, const void* data)
|
||||||
{
|
{
|
||||||
NSImage* image;
|
NSImage* image;
|
||||||
@ -1223,18 +1223,18 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int cx
|
|||||||
if (rep == nil)
|
if (rep == nil)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
memcpy([rep bitmapData], data, 4 * width * height);
|
memcpy([rep bitmapData], data, width * height * 4);
|
||||||
|
|
||||||
image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
|
image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
|
||||||
[image addRepresentation: rep];
|
[image addRepresentation: rep];
|
||||||
|
|
||||||
cursor->ns.handle = [[NSCursor alloc] initWithImage:image
|
cursor->ns.object = [[NSCursor alloc] initWithImage:image
|
||||||
hotSpot:NSMakePoint(cx, cy)];
|
hotSpot:NSMakePoint(xhot, yhot)];
|
||||||
|
|
||||||
[image release];
|
[image release];
|
||||||
[rep release];
|
[rep release];
|
||||||
|
|
||||||
if (cursor->ns.handle == nil)
|
if (cursor->ns.object == nil)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
@ -1242,7 +1242,8 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int cx
|
|||||||
|
|
||||||
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
|
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
|
||||||
{
|
{
|
||||||
[(NSCursor*) cursor->ns.handle release];
|
if (cursor->ns.object)
|
||||||
|
[(NSCursor*) cursor->ns.object release];
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
|
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
|
||||||
@ -1250,7 +1251,7 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
|
|||||||
if (window->cursorMode == GLFW_CURSOR_NORMAL && window->ns.cursorInside)
|
if (window->cursorMode == GLFW_CURSOR_NORMAL && window->ns.cursorInside)
|
||||||
{
|
{
|
||||||
if (cursor)
|
if (cursor)
|
||||||
[(NSCursor*) cursor->ns.handle set];
|
[(NSCursor*) cursor->ns.object set];
|
||||||
else
|
else
|
||||||
[[NSCursor arrowCursor] set];
|
[[NSCursor arrowCursor] set];
|
||||||
}
|
}
|
||||||
|
21
src/input.c
21
src/input.c
@ -353,7 +353,7 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
|
|||||||
_glfwPlatformSetCursorPos(window, xpos, ypos);
|
_glfwPlatformSetCursorPos(window, xpos, ypos);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI GLFWcursor* glfwCreateCursor(int width, int height, int cx, int cy,
|
GLFWAPI GLFWcursor* glfwCreateCursor(int width, int height, int xhot, int yhot,
|
||||||
int format, const void* data)
|
int format, const void* data)
|
||||||
{
|
{
|
||||||
_GLFWcursor* cursor;
|
_GLFWcursor* cursor;
|
||||||
@ -361,16 +361,15 @@ GLFWAPI GLFWcursor* glfwCreateCursor(int width, int height, int cx, int cy,
|
|||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
|
||||||
cursor = calloc(1, sizeof(_GLFWcursor));
|
cursor = calloc(1, sizeof(_GLFWcursor));
|
||||||
|
|
||||||
if (!_glfwPlatformCreateCursor(cursor, width, height, cx, cy, format, data))
|
|
||||||
{
|
|
||||||
free(cursor);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor->next = _glfw.cursorListHead;
|
cursor->next = _glfw.cursorListHead;
|
||||||
_glfw.cursorListHead = cursor;
|
_glfw.cursorListHead = cursor;
|
||||||
|
|
||||||
|
if (!_glfwPlatformCreateCursor(cursor, width, height, xhot, yhot, format, data))
|
||||||
|
{
|
||||||
|
glfwDestroyCursor((GLFWcursor*) cursor);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return (GLFWcursor*) cursor;
|
return (GLFWcursor*) cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,14 +384,12 @@ GLFWAPI void glfwDestroyCursor(GLFWcursor* handle)
|
|||||||
|
|
||||||
// Make sure the cursor is not being used by any window
|
// Make sure the cursor is not being used by any window
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = _glfw.windowListHead;
|
_GLFWwindow* window;
|
||||||
|
|
||||||
while (window)
|
for (window = _glfw.windowListHead; window; window = window->next)
|
||||||
{
|
{
|
||||||
if (window->cursor == cursor)
|
if (window->cursor == cursor)
|
||||||
glfwSetCursor((GLFWwindow*) window, NULL);
|
glfwSetCursor((GLFWwindow*) window, NULL);
|
||||||
|
|
||||||
window = window->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,7 +588,7 @@ int _glfwPlatformExtensionSupported(const char* extension);
|
|||||||
*/
|
*/
|
||||||
GLFWglproc _glfwPlatformGetProcAddress(const char* procname);
|
GLFWglproc _glfwPlatformGetProcAddress(const char* procname);
|
||||||
|
|
||||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int cx, int cy,
|
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int xhot, int yhot,
|
||||||
int format, const void* data);
|
int format, const void* data);
|
||||||
|
|
||||||
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor);
|
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor);
|
||||||
|
@ -1223,63 +1223,60 @@ void _glfwPlatformApplyCursorMode(_GLFWwindow* window)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int cx, int cy,
|
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int xhot, int yhot,
|
||||||
int format, const void* data)
|
int format, const void* data)
|
||||||
{
|
{
|
||||||
HDC hdc;
|
HDC dc;
|
||||||
HBITMAP hBitmap, hMonoBitmap;
|
HBITMAP bitmap, mask;
|
||||||
BITMAPV5HEADER bi;
|
BITMAPV5HEADER bi;
|
||||||
ICONINFO ii;
|
ICONINFO ii;
|
||||||
DWORD *buffer = 0;
|
DWORD* target = 0;
|
||||||
BYTE *image = (BYTE*) data;
|
BYTE* source = (BYTE*) data;
|
||||||
int i, size = width * height;
|
int i;
|
||||||
|
|
||||||
ZeroMemory(&bi, sizeof(BITMAPV5HEADER));
|
|
||||||
|
|
||||||
|
ZeroMemory(&bi, sizeof(bi));
|
||||||
bi.bV5Size = sizeof(BITMAPV5HEADER);
|
bi.bV5Size = sizeof(BITMAPV5HEADER);
|
||||||
bi.bV5Width = width;
|
bi.bV5Width = width;
|
||||||
bi.bV5Height = -height;
|
bi.bV5Height = -height;
|
||||||
bi.bV5Planes = 1;
|
bi.bV5Planes = 1;
|
||||||
bi.bV5BitCount = 32;
|
bi.bV5BitCount = 32;
|
||||||
bi.bV5Compression = BI_BITFIELDS;
|
bi.bV5Compression = BI_BITFIELDS;
|
||||||
bi.bV5RedMask = 0x00FF0000;
|
bi.bV5RedMask = 0x00ff0000;
|
||||||
bi.bV5GreenMask = 0x0000FF00;
|
bi.bV5GreenMask = 0x0000ff00;
|
||||||
bi.bV5BlueMask = 0x000000FF;
|
bi.bV5BlueMask = 0x000000ff;
|
||||||
bi.bV5AlphaMask = 0xFF000000;
|
bi.bV5AlphaMask = 0xff000000;
|
||||||
|
|
||||||
hdc = GetDC(NULL);
|
dc = GetDC(NULL);
|
||||||
|
bitmap = CreateDIBSection(dc, (BITMAPINFO*) &bi, DIB_RGB_COLORS,
|
||||||
|
(void**) &target, NULL, (DWORD) 0);
|
||||||
|
ReleaseDC(NULL, dc);
|
||||||
|
|
||||||
hBitmap = CreateDIBSection(hdc, (BITMAPINFO*) &bi, DIB_RGB_COLORS, (void**) &buffer,
|
if (!bitmap)
|
||||||
NULL, (DWORD) 0);
|
|
||||||
|
|
||||||
ReleaseDC(NULL, hdc);
|
|
||||||
|
|
||||||
if (hBitmap == NULL)
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
hMonoBitmap = CreateBitmap(width, height, 1, 1, NULL);
|
mask = CreateBitmap(width, height, 1, 1, NULL);
|
||||||
|
if (!mask)
|
||||||
if (hMonoBitmap == NULL)
|
|
||||||
{
|
{
|
||||||
DeleteObject(hBitmap);
|
DeleteObject(bitmap);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < size; i++, buffer++, image += 4)
|
for (i = 0; i < width * height; i++, target++, source += 4)
|
||||||
*buffer = (image[3] << 24) | (image[0] << 16) | (image[1] << 8) | image[2];
|
*target = (source[3] << 24) | (source[0] << 16) | (source[1] << 8) | source[2];
|
||||||
|
|
||||||
|
ZeroMemory(&ii, sizeof(ii));
|
||||||
ii.fIcon = FALSE;
|
ii.fIcon = FALSE;
|
||||||
ii.xHotspot = cx;
|
ii.xHotspot = xhot;
|
||||||
ii.yHotspot = cy;
|
ii.yHotspot = yhot;
|
||||||
ii.hbmMask = hMonoBitmap;
|
ii.hbmMask = mask;
|
||||||
ii.hbmColor = hBitmap;
|
ii.hbmColor = bitmap;
|
||||||
|
|
||||||
cursor->win32.handle = (HCURSOR) CreateIconIndirect(&ii);
|
cursor->win32.handle = (HCURSOR) CreateIconIndirect(&ii);
|
||||||
|
|
||||||
DeleteObject(hBitmap);
|
DeleteObject(bitmap);
|
||||||
DeleteObject(hMonoBitmap);
|
DeleteObject(mask);
|
||||||
|
|
||||||
if (cursor->win32.handle == NULL)
|
if (!cursor->win32.handle)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
@ -1287,6 +1284,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int cx
|
|||||||
|
|
||||||
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
|
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
|
||||||
{
|
{
|
||||||
|
if (cursor->win32.handle)
|
||||||
DestroyIcon((HICON) cursor->win32.handle);
|
DestroyIcon((HICON) cursor->win32.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1302,7 +1300,7 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
|
|||||||
if (cursor)
|
if (cursor)
|
||||||
SetCursor(cursor->win32.handle);
|
SetCursor(cursor->win32.handle);
|
||||||
else
|
else
|
||||||
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
SetCursor(LoadCursorW(NULL, IDC_ARROW));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1356,30 +1356,26 @@ void _glfwPlatformApplyCursorMode(_GLFWwindow* window)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int cx, int cy,
|
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int xhot, int yhot,
|
||||||
int format, const void* data)
|
int format, const void* data)
|
||||||
{
|
{
|
||||||
XcursorImage* cursorImage;
|
int i;
|
||||||
XcursorPixel* buffer;
|
|
||||||
unsigned char* image = (unsigned char*) data;
|
|
||||||
int i, size = width * height;
|
|
||||||
|
|
||||||
cursorImage = XcursorImageCreate(width, height);
|
XcursorImage* native = XcursorImageCreate(width, height);
|
||||||
|
if (native == NULL)
|
||||||
if (cursorImage == NULL)
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
cursorImage->xhot = cx;
|
native->xhot = xhot;
|
||||||
cursorImage->yhot = cy;
|
native->yhot = yhot;
|
||||||
|
|
||||||
buffer = cursorImage->pixels;
|
unsigned char* source = (unsigned char*) data;
|
||||||
|
XcursorPixel* target = native->pixels;
|
||||||
|
|
||||||
for (i = 0; i < size; i++, buffer++, image += 4)
|
for (i = 0; i < width * height; i++, target++, source += 4)
|
||||||
*buffer = (image[3] << 24) | (image[0] << 16) | (image[1] << 8) | image[2];
|
*target = (source[3] << 24) | (source[0] << 16) | (source[1] << 8) | source[2];
|
||||||
|
|
||||||
cursor->x11.handle = XcursorImageLoadCursor(_glfw.x11.display, cursorImage);
|
cursor->x11.handle = XcursorImageLoadCursor(_glfw.x11.display, native);
|
||||||
|
XcursorImageDestroy(native);
|
||||||
XcursorImageDestroy(cursorImage);
|
|
||||||
|
|
||||||
if (cursor->x11.handle == None)
|
if (cursor->x11.handle == None)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
@ -1389,6 +1385,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int cx
|
|||||||
|
|
||||||
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
|
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
|
||||||
{
|
{
|
||||||
|
if (cursor->x11.handle)
|
||||||
XFreeCursor(_glfw.x11.display, cursor->x11.handle);
|
XFreeCursor(_glfw.x11.display, cursor->x11.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,11 +37,15 @@ static int W = 640;
|
|||||||
static int H = 480;
|
static int H = 480;
|
||||||
static int delay = 0;
|
static int delay = 0;
|
||||||
|
|
||||||
static GLFWwindow* windows[2] = {NULL, NULL};
|
static GLFWwindow* windows[2] = { NULL, NULL };
|
||||||
static GLFWwindow* activeWindow = NULL;
|
static GLFWwindow* activeWindow = NULL;
|
||||||
static GLFWcursor* cursor = NULL;
|
static GLFWcursor* cursor = NULL;
|
||||||
|
|
||||||
static struct { int key; double time; } commands[] = {
|
static struct
|
||||||
|
{
|
||||||
|
int key;
|
||||||
|
double time;
|
||||||
|
} commands[] = {
|
||||||
{GLFW_KEY_H, 0},
|
{GLFW_KEY_H, 0},
|
||||||
{GLFW_KEY_C, 0},
|
{GLFW_KEY_C, 0},
|
||||||
{GLFW_KEY_D, 0},
|
{GLFW_KEY_D, 0},
|
||||||
@ -54,8 +58,11 @@ static struct { int key; double time; } commands[] = {
|
|||||||
|
|
||||||
static int CommandCount = sizeof(commands) / sizeof(commands[0]);
|
static int CommandCount = sizeof(commands) / sizeof(commands[0]);
|
||||||
|
|
||||||
static struct { int w, h; } cursorSize[] = {
|
static struct
|
||||||
{24, 24}, {13, 37}, {5, 53}, {43, 64}, {300, 300}
|
{
|
||||||
|
int w, h;
|
||||||
|
} cursorSize[] = {
|
||||||
|
{ 24, 24 }, { 13, 37 }, { 5, 53 }, { 43, 64 }, { 300, 300 }
|
||||||
};
|
};
|
||||||
|
|
||||||
static int SizeCount = sizeof(cursorSize) / sizeof(cursorSize[0]);
|
static int SizeCount = sizeof(cursorSize) / sizeof(cursorSize[0]);
|
||||||
@ -92,7 +99,7 @@ static void command_callback(int key)
|
|||||||
{
|
{
|
||||||
for (x = 0; x < w; x++)
|
for (x = 0; x < w; x++)
|
||||||
{
|
{
|
||||||
image[i++] = 0xFF;
|
image[i++] = 0xff;
|
||||||
image[i++] = 0;
|
image[i++] = 0;
|
||||||
image[i++] = 255 * y / h;
|
image[i++] = 255 * y / h;
|
||||||
image[i++] = 255 * x / w;
|
image[i++] = 255 * x / w;
|
||||||
@ -103,8 +110,9 @@ static void command_callback(int key)
|
|||||||
currentSize = (currentSize + 1) % SizeCount;
|
currentSize = (currentSize + 1) % SizeCount;
|
||||||
free(image);
|
free(image);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case GLFW_KEY_D:
|
case GLFW_KEY_D:
|
||||||
{
|
{
|
||||||
@ -113,8 +121,9 @@ static void command_callback(int key)
|
|||||||
glfwDestroyCursor(cursor);
|
glfwDestroyCursor(cursor);
|
||||||
cursor = NULL;
|
cursor = NULL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case GLFW_KEY_S:
|
case GLFW_KEY_S:
|
||||||
{
|
{
|
||||||
@ -122,31 +131,24 @@ static void command_callback(int key)
|
|||||||
glfwSetCursor(activeWindow, cursor);
|
glfwSetCursor(activeWindow, cursor);
|
||||||
else
|
else
|
||||||
printf("The cursor is not created\n");
|
printf("The cursor is not created\n");
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case GLFW_KEY_N:
|
case GLFW_KEY_N:
|
||||||
{
|
|
||||||
glfwSetCursor(activeWindow, NULL);
|
glfwSetCursor(activeWindow, NULL);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GLFW_KEY_1:
|
case GLFW_KEY_1:
|
||||||
{
|
|
||||||
glfwSetInputMode(activeWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(activeWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GLFW_KEY_2:
|
case GLFW_KEY_2:
|
||||||
{
|
|
||||||
glfwSetInputMode(activeWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
glfwSetInputMode(activeWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GLFW_KEY_3:
|
case GLFW_KEY_3:
|
||||||
{
|
|
||||||
glfwSetInputMode(activeWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
glfwSetInputMode(activeWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user