Module dlangui.graphics.resources
This module contains resource management and drawables implementation.
imageCache
is RAM cache of decoded images (as DrawBuf).
drawableCache
is cache of Drawables.
Supports nine-patch PNG images in .9.png files (like in Android).
Supports state drawables using XML files similar to ones in Android.
When your application uses custom resources, you can embed resources into executable and/or specify external resource directory(s).
To embed resources, put them into views/res directory, and create file views/resources.list with list of all files to embed.
Use following code to embed resources:
/// entry point for dlangui based application
extern (C) int UIAppMain(string[] args) {
// embed non-standard resources listed in views/resources.list into executable
embeddedResourceList .addResources(embedResourcesFromList!("resources.list")());
...
Resource list resources.list file may look similar to following:
res/i18n/en .ini
res/i18n/ru .ini
res/mdpi/cr3_logo .png
res/mdpi/document-open .png
res/mdpi/document-properties .png
res/mdpi/document-save .png
res/mdpi/edit-copy .png
res/mdpi/edit-paste .png
res/mdpi/edit-undo .png
res/mdpi/tx_fabric .jpg
res/theme_custom1 .xml
As well you can specify list of external directories to get resources from.
/// entry point for dlangui based application
extern (C) int UIAppMain(string[] args) {
// resource directory search paths
string[] resourceDirs = [
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;
When same file exists in both embedded and external resources, one from external resource directory will be used - it's useful for developing and testing of resources.
Synopsis
import dlangui .graphics .resources;
// embed non-standard resources listed in views/resources.list into executable
embeddedResourceList .addResources(embedResourcesFromList!("resources.list")());
Functions
Name | Description |
---|---|
attrValue
|
|
attrValue
|
|
createColorDrawable
|
decode solid color / gradient / frame drawable from string like #AARRGGBB, e.g. #5599AA |
decodeDimension
|
decode size string, e.g. 1px or 2 or 3pt |
drawableCache
|
drawable cache singleton
|
embedResource
|
|
embedResources
|
embed all resources from list |
embedResourcesFromList
|
embed all resources from list |
embedStandardDlangUIResources
|
|
extractStateFlag
|
|
extractStateFlags
|
converts XML attribute name to State (see http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList) |
imageCache
|
image cache singleton
|
loadResourceBytes
|
load resource bytes from embedded resource or file |
splitLines
|
split string into lines, autodetect line endings |
Classes
Name | Description |
---|---|
Drawable
|
Base class for all drawables |
DrawableCache
|
|
EmptyDrawable
|
|
FrameDrawable
|
solid borders (may be of different width ) and, optionally, solid inner area
|
ImageCache
|
decoded raster images cache (png, jpeg) -- access by filenames |
ImageDrawable
|
|
OpenGLDrawable
|
Custom drawing inside openGL |
SolidFillDrawable
|
|
StateDrawable
|
Drawable which is drawn depending on state (see http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList)
|
Structs
Name | Description |
---|---|
EmbeddedResource
|
|
EmbeddedResourceList
|
Enums
Name | Description |
---|---|
DimensionUnits
|
Global variables
Name | Type | Description |
---|---|---|
embeddedResourceList
|
EmbeddedResourceList
|
|
EMBEDDED_RESOURCE_PREFIX
|
immutable(char[])
|
filename prefix for embedded resources |
_drawableCache
|
DrawableCache
|
|
_imageCache
|
ImageCache
|
Aliases
Name | Type | Description |
---|---|---|
DrawableRef
|
Authors
Vadim Lopatin, coolreader.org@gmail.com
Copyright
Vadim Lopatin, 2014
License
Boost License 1.0