Make some backend code safer
This commit is contained in:
parent
6456649e11
commit
5395b00a95
2 changed files with 30 additions and 7 deletions
|
@ -245,6 +245,8 @@ void Backend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsi
|
||||||
|
|
||||||
GLFWimage glfw_image = {(int)width, (int)height, rgba_pixels};
|
GLFWimage glfw_image = {(int)width, (int)height, rgba_pixels};
|
||||||
cursor = glfwCreateCursor(&glfw_image, 0, 0);
|
cursor = glfwCreateCursor(&glfw_image, 0, 0);
|
||||||
|
|
||||||
|
if (cursor != NULL)
|
||||||
glfwSetCursor(window, cursor);
|
glfwSetCursor(window, cursor);
|
||||||
|
|
||||||
free(rgba_pixels);
|
free(rgba_pixels);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
@ -25,6 +26,7 @@ BOOL bActive = TRUE;
|
||||||
|
|
||||||
static BOOL keyboard_state[BACKEND_KEYBOARD_TOTAL];
|
static BOOL keyboard_state[BACKEND_KEYBOARD_TOTAL];
|
||||||
|
|
||||||
|
static unsigned char *cursor_surface_pixels;
|
||||||
static SDL_Surface *cursor_surface;
|
static SDL_Surface *cursor_surface;
|
||||||
static SDL_Cursor *cursor;
|
static SDL_Cursor *cursor;
|
||||||
|
|
||||||
|
@ -50,6 +52,8 @@ void Backend_Deinit(void)
|
||||||
if (cursor_surface != NULL)
|
if (cursor_surface != NULL)
|
||||||
SDL_FreeSurface(cursor_surface);
|
SDL_FreeSurface(cursor_surface);
|
||||||
|
|
||||||
|
free(cursor_surface_pixels);
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,16 +82,33 @@ void Backend_HideMouse(void)
|
||||||
void Backend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height)
|
void Backend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height)
|
||||||
{
|
{
|
||||||
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom((void*)rgb_pixels, width, height, 0, width * 3, SDL_PIXELFORMAT_RGB24);
|
SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom((void*)rgb_pixels, width, height, 0, width * 3, SDL_PIXELFORMAT_RGB24);
|
||||||
|
|
||||||
|
if (surface != NULL)
|
||||||
|
{
|
||||||
SDL_SetWindowIcon(window, surface);
|
SDL_SetWindowIcon(window, surface);
|
||||||
SDL_FreeSurface(surface);
|
SDL_FreeSurface(surface);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height)
|
void Backend_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);
|
cursor_surface_pixels = (unsigned char*)malloc(width * height * 3);
|
||||||
SDL_SetColorKey(cursor_surface, SDL_TRUE, SDL_MapRGB(cursor_surface->format, 0xFF, 0, 0xFF));
|
|
||||||
|
if (cursor_surface_pixels != NULL)
|
||||||
|
{
|
||||||
|
cursor_surface = SDL_CreateRGBSurfaceWithFormatFrom(cursor_surface_pixels, width, height, 0, width * 3, SDL_PIXELFORMAT_RGB24);
|
||||||
|
|
||||||
|
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);
|
SDL_SetCursor(cursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlaybackBackend_EnableDragAndDrop(void)
|
void PlaybackBackend_EnableDragAndDrop(void)
|
||||||
|
|
Loading…
Add table
Reference in a new issue