mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 17:17:09 -04:00
Launcher input widget DPI scales properly
This commit is contained in:
parent
7e7bfb00da
commit
fdf92e047b
@ -16,4 +16,5 @@
|
||||
* 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
|
||||
* Can't bind controls to mouse buttons
|
||||
* Does not work at all on 64 bit macOS
|
@ -6,7 +6,6 @@
|
||||
#include "Entity.h"
|
||||
#include "Inventory.h"
|
||||
#include "Event.h"
|
||||
#include "Platform.h"
|
||||
#include "Picking.h"
|
||||
|
||||
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. */
|
||||
CC_API void Event_Register(struct Event_Void* handlers, void* obj, Event_Void_Callback handler);
|
||||
/* 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);
|
||||
#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))
|
||||
|
@ -154,6 +154,10 @@ void Gui_RefreshAll(void) {
|
||||
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_Refresh(struct Screen* s) {
|
||||
s->VTABLE->ContextLost(s);
|
||||
@ -421,8 +425,7 @@ static void OnReset(void) {
|
||||
}
|
||||
|
||||
static void OnFree(void) {
|
||||
while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]);
|
||||
|
||||
Gui_RemoveAll();
|
||||
OnContextLost(NULL);
|
||||
OnReset();
|
||||
}
|
||||
|
@ -185,6 +185,7 @@ struct Screen* Gui_GetBlocksWorld(void);
|
||||
struct Screen* Gui_GetClosable(void);
|
||||
|
||||
void Gui_RefreshAll(void);
|
||||
void Gui_RemoveAll(void);
|
||||
void Gui_RefreshChat(void);
|
||||
void Gui_Refresh(struct Screen* s);
|
||||
|
||||
|
@ -757,7 +757,7 @@ void InputHandler_PickBlocks(void) {
|
||||
static cc_bool InputHandler_IsShutdown(int key) {
|
||||
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
|
||||
return key == 'Q' && Key_IsWinPressed();
|
||||
#else
|
||||
|
@ -13,10 +13,18 @@
|
||||
#ifndef CC_BUILD_WEB
|
||||
static int xBorder, xBorder2, xBorder3, xBorder4;
|
||||
static int yBorder, yBorder2, yBorder3, yBorder4;
|
||||
static int xInputOffset, yInputOffset;
|
||||
static int caretOffset, caretWidth, caretHeight;
|
||||
|
||||
void LWidget_CalcOffsets(void) {
|
||||
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;
|
||||
|
||||
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) {
|
||||
@ -244,14 +252,16 @@ static void LInput_DrawText(struct LInput* w, struct DrawTextArgs* args) {
|
||||
|
||||
if (w->text.length || !w->hintText) {
|
||||
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 {
|
||||
args->text = String_FromReadonly(w->hintText);
|
||||
args->font = &Launcher_HintFont;
|
||||
|
||||
hintHeight = Drawer2D_TextHeight(args);
|
||||
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);
|
||||
DrawTextArgs_Make(&args, &text, &Launcher_TextFont, true);
|
||||
|
||||
r.X = w->x + 5;
|
||||
r.Y = w->y + w->height - 5; r.Height = 2;
|
||||
r.X = w->x + xInputOffset;
|
||||
r.Y = w->y + w->height - caretOffset; r.Height = caretHeight;
|
||||
|
||||
if (w->caretPos == -1) {
|
||||
r.X += Drawer2D_TextWidth(&args);
|
||||
r.Width = 10;
|
||||
r.Width = caretWidth;
|
||||
} else {
|
||||
args.text = String_UNSAFE_Substring(&text, 0, w->caretPos);
|
||||
r.X += Drawer2D_TextWidth(&args);
|
||||
|
@ -168,7 +168,7 @@ static void OnResize(void* obj) {
|
||||
static cc_bool IsShutdown(int key) {
|
||||
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
|
||||
return key == 'Q' && Key_IsWinPressed();
|
||||
#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->VTABLE = &DisconnectScreen_VTABLE;
|
||||
|
||||
/* Get rid of all other menus instead of just hiding to reduce GPU usage */
|
||||
while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]);
|
||||
/* Remove all screens instead of just drawing over them to reduce GPU usage */
|
||||
Gui_RemoveAll();
|
||||
Gui_Add((struct Screen*)s, GUI_PRIORITY_DISCONNECT);
|
||||
}
|
||||
|
||||
|
@ -1157,7 +1157,6 @@ static void ApplyIcon(void) { }
|
||||
|
||||
void Window_Create(int width, int height) {
|
||||
XSetWindowAttributes attributes = { 0 };
|
||||
XSizeHints hints = { 0 };
|
||||
Atom protocols[2];
|
||||
struct GraphicsMode mode;
|
||||
cc_uintptr addr;
|
||||
@ -1187,11 +1186,6 @@ void Window_Create(int width, int height) {
|
||||
CWColormap | CWEventMask | CWBackPixel | CWBorderPixel, &attributes);
|
||||
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 */
|
||||
protocols[0] = wm_destroy;
|
||||
protocols[1] = net_wm_ping;
|
||||
|
Loading…
x
Reference in New Issue
Block a user