diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/String.cpp | 4 | ||||
-rw-r--r-- | src/common/io/Resource.cpp | 15 | ||||
-rw-r--r-- | src/ui/CMakeLists.txt | 7 | ||||
-rw-r--r-- | src/ui/UiManager.cpp | 12 |
4 files changed, 25 insertions, 13 deletions
diff --git a/src/common/String.cpp b/src/common/String.cpp index 62943059..e791d119 100644 --- a/src/common/String.cpp +++ b/src/common/String.cpp @@ -33,6 +33,10 @@ String String::FromUtf8(const char* str, Index size) { return result; } +String String::FromStdPath(const std::filesystem::path& path) { + return String::FromUtf8(path.string()); +} + char16_t String::kEmptyBuffer[1] = {0}; String::String(const_pointer str) : String(str, GetStrSize(str)) {} diff --git a/src/common/io/Resource.cpp b/src/common/io/Resource.cpp index e2ff8004..da16b578 100644 --- a/src/common/io/Resource.cpp +++ b/src/common/io/Resource.cpp @@ -7,10 +7,19 @@ #endif namespace cru::io { -std::unique_ptr<Stream> CreateStreamFromResourcePath(const String& path) { +std::filesystem::path GetResourceDir() { #if defined(CRU_PLATFORM_OSX) - // CFBundleRef main_bundle = CFBundleGetMainBundle(); - throw Exception(u"Not implemented."); + CFBundleRef main_bundle = CFBundleGetMainBundle(); + CFURLRef bundle_url = CFBundleCopyBundleURL(main_bundle); + CFStringRef cf_string_ref = + CFURLCopyFileSystemPath(bundle_url, kCFURLPOSIXPathStyle); + std::filesystem::path bundle_path( + CFStringGetCStringPtr(cf_string_ref, kCFStringEncodingUTF8)); + + CFRelease(bundle_url); + CFRelease(cf_string_ref); + + return bundle_path / "Contents/Resources"; #elif defined(CRU_PLATFORM_WINDOWS) throw Exception(u"Not implemented."); #else diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 0c81b6c7..a86e24c0 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -59,10 +59,3 @@ add_library(cru_ui SHARED ) target_compile_definitions(cru_ui PRIVATE CRU_UI_EXPORT_API) target_link_libraries(cru_ui PUBLIC cru_platform_gui cru_xml) - -file(GLOB_RECURSE CRU_UI_RES_SOURCES "${CRU_ASSETS_DIR}/cru/ui/*") -target_sources(cru_ui PUBLIC ${CRU_UI_RES_SOURCES}) -foreach (CRU_UI_RES_FILE ${CRU_UI_RES_SOURCES}) - file(RELATIVE_PATH CRU_UI_RES_PATH ${CRU_ASSETS_DIR} ${CRU_UI_RES_FILE}) - set_property(SOURCE ${CRU_UI_RES_FILE} PROPERTY MACOSX_PACKAGE_LOCATION "Resources/${CRU_UI_RES_PATH}") -endforeach(CRU_UI_RES_FILE) diff --git a/src/ui/UiManager.cpp b/src/ui/UiManager.cpp index e374cc2e..62dce6a7 100644 --- a/src/ui/UiManager.cpp +++ b/src/ui/UiManager.cpp @@ -3,6 +3,7 @@ #include "Helper.hpp" #include "cru/common/io/FileStream.hpp" #include "cru/common/io/OpenFileFlag.hpp" +#include "cru/common/io/Resource.hpp" #include "cru/platform/graphics/Brush.hpp" #include "cru/platform/graphics/Factory.hpp" #include "cru/platform/graphics/Font.hpp" @@ -37,9 +38,14 @@ UiManager* UiManager::GetInstance() { UiManager::UiManager() { const auto factory = GetGraphicsFactory(); - // TODO: Resource file path!!! - ReadResourcesFile( - u"/Users/crupest/codes/cru/assets/cru/ui/DefaultResources.xml"); + std::filesystem::path resourses_file = + cru::io::GetResourceDir() / "cru/ui/DefaultResources.xml"; + + if (!std::filesystem::exists(resourses_file)) { + throw Exception(u"Default resources file not found."); + } + + ReadResourcesFile(String::FromStdPath(resourses_file)); theme_resource_.default_font_family = u""; |