aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-25 18:39:14 +0800
committercrupest <crupest@outlook.com>2022-01-25 18:39:14 +0800
commitd3aa43d9ea0dfc32935767cf60a89af2736dc339 (patch)
treee8cf043ac6d9a2e6ce038ad6b1f57079834ef129 /src
parent71c01a175a939d1a519ab235fdfdeec1101f8b84 (diff)
downloadcru-d3aa43d9ea0dfc32935767cf60a89af2736dc339.tar.gz
cru-d3aa43d9ea0dfc32935767cf60a89af2736dc339.tar.bz2
cru-d3aa43d9ea0dfc32935767cf60a89af2736dc339.zip
...
Diffstat (limited to 'src')
-rw-r--r--src/common/String.cpp4
-rw-r--r--src/common/io/Resource.cpp15
-rw-r--r--src/ui/CMakeLists.txt7
-rw-r--r--src/ui/UiManager.cpp12
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"";