From 03a87383ebd640b335b4a6b2999d77f1e3841ef5 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Thu, 31 Aug 2017 11:43:57 +0300 Subject: [PATCH] resources import with path - step 1 for better resource/different DPI management; is possible after import with path is fixed in DMD on windows --- src/dlangui/graphics/resources.d | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/dlangui/graphics/resources.d b/src/dlangui/graphics/resources.d index b82dd74c..20b415fc 100644 --- a/src/dlangui/graphics/resources.d +++ b/src/dlangui/graphics/resources.d @@ -112,9 +112,11 @@ immutable string EMBEDDED_RESOURCE_PREFIX = "@embedded@/"; struct EmbeddedResource { immutable string name; immutable ubyte[] data; - this(immutable string name, immutable ubyte[] data) { + immutable string dir; + this(immutable string name, immutable ubyte[] data, immutable string dir = null) { this.name = name; this.data = data; + this.dir = dir; } } @@ -169,7 +171,13 @@ __gshared EmbeddedResourceList embeddedResourceList; //immutable string test_res = import("res/background.xml"); // Unfortunately, import with full pathes does not work on Windows -//version = USE_FULL_PATH_FOR_RESOURCES; +version = USE_FULL_PATH_FOR_RESOURCES; + +string resDirName(string fullname) { + immutable string step0 = fullname.dirName; + immutable string step1 = step0.startsWith("res/") ? step0[4 .. $] : step0; + return step1 == "." ? null : step1; +} EmbeddedResource[] embedResource(string resourceName)() { static if (resourceName.startsWith("#")) { @@ -182,8 +190,10 @@ EmbeddedResource[] embedResource(string resourceName)() { } static if (name.length > 0) { immutable ubyte[] data = cast(immutable ubyte[])import(name); + immutable string resname = baseName(name); + immutable string resdir = resDirName(name); static if (data.length > 0) - return [EmbeddedResource(name, data)]; + return [EmbeddedResource(resname, data, resdir)]; else return []; } else