mirror of
https://github.com/glfw/glfw.git
synced 2026-09-19 07:05:49 +00:00
Added GLFWimage struct.
This commit is contained in:
+12
-11
@@ -1201,37 +1201,38 @@ void _glfwPlatformApplyCursorMode(_GLFWwindow* window)
|
||||
CGAssociateMouseAndMouseCursorPosition(true);
|
||||
}
|
||||
|
||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int xhot, int yhot,
|
||||
int format, const void* data)
|
||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
|
||||
const GLFWimage* image,
|
||||
int xhot, int yhot)
|
||||
{
|
||||
NSImage* image;
|
||||
NSImage* native;
|
||||
NSBitmapImageRep* rep;
|
||||
|
||||
rep = [[NSBitmapImageRep alloc]
|
||||
initWithBitmapDataPlanes:NULL
|
||||
pixelsWide:width
|
||||
pixelsHigh:height
|
||||
pixelsWide:image->width
|
||||
pixelsHigh:image->height
|
||||
bitsPerSample:8
|
||||
samplesPerPixel:4
|
||||
hasAlpha:YES
|
||||
isPlanar:NO
|
||||
colorSpaceName:NSCalibratedRGBColorSpace
|
||||
bitmapFormat:NSAlphaNonpremultipliedBitmapFormat
|
||||
bytesPerRow:width * 4
|
||||
bytesPerRow:image->width * 4
|
||||
bitsPerPixel:32];
|
||||
|
||||
if (rep == nil)
|
||||
return GL_FALSE;
|
||||
|
||||
memcpy([rep bitmapData], data, width * height * 4);
|
||||
memcpy([rep bitmapData], image->pixels, image->width * image->height * 4);
|
||||
|
||||
image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
|
||||
[image addRepresentation: rep];
|
||||
native = [[NSImage alloc] initWithSize:NSMakeSize(image->width, image->height)];
|
||||
[native addRepresentation: rep];
|
||||
|
||||
cursor->ns.object = [[NSCursor alloc] initWithImage:image
|
||||
cursor->ns.object = [[NSCursor alloc] initWithImage:native
|
||||
hotSpot:NSMakePoint(xhot, yhot)];
|
||||
|
||||
[image release];
|
||||
[native release];
|
||||
[rep release];
|
||||
|
||||
if (cursor->ns.object == nil)
|
||||
|
||||
+2
-3
@@ -353,8 +353,7 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
|
||||
_glfwPlatformSetCursorPos(window, xpos, ypos);
|
||||
}
|
||||
|
||||
GLFWAPI GLFWcursor* glfwCreateCursor(int width, int height, int xhot, int yhot,
|
||||
int format, const void* data)
|
||||
GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot)
|
||||
{
|
||||
_GLFWcursor* cursor;
|
||||
|
||||
@@ -364,7 +363,7 @@ GLFWAPI GLFWcursor* glfwCreateCursor(int width, int height, int xhot, int yhot,
|
||||
cursor->next = _glfw.cursorListHead;
|
||||
_glfw.cursorListHead = cursor;
|
||||
|
||||
if (!_glfwPlatformCreateCursor(cursor, width, height, xhot, yhot, format, data))
|
||||
if (!_glfwPlatformCreateCursor(cursor, image, xhot, yhot))
|
||||
{
|
||||
glfwDestroyCursor((GLFWcursor*) cursor);
|
||||
return NULL;
|
||||
|
||||
+1
-2
@@ -588,8 +588,7 @@ int _glfwPlatformExtensionSupported(const char* extension);
|
||||
*/
|
||||
GLFWglproc _glfwPlatformGetProcAddress(const char* procname);
|
||||
|
||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int xhot, int yhot,
|
||||
int format, const void* data);
|
||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot);
|
||||
|
||||
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor);
|
||||
|
||||
|
||||
+8
-7
@@ -1223,21 +1223,22 @@ void _glfwPlatformApplyCursorMode(_GLFWwindow* window)
|
||||
}
|
||||
}
|
||||
|
||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int xhot, int yhot,
|
||||
int format, const void* data)
|
||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
|
||||
const GLFWimage* image,
|
||||
int xhot, int yhot)
|
||||
{
|
||||
HDC dc;
|
||||
HBITMAP bitmap, mask;
|
||||
BITMAPV5HEADER bi;
|
||||
ICONINFO ii;
|
||||
DWORD* target = 0;
|
||||
BYTE* source = (BYTE*) data;
|
||||
BYTE* source = (BYTE*) image->pixels;
|
||||
int i;
|
||||
|
||||
ZeroMemory(&bi, sizeof(bi));
|
||||
bi.bV5Size = sizeof(BITMAPV5HEADER);
|
||||
bi.bV5Width = width;
|
||||
bi.bV5Height = -height;
|
||||
bi.bV5Width = image->width;
|
||||
bi.bV5Height = -image->height;
|
||||
bi.bV5Planes = 1;
|
||||
bi.bV5BitCount = 32;
|
||||
bi.bV5Compression = BI_BITFIELDS;
|
||||
@@ -1254,14 +1255,14 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int xh
|
||||
if (!bitmap)
|
||||
return GL_FALSE;
|
||||
|
||||
mask = CreateBitmap(width, height, 1, 1, NULL);
|
||||
mask = CreateBitmap(image->width, image->height, 1, 1, NULL);
|
||||
if (!mask)
|
||||
{
|
||||
DeleteObject(bitmap);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < width * height; i++, target++, source += 4)
|
||||
for (i = 0; i < image->width * image->height; i++, target++, source += 4)
|
||||
*target = (source[3] << 24) | (source[0] << 16) | (source[1] << 8) | source[2];
|
||||
|
||||
ZeroMemory(&ii, sizeof(ii));
|
||||
|
||||
+6
-5
@@ -1356,22 +1356,23 @@ void _glfwPlatformApplyCursorMode(_GLFWwindow* window)
|
||||
}
|
||||
}
|
||||
|
||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int width, int height, int xhot, int yhot,
|
||||
int format, const void* data)
|
||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
|
||||
const GLFWimage* image,
|
||||
int xhot, int yhot)
|
||||
{
|
||||
int i;
|
||||
|
||||
XcursorImage* native = XcursorImageCreate(width, height);
|
||||
XcursorImage* native = XcursorImageCreate(image->width, image->height);
|
||||
if (native == NULL)
|
||||
return GL_FALSE;
|
||||
|
||||
native->xhot = xhot;
|
||||
native->yhot = yhot;
|
||||
|
||||
unsigned char* source = (unsigned char*) data;
|
||||
unsigned char* source = (unsigned char*) image->pixels;
|
||||
XcursorPixel* target = native->pixels;
|
||||
|
||||
for (i = 0; i < width * height; i++, target++, source += 4)
|
||||
for (i = 0; i < image->width * image->height; i++, target++, source += 4)
|
||||
*target = (source[3] << 24) | (source[0] << 16) | (source[1] << 8) | source[2];
|
||||
|
||||
cursor->x11.handle = XcursorImageLoadCursor(_glfw.x11.display, native);
|
||||
|
||||
Reference in New Issue
Block a user