mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 09:34:35 -05:00
Initial WIP for scaling launcher widgets depending on DPI
This commit is contained in:
parent
8fb63080c8
commit
8dc0006211
6 changed files with 31 additions and 16 deletions
|
@ -87,6 +87,9 @@ int Gui_CalcPos(uint8_t anchor, int offset, int size, int axisLen) {
|
|||
return (axisLen - size) / 2 + offset;
|
||||
}
|
||||
|
||||
int Gui_ScaleX(int x) { return x * Display_DpiX / DISPLAY_DEFAULT_DPI; }
|
||||
int Gui_ScaleY(int y) { return y * Display_DpiY / DISPLAY_DEFAULT_DPI; }
|
||||
|
||||
bool Gui_Contains(int recX, int recY, int width, int height, int x, int y) {
|
||||
return x >= recX && y >= recY && x < (recX + width) && y < (recY + height);
|
||||
}
|
||||
|
|
|
@ -105,6 +105,11 @@ extern int Gui_OverlaysCount;
|
|||
/* Calculates position of an element on a particular axis */
|
||||
/* For example, to calculate X position of a text widget on screen */
|
||||
int Gui_CalcPos(uint8_t anchor, int offset, int size, int axisLen);
|
||||
/* Scales the given X coordinate from 96 dpi to current display dpi. */
|
||||
int Gui_ScaleX(int x);
|
||||
/* Scales the given Y coordinate from 96 dpi to current display dpi. */
|
||||
int Gui_ScaleY(int y);
|
||||
|
||||
/* Returns whether the given rectangle contains the given point. */
|
||||
bool Gui_Contains(int recX, int recY, int width, int height, int x, int y);
|
||||
/* Gets the screen that the user is currently interacting with. */
|
||||
|
|
|
@ -790,6 +790,10 @@ static void MainScreen_Init(struct LScreen* s_) {
|
|||
|
||||
LInput_SetText(&s->iptUsername, &user);
|
||||
LInput_SetText(&s->iptPassword, &pass);
|
||||
|
||||
char xyz[64]; String aaa = String_FromArray(xyz);
|
||||
String_Format2(&aaa, "&aDPI: %i,%i", &Display_DpiX, &Display_DpiY);
|
||||
LLabel_SetText(&s->lblStatus, &aaa);
|
||||
}
|
||||
|
||||
static void MainScreen_Reposition(struct LScreen* s_) {
|
||||
|
|
|
@ -17,14 +17,14 @@
|
|||
void LWidget_SetLocation(void* widget, uint8_t horAnchor, uint8_t verAnchor, int xOffset, int yOffset) {
|
||||
struct LWidget* w = (struct LWidget*)widget;
|
||||
w->HorAnchor = horAnchor; w->VerAnchor = verAnchor;
|
||||
w->XOffset = xOffset; w->YOffset = yOffset;
|
||||
w->XOffset = xOffset; w->YOffset = yOffset;
|
||||
LWidget_CalcPosition(widget);
|
||||
}
|
||||
|
||||
void LWidget_CalcPosition(void* widget) {
|
||||
struct LWidget* w = (struct LWidget*)widget;
|
||||
w->X = Gui_CalcPos(w->HorAnchor, w->XOffset, w->Width, Window_Width);
|
||||
w->Y = Gui_CalcPos(w->VerAnchor, w->YOffset, w->Height, Window_Height);
|
||||
w->X = Gui_CalcPos(w->HorAnchor, Gui_ScaleX(w->XOffset), w->Width, Window_Width);
|
||||
w->Y = Gui_CalcPos(w->VerAnchor, Gui_ScaleY(w->YOffset), w->Height, Window_Height);
|
||||
}
|
||||
|
||||
void LWidget_Draw(void* widget) {
|
||||
|
@ -145,7 +145,8 @@ void LButton_Init(struct LButton* w, const FontDesc* font, int width, int height
|
|||
w->VTABLE = &lbutton_VTABLE;
|
||||
w->TabSelectable = true;
|
||||
w->Font = *font;
|
||||
w->Width = width; w->Height = height;
|
||||
w->Width = Gui_ScaleX(width);
|
||||
w->Height = Gui_ScaleY(height);
|
||||
String_InitArray(w->Text, w->_TextBuffer);
|
||||
}
|
||||
|
||||
|
@ -438,9 +439,10 @@ void LInput_Init(struct LInput* w, const FontDesc* font, int width, int height,
|
|||
w->TabSelectable = true;
|
||||
String_InitArray(w->Text, w->_TextBuffer);
|
||||
w->Font = *font;
|
||||
|
||||
w->MinWidth = width;
|
||||
w->Width = width; w->Height = height;
|
||||
|
||||
w->Width = Gui_ScaleX(width);
|
||||
w->Height = Gui_ScaleY(height);
|
||||
w->MinWidth = w->Width;
|
||||
LWidget_CalcPosition(w);
|
||||
|
||||
w->HintFont = *hintFont;
|
||||
|
@ -625,7 +627,8 @@ static struct LWidgetVTABLE lslider_VTABLE = {
|
|||
};
|
||||
void LSlider_Init(struct LSlider* w, int width, int height) {
|
||||
w->VTABLE = &lslider_VTABLE;
|
||||
w->Width = width; w->Height = height;
|
||||
w->Width = Gui_ScaleX(width);
|
||||
w->Height = Gui_ScaleY(height);
|
||||
w->MaxValue = 100;
|
||||
}
|
||||
|
||||
|
|
|
@ -899,9 +899,6 @@ static struct EntryList font_list;
|
|||
static bool font_list_changed;
|
||||
static void Font_Init(void);
|
||||
|
||||
#define DPI_PIXEL 72
|
||||
#define DPI_DEVICE 96 /* TODO: GetDeviceCaps(hdc, LOGPIXELSY) in Window_Init ? */
|
||||
|
||||
struct FontData {
|
||||
FT_Face face;
|
||||
struct Stream src, file;
|
||||
|
@ -1045,10 +1042,8 @@ ReturnCode Font_Make(FontDesc* desc, const String* fontName, int size, int style
|
|||
if ((err = FontData_Init(&path, data, &args))) { Mem_Free(data); return err; }
|
||||
desc->Handle = data;
|
||||
|
||||
if ((err = FT_New_Face(ft_lib, &args, faceIndex, &data->face))) return err;
|
||||
if ((err = FT_Set_Char_Size(data->face, size * 64, 0, DPI_DEVICE, 0))) return err;
|
||||
|
||||
return 0;
|
||||
if ((err = FT_New_Face(ft_lib, &args, faceIndex, &data->face))) return err;
|
||||
return FT_Set_Char_Size(data->face, size * 64, 0, Display_DpiX, Display_DpiY);
|
||||
}
|
||||
|
||||
void Font_Free(FontDesc* desc) {
|
||||
|
|
|
@ -2842,13 +2842,18 @@ static void Window_HandleAppEvent(struct android_app* app, int32_t cmd) {
|
|||
|
||||
void Window_Init(void) {
|
||||
struct android_app* app = (struct android_app*)App_Ptr;
|
||||
JNIEnv* env;
|
||||
|
||||
/* TODO: or WINDOW_FORMAT_RGBX_8888 ?? */
|
||||
ANativeActivity_setWindowFormat(app->activity, WINDOW_FORMAT_RGBA_8888);
|
||||
ANativeActivity_setWindowFlags(app->activity, AWINDOW_FLAG_FULLSCREEN, 0);
|
||||
|
||||
app->onAppCmd = Window_HandleAppEvent;
|
||||
app->onInputEvent = Window_HandleInputEvent;
|
||||
|
||||
JavaGetCurrentEnv(env);
|
||||
Display_BitsPerPixel = 32;
|
||||
Display_DpiX = JavaCallInt(env, "getDpiX", "()I", NULL);
|
||||
Display_DpiY = JavaCallInt(env, "getDpiY", "()I", NULL);
|
||||
}
|
||||
|
||||
void Window_Create(int x, int y, int width, int height, struct GraphicsMode* mode) {
|
||||
|
|
Loading…
Add table
Reference in a new issue