mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 03:25:14 -04:00
Fix launcher widgets having their alignment stuffed when using differently sized font
A good example of such a font is Lucida Console
This commit is contained in:
parent
03a264bd91
commit
027677e320
@ -79,7 +79,6 @@ typedef struct FontDesc_ { void* Handle; uint16_t Size, Style; } FontDesc;
|
||||
typedef struct TextureRec_ { float U1, V1, U2, V2; } TextureRec;
|
||||
|
||||
/*#define CC_BUILD_GL11*/
|
||||
/*#define CC_BUILD_SOLARIS*/
|
||||
#ifndef CC_BUILD_MANUAL
|
||||
#ifdef _WIN32
|
||||
#define CC_BUILD_D3D9
|
||||
@ -108,6 +107,7 @@ typedef struct TextureRec_ { float U1, V1, U2, V2; } TextureRec;
|
||||
#define CC_BUILD_WEB
|
||||
#define CC_BUILD_SDL
|
||||
#define CC_BUILD_POSIX
|
||||
#define CC_BUILD_GLMODERN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -976,21 +976,22 @@ void Gfx_OnWindowResize(void) {
|
||||
* - OpenGL 2.0 (alternative modern-ish backend)
|
||||
*/
|
||||
#ifndef CC_BUILD_D3D9
|
||||
#ifdef CC_BUILD_WIN
|
||||
#if defined CC_BUILD_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef CC_BUILD_OSX
|
||||
#include <GL/gl.h>
|
||||
#elif defined CC_BUILD_OSX
|
||||
#include <OpenGL/gl.h>
|
||||
#elif defined CC_BUILD_GLMODERN
|
||||
#include <GLES2/gl2.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#ifdef CC_BUILD_GL11
|
||||
#if defined CC_BUILD_GL11
|
||||
static GfxResourceID gl_activeList;
|
||||
#define gl_DYNAMICLISTID 1234567891
|
||||
static void* gl_dynamicListData;
|
||||
#elif CC_BUILD_GLMODERN
|
||||
#elif defined CC_BUILD_GLMODERN
|
||||
#define _glBindBuffer(t,b) glBindBuffer(t,b)
|
||||
#define _glDeleteBuffers(n,b) glDeleteBuffers(n,b)
|
||||
#define _glGenBuffers(n,b) glGenBuffers(n,b)
|
||||
|
@ -80,6 +80,9 @@ bool Widget_Contains(void* widget, int x, int y) {
|
||||
int Gui_CalcPos(uint8_t anchor, int offset, int size, int axisLen) {
|
||||
if (anchor == ANCHOR_MIN) return offset;
|
||||
if (anchor == ANCHOR_MAX) return axisLen - size - offset;
|
||||
|
||||
if (anchor == ANCHOR_CENTRE_MIN) return (axisLen / 2) + offset;
|
||||
if (anchor == ANCHOR_CENTRE_MAX) return (axisLen / 2) - size - offset;
|
||||
return (axisLen - size) / 2 + offset;
|
||||
}
|
||||
|
||||
|
@ -8,9 +8,11 @@
|
||||
*/
|
||||
|
||||
enum GuiAnchor {
|
||||
ANCHOR_MIN, /* Left or top */
|
||||
ANCHOR_CENTRE, /* Middle */
|
||||
ANCHOR_MAX /* Bottom or right */
|
||||
ANCHOR_MIN, /* = offset */
|
||||
ANCHOR_CENTRE, /* = (axis/2) - (size/2) - offset; */
|
||||
ANCHOR_MAX, /* = axis - size - offset */
|
||||
ANCHOR_CENTRE_MIN, /* = (axis/2) + offset */
|
||||
ANCHOR_CENTRE_MAX, /* = (axis/2) - size - offset */
|
||||
};
|
||||
|
||||
struct IGameComponent;
|
||||
|
15
src/Http.c
15
src/Http.c
@ -20,9 +20,14 @@
|
||||
|
||||
#include <windows.h>
|
||||
#include <wininet.h>
|
||||
|
||||
#define HTTP_QUERY_ETAG 54 /* Missing from some old MingW32 headers */
|
||||
#endif
|
||||
|
||||
/* Can't use curl for the web */
|
||||
#ifdef CC_BUILD_WEB
|
||||
#undef CC_BUILD_POSIX
|
||||
#endif
|
||||
|
||||
/* POSIX is mainly shared between Linux and OSX */
|
||||
#ifdef CC_BUILD_POSIX
|
||||
#include <curl/curl.h>
|
||||
@ -442,6 +447,14 @@ static void Http_SysFree(void) {
|
||||
curl_global_cleanup();
|
||||
}
|
||||
#endif
|
||||
#ifdef CC_BUILD_WEB
|
||||
/* TODO: Implement this backend */
|
||||
static void Http_SysInit(void) { }
|
||||
static ReturnCode Http_SysDo(struct HttpRequest* req, volatile int* progress) {
|
||||
return ReturnCode_NotSupported;
|
||||
}
|
||||
static void Http_SysFree(void) { }
|
||||
#endif
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
|
@ -309,20 +309,19 @@ static void ChooseModeScreen_Init(struct LScreen* s_) {
|
||||
|
||||
static void ChooseModeScreen_Reposition(struct LScreen* s_) {
|
||||
struct ChooseModeScreen* s = (struct ChooseModeScreen*)s_;
|
||||
int middle = Game.Width / 2;
|
||||
LWidget_SetLocation(&s->LblTitle, ANCHOR_CENTRE, ANCHOR_CENTRE, 10, -135);
|
||||
|
||||
LWidget_SetLocation(&s->BtnEnhanced, ANCHOR_MIN, ANCHOR_CENTRE, middle - 250, -72);
|
||||
LWidget_SetLocation(&s->LblEnhanced[0], ANCHOR_MIN, ANCHOR_CENTRE, middle - 85, -72 - 12);
|
||||
LWidget_SetLocation(&s->LblEnhanced[1], ANCHOR_MIN, ANCHOR_CENTRE, middle - 85, -72 + 12);
|
||||
LWidget_SetLocation(&s->BtnEnhanced, ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -250, -72);
|
||||
LWidget_SetLocation(&s->LblEnhanced[0], ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -85, -72 - 12);
|
||||
LWidget_SetLocation(&s->LblEnhanced[1], ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -85, -72 + 12);
|
||||
|
||||
LWidget_SetLocation(&s->BtnClassicHax, ANCHOR_MIN, ANCHOR_CENTRE, middle - 250, 0);
|
||||
LWidget_SetLocation(&s->LblClassicHax[0], ANCHOR_MIN, ANCHOR_CENTRE, middle - 85, 0 - 12);
|
||||
LWidget_SetLocation(&s->LblClassicHax[1], ANCHOR_MIN, ANCHOR_CENTRE, middle - 85, 0 + 12);
|
||||
LWidget_SetLocation(&s->BtnClassicHax, ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -250, 0);
|
||||
LWidget_SetLocation(&s->LblClassicHax[0], ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -85, 0 - 12);
|
||||
LWidget_SetLocation(&s->LblClassicHax[1], ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -85, 0 + 12);
|
||||
|
||||
LWidget_SetLocation(&s->BtnClassic, ANCHOR_MIN, ANCHOR_CENTRE, middle - 250, 72);
|
||||
LWidget_SetLocation(&s->LblClassic[0], ANCHOR_MIN, ANCHOR_CENTRE, middle - 85, 72 - 12);
|
||||
LWidget_SetLocation(&s->LblClassic[1], ANCHOR_MIN, ANCHOR_CENTRE, middle - 85, 72 + 12);
|
||||
LWidget_SetLocation(&s->BtnClassic, ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -250, 72);
|
||||
LWidget_SetLocation(&s->LblClassic[0], ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -85, 72 - 12);
|
||||
LWidget_SetLocation(&s->LblClassic[1], ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -85, 72 + 12);
|
||||
|
||||
LWidget_SetLocation(&s->LblHelp, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 160);
|
||||
LWidget_SetLocation(&s->BtnBack, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 170);
|
||||
@ -498,11 +497,11 @@ static void ColoursScreen_Reposition(struct LScreen* s_) {
|
||||
LWidget_SetLocation(&s->IptColours[i*3 + 2], ANCHOR_CENTRE, ANCHOR_CENTRE, 160, y);
|
||||
}
|
||||
|
||||
LWidget_SetLocation(&s->LblNames[0], ANCHOR_CENTRE, ANCHOR_CENTRE, -60, -100);
|
||||
LWidget_SetLocation(&s->LblNames[1], ANCHOR_CENTRE, ANCHOR_CENTRE, -70, -60);
|
||||
LWidget_SetLocation(&s->LblNames[2], ANCHOR_CENTRE, ANCHOR_CENTRE, -80, -20);
|
||||
LWidget_SetLocation(&s->LblNames[3], ANCHOR_CENTRE, ANCHOR_CENTRE, -40, 20);
|
||||
LWidget_SetLocation(&s->LblNames[4], ANCHOR_CENTRE, ANCHOR_CENTRE, -70, 60);
|
||||
LWidget_SetLocation(&s->LblNames[0], ANCHOR_CENTRE_MAX, ANCHOR_CENTRE, 10, -100);
|
||||
LWidget_SetLocation(&s->LblNames[1], ANCHOR_CENTRE_MAX, ANCHOR_CENTRE, 10, -60);
|
||||
LWidget_SetLocation(&s->LblNames[2], ANCHOR_CENTRE_MAX, ANCHOR_CENTRE, 10, -20);
|
||||
LWidget_SetLocation(&s->LblNames[3], ANCHOR_CENTRE_MAX, ANCHOR_CENTRE, 10, 20);
|
||||
LWidget_SetLocation(&s->LblNames[4], ANCHOR_CENTRE_MAX, ANCHOR_CENTRE, 10, 60);
|
||||
|
||||
LWidget_SetLocation(&s->LblRGB[0], ANCHOR_CENTRE, ANCHOR_CENTRE, 30, -130);
|
||||
LWidget_SetLocation(&s->LblRGB[1], ANCHOR_CENTRE, ANCHOR_CENTRE, 95, -130);
|
||||
@ -1372,14 +1371,14 @@ static void SettingsScreen_Init(struct LScreen* s_) {
|
||||
|
||||
static void SettingsScreen_Reposition(struct LScreen* s_) {
|
||||
struct SettingsScreen* s = (struct SettingsScreen*)s_;
|
||||
LWidget_SetLocation(&s->BtnUpdates, ANCHOR_CENTRE, ANCHOR_CENTRE, -135, -120);
|
||||
LWidget_SetLocation(&s->LblUpdates, ANCHOR_CENTRE, ANCHOR_CENTRE, 10, -120);
|
||||
LWidget_SetLocation(&s->BtnUpdates, ANCHOR_CENTRE, ANCHOR_CENTRE, -135, -120);
|
||||
LWidget_SetLocation(&s->LblUpdates, ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -70, -120);
|
||||
|
||||
LWidget_SetLocation(&s->BtnMode, ANCHOR_CENTRE, ANCHOR_CENTRE, -135, -70);
|
||||
LWidget_SetLocation(&s->LblMode, ANCHOR_CENTRE, ANCHOR_CENTRE, 55, -70);
|
||||
LWidget_SetLocation(&s->BtnMode, ANCHOR_CENTRE, ANCHOR_CENTRE, -135, -70);
|
||||
LWidget_SetLocation(&s->LblMode, ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -70, -70);
|
||||
|
||||
LWidget_SetLocation(&s->BtnColours, ANCHOR_CENTRE, ANCHOR_CENTRE, -135, -20);
|
||||
LWidget_SetLocation(&s->LblColours, ANCHOR_CENTRE, ANCHOR_CENTRE, 65, -20);
|
||||
LWidget_SetLocation(&s->BtnColours, ANCHOR_CENTRE, ANCHOR_CENTRE, -135, -20);
|
||||
LWidget_SetLocation(&s->LblColours, ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -70, -20);
|
||||
|
||||
LWidget_SetLocation(&s->BtnBack, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 170);
|
||||
}
|
||||
|
14
src/Logger.c
14
src/Logger.c
@ -7,6 +7,20 @@
|
||||
|
||||
static void Logger_AbortCommon(ReturnCode result, const char* raw_msg, void* ctx);
|
||||
|
||||
#ifdef CC_BUILD_WEB
|
||||
/* Can't see native CPU state with javascript */
|
||||
#undef CC_BUILD_POSIX
|
||||
|
||||
static void Logger_DumpBacktrace(String* str, void* ctx) { }
|
||||
static void Logger_DumpRegisters(void* ctx) { }
|
||||
static void Logger_DumpMisc(void* ctx) { }
|
||||
|
||||
void Logger_Hook(void) { }
|
||||
void Logger_Abort2(ReturnCode result, const char* raw_msg) {
|
||||
Logger_AbortCommon(result, raw_msg, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CC_BUILD_WIN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOSERVICE
|
||||
|
@ -110,6 +110,7 @@ const ReturnCode ReturnCode_SocketWouldBlock = EWOULDBLOCK;
|
||||
#ifdef CC_BUILD_WEB
|
||||
#include <emscripten.h>
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#endif
|
||||
|
||||
|
||||
@ -1293,6 +1294,10 @@ static void Font_Init(void) {
|
||||
String_FromConst("/System/Library/Fonts"),
|
||||
String_FromConst("/Library/Fonts")
|
||||
};
|
||||
#endif
|
||||
#ifdef CC_BUILD_WEB
|
||||
/* TODO: Implement fonts */
|
||||
const static String dirs[1] = { String_FromConst("Fonts") };
|
||||
#endif
|
||||
const static String cachePath = String_FromConst(FONT_CACHE_FILE);
|
||||
FT_Error err;
|
||||
@ -1969,9 +1974,10 @@ ReturnCode Platform_GetExePath(String* path) {
|
||||
#ifdef CC_BUILD_WEB
|
||||
ReturnCode Platform_StartOpen(const String* args) {
|
||||
char str[600];
|
||||
Platfrom_ConvetString(args, str);
|
||||
Platform_ConvertString(str, args);
|
||||
EM_ASM_({ window.open(Pointer_stringify($0)); }, str);
|
||||
}
|
||||
ReturnCode Platform_GetExePath(String* path) { return ReturnCode_NotSupported; }
|
||||
#endif
|
||||
|
||||
void* Platform_GetSymbolFrom(const char* filename, const char* name) {
|
||||
@ -2236,3 +2242,11 @@ void Platform_Init(void) {
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
}
|
||||
#endif
|
||||
#ifdef CC_BUILD_WEB
|
||||
void Platform_Init(void) {
|
||||
/* TODO: Actually get real window size here */
|
||||
DisplayDevice_Default.Bounds.Width = 900;
|
||||
DisplayDevice_Default.Bounds.Height = 700;
|
||||
DisplayDevice_Default.BitsPerPixel = 32;
|
||||
}
|
||||
#endif
|
||||
|
10
src/Utils.c
10
src/Utils.c
@ -13,8 +13,8 @@
|
||||
*#########################################################################################################################*/
|
||||
|
||||
#define DAYS_IN_400_YEARS 146097 /* (400*365) + 97 */
|
||||
static uint16_t DateTime_DaysTotal[13] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
|
||||
static uint16_t DateTime_DaysTotalLeap[13] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
|
||||
const static uint16_t daysTotal[13] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
|
||||
const static uint16_t daysTotalLeap[13] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
|
||||
|
||||
static bool DateTime_IsLeapYear(int year) {
|
||||
if ((year % 4) != 0) return false;
|
||||
@ -30,7 +30,7 @@ int DateTime_TotalDays(const struct DateTime* time) {
|
||||
days += (y / 4) - (y / 100) + (y / 400);
|
||||
|
||||
/* Add days of prior months in this year */
|
||||
days += DateTime_DaysTotal[time->Month - 1];
|
||||
days += daysTotal[time->Month - 1];
|
||||
/* Add Feb 29, if this is a leap year, and day of point in time is after Feb 28 */
|
||||
if (DateTime_IsLeapYear(time->Year) && time->Month > 2) days++;
|
||||
/* Add days in this month */
|
||||
@ -63,7 +63,7 @@ void DateTime_FromTotalMs(struct DateTime* time, TimeMS ms) {
|
||||
time->Hour = dayMS % HOURS_PER_DAY; dayMS /= HOURS_PER_DAY;
|
||||
|
||||
/* Then work out day/month/year component (inverse TotalDays operation) */
|
||||
/* Probably not the most efficient way of doing this. But it passes my tests at */
|
||||
/* Not the most efficient way of doing this. But it passes my tests at */
|
||||
/* https://gist.github.com/UnknownShadow200/30993c66464bb03ead01577f3ab2a653 */
|
||||
days = (int)(ms / MILLIS_PER_DAY);
|
||||
year = 1 + ((days / DAYS_IN_400_YEARS) * 400); days %= DAYS_IN_400_YEARS;
|
||||
@ -77,7 +77,7 @@ void DateTime_FromTotalMs(struct DateTime* time, TimeMS ms) {
|
||||
}
|
||||
|
||||
time->Year = year;
|
||||
totalDays = leap ? DateTime_DaysTotalLeap : DateTime_DaysTotal;
|
||||
totalDays = leap ? daysTotalLeap : daysTotal;
|
||||
|
||||
for (month = 1; month <= 12; month++) {
|
||||
if (days >= totalDays[month]) continue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user