# HG changeset patch # User Michael Pavone # Date 1517990832 28800 # Node ID b96f9fae757faaf7cdd6a75addfd269b459ba71a # Parent c416ace65ff1451633656c5d8536019cfb7c5bf8 Fix Windows build, added Windows default_font_path implementation diff -r c416ace65ff1 -r b96f9fae757f Makefile --- a/Makefile Tue Feb 06 22:44:11 2018 -0800 +++ b/Makefile Wed Feb 07 00:07:12 2018 -0800 @@ -16,6 +16,7 @@ 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 @@ MEM:=mem.o TERMINAL:=terminal.o +FONT:=nuklear_ui/font.o EXE:= ifeq ($(OS),Darwin) @@ -127,7 +129,7 @@ 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) \ diff -r c416ace65ff1 -r b96f9fae757f menu.c --- a/menu.c Tue Feb 06 22:44:11 2018 -0800 +++ b/menu.c Wed Feb 07 00:07:12 2018 -0800 @@ -121,7 +121,7 @@ } return dst; } - +#include void * menu_write_w(uint32_t address, void * context, uint16_t value) { m68k_context *m68k = context; @@ -132,7 +132,7 @@ switch (address >> 2) { case 0: { -#ifdef _WIN32 +#if _WIN32 //handle virtual "drives" directory if (menu->curpath[0] == PATH_SEP[0]) { char drivestrings[4096]; diff -r c416ace65ff1 -r b96f9fae757f nuklear_ui/font_win.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nuklear_ui/font_win.c Wed Feb 07 00:07:12 2018 -0800 @@ -0,0 +1,56 @@ +#include +#include +#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; +} diff -r c416ace65ff1 -r b96f9fae757f paths.c --- a/paths.c Tue Feb 06 22:44:11 2018 -0800 +++ b/paths.c Wed Feb 07 00:07:12 2018 -0800 @@ -108,7 +108,7 @@ #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);