ref: ff70664604b15d63851fe2ba69ba82025f4f8a8a
parent: 7bd6ff861796d8d50eb9eb1f8e59cd81bdf9614f
author: Clownacy <Clownacy@users.noreply.github.com>
date: Wed Apr 1 12:11:34 EDT 2020
Cleanup and fixes
--- a/src/Backends/Platform.h
+++ b/src/Backends/Platform.h
@@ -6,6 +6,7 @@
void PlatformBackend_Init(void);
void PlatformBackend_Deinit(void);
+void PlatformBackend_PostWindowCreation(void);
BOOL PlatformBackend_GetBasePath(char *string_buffer);
BOOL PlatformBackend_SystemTask(void);
void PlatformBackend_ShowMessageBox(const char *title, const char *message);
--- a/src/Backends/Platform/GLFW3.cpp
+++ b/src/Backends/Platform/GLFW3.cpp
@@ -1,6 +1,8 @@
#include "../Platform.h"
#include <chrono>
+#include <stddef.h>
+#include <stdlib.h>
#include <thread>
#include <GLFW/glfw3.h>
@@ -9,16 +11,18 @@
#include "../../WindowsWrapper.h"
+#include "../../Bitmap.h"
#include "../../KeyControl.h"
#include "../../Main.h"
#include "../../Organya.h"
#include "../../Profile.h"
+#include "../../Resource.h"
BOOL bActive = TRUE;
extern GLFWwindow *window;
-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)
{
(void)window;
(void)scancode;
@@ -194,7 +198,7 @@
}
}
-void WindowFocusCallback(GLFWwindow *window, int focused)
+static void WindowFocusCallback(GLFWwindow *window, int focused)
{
(void)window;
@@ -204,13 +208,11 @@
InactiveWindow();
}
-void WindowSizeCallback(GLFWwindow *window, int width, int height)
+static void WindowSizeCallback(GLFWwindow *window, int width, int height)
{
(void)window;
- (void)width;
- (void)height;
- Backend_HandleWindowResize();
+ Backend_HandleWindowResize(width, height);
}
void PlatformBackend_Init(void)
@@ -221,6 +223,54 @@
void PlatformBackend_Deinit(void)
{
glfwTerminate();
+}
+
+void PlatformBackend_PostWindowCreation(void)
+{
+ // Hook callbacks
+ glfwSetKeyCallback(window, KeyCallback);
+ glfwSetWindowFocusCallback(window, WindowFocusCallback);
+ glfwSetWindowSizeCallback(window, WindowSizeCallback);
+
+ // Set up window icon
+
+ // TODO - GLFW_ICON
+#ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does)
+ size_t resource_size;
+ const unsigned char *resource_data = FindResource("ICON_MINI", "ICON", &resource_size);
+
+ unsigned int width, height;
+ unsigned char *rgb_pixels = DecodeBitmap(resource_data, resource_size, &width, &height);
+
+ if (rgb_pixels != NULL)
+ {
+ unsigned char *rgba_pixels = (unsigned char*)malloc(width * height * 4);
+
+ 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)
+ {
+ *rgba_pointer++ = *rgb_pointer++;
+ *rgba_pointer++ = *rgb_pointer++;
+ *rgba_pointer++ = *rgb_pointer++;
+ *rgba_pointer++ = 0xFF;
+ }
+ }
+
+ GLFWimage glfw_image = {(int)width, (int)height, rgba_pixels};
+ glfwSetWindowIcon(window, 1, &glfw_image);
+
+ free(rgba_pixels);
+ }
+
+ FreeBitmap(rgb_pixels);
+ }
+#endif
}
BOOL PlatformBackend_GetBasePath(char *string_buffer)
--- a/src/Backends/Platform/SDL2.cpp
+++ b/src/Backends/Platform/SDL2.cpp
@@ -10,7 +10,10 @@
#include "../../Main.h"
#include "../../Organya.h"
#include "../../Profile.h"
+#include "../../Resource.h"
+extern SDL_Window *window;
+
BOOL bActive = TRUE;
void PlatformBackend_Init(void)
@@ -23,6 +26,13 @@
#endif
SDL_InitSubSystem(SDL_INIT_VIDEO);
+
+ puts("Available SDL2 video drivers:");
+
+ for (int i = 0; i < SDL_GetNumVideoDrivers(); ++i)
+ puts(SDL_GetVideoDriver(i));
+
+ printf("Selected SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
}
void PlatformBackend_Deinit(void)
@@ -30,6 +40,19 @@
SDL_Quit();
}
+void PlatformBackend_PostWindowCreation(void)
+{
+ // Set up window icon
+#ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does)
+ size_t resource_size;
+ const unsigned char *resource_data = FindResource("ICON_MINI", "ICON", &resource_size);
+ SDL_RWops *rwops = SDL_RWFromConstMem(resource_data, resource_size);
+ SDL_Surface *icon_surface = SDL_LoadBMP_RW(rwops, 1);
+ SDL_SetWindowIcon(window, icon_surface);
+ SDL_FreeSurface(icon_surface);
+#endif
+}
+
BOOL PlatformBackend_GetBasePath(char *string_buffer)
{
char *base_path = SDL_GetBasePath();
@@ -240,7 +263,7 @@
case SDL_WINDOWEVENT_RESIZED:
case SDL_WINDOWEVENT_SIZE_CHANGED:
- Backend_HandleWindowResize();
+ Backend_HandleWindowResize(event.window.data1, event.window.data2);
break;
}
@@ -262,7 +285,7 @@
void PlatformBackend_ShowMessageBox(const char *title, const char *message)
{
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, NULL);
+ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, window);
}
unsigned long PlatformBackend_GetTicks(void)
--- a/src/Backends/Rendering.h
+++ b/src/Backends/Rendering.h
@@ -23,4 +23,4 @@
void Backend_DrawGlyph(Backend_Glyph *glyph, long x, long y);
void Backend_FlushGlyphs(void);
void Backend_HandleRenderTargetLoss(void);
-void Backend_HandleWindowResize(void);
+void Backend_HandleWindowResize(unsigned int width, unsigned int height);
--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -1029,7 +1029,8 @@
// No problem for us
}
-void Backend_HandleWindowResize(void)
+void Backend_HandleWindowResize(unsigned int width, unsigned int height)
{
- // No problem for us
+ actual_screen_width = width;
+ actual_screen_height = height;
}
--- a/src/Backends/Rendering/SDLSurface.cpp
+++ b/src/Backends/Rendering/SDLSurface.cpp
@@ -1,14 +1,14 @@
#include "../Rendering.h"
#include <stddef.h>
-#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "SDL.h"
#include "../../WindowsWrapper.h"
-#include "../../Resource.h"
+#include "../Platform.h"
typedef struct Backend_Surface
{
@@ -44,26 +44,10 @@
Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
{
- puts("Available SDL2 video drivers:");
-
- for (int i = 0; i < SDL_GetNumVideoDrivers(); ++i)
- puts(SDL_GetVideoDriver(i));
-
- printf("Selected SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
-
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
if (window != NULL)
{
- #ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does)
- size_t resource_size;
- const unsigned char *resource_data = FindResource("ICON_MINI", "ICON", &resource_size);
- SDL_RWops *rwops = SDL_RWFromConstMem(resource_data, resource_size);
- SDL_Surface *icon_surface = SDL_LoadBMP_RW(rwops, 1);
- SDL_SetWindowIcon(window, icon_surface);
- SDL_FreeSurface(icon_surface);
- #endif
-
if (fullscreen)
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
@@ -72,9 +56,15 @@
framebuffer.sdlsurface = SDL_CreateRGBSurfaceWithFormat(0, window_sdlsurface->w, window_sdlsurface->h, 0, SDL_PIXELFORMAT_RGB24);
if (framebuffer.sdlsurface != NULL)
+ {
+ PlatformBackend_PostWindowCreation();
+
return &framebuffer;
+ }
else
+ {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (SDLSurface rendering backend)", "Could not create framebuffer surface", window);
+ }
SDL_DestroyWindow(window);
}
--- a/src/Backends/Rendering/SDLTexture.cpp
+++ b/src/Backends/Rendering/SDLTexture.cpp
@@ -1,8 +1,8 @@
#include "../Rendering.h"
#include <stddef.h>
-#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "SDL.h"
@@ -11,10 +11,10 @@
#include "../../WindowsWrapper.h"
+#inclide "../Platform.h"
#include "../../Draw.h"
#include "../../Ending.h"
#include "../../MapName.h"
-#include "../../Resource.h"
#include "../../TextScr.h"
typedef struct Backend_Surface
@@ -116,13 +116,6 @@
Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
{
- puts("Available SDL2 video drivers:");
-
- for (int i = 0; i < SDL_GetNumVideoDrivers(); ++i)
- puts(SDL_GetVideoDriver(i));
-
- printf("Selected SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
-
puts("Available SDL2 render drivers:");
for (int i = 0; i < SDL_GetNumRenderDrivers(); ++i)
@@ -136,15 +129,6 @@
if (window != NULL)
{
- #ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does)
- size_t resource_size;
- const unsigned char *resource_data = FindResource("ICON_MINI", "ICON", &resource_size);
- SDL_RWops *rwops = SDL_RWFromConstMem(resource_data, resource_size);
- SDL_Surface *icon_surface = SDL_LoadBMP_RW(rwops, 1);
- SDL_SetWindowIcon(window, icon_surface);
- SDL_FreeSurface(icon_surface);
- #endif
-
if (fullscreen)
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
@@ -179,6 +163,8 @@
config.generate_texture_callback = GlyphBatch_CreateTexture;
config.delete_texture_callback = GlyphBatch_DestroyTexture;
spritebatch_init(&glyph_batcher, &config, NULL);
+
+ PlatformBackend_PostWindowCreation();
return &framebuffer;
}
--- a/src/Backends/Rendering/Software.cpp
+++ b/src/Backends/Rendering/Software.cpp
@@ -1,7 +1,6 @@
#include "../Rendering.h"
#include <stddef.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -9,7 +8,7 @@
#include "../../WindowsWrapper.h"
-#include "../../Resource.h"
+#include "../Platform.h"
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
@@ -39,26 +38,10 @@
Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
{
- puts("Available SDL2 video drivers:");
-
- for (int i = 0; i < SDL_GetNumVideoDrivers(); ++i)
- puts(SDL_GetVideoDriver(i));
-
- printf("Selected SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
-
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
if (window != NULL)
{
- #ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does)
- size_t resource_size;
- const unsigned char *resource_data = FindResource("ICON_MINI", "ICON", &resource_size);
- SDL_RWops *rwops = SDL_RWFromConstMem(resource_data, resource_size);
- SDL_Surface *icon_surface = SDL_LoadBMP_RW(rwops, 1);
- SDL_SetWindowIcon(window, icon_surface);
- SDL_FreeSurface(icon_surface);
- #endif
-
if (fullscreen)
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
@@ -73,11 +56,13 @@
framebuffer.height = framebuffer_sdlsurface->h;
framebuffer.pitch = framebuffer_sdlsurface->pitch;
+ PlatformBackend_PostWindowCreation();
+
return &framebuffer;
}
else
{
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (software rendering backend)", "Could not create framebuffer surface", window);
+ PlatformBackend_ShowMessageBox("Fatal error (software rendering backend)", "Could not create framebuffer surface");
}
SDL_DestroyWindow(window);
@@ -84,7 +69,7 @@
}
else
{
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (software rendering backend)", "Could not create window", NULL);
+ PlatformBackend_ShowMessageBox("Fatal error (software rendering backend)", "Could not create window");
}
return NULL;
--- a/src/Backends/Window/GLFW3-OpenGL3.cpp
+++ b/src/Backends/Window/GLFW3-OpenGL3.cpp
@@ -13,16 +13,10 @@
#include "../../WindowsWrapper.h"
#include "../Platform.h"
-#include "../../Bitmap.h"
-#include "../../Resource.h"
// Horrible hacks
GLFWwindow *window;
-void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods);
-void WindowFocusCallback(GLFWwindow *window, int focused);
-void WindowSizeCallback(GLFWwindow *window, int width, int height);
-
BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen)
{
#ifdef USE_OPENGLES2
@@ -56,44 +50,6 @@
if (window != NULL)
{
- #ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does)
- size_t resource_size;
- const unsigned char *resource_data = FindResource("ICON_MINI", "ICON", &resource_size);
-
- unsigned int width, height;
- unsigned char *rgb_pixels = DecodeBitmap(resource_data, resource_size, &width, &height);
-
- if (rgb_pixels != NULL)
- {
- unsigned char *rgba_pixels = (unsigned char*)malloc(width * height * 4);
-
- 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)
- {
- *rgba_pointer++ = *rgb_pointer++;
- *rgba_pointer++ = *rgb_pointer++;
- *rgba_pointer++ = *rgb_pointer++;
- *rgba_pointer++ = 0xFF;
- }
- }
-
- GLFWimage glfw_image = {(int)width, (int)height, rgba_pixels};
- glfwSetWindowIcon(window, 1, &glfw_image);
-
- free(rgba_pixels);
- }
-
- FreeBitmap(rgb_pixels);
- }
- #endif
-
-
glfwMakeContextCurrent(window);
#ifndef USE_OPENGLES2
@@ -103,9 +59,7 @@
if (GLAD_GL_VERSION_3_2)
{
#endif
- glfwSetKeyCallback(window, KeyCallback);
- glfwSetWindowFocusCallback(window, WindowFocusCallback);
- glfwSetWindowSizeCallback(window, WindowSizeCallback);
+ PlatformBackend_PostWindowCreation();
return TRUE;
#ifndef USE_OPENGLES2
--- a/src/Backends/Window/SDL2-OpenGL3.cpp
+++ b/src/Backends/Window/SDL2-OpenGL3.cpp
@@ -11,20 +11,15 @@
#include "../../WindowsWrapper.h"
+#include "../Platform.h"
#include "../../Resource.h"
-static SDL_Window *window;
+SDL_Window *window;
+
static SDL_GLContext context;
BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen)
{
- puts("Available SDL2 video drivers:");
-
- for (int i = 0; i < SDL_GetNumVideoDrivers(); ++i)
- puts(SDL_GetVideoDriver(i));
-
- printf("Selected SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
-
#ifdef USE_OPENGLES2
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
@@ -37,19 +32,10 @@
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
#endif
- window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, *screen_width, *screen_height, SDL_WINDOW_OPENGL);
+ window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, *screen_width, *screen_height, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
if (window != NULL)
{
- #ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does)
- size_t resource_size;
- const unsigned char *resource_data = FindResource("ICON_MINI", "ICON", &resource_size);
- SDL_RWops *rwops = SDL_RWFromConstMem(resource_data, resource_size);
- SDL_Surface *icon_surface = SDL_LoadBMP_RW(rwops, 1);
- SDL_SetWindowIcon(window, icon_surface);
- SDL_FreeSurface(icon_surface);
- #endif
-
if (fullscreen)
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
@@ -66,23 +52,25 @@
if (GLAD_GL_VERSION_3_2)
{
#endif
+ PlatformBackend_PostWindowCreation();
+
return TRUE;
#ifndef USE_OPENGLES2
}
else
{
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (OpenGL rendering backend)", "Your system does not support OpenGL 3.2", window);
+ PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Your system does not support OpenGL 3.2");
}
}
else
{
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (OpenGL rendering backend)", "Could not load OpenGL functions", window);
+ PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not load OpenGL functions");
}
#endif
}
else
{
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (OpenGL rendering backend)", "SDL_GL_MakeCurrent failed", window);
+ PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "SDL_GL_MakeCurrent failed");
}
SDL_GL_DeleteContext(context);
@@ -89,7 +77,7 @@
}
else
{
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (OpenGL rendering backend)", "Could not create OpenGL context", window);
+ PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not create OpenGL context");
}
SDL_DestroyWindow(window);
@@ -96,7 +84,7 @@
}
else
{
- SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (OpenGL rendering backend)", "Could not create window", NULL);
+ PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not create window");
}
return FALSE;
--
⑨