SDL3: Try to centre window and fix compiling error

This commit is contained in:
UnknownShadow200 2024-04-01 14:38:39 +11:00
parent 1db08d9246
commit 0ff916fbfc
5 changed files with 17 additions and 39 deletions

View File

@ -1,21 +0,0 @@
* Blocks over 256 are not saved or loaded at all.
* Custom block information for blocks over 256 is not saved or loaded at all.
* /hold 0 prevents you deleting blocks until you change to another.
* Sometimes when holding air and your own model is a block model, you crash.
* Labels and buttons overlap in launcher with some fonts. (e.g. Lucida Console)
* terrain.png with width under 16 insta-crash the game
* catbox.moe texture packs/terrain.png links insta-crash the game
* Sometimes you randomly crash reading leveldatachunk packet on OSX
* Models with size of over 2 are not supported at all
* Direct3D9 backend uses an ill-formed vertex format that works by accident
* Alt text doesn't update its Y position if you click on chat
* Menu inputs (save, edit hotkey, water level, etc) are reset on window resize
* Chat input caret is reset on window resize
* Position in chat (if you scrolled up into history) is reset on window resize
* Two blank lines get shown in chat when you type /client cuboid
* Alt text is closed on window resize
* Changing server texture packs sometimes still retains textures from previous one
* Crashes at startup when another process has exclusively acquired Direct3D9 device
* Can't bind controls to mouse buttons
* Does not work at all on 64 bit macOS
* Making a gas block undeletable doesn't prevent placing blocks over it

View File

@ -1,5 +0,0 @@
Here lies ClassicalSharp, the original C# client. (works with Mono and .NET framework 2.0)
It has unfixed bugs and missing features. There's no reason to use it anymore.
For licensing, please see license.txt inside ClassicalSharp.zip.
Absolutely no support or assistance will be provided for ClassicalSharp.

View File

@ -1,5 +1,5 @@
#include "Core.h" #include "Core.h"
#if defined CC_BUILD_SDL #if defined CC_BUILD_SDL2
#include "_WindowBase.h" #include "_WindowBase.h"
#include "Graphics.h" #include "Graphics.h"
#include "String.h" #include "String.h"
@ -9,7 +9,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
static SDL_Window* win_handle; static SDL_Window* win_handle;
#warning "Some features are missing from the SDL backend. If possible, it is recommended that you use a native windowing backend instead" #warning "Some features are missing from the SDL2 backend. If possible, it is recommended that you use a native windowing backend instead"
static void RefreshWindowBounds(void) { static void RefreshWindowBounds(void) {
SDL_GetWindowSize(win_handle, &Window_Main.Width, &Window_Main.Height); SDL_GetWindowSize(win_handle, &Window_Main.Width, &Window_Main.Height);
@ -41,10 +41,7 @@ void Window_Init(void) {
void Window_Free(void) { } void Window_Free(void) { }
static void DoCreateWindow(int width, int height, int flags) { static void DoCreateWindow(int width, int height, int flags) {
int x = Display_CentreX(width); win_handle = SDL_CreateWindow(NULL, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height,
int y = Display_CentreY(height);
win_handle = SDL_CreateWindow(NULL, x, y, width, height,
flags | SDL_WINDOW_RESIZABLE); flags | SDL_WINDOW_RESIZABLE);
if (!win_handle) Window_SDLFail("creating window"); if (!win_handle) Window_SDLFail("creating window");

View File

@ -10,8 +10,6 @@
static SDL_Window* win_handle; static SDL_Window* win_handle;
static Uint32 dlg_event; static Uint32 dlg_event;
#warning "Some features are missing from the SDL3 backend. If possible, it is recommended that you use a native windowing backend instead"
static void RefreshWindowBounds(void) { static void RefreshWindowBounds(void) {
SDL_GetWindowSize(win_handle, &Window_Main.Width, &Window_Main.Height); SDL_GetWindowSize(win_handle, &Window_Main.Width, &Window_Main.Height);
} }
@ -29,7 +27,7 @@ static void Window_SDLFail(const char* place) {
void Window_Init(void) { void Window_Init(void) {
SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_VIDEO);
#ifdef CC_BUILD_FLATPAK #ifdef CC_BUILD_FLATPAK
SDL_SetHint(SDL_HINT_APP_ID, "net.classicube.flatpak.client"); SDL_SetHint(SDL_HINT_APP_ID, "net.classicube.flatpak.client");
#endif #endif
int displayID = SDL_GetPrimaryDisplay(); int displayID = SDL_GetPrimaryDisplay();
Input.Sources = INPUT_SOURCE_NORMAL; Input.Sources = INPUT_SOURCE_NORMAL;
@ -47,9 +45,16 @@ void Window_Init(void) {
void Window_Free(void) { } void Window_Free(void) { }
static void DoCreateWindow(int width, int height, int flags) { static void DoCreateWindow(int width, int height, int flags) {
win_handle = SDL_CreateWindow(NULL, width, height, SDL_PropertiesID props = SDL_CreateProperties();
flags | SDL_WINDOW_RESIZABLE); SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, SDL_WINDOWPOS_CENTERED);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, SDL_WINDOWPOS_CENTERED);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, width);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, height);
SDL_SetNumberProperty(props, "flags", flags | SDL_WINDOW_RESIZABLE);
win_handle = SDL_CreateWindowWithProperties(props);
if (!win_handle) Window_SDLFail("creating window"); if (!win_handle) Window_SDLFail("creating window");
SDL_DestroyProperties(props);
RefreshWindowBounds(); RefreshWindowBounds();
Window_Main.Exists = true; Window_Main.Exists = true;
@ -100,7 +105,9 @@ int Window_IsObscured(void) {
return flags & SDL_WINDOW_OCCLUDED; return flags & SDL_WINDOW_OCCLUDED;
} }
void Window_Show(void) { SDL_ShowWindow(win_handle); } void Window_Show(void) {
SDL_ShowWindow(win_handle);
}
void Window_SetSize(int width, int height) { void Window_SetSize(int width, int height) {
SDL_SetWindowSize(win_handle, width, height); SDL_SetWindowSize(win_handle, width, height);
@ -199,7 +206,7 @@ static void OnTextEvent(const SDL_Event* e) {
int i, len; int i, len;
src = e->text.text; src = e->text.text;
len = String_CalcLen(src, SDL_TEXTINPUTEVENT_TEXT_SIZE); len = String_Length(src);
while (len > 0) { while (len > 0) {
i = Convert_Utf8ToCodepoint(&cp, src, len); i = Convert_Utf8ToCodepoint(&cp, src, len);