mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 17:47:12 -04:00
Launcher input widget DPI scales properly
This commit is contained in:
parent
7e7bfb00da
commit
fdf92e047b
@ -17,3 +17,4 @@
|
|||||||
* Changing server texture packs sometimes still retains textures from previous one
|
* Changing server texture packs sometimes still retains textures from previous one
|
||||||
* Crashes at startup when another process has exclusively acquired Direct3D9 device
|
* Crashes at startup when another process has exclusively acquired Direct3D9 device
|
||||||
* Can't bind controls to mouse buttons
|
* Can't bind controls to mouse buttons
|
||||||
|
* Does not work at all on 64 bit macOS
|
@ -6,7 +6,6 @@
|
|||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "Inventory.h"
|
#include "Inventory.h"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "Platform.h"
|
|
||||||
#include "Picking.h"
|
#include "Picking.h"
|
||||||
|
|
||||||
struct _BlockLists Blocks;
|
struct _BlockLists Blocks;
|
||||||
|
@ -74,7 +74,6 @@ struct Event_RawMove {
|
|||||||
/* NOTE: Trying to register a callback twice or over EVENT_MAX_CALLBACKS callbacks will terminate the game. */
|
/* NOTE: Trying to register a callback twice or over EVENT_MAX_CALLBACKS callbacks will terminate the game. */
|
||||||
CC_API void Event_Register(struct Event_Void* handlers, void* obj, Event_Void_Callback handler);
|
CC_API void Event_Register(struct Event_Void* handlers, void* obj, Event_Void_Callback handler);
|
||||||
/* Unregisters a callback function for the given event. */
|
/* Unregisters a callback function for the given event. */
|
||||||
/* NOTE: Trying to unregister a non-registered callback will terminate the game. */
|
|
||||||
CC_API void Event_Unregister(struct Event_Void* handlers, void* obj, Event_Void_Callback handler);
|
CC_API void Event_Unregister(struct Event_Void* handlers, void* obj, Event_Void_Callback handler);
|
||||||
#define Event_Register_(handlers, obj, handler) Event_Register((struct Event_Void*)(handlers), obj, (Event_Void_Callback)(handler))
|
#define Event_Register_(handlers, obj, handler) Event_Register((struct Event_Void*)(handlers), obj, (Event_Void_Callback)(handler))
|
||||||
#define Event_Unregister_(handlers, obj, handler) Event_Unregister((struct Event_Void*)(handlers), obj, (Event_Void_Callback)(handler))
|
#define Event_Unregister_(handlers, obj, handler) Event_Unregister((struct Event_Void*)(handlers), obj, (Event_Void_Callback)(handler))
|
||||||
|
@ -154,6 +154,10 @@ void Gui_RefreshAll(void) {
|
|||||||
OnContextRecreated(NULL);
|
OnContextRecreated(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Gui_RemoveAll(void) {
|
||||||
|
while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]);
|
||||||
|
}
|
||||||
|
|
||||||
void Gui_RefreshChat(void) { Gui_Refresh((struct Screen*)Gui_Chat); }
|
void Gui_RefreshChat(void) { Gui_Refresh((struct Screen*)Gui_Chat); }
|
||||||
void Gui_Refresh(struct Screen* s) {
|
void Gui_Refresh(struct Screen* s) {
|
||||||
s->VTABLE->ContextLost(s);
|
s->VTABLE->ContextLost(s);
|
||||||
@ -421,8 +425,7 @@ static void OnReset(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void OnFree(void) {
|
static void OnFree(void) {
|
||||||
while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]);
|
Gui_RemoveAll();
|
||||||
|
|
||||||
OnContextLost(NULL);
|
OnContextLost(NULL);
|
||||||
OnReset();
|
OnReset();
|
||||||
}
|
}
|
||||||
|
@ -185,6 +185,7 @@ struct Screen* Gui_GetBlocksWorld(void);
|
|||||||
struct Screen* Gui_GetClosable(void);
|
struct Screen* Gui_GetClosable(void);
|
||||||
|
|
||||||
void Gui_RefreshAll(void);
|
void Gui_RefreshAll(void);
|
||||||
|
void Gui_RemoveAll(void);
|
||||||
void Gui_RefreshChat(void);
|
void Gui_RefreshChat(void);
|
||||||
void Gui_Refresh(struct Screen* s);
|
void Gui_Refresh(struct Screen* s);
|
||||||
|
|
||||||
|
@ -757,7 +757,7 @@ void InputHandler_PickBlocks(void) {
|
|||||||
static cc_bool InputHandler_IsShutdown(int key) {
|
static cc_bool InputHandler_IsShutdown(int key) {
|
||||||
if (key == KEY_F4 && Key_IsAltPressed()) return true;
|
if (key == KEY_F4 && Key_IsAltPressed()) return true;
|
||||||
|
|
||||||
/* On OSX, Cmd+Q should also terminate the process */
|
/* On macOS, Cmd+Q should also end the process */
|
||||||
#ifdef CC_BUILD_OSX
|
#ifdef CC_BUILD_OSX
|
||||||
return key == 'Q' && Key_IsWinPressed();
|
return key == 'Q' && Key_IsWinPressed();
|
||||||
#else
|
#else
|
||||||
|
@ -13,10 +13,18 @@
|
|||||||
#ifndef CC_BUILD_WEB
|
#ifndef CC_BUILD_WEB
|
||||||
static int xBorder, xBorder2, xBorder3, xBorder4;
|
static int xBorder, xBorder2, xBorder3, xBorder4;
|
||||||
static int yBorder, yBorder2, yBorder3, yBorder4;
|
static int yBorder, yBorder2, yBorder3, yBorder4;
|
||||||
|
static int xInputOffset, yInputOffset;
|
||||||
|
static int caretOffset, caretWidth, caretHeight;
|
||||||
|
|
||||||
void LWidget_CalcOffsets(void) {
|
void LWidget_CalcOffsets(void) {
|
||||||
xBorder = Display_ScaleX(1); xBorder2 = xBorder * 2; xBorder3 = xBorder * 3; xBorder4 = xBorder * 4;
|
xBorder = Display_ScaleX(1); xBorder2 = xBorder * 2; xBorder3 = xBorder * 3; xBorder4 = xBorder * 4;
|
||||||
yBorder = Display_ScaleY(1); yBorder2 = yBorder * 2; yBorder3 = yBorder * 3; yBorder4 = yBorder * 4;
|
yBorder = Display_ScaleY(1); yBorder2 = yBorder * 2; yBorder3 = yBorder * 3; yBorder4 = yBorder * 4;
|
||||||
|
|
||||||
|
xInputOffset = Display_ScaleX(5);
|
||||||
|
yInputOffset = Display_ScaleY(2);
|
||||||
|
caretOffset = Display_ScaleY(5);
|
||||||
|
caretWidth = Display_ScaleX(10);
|
||||||
|
caretHeight = Display_ScaleY(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LWidget_SetLocation(void* widget, cc_uint8 horAnchor, cc_uint8 verAnchor, int xOffset, int yOffset) {
|
void LWidget_SetLocation(void* widget, cc_uint8 horAnchor, cc_uint8 verAnchor, int xOffset, int yOffset) {
|
||||||
@ -244,14 +252,16 @@ static void LInput_DrawText(struct LInput* w, struct DrawTextArgs* args) {
|
|||||||
|
|
||||||
if (w->text.length || !w->hintText) {
|
if (w->text.length || !w->hintText) {
|
||||||
y = w->y + (w->height - w->_textHeight) / 2;
|
y = w->y + (w->height - w->_textHeight) / 2;
|
||||||
Drawer2D_DrawText(&Launcher_Framebuffer, args, w->x + 5, y + 2);
|
Drawer2D_DrawText(&Launcher_Framebuffer, args,
|
||||||
|
w->x + xInputOffset, y + yInputOffset);
|
||||||
} else {
|
} else {
|
||||||
args->text = String_FromReadonly(w->hintText);
|
args->text = String_FromReadonly(w->hintText);
|
||||||
args->font = &Launcher_HintFont;
|
args->font = &Launcher_HintFont;
|
||||||
|
|
||||||
hintHeight = Drawer2D_TextHeight(args);
|
hintHeight = Drawer2D_TextHeight(args);
|
||||||
y = w->y + (w->height - hintHeight) / 2;
|
y = w->y + (w->height - hintHeight) / 2;
|
||||||
Drawer2D_DrawText(&Launcher_Framebuffer, args, w->x + 5, y);
|
Drawer2D_DrawText(&Launcher_Framebuffer, args,
|
||||||
|
w->x + xInputOffset, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,12 +300,12 @@ static Rect2D LInput_MeasureCaret(struct LInput* w) {
|
|||||||
LInput_GetText(w, &text);
|
LInput_GetText(w, &text);
|
||||||
DrawTextArgs_Make(&args, &text, &Launcher_TextFont, true);
|
DrawTextArgs_Make(&args, &text, &Launcher_TextFont, true);
|
||||||
|
|
||||||
r.X = w->x + 5;
|
r.X = w->x + xInputOffset;
|
||||||
r.Y = w->y + w->height - 5; r.Height = 2;
|
r.Y = w->y + w->height - caretOffset; r.Height = caretHeight;
|
||||||
|
|
||||||
if (w->caretPos == -1) {
|
if (w->caretPos == -1) {
|
||||||
r.X += Drawer2D_TextWidth(&args);
|
r.X += Drawer2D_TextWidth(&args);
|
||||||
r.Width = 10;
|
r.Width = caretWidth;
|
||||||
} else {
|
} else {
|
||||||
args.text = String_UNSAFE_Substring(&text, 0, w->caretPos);
|
args.text = String_UNSAFE_Substring(&text, 0, w->caretPos);
|
||||||
r.X += Drawer2D_TextWidth(&args);
|
r.X += Drawer2D_TextWidth(&args);
|
||||||
|
@ -168,7 +168,7 @@ static void OnResize(void* obj) {
|
|||||||
static cc_bool IsShutdown(int key) {
|
static cc_bool IsShutdown(int key) {
|
||||||
if (key == KEY_F4 && Key_IsAltPressed()) return true;
|
if (key == KEY_F4 && Key_IsAltPressed()) return true;
|
||||||
|
|
||||||
/* On macOS, Cmd+Q should also terminate the process */
|
/* On macOS, Cmd+Q should also end the process */
|
||||||
#ifdef CC_BUILD_OSX
|
#ifdef CC_BUILD_OSX
|
||||||
return key == 'Q' && Key_IsWinPressed();
|
return key == 'Q' && Key_IsWinPressed();
|
||||||
#else
|
#else
|
||||||
|
@ -1925,8 +1925,8 @@ void DisconnectScreen_Show(const String* title, const String* message) {
|
|||||||
s->canReconnect = !(String_CaselessStarts(&why, &kick) || String_CaselessStarts(&why, &ban));
|
s->canReconnect = !(String_CaselessStarts(&why, &kick) || String_CaselessStarts(&why, &ban));
|
||||||
s->VTABLE = &DisconnectScreen_VTABLE;
|
s->VTABLE = &DisconnectScreen_VTABLE;
|
||||||
|
|
||||||
/* Get rid of all other menus instead of just hiding to reduce GPU usage */
|
/* Remove all screens instead of just drawing over them to reduce GPU usage */
|
||||||
while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]);
|
Gui_RemoveAll();
|
||||||
Gui_Add((struct Screen*)s, GUI_PRIORITY_DISCONNECT);
|
Gui_Add((struct Screen*)s, GUI_PRIORITY_DISCONNECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1157,7 +1157,6 @@ static void ApplyIcon(void) { }
|
|||||||
|
|
||||||
void Window_Create(int width, int height) {
|
void Window_Create(int width, int height) {
|
||||||
XSetWindowAttributes attributes = { 0 };
|
XSetWindowAttributes attributes = { 0 };
|
||||||
XSizeHints hints = { 0 };
|
|
||||||
Atom protocols[2];
|
Atom protocols[2];
|
||||||
struct GraphicsMode mode;
|
struct GraphicsMode mode;
|
||||||
cc_uintptr addr;
|
cc_uintptr addr;
|
||||||
@ -1187,11 +1186,6 @@ void Window_Create(int width, int height) {
|
|||||||
CWColormap | CWEventMask | CWBackPixel | CWBorderPixel, &attributes);
|
CWColormap | CWEventMask | CWBackPixel | CWBorderPixel, &attributes);
|
||||||
if (!win_handle) Logger_Abort("XCreateWindow failed");
|
if (!win_handle) Logger_Abort("XCreateWindow failed");
|
||||||
|
|
||||||
hints.base_width = width;
|
|
||||||
hints.base_height = height;
|
|
||||||
hints.flags = PSize | PPosition;
|
|
||||||
XSetWMNormalHints(win_display, win_handle, &hints);
|
|
||||||
|
|
||||||
/* Register for window destroy notification */
|
/* Register for window destroy notification */
|
||||||
protocols[0] = wm_destroy;
|
protocols[0] = wm_destroy;
|
||||||
protocols[1] = net_wm_ping;
|
protocols[1] = net_wm_ping;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user