mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 17:12:25 -05:00
Webclient: Add list of common sytem fonts
This commit is contained in:
parent
20ce465eb5
commit
7477751096
5 changed files with 54 additions and 37 deletions
|
@ -678,8 +678,20 @@ struct IGameComponent Drawer2D_Component = {
|
|||
*#########################################################################################################################*/
|
||||
#ifdef CC_BUILD_WEB
|
||||
const cc_string* Font_UNSAFE_GetDefault(void) { return &font_candidates[0]; }
|
||||
void Font_GetNames(struct StringsBuffer* buffer) { }
|
||||
cc_string Font_Lookup(const cc_string* fontName, int flags) { return String_Empty; }
|
||||
|
||||
void Font_GetNames(struct StringsBuffer* buffer) {
|
||||
static const char* font_names[] = {
|
||||
"Arial", "Arial Black", "Courier New", "Comic Sans MS", "Georgia", "Garamond",
|
||||
"Helvetica", "Impact", "Tahoma", "Times New Roman", "Trebuchet MS", "Verdana",
|
||||
"cursive", "fantasy", "monospace", "sans-serif", "serif", "system-ui"
|
||||
};
|
||||
int i;
|
||||
|
||||
for (i = 0; i < Array_Elems(font_names); i++) {
|
||||
cc_string str = String_FromReadonly(font_names[i]);
|
||||
StringsBuffer_Add(buffer, &str);
|
||||
}
|
||||
}
|
||||
|
||||
cc_result Font_Make(struct FontDesc* desc, const cc_string* fontName, int size, int flags) {
|
||||
desc->size = size;
|
||||
|
@ -692,10 +704,13 @@ cc_result Font_Make(struct FontDesc* desc, const cc_string* fontName, int size,
|
|||
String_CopyToRaw(desc->handle, fontName->length + 1, fontName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Font_MakeDefault(struct FontDesc* desc, int size, int flags) {
|
||||
font_candidates[0].length = 0;
|
||||
String_AppendConst(&font_candidates[0], "serif");
|
||||
Font_Make(desc, &font_candidates[0], size, flags);
|
||||
cc_string str = font_candidates[0];
|
||||
/* Fallback to arial */
|
||||
if (!str.length) str = font_candidates[1];
|
||||
|
||||
Font_Make(desc, &str, size, flags);
|
||||
}
|
||||
|
||||
void Font_Free(struct FontDesc* desc) {
|
||||
|
@ -727,6 +742,8 @@ static FT_Library ft_lib;
|
|||
static struct FT_MemoryRec_ ft_mem;
|
||||
static struct StringsBuffer font_list;
|
||||
static cc_bool fonts_changed;
|
||||
/* Finds the path and face number of the given system font, with closest matching style */
|
||||
static cc_string Font_Lookup(const cc_string* fontName, int flags);
|
||||
|
||||
struct SysFont {
|
||||
FT_Face face;
|
||||
|
@ -973,6 +990,7 @@ void Font_GetNames(struct StringsBuffer* buffer) {
|
|||
name.length -= 2;
|
||||
StringsBuffer_Add(buffer, &name);
|
||||
}
|
||||
StringsBuffer_Sort(buffer);
|
||||
}
|
||||
|
||||
static cc_string Font_LookupOf(const cc_string* fontName, const char type) {
|
||||
|
|
|
@ -109,8 +109,6 @@ CC_API void Font_GetNames(struct StringsBuffer* buffer);
|
|||
|
||||
/* Sets padding for a bitmapped font */
|
||||
void Font_SetPadding(struct FontDesc* desc, int amount);
|
||||
/* Finds the path and face number of the given system font, with closest matching style */
|
||||
cc_string Font_Lookup(const cc_string* fontName, int flags);
|
||||
/* Allocates a new system font from the given arguments */
|
||||
cc_result Font_Make(struct FontDesc* desc, const cc_string* fontName, int size, int flags);
|
||||
/* Allocates a new system font from the given arguments using default system font */
|
||||
|
|
33
src/Menus.c
33
src/Menus.c
|
@ -289,32 +289,6 @@ static void ListScreen_MoveForwards(void* screen, void* b) {
|
|||
ListScreen_PageClick(s, true);
|
||||
}
|
||||
|
||||
static void ListScreen_QuickSort(int left, int right) {
|
||||
struct StringsBuffer* buffer = &ListScreen.entries;
|
||||
cc_uint32* keys = buffer->flagsBuffer; cc_uint32 key;
|
||||
|
||||
while (left < right) {
|
||||
int i = left, j = right;
|
||||
cc_string pivot = StringsBuffer_UNSAFE_Get(buffer, (i + j) >> 1);
|
||||
cc_string strI, strJ;
|
||||
|
||||
/* partition the list */
|
||||
while (i <= j) {
|
||||
while ((strI = StringsBuffer_UNSAFE_Get(buffer, i), String_Compare(&pivot, &strI)) > 0) i++;
|
||||
while ((strJ = StringsBuffer_UNSAFE_Get(buffer, j), String_Compare(&pivot, &strJ)) < 0) j--;
|
||||
QuickSort_Swap_Maybe();
|
||||
}
|
||||
/* recurse into the smaller subset */
|
||||
QuickSort_Recurse(ListScreen_QuickSort)
|
||||
}
|
||||
}
|
||||
|
||||
CC_NOINLINE static void ListScreen_Sort(struct ListScreen* s) {
|
||||
if (s->entries.count) {
|
||||
ListScreen_QuickSort(0, s->entries.count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
static cc_string ListScreen_UNSAFE_GetCur(struct ListScreen* s, void* widget) {
|
||||
int i = Screen_Index(s, widget);
|
||||
return ListScreen_UNSAFE_Get(s, s->currentIndex + i);
|
||||
|
@ -1583,7 +1557,7 @@ static void TexturePackScreen_FilterFiles(const cc_string* path, void* obj) {
|
|||
static void TexturePackScreen_LoadEntries(struct ListScreen* s) {
|
||||
static const cc_string path = String_FromConst(TEXPACKS_DIR);
|
||||
Directory_Enum(&path, &s->entries, TexturePackScreen_FilterFiles);
|
||||
ListScreen_Sort(s);
|
||||
StringsBuffer_Sort(&s->entries);
|
||||
}
|
||||
|
||||
#ifdef CC_BUILD_WEB
|
||||
|
@ -1648,7 +1622,6 @@ static void FontListScreen_UpdateEntry(struct ListScreen* s, struct ButtonWidget
|
|||
|
||||
static void FontListScreen_LoadEntries(struct ListScreen* s) {
|
||||
Font_GetNames(&s->entries);
|
||||
ListScreen_Sort(s);
|
||||
ListScreen_Select(s, Font_UNSAFE_GetDefault());
|
||||
}
|
||||
|
||||
|
@ -1720,7 +1693,7 @@ static void HotkeyListScreen_LoadEntries(struct ListScreen* s) {
|
|||
|
||||
/* Placeholder for 'add new hotkey' */
|
||||
StringsBuffer_Add(&s->entries, &String_Empty);
|
||||
ListScreen_Sort(s);
|
||||
StringsBuffer_Sort(&s->entries);
|
||||
}
|
||||
|
||||
static void HotkeyListScreen_UpdateEntry(struct ListScreen* s, struct ButtonWidget* button, const cc_string* text) {
|
||||
|
@ -1774,7 +1747,7 @@ static void LoadLevelScreen_FilterFiles(const cc_string* path, void* obj) {
|
|||
static void LoadLevelScreen_LoadEntries(struct ListScreen* s) {
|
||||
static const cc_string path = String_FromConst("maps");
|
||||
Directory_Enum(&path, &s->entries, LoadLevelScreen_FilterFiles);
|
||||
ListScreen_Sort(s);
|
||||
StringsBuffer_Sort(&s->entries);
|
||||
}
|
||||
|
||||
#ifdef CC_BUILD_WEB
|
||||
|
|
26
src/String.c
26
src/String.c
|
@ -872,6 +872,32 @@ void StringsBuffer_Remove(struct StringsBuffer* buffer, int index) {
|
|||
buffer->totalLength -= len;
|
||||
}
|
||||
|
||||
static struct StringsBuffer* sort_buffer;
|
||||
static void StringsBuffer_QuickSort(int left, int right) {
|
||||
struct StringsBuffer* buffer = sort_buffer;
|
||||
cc_uint32* keys = buffer->flagsBuffer; cc_uint32 key;
|
||||
|
||||
while (left < right) {
|
||||
int i = left, j = right;
|
||||
cc_string pivot = StringsBuffer_UNSAFE_Get(buffer, (i + j) >> 1);
|
||||
cc_string strI, strJ;
|
||||
|
||||
/* partition the list */
|
||||
while (i <= j) {
|
||||
while ((strI = StringsBuffer_UNSAFE_Get(buffer, i), String_Compare(&pivot, &strI)) > 0) i++;
|
||||
while ((strJ = StringsBuffer_UNSAFE_Get(buffer, j), String_Compare(&pivot, &strJ)) < 0) j--;
|
||||
QuickSort_Swap_Maybe();
|
||||
}
|
||||
/* recurse into the smaller subset */
|
||||
QuickSort_Recurse(StringsBuffer_QuickSort)
|
||||
}
|
||||
}
|
||||
|
||||
void StringsBuffer_Sort(struct StringsBuffer* buffer) {
|
||||
sort_buffer = buffer;
|
||||
StringsBuffer_QuickSort(0, buffer->count - 1);
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------Word wrapper-------------------------------------------------------*
|
||||
|
|
|
@ -241,6 +241,8 @@ STRING_REF void StringsBuffer_UNSAFE_GetRaw(struct StringsBuffer* buffer, int i,
|
|||
CC_API void StringsBuffer_Add(struct StringsBuffer* buffer, const cc_string* str);
|
||||
/* Removes the i'th string from the given buffer, shifting following strings downwards */
|
||||
CC_API void StringsBuffer_Remove(struct StringsBuffer* buffer, int index);
|
||||
/* Sorts all the entries in the given buffer using String_Compare */
|
||||
void StringsBuffer_Sort(struct StringsBuffer* buffer);
|
||||
|
||||
/* Performs line wrapping on the given string. */
|
||||
/* e.g. "some random tex|t* (| is lineLen) becomes "some random" "text" */
|
||||
|
|
Loading…
Reference in a new issue