From 55c170ff92d40ac6d8e780d6b51411107061d7f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Mon, 28 Jan 2019 18:05:39 -0800 Subject: [PATCH] Cleanup. --- examples/20-nanovg/nanovg.cpp | 38 ++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/examples/20-nanovg/nanovg.cpp b/examples/20-nanovg/nanovg.cpp index 7e902022d..353436fbc 100644 --- a/examples/20-nanovg/nanovg.cpp +++ b/examples/20-nanovg/nanovg.cpp @@ -977,7 +977,7 @@ struct DemoData int images[12]; }; -int createImage(struct NVGcontext* _ctx, const char* _filePath, int _imageFlags) +int32_t createImage(struct NVGcontext* _ctx, const char* _filePath, int _imageFlags) { uint32_t size; void* data = load(_filePath, &size); @@ -999,7 +999,7 @@ int createImage(struct NVGcontext* _ctx, const char* _filePath, int _imageFlags) return 0; } - int texId = nvgCreateImageRGBA( + int32_t texId = nvgCreateImageRGBA( _ctx , imageContainer->m_width , imageContainer->m_height @@ -1012,6 +1012,18 @@ int createImage(struct NVGcontext* _ctx, const char* _filePath, int _imageFlags) return texId; } +int32_t createFont(NVGcontext* _ctx, const char* _name, const char* _filePath) +{ + uint32_t size; + void* data = load(_filePath, &size); + if (NULL == data) + { + return -1; + } + + return nvgCreateFontMem(_ctx, _name, (uint8_t*)data, size, 0); +} + int loadDemoData(struct NVGcontext* vg, struct DemoData* data) { int i; @@ -1031,38 +1043,40 @@ int loadDemoData(struct NVGcontext* vg, struct DemoData* data) } } - data->fontIcons = nvgCreateFont(vg, "icons", "font/entypo.ttf"); + int32_t result = 0; + + data->fontIcons = createFont(vg, "icons", "font/entypo.ttf"); if (data->fontIcons == -1) { bx::debugPrintf("Could not add font icons.\n"); - return -1; + result = -1; } - data->fontNormal = nvgCreateFont(vg, "sans", "font/roboto-regular.ttf"); + data->fontNormal = createFont(vg, "sans", "font/roboto-regular.ttf"); if (data->fontNormal == -1) { bx::debugPrintf("Could not add font italic.\n"); - return -1; + result = -1; } - data->fontBold = nvgCreateFont(vg, "sans-bold", "font/roboto-bold.ttf"); + data->fontBold = createFont(vg, "sans-bold", "font/roboto-bold.ttf"); if (data->fontBold == -1) { bx::debugPrintf("Could not add font bold.\n"); - return -1; + result = -1; } - data->fontEmoji = nvgCreateFont(vg, "emoji", "font/NotoEmoji-Regular.ttf"); + data->fontEmoji = createFont(vg, "emoji", "font/NotoEmoji-Regular.ttf"); if (data->fontEmoji == -1) { bx::debugPrintf("Could not add font emoji.\n"); - return -1; + result = -1; } nvgAddFallbackFontId(vg, data->fontNormal, data->fontEmoji); nvgAddFallbackFontId(vg, data->fontBold, data->fontEmoji); - return 0; + return result; } void freeDemoData(struct NVGcontext* vg, struct DemoData* data) @@ -1408,7 +1422,7 @@ public: loadDemoData(m_nvg, &m_data); - bndSetFont(nvgCreateFont(m_nvg, "droidsans", "font/droidsans.ttf") ); + bndSetFont(createFont(m_nvg, "droidsans", "font/droidsans.ttf") ); bndSetIconImage(createImage(m_nvg, "images/blender_icons16.png", 0) ); m_timeOffset = bx::getHPCounter();