embedded resources in examples; embedded i18n resources support
|
@ -9,7 +9,7 @@
|
||||||
"targetType": "executable",
|
"targetType": "executable",
|
||||||
"targetName": "example1",
|
"targetName": "example1",
|
||||||
|
|
||||||
"copyFiles": ["res"],
|
"stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi"],
|
||||||
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dlangui:dlanguilib": "*"
|
"dlangui:dlanguilib": "*"
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
<otherDMD>0</otherDMD>
|
<otherDMD>0</otherDMD>
|
||||||
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
|
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
|
||||||
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source $(SolutionDir)/../de_image/source/interfaces $(SolutionDir)/../de_image/source/png $(SolutionDir)/../dlib</imppath>
|
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source $(SolutionDir)/../de_image/source/interfaces $(SolutionDir)/../de_image/source/png $(SolutionDir)/../dlib</imppath>
|
||||||
<fileImppath />
|
<fileImppath>views views/res views/res/i18n views/res/mdpi</fileImppath>
|
||||||
<outdir>$(ConfigurationName)</outdir>
|
<outdir>$(ConfigurationName)</outdir>
|
||||||
<objdir>$(OutDir)</objdir>
|
<objdir>$(OutDir)</objdir>
|
||||||
<objname />
|
<objname />
|
||||||
|
|
|
@ -169,21 +169,25 @@ enum : int {
|
||||||
/// entry point for dlangui based application
|
/// entry point for dlangui based application
|
||||||
extern (C) int UIAppMain(string[] args) {
|
extern (C) int UIAppMain(string[] args) {
|
||||||
// resource directory search paths
|
// resource directory search paths
|
||||||
string[] resourceDirs = [
|
// not required if only embedded resources are used
|
||||||
appendPath(exePath, "../../../res/"), // for Visual D and DUB builds
|
//string[] resourceDirs = [
|
||||||
appendPath(exePath, "../../../res/mdpi/"), // for Visual D and DUB builds
|
// appendPath(exePath, "../../../res/"), // for Visual D and DUB builds
|
||||||
appendPath(exePath, "../../../../res/"),// for Mono-D builds
|
// appendPath(exePath, "../../../res/mdpi/"), // for Visual D and DUB builds
|
||||||
appendPath(exePath, "../../../../res/mdpi/"),// for Mono-D builds
|
// appendPath(exePath, "../../../../res/"),// for Mono-D builds
|
||||||
appendPath(exePath, "res/"), // when res dir is located at the same directory as executable
|
// appendPath(exePath, "../../../../res/mdpi/"),// for Mono-D builds
|
||||||
appendPath(exePath, "../res/"), // when res dir is located at project directory
|
// appendPath(exePath, "res/"), // when res dir is located at the same directory as executable
|
||||||
appendPath(exePath, "../../res/"), // when res dir is located at the same directory as executable
|
// appendPath(exePath, "../res/"), // when res dir is located at project directory
|
||||||
appendPath(exePath, "res/mdpi/"), // when res dir is located at the same directory as executable
|
// appendPath(exePath, "../../res/"), // when res dir is located at the same directory as executable
|
||||||
appendPath(exePath, "../res/mdpi/"), // when res dir is located at project directory
|
// appendPath(exePath, "res/mdpi/"), // when res dir is located at the same directory as executable
|
||||||
appendPath(exePath, "../../res/mdpi/") // when res dir is located at the same directory as executable
|
// appendPath(exePath, "../res/mdpi/"), // when res dir is located at project directory
|
||||||
];
|
// appendPath(exePath, "../../res/mdpi/") // when res dir is located at the same directory as executable
|
||||||
|
//];
|
||||||
// setup resource directories - will use only existing directories
|
// setup resource directories - will use only existing directories
|
||||||
Platform.instance.resourceDirs = resourceDirs;
|
//Platform.instance.resourceDirs = resourceDirs;
|
||||||
|
|
||||||
|
// embed resources listed in views/resources.list into executable
|
||||||
|
embeddedResourceList.addResources(embedResourcesFromList!("resources.list")());
|
||||||
|
|
||||||
// select translation file - for english language
|
// select translation file - for english language
|
||||||
Platform.instance.uiLanguage = "en";
|
Platform.instance.uiLanguage = "en";
|
||||||
// load theme from file "theme_default.xml"
|
// load theme from file "theme_default.xml"
|
||||||
|
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 828 B After Width: | Height: | Size: 828 B |
Before Width: | Height: | Size: 892 B After Width: | Height: | Size: 892 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 605 B After Width: | Height: | Size: 605 B |
Before Width: | Height: | Size: 593 B After Width: | Height: | Size: 593 B |
Before Width: | Height: | Size: 701 B After Width: | Height: | Size: 701 B |
Before Width: | Height: | Size: 635 B After Width: | Height: | Size: 635 B |
Before Width: | Height: | Size: 771 B After Width: | Height: | Size: 771 B |
Before Width: | Height: | Size: 559 B After Width: | Height: | Size: 559 B |
Before Width: | Height: | Size: 436 B After Width: | Height: | Size: 436 B |
Before Width: | Height: | Size: 368 B After Width: | Height: | Size: 368 B |
Before Width: | Height: | Size: 598 B After Width: | Height: | Size: 598 B |
Before Width: | Height: | Size: 753 B After Width: | Height: | Size: 753 B |
Before Width: | Height: | Size: 810 B After Width: | Height: | Size: 810 B |
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.8 KiB |
|
@ -0,0 +1,16 @@
|
||||||
|
res/i18n/en.ini
|
||||||
|
res/i18n/ru.ini
|
||||||
|
res/mdpi/cr3_logo.png
|
||||||
|
res/mdpi/document-close.png
|
||||||
|
res/mdpi/document-open-recent.png
|
||||||
|
res/mdpi/document-open.png
|
||||||
|
res/mdpi/document-properties.png
|
||||||
|
res/mdpi/document-save-as.png
|
||||||
|
res/mdpi/document-save.png
|
||||||
|
res/mdpi/edit-copy.png
|
||||||
|
res/mdpi/edit-cut.png
|
||||||
|
res/mdpi/edit-paste.png
|
||||||
|
res/mdpi/edit-redo.png
|
||||||
|
res/mdpi/edit-undo.png
|
||||||
|
res/mdpi/tx_fabric.jpg
|
||||||
|
res/theme_custom1.xml
|
|
@ -28,22 +28,9 @@ extern (C) int UIAppMain(string[] args) {
|
||||||
//auto power2 = delegate(int X) { return X * X; };
|
//auto power2 = delegate(int X) { return X * X; };
|
||||||
auto power2 = (int X) => X * X;
|
auto power2 = (int X) => X * X;
|
||||||
|
|
||||||
// resource directory search paths
|
// embed resources listed in views/resources.list into executable
|
||||||
string[] resourceDirs = [
|
embeddedResourceList.addResources(embedResourcesFromList!("resources.list")());
|
||||||
appendPath(exePath, "../../../res/"), // for Visual D and DUB builds
|
|
||||||
appendPath(exePath, "../../../res/mdpi/"), // for Visual D and DUB builds
|
|
||||||
appendPath(exePath, "../../../../res/"),// for Mono-D builds
|
|
||||||
appendPath(exePath, "../../../../res/mdpi/"),// for Mono-D builds
|
|
||||||
appendPath(exePath, "res/"), // when res dir is located at the same directory as executable
|
|
||||||
appendPath(exePath, "../res/"), // when res dir is located at project directory
|
|
||||||
appendPath(exePath, "../../res/"), // when res dir is located at the same directory as executable
|
|
||||||
appendPath(exePath, "res/mdpi/"), // when res dir is located at the same directory as executable
|
|
||||||
appendPath(exePath, "../res/mdpi/"), // when res dir is located at project directory
|
|
||||||
appendPath(exePath, "../../res/mdpi/") // when res dir is located at the same directory as executable
|
|
||||||
];
|
|
||||||
|
|
||||||
// setup resource directories - will use only existing directories
|
|
||||||
Platform.instance.resourceDirs = resourceDirs;
|
|
||||||
// select translation file - for english language
|
// select translation file - for english language
|
||||||
Platform.instance.uiLanguage = "en";
|
Platform.instance.uiLanguage = "en";
|
||||||
// load theme from file "theme_default.xml"
|
// load theme from file "theme_default.xml"
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
<otherDMD>0</otherDMD>
|
<otherDMD>0</otherDMD>
|
||||||
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
|
<program>$(DMDInstallDir)windows\bin\dmd.exe</program>
|
||||||
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source $(SolutionDir)/../de_image/source/interfaces $(SolutionDir)/../de_image/source/png $(SolutionDir)/../dlib</imppath>
|
<imppath>$(SolutionDir)/src $(SolutionDir)/3rdparty $(SolutionDir)/3rdparty/libpng/source $(SolutionDir)/../DerelictGL3/source $(SolutionDir)/../DerelictUtil/source $(SolutionDir)/../DerelictFT/source $(SolutionDir)/../DerelictSDL2/source $(SolutionDir)/../de_image/source/interfaces $(SolutionDir)/../de_image/source/png $(SolutionDir)/../dlib</imppath>
|
||||||
<fileImppath />
|
<fileImppath>views views/res views/mdpi views/i18n</fileImppath>
|
||||||
<outdir>$(ConfigurationName)</outdir>
|
<outdir>$(ConfigurationName)</outdir>
|
||||||
<objdir>$(OutDir)</objdir>
|
<objdir>$(OutDir)</objdir>
|
||||||
<objname />
|
<objname />
|
||||||
|
@ -89,7 +89,6 @@
|
||||||
<resfile />
|
<resfile />
|
||||||
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
|
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
|
||||||
<useStdLibPath>1</useStdLibPath>
|
<useStdLibPath>1</useStdLibPath>
|
||||||
<cRuntime>2</cRuntime>
|
|
||||||
<additionalOptions>-profile</additionalOptions>
|
<additionalOptions>-profile</additionalOptions>
|
||||||
<preBuildCommand />
|
<preBuildCommand />
|
||||||
<postBuildCommand />
|
<postBuildCommand />
|
||||||
|
@ -184,7 +183,6 @@
|
||||||
<resfile />
|
<resfile />
|
||||||
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
|
<exefile>$(OutDir)\$(ProjectName).exe</exefile>
|
||||||
<useStdLibPath>1</useStdLibPath>
|
<useStdLibPath>1</useStdLibPath>
|
||||||
<cRuntime>1</cRuntime>
|
|
||||||
<additionalOptions />
|
<additionalOptions />
|
||||||
<preBuildCommand />
|
<preBuildCommand />
|
||||||
<postBuildCommand />
|
<postBuildCommand />
|
||||||
|
@ -192,7 +190,7 @@
|
||||||
</Config>
|
</Config>
|
||||||
<Folder name="tetris">
|
<Folder name="tetris">
|
||||||
<File path="src\gui.d" />
|
<File path="src\gui.d" />
|
||||||
<File path="src\tetris.d" />
|
|
||||||
<File path="src\model.d" />
|
<File path="src\model.d" />
|
||||||
|
<File path="src\tetris.d" />
|
||||||
</Folder>
|
</Folder>
|
||||||
</DProject>
|
</DProject>
|
||||||
|
|
Before Width: | Height: | Size: 843 B After Width: | Height: | Size: 843 B |
Before Width: | Height: | Size: 834 B After Width: | Height: | Size: 834 B |
Before Width: | Height: | Size: 810 B After Width: | Height: | Size: 810 B |
Before Width: | Height: | Size: 971 B After Width: | Height: | Size: 971 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 374 B After Width: | Height: | Size: 374 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.8 KiB |
|
@ -0,0 +1,10 @@
|
||||||
|
res/arrow-down.png
|
||||||
|
res/arrow-left.png
|
||||||
|
res/arrow-right.png
|
||||||
|
res/dtetris-logo1.png
|
||||||
|
res/levelup.png
|
||||||
|
res/pause.png
|
||||||
|
res/popup_background.9.png
|
||||||
|
res/rotate.png
|
||||||
|
res/tetris_logo_big.png
|
||||||
|
res/tx_fabric.jpg
|
|
@ -63,9 +63,12 @@ module dlangui.core.i18n;
|
||||||
import dlangui.core.types;
|
import dlangui.core.types;
|
||||||
import dlangui.core.logger;
|
import dlangui.core.logger;
|
||||||
import dlangui.core.files;
|
import dlangui.core.files;
|
||||||
|
import dlangui.graphics.resources;
|
||||||
private import dlangui.core.linestream;
|
private import dlangui.core.linestream;
|
||||||
private import std.utf;
|
private import std.utf;
|
||||||
private import std.algorithm;
|
private import std.algorithm;
|
||||||
|
private import std.string;
|
||||||
|
private import std.file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Container for UI string - either raw value or string resource ID
|
Container for UI string - either raw value or string resource ID
|
||||||
|
@ -290,10 +293,22 @@ synchronized class UIStringTranslator {
|
||||||
if (ch == '/' || ch == '\\')
|
if (ch == '/' || ch == '\\')
|
||||||
hasPathDelimiters = true;
|
hasPathDelimiters = true;
|
||||||
string[] res;
|
string[] res;
|
||||||
if (!hasPathDelimiters && _resourceDirs.length) {
|
if (!hasPathDelimiters) {
|
||||||
foreach (dir; _resourceDirs)
|
string fn = EMBEDDED_RESOURCE_PREFIX ~ "std_" ~ filename;
|
||||||
res ~= dir ~ filename;
|
string s = cast(string)loadResourceBytes(fn);
|
||||||
|
if (s)
|
||||||
|
res ~= fn;
|
||||||
|
fn = EMBEDDED_RESOURCE_PREFIX ~ filename;
|
||||||
|
s = cast(string)loadResourceBytes(fn);
|
||||||
|
if (s)
|
||||||
|
res ~= fn;
|
||||||
|
foreach (dir; _resourceDirs) {
|
||||||
|
fn = dir ~ filename;
|
||||||
|
if (exists(fn) && isFile(fn))
|
||||||
|
res ~= fn;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// full path
|
||||||
res ~= filename;
|
res ~= filename;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -350,13 +365,9 @@ private shared class UIStringList {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
/// load strings from stream
|
/// load strings from stream
|
||||||
bool load(std.stream.InputStream stream) {
|
bool load(dstring[] lines) {
|
||||||
dlangui.core.linestream.LineStream lines = dlangui.core.linestream.LineStream.create(stream, "");
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (;;) {
|
foreach (s; lines) {
|
||||||
dchar[] s = lines.readLine();
|
|
||||||
if (s is null)
|
|
||||||
break;
|
|
||||||
int eqpos = -1;
|
int eqpos = -1;
|
||||||
int firstNonspace = -1;
|
int firstNonspace = -1;
|
||||||
int lastNonspace = -1;
|
int lastNonspace = -1;
|
||||||
|
@ -379,23 +390,33 @@ private shared class UIStringList {
|
||||||
return count > 0;
|
return count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// convert to utf32 and split by lines (detecting line endings)
|
||||||
|
static dstring[] splitLines(string src) {
|
||||||
|
dstring dsrc = toUTF32(src);
|
||||||
|
dstring[] split1 = split(dsrc, "\r\n");
|
||||||
|
dstring[] split2 = split(dsrc, "\r");
|
||||||
|
dstring[] split3 = split(dsrc, "\n");
|
||||||
|
if (split1.length >= split2.length && split1.length >= split3.length)
|
||||||
|
return split1;
|
||||||
|
if (split2.length > split3.length)
|
||||||
|
return split2;
|
||||||
|
return split3;
|
||||||
|
}
|
||||||
|
|
||||||
/// load strings from file (utf8, id=value lines)
|
/// load strings from file (utf8, id=value lines)
|
||||||
bool load(string[] filenames) {
|
bool load(string[] filenames) {
|
||||||
clear();
|
clear();
|
||||||
bool res = false;
|
bool res = false;
|
||||||
foreach(filename; filenames) {
|
foreach(filename; filenames) {
|
||||||
import std.stream;
|
|
||||||
import std.file;
|
|
||||||
try {
|
try {
|
||||||
debug Log.d("Loading string resources from file ", filename);
|
debug Log.d("Loading string resources from file ", filename);
|
||||||
if (!exists(filename) || !isFile(filename)) {
|
string s = cast(string)loadResourceBytes(filename);
|
||||||
Log.e("File does not exist: ", filename);
|
if (!s) {
|
||||||
|
Log.e("Cannot load i18n resource from file ", filename);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std.stream.File f = new std.stream.File(filename);
|
res = load(splitLines(s)) || res;
|
||||||
scope(exit) { f.close(); }
|
} catch (Exception e) {
|
||||||
res = load(f) || res;
|
|
||||||
} catch (StreamFileException e) {
|
|
||||||
Log.e("Cannot read string resources from file ", filename);
|
Log.e("Cannot read string resources from file ", filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ res/exit.png
|
||||||
res/fileclose.png
|
res/fileclose.png
|
||||||
res/fileopen.png
|
res/fileopen.png
|
||||||
res/frame_blue.9.png
|
res/frame_blue.9.png
|
||||||
res/i18n/en.ini
|
res/i18n/std_en.ini
|
||||||
res/i18n/ru.ini
|
res/i18n/std_ru.ini
|
||||||
res/list_item_background.xml
|
res/list_item_background.xml
|
||||||
res/list_item_background_solid.xml
|
res/list_item_background_solid.xml
|
||||||
res/main_menu_item_background.xml
|
res/main_menu_item_background.xml
|
||||||
|
|