ref: baf88b0d4b24d456ef92f0bdc92c96235ed757cd
parent: 51e6cb5a6cf6698e53d8ceac975dada5c5bbf4ee
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri Sep 25 09:56:23 EDT 2020
Convert cursors to RGBA ...instead of colour-keyed RGB. Less goofing-around for the user.
binary files a/assets/resources/CURSOR/CURSOR_IKA.png b/assets/resources/CURSOR/CURSOR_IKA.png differ
binary files a/assets/resources/CURSOR/CURSOR_NORMAL.png b/assets/resources/CURSOR/CURSOR_NORMAL.png differ
--- a/src/Backends/Misc.h
+++ b/src/Backends/Misc.h
@@ -92,7 +92,7 @@
bool Backend_GetBasePath(std::string *string_buffer);
void Backend_HideMouse(void);
void Backend_SetWindowIcon(const unsigned char *rgb_pixels, size_t width, size_t height);
-void Backend_SetCursor(const unsigned char *rgb_pixels, size_t width, size_t height);
+void Backend_SetCursor(const unsigned char *rgba_pixels, size_t width, size_t height);
void PlaybackBackend_EnableDragAndDrop(void);
bool Backend_SystemTask(bool active);
void Backend_GetKeyboardState(bool *keyboard_state);
--- a/src/Backends/Platform/GLFW3.cpp
+++ b/src/Backends/Platform/GLFW3.cpp
@@ -229,45 +229,13 @@
}
}
-void Backend_SetCursor(const unsigned char *rgb_pixels, size_t width, size_t height)
+void Backend_SetCursor(const unsigned char *rgba_pixels, size_t width, size_t height)
{
- // Convert to RGBA, since that's the only thing GLFW3 accepts
- unsigned char *rgba_pixels = (unsigned char*)malloc(width * height * 4);
+ GLFWimage glfw_image = {(int)width, (int)height, rgba_pixels};
+ cursor = glfwCreateCursor(&glfw_image, 0, 0);
- const unsigned char *rgb_pointer = rgb_pixels;
- unsigned char *rgba_pointer = rgba_pixels;
-
- if (rgba_pixels != NULL)
- {
- for (size_t y = 0; y < height; ++y)
- {
- for (size_t x = 0; x < width; ++x)
- {
- if (rgb_pointer[0] == 0xFF && rgb_pointer[1] == 0 && rgb_pointer[2] == 0xFF) // Colour-key
- {
- *rgba_pointer++ = *rgb_pointer++;
- *rgba_pointer++ = *rgb_pointer++;
- *rgba_pointer++ = *rgb_pointer++;
- *rgba_pointer++ = 0;
- }
- else
- {
- *rgba_pointer++ = *rgb_pointer++;
- *rgba_pointer++ = *rgb_pointer++;
- *rgba_pointer++ = *rgb_pointer++;
- *rgba_pointer++ = 0xFF;
- }
- }
- }
-
- GLFWimage glfw_image = {(int)width, (int)height, rgba_pixels};
- cursor = glfwCreateCursor(&glfw_image, 0, 0);
-
- if (cursor != NULL)
- glfwSetCursor(window, cursor);
-
- free(rgba_pixels);
- }
+ if (cursor != NULL)
+ glfwSetCursor(window, cursor);
}
void Backend_EnableDragAndDrop(void)
--- a/src/Backends/Platform/Null.cpp
+++ b/src/Backends/Platform/Null.cpp
@@ -41,9 +41,9 @@
(void)height;
}
-void Backend_SetCursor(const unsigned char *rgb_pixels, size_t width, size_t height)
+void Backend_SetCursor(const unsigned char *rgba_pixels, size_t width, size_t height)
{
- (void)rgb_pixels;
+ (void)rgba_pixels;
(void)width;
(void)height;
}
--- a/src/Backends/Platform/SDL2.cpp
+++ b/src/Backends/Platform/SDL2.cpp
@@ -134,25 +134,22 @@
}
}
-void Backend_SetCursor(const unsigned char *rgb_pixels, size_t width, size_t height)
+void Backend_SetCursor(const unsigned char *rgba_pixels, size_t width, size_t height)
{
- cursor_surface_pixels = (unsigned char*)malloc(width * height * 3);
+ cursor_surface_pixels = (unsigned char*)malloc(width * height * 4);
if (cursor_surface_pixels != NULL)
{
- memcpy(cursor_surface_pixels, rgb_pixels, width * height * 3);
+ memcpy(cursor_surface_pixels, rgba_pixels, width * height * 4);
- cursor_surface = SDL_CreateRGBSurfaceWithFormatFrom(cursor_surface_pixels, width, height, 0, width * 3, SDL_PIXELFORMAT_RGB24);
+ cursor_surface = SDL_CreateRGBSurfaceWithFormatFrom(cursor_surface_pixels, width, height, 0, width * 4, SDL_PIXELFORMAT_RGBA32);
if (cursor_surface != NULL)
{
- if (SDL_SetColorKey(cursor_surface, SDL_TRUE, SDL_MapRGB(cursor_surface->format, 0xFF, 0, 0xFF)) == 0)
- {
- cursor = SDL_CreateColorCursor(cursor_surface, 0, 0);
+ cursor = SDL_CreateColorCursor(cursor_surface, 0, 0);
- if (cursor != NULL)
- SDL_SetCursor(cursor);
- }
+ if (cursor != NULL)
+ SDL_SetCursor(cursor);
}
}
else
--- a/src/Backends/Platform/WiiU.cpp
+++ b/src/Backends/Platform/WiiU.cpp
@@ -83,9 +83,9 @@
(void)height;
}
-void Backend_SetCursor(const unsigned char *rgb_pixels, size_t width, size_t height)
+void Backend_SetCursor(const unsigned char *rgba_pixels, size_t width, size_t height)
{
- (void)rgb_pixels;
+ (void)rgba_pixels;
(void)width;
(void)height;
}
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -312,12 +312,12 @@
if (cursor_resource_data != NULL)
{
size_t cursor_width, cursor_height;
- unsigned char *cursor_rgb_pixels = DecodeBitmap(cursor_resource_data, cursor_resource_size, &cursor_width, &cursor_height, 3);
+ unsigned char *cursor_rgba_pixels = DecodeBitmap(cursor_resource_data, cursor_resource_size, &cursor_width, &cursor_height, 4);
- if (cursor_rgb_pixels != NULL)
+ if (cursor_rgba_pixels != NULL)
{
- Backend_SetCursor(cursor_rgb_pixels, cursor_width, cursor_height);
- FreeBitmap(cursor_rgb_pixels);
+ Backend_SetCursor(cursor_rgba_pixels, cursor_width, cursor_height);
+ FreeBitmap(cursor_rgba_pixels);
}
}