mirror of
https://github.com/glfw/glfw.git
synced 2026-09-20 16:30:45 +00:00
Added GLFWimage struct.
This commit is contained in:
+22
-18
@@ -88,29 +88,33 @@ static void command_callback(int key)
|
||||
|
||||
case GLFW_KEY_C:
|
||||
{
|
||||
if (cursor == NULL)
|
||||
int x, y;
|
||||
GLFWimage image;
|
||||
unsigned char* pixels;
|
||||
|
||||
if (cursor)
|
||||
break;
|
||||
|
||||
image.width = cursorSize[currentSize].w;
|
||||
image.height = cursorSize[currentSize].h;
|
||||
|
||||
pixels = malloc(4 * image.width * image.height);
|
||||
image.pixels = pixels;
|
||||
|
||||
for (y = 0; y < image.height; y++)
|
||||
{
|
||||
int w = cursorSize[currentSize].w;
|
||||
int h = cursorSize[currentSize].h;
|
||||
int x, y, i = 0;
|
||||
unsigned char *image = malloc(4 * w * h);
|
||||
|
||||
for (y = 0; y < h; y++)
|
||||
for (x = 0; x < image.width; x++)
|
||||
{
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
image[i++] = 0xff;
|
||||
image[i++] = 0;
|
||||
image[i++] = 255 * y / h;
|
||||
image[i++] = 255 * x / w;
|
||||
}
|
||||
*pixels++ = 0xff;
|
||||
*pixels++ = 0;
|
||||
*pixels++ = 255 * y / image.height;
|
||||
*pixels++ = 255 * x / image.width;
|
||||
}
|
||||
|
||||
cursor = glfwCreateCursor(w, h, w / 2, h / 2, 0, image);
|
||||
currentSize = (currentSize + 1) % SizeCount;
|
||||
free(image);
|
||||
}
|
||||
|
||||
cursor = glfwCreateCursor(&image, image.width / 2, image.height / 2);
|
||||
currentSize = (currentSize + 1) % SizeCount;
|
||||
free(image.pixels);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -66,10 +66,11 @@ static float star(int x, int y, float t)
|
||||
static GLFWcursor* load_frame(float t)
|
||||
{
|
||||
int i = 0, x, y;
|
||||
const GLFWimage image = { SIZE, SIZE, buffer };
|
||||
|
||||
for (y = 0; y < SIZE; y++)
|
||||
for (y = 0; y < image.width; y++)
|
||||
{
|
||||
for (x = 0; x < SIZE; x++)
|
||||
for (x = 0; x < image.height; x++)
|
||||
{
|
||||
buffer[i++] = 255;
|
||||
buffer[i++] = 255;
|
||||
@@ -78,7 +79,7 @@ static GLFWcursor* load_frame(float t)
|
||||
}
|
||||
}
|
||||
|
||||
return glfwCreateCursor(SIZE, SIZE, SIZE / 2, SIZE / 2, 0, buffer);
|
||||
return glfwCreateCursor(&image, image.width / 2, image.height / 2);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
||||
Reference in New Issue
Block a user