Restore custom cursor support
This commit is contained in:
parent
f23117bbdc
commit
add0627f03
4 changed files with 79 additions and 25 deletions
|
@ -10,6 +10,7 @@ void PlatformBackend_PostWindowCreation(void);
|
||||||
BOOL PlatformBackend_GetBasePath(char *string_buffer);
|
BOOL PlatformBackend_GetBasePath(char *string_buffer);
|
||||||
void PlatformBackend_HideMouse(void);
|
void PlatformBackend_HideMouse(void);
|
||||||
void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height);
|
void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height);
|
||||||
|
void PlatformBackend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height);
|
||||||
BOOL PlatformBackend_SystemTask(void);
|
BOOL PlatformBackend_SystemTask(void);
|
||||||
void PlatformBackend_ShowMessageBox(const char *title, const char *message);
|
void PlatformBackend_ShowMessageBox(const char *title, const char *message);
|
||||||
unsigned long PlatformBackend_GetTicks(void);
|
unsigned long PlatformBackend_GetTicks(void);
|
||||||
|
|
|
@ -18,9 +18,11 @@
|
||||||
#include "../../Profile.h"
|
#include "../../Profile.h"
|
||||||
#include "../../Resource.h"
|
#include "../../Resource.h"
|
||||||
|
|
||||||
|
GLFWwindow *window;
|
||||||
|
|
||||||
BOOL bActive = TRUE;
|
BOOL bActive = TRUE;
|
||||||
|
|
||||||
GLFWwindow *window;
|
static GLFWcursor* cursor;
|
||||||
|
|
||||||
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||||
{
|
{
|
||||||
|
@ -222,6 +224,9 @@ void PlatformBackend_Init(void)
|
||||||
|
|
||||||
void PlatformBackend_Deinit(void)
|
void PlatformBackend_Deinit(void)
|
||||||
{
|
{
|
||||||
|
if (cursor != NULL)
|
||||||
|
glfwDestroyCursor(cursor);
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +275,43 @@ void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlatformBackend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height)
|
||||||
|
{
|
||||||
|
unsigned char *rgba_pixels = (unsigned char*)malloc(width * height * 4);
|
||||||
|
|
||||||
|
const unsigned char *rgb_pointer = rgb_pixels;
|
||||||
|
unsigned char *rgba_pointer = rgba_pixels;
|
||||||
|
|
||||||
|
if (rgba_pixels != NULL)
|
||||||
|
{
|
||||||
|
for (unsigned int y = 0; y < height; ++y)
|
||||||
|
{
|
||||||
|
for (unsigned int x = 0; x < width; ++x)
|
||||||
|
{
|
||||||
|
if (rgb_pointer[0] == 0xFF && rgb_pointer[1] == 0 && rgb_pointer[2] == 0xFF)
|
||||||
|
{
|
||||||
|
*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);
|
||||||
|
glfwSetCursor(window, cursor);
|
||||||
|
|
||||||
|
free(rgba_pixels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BOOL PlatformBackend_SystemTask(void)
|
BOOL PlatformBackend_SystemTask(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,9 @@ SDL_Window *window;
|
||||||
|
|
||||||
BOOL bActive = TRUE;
|
BOOL bActive = TRUE;
|
||||||
|
|
||||||
|
static SDL_Surface *cursor_surface;
|
||||||
|
static SDL_Cursor *cursor;
|
||||||
|
|
||||||
void PlatformBackend_Init(void)
|
void PlatformBackend_Init(void)
|
||||||
{
|
{
|
||||||
SDL_Init(SDL_INIT_EVENTS);
|
SDL_Init(SDL_INIT_EVENTS);
|
||||||
|
@ -37,6 +40,12 @@ void PlatformBackend_Init(void)
|
||||||
|
|
||||||
void PlatformBackend_Deinit(void)
|
void PlatformBackend_Deinit(void)
|
||||||
{
|
{
|
||||||
|
if (cursor != NULL)
|
||||||
|
SDL_FreeCursor(cursor);
|
||||||
|
|
||||||
|
if (cursor_surface != NULL)
|
||||||
|
SDL_FreeSurface(cursor_surface);
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +77,14 @@ void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int
|
||||||
SDL_FreeSurface(surface);
|
SDL_FreeSurface(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlatformBackend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height)
|
||||||
|
{
|
||||||
|
cursor_surface = SDL_CreateRGBSurfaceWithFormatFrom((void*)rgb_pixels, width, height, 0, width * 3, SDL_PIXELFORMAT_RGB24);
|
||||||
|
SDL_SetColorKey(cursor_surface, SDL_TRUE, SDL_MapRGB(cursor_surface->format, 0xFF, 0, 0xFF));
|
||||||
|
cursor = SDL_CreateColorCursor(cursor_surface, 0, 0);
|
||||||
|
SDL_SetCursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
BOOL PlatformBackend_SystemTask(void)
|
BOOL PlatformBackend_SystemTask(void)
|
||||||
{
|
{
|
||||||
while (SDL_PollEvent(NULL) || !bActive)
|
while (SDL_PollEvent(NULL) || !bActive)
|
||||||
|
|
42
src/Main.cpp
42
src/Main.cpp
|
@ -223,8 +223,6 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 0))
|
if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 0))
|
||||||
{
|
{
|
||||||
//SDL_FreeCursor(cursor);
|
|
||||||
//SDL_FreeSurface(cursor_surface);
|
|
||||||
PlatformBackend_Deinit();
|
PlatformBackend_Deinit();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -233,8 +231,6 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 1))
|
if (!StartDirectDraw(lpWindowName, windowWidth, windowHeight, 1))
|
||||||
{
|
{
|
||||||
//SDL_FreeCursor(cursor);
|
|
||||||
//SDL_FreeSurface(cursor_surface);
|
|
||||||
PlatformBackend_Deinit();
|
PlatformBackend_Deinit();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -285,25 +281,29 @@ int main(int argc, char *argv[])
|
||||||
size_t window_icon_resource_size;
|
size_t window_icon_resource_size;
|
||||||
const unsigned char *window_icon_resource_data = FindResource("ICON_MINI", "ICON", &window_icon_resource_size);
|
const unsigned char *window_icon_resource_data = FindResource("ICON_MINI", "ICON", &window_icon_resource_size);
|
||||||
|
|
||||||
unsigned int width, height;
|
unsigned int window_icon_width, window_icon_height;
|
||||||
unsigned char *rgb_pixels = DecodeBitmap(window_icon_resource_data, window_icon_resource_size, &width, &height);
|
unsigned char *window_icon_rgb_pixels = DecodeBitmap(window_icon_resource_data, window_icon_resource_size, &window_icon_width, &window_icon_height);
|
||||||
|
|
||||||
if (rgb_pixels != NULL)
|
if (window_icon_rgb_pixels != NULL)
|
||||||
{
|
{
|
||||||
PlatformBackend_SetWindowIcon(rgb_pixels, width, height);
|
PlatformBackend_SetWindowIcon(window_icon_rgb_pixels, window_icon_width, window_icon_height);
|
||||||
FreeBitmap(rgb_pixels);
|
FreeBitmap(window_icon_rgb_pixels);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/*
|
|
||||||
// Set up the cursor
|
// Set up the cursor
|
||||||
size_t resource_size;
|
size_t cursor_resource_size;
|
||||||
const unsigned char *resource_data = FindResource("CURSOR_NORMAL", "CURSOR", &resource_size);
|
const unsigned char *cursor_resource_data = FindResource("CURSOR_NORMAL", "CURSOR", &cursor_resource_size);
|
||||||
SDL_RWops *rwops = SDL_RWFromConstMem(resource_data, resource_size);
|
|
||||||
SDL_Surface *cursor_surface = SDL_LoadBMP_RW(rwops, 1);
|
unsigned int cursor_width, cursor_height;
|
||||||
SDL_SetColorKey(cursor_surface, SDL_TRUE, SDL_MapRGB(cursor_surface->format, 0xFF, 0, 0xFF));
|
unsigned char *cursor_rgb_pixels = DecodeBitmap(cursor_resource_data, cursor_resource_size, &cursor_width, &cursor_height);
|
||||||
SDL_Cursor *cursor = SDL_CreateColorCursor(cursor_surface, 0, 0);
|
|
||||||
SDL_SetCursor(cursor);
|
if (cursor_rgb_pixels != NULL)
|
||||||
*/
|
{
|
||||||
|
PlatformBackend_SetCursor(cursor_rgb_pixels, cursor_width, cursor_height);
|
||||||
|
FreeBitmap(cursor_rgb_pixels);
|
||||||
|
}
|
||||||
|
|
||||||
if (IsKeyFile("fps"))
|
if (IsKeyFile("fps"))
|
||||||
bFps = TRUE;
|
bFps = TRUE;
|
||||||
|
|
||||||
|
@ -323,8 +323,6 @@ int main(int argc, char *argv[])
|
||||||
// Draw to screen
|
// Draw to screen
|
||||||
if (!Flip_SystemTask())
|
if (!Flip_SystemTask())
|
||||||
{
|
{
|
||||||
//SDL_FreeCursor(cursor);
|
|
||||||
//SDL_FreeSurface(cursor_surface);
|
|
||||||
PlatformBackend_Deinit();
|
PlatformBackend_Deinit();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -350,10 +348,6 @@ int main(int argc, char *argv[])
|
||||||
EndTextObject();
|
EndTextObject();
|
||||||
EndDirectSound();
|
EndDirectSound();
|
||||||
EndDirectDraw();
|
EndDirectDraw();
|
||||||
/*
|
|
||||||
SDL_FreeCursor(cursor);
|
|
||||||
SDL_FreeSurface(cursor_surface);
|
|
||||||
*/
|
|
||||||
|
|
||||||
PlatformBackend_Deinit();
|
PlatformBackend_Deinit();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue