diff options
author | Michael Pavone <pavone@retrodev.com> | 2018-02-07 00:07:12 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2018-02-07 00:07:12 -0800 |
commit | a956d5e1f82e98097602e289ac8f02374ea3b5e7 (patch) | |
tree | 13034bf443f7ca1bdcc9d4a29074f3ebd768c078 | |
parent | 60e74d48cd8c59f412128d98908f2b04b2b07586 (diff) |
Fix Windows build, added Windows default_font_path implementation
--HG--
branch : nuklear_ui
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | menu.c | 4 | ||||
-rw-r--r-- | nuklear_ui/font_win.c | 56 | ||||
-rw-r--r-- | paths.c | 2 |
4 files changed, 62 insertions, 4 deletions
@@ -16,6 +16,7 @@ endif MEM:=mem_win.o TERMINAL:=terminal_win.o +FONT:=nuklear_ui/font_win.o EXE:=.exe CC:=i686-w64-mingw32-gcc-win32 CFLAGS:=-std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration -I"$(SDL2_PREFIX)/include/SDL2" -I"$(GLEW_PREFIX)/include" -DGLEW_STATIC @@ -26,6 +27,7 @@ else MEM:=mem.o TERMINAL:=terminal.o +FONT:=nuklear_ui/font.o EXE:= ifeq ($(OS),Darwin) @@ -127,7 +129,7 @@ endif Z80OBJS=z80inst.o z80_to_x86.o AUDIOOBJS=ym2612.o psg.o wave.o CONFIGOBJS=config.o tern.o util.o paths.o -NUKLEAROBJS=nuklear_ui/font.o nuklear_ui/blastem_nuklear.o +NUKLEAROBJS=$(FONT) nuklear_ui/blastem_nuklear.o MAINOBJS=blastem.o system.o genesis.o debug.o gdb_remote.o vdp.o render_sdl.o ppm.o io.o romdb.o hash.o menu.o xband.o \ realtec.o i2c.o nor.o sega_mapper.o multi_game.o serialize.o $(TERMINAL) $(CONFIGOBJS) gst.o $(M68KOBJS) \ @@ -121,7 +121,7 @@ uint32_t copy_dir_entry_to_guest(uint32_t dst, m68k_context *m68k, char *name, u } return dst; } - +#include <windows.h> void * menu_write_w(uint32_t address, void * context, uint16_t value) { m68k_context *m68k = context; @@ -132,7 +132,7 @@ void * menu_write_w(uint32_t address, void * context, uint16_t value) switch (address >> 2) { case 0: { -#ifdef _WIN32 +#if _WIN32 //handle virtual "drives" directory if (menu->curpath[0] == PATH_SEP[0]) { char drivestrings[4096]; diff --git a/nuklear_ui/font_win.c b/nuklear_ui/font_win.c new file mode 100644 index 0000000..c95fcb3 --- /dev/null +++ b/nuklear_ui/font_win.c @@ -0,0 +1,56 @@ +#include <windows.h> +#include <shlobj.h> +#include "../paths.h" +#include "../util.h" + +char *default_font_path(void) +{ + NONCLIENTMETRICSA metrics = { + .cbSize = sizeof(metrics) + }; + char *pref_name = NULL; + if (SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, sizeof(metrics), &metrics, 0)) { + pref_name = metrics.lfCaptionFont.lfFaceName; + } + char windows[MAX_PATH]; + SHGetFolderPathA(NULL, CSIDL_WINDOWS, NULL, 0, windows); + char *fonts = path_append(windows, "Fonts"); + size_t num_entries; + char *preferred = NULL, *tahoma = NULL, *arial = NULL; + dir_entry *entries = get_dir_list(fonts, &num_entries); + for (size_t i = 0; i < num_entries; i++) + { + if (entries[i].is_dir) { + continue; + } + char *ext = path_extension(entries[i].name); + if (!ext || strcasecmp(ext, "ttf")) { + //not a truetype font, ignore + free(ext); + continue; + } + free(ext); + char *base = basename_no_extension(entries[i].name); + if (!strcasecmp(base, pref_name)) { + preferred = entries[i].name; + free(base); + break; + } else if (!strcasecmp(base, "tahoma")) { + tahoma = entries[i].name; + } else if (!strcasecmp(base, "arial")) { + arial = entries[i].name; + } + free(base); + } + char *path = NULL; + if (preferred) { + path = path_append(fonts, preferred); + } else if(tahoma) { + path = path_append(fonts, tahoma); + } else if(arial) { + path = path_append(fonts, arial); + } + free(fonts); + free_dir_list(entries, num_entries); + return path; +} @@ -108,7 +108,7 @@ char *path_append(const char *base, const char *suffix) #ifdef _WIN32 //handle transition from root of a drive to virtual root if (base[1] == ':' && !base[2]) { - return strdup(PATH_SEP) + return strdup(PATH_SEP); } #endif size_t len = strlen(base); |