Module dcanvas.graphics.resources
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 dcanvas 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 dcanvas 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 dcanvas .graphics .resources;
// embed non-standard resources listed in views/resources.list into executable
embeddedResourceList .addResources(embedResourcesFromList!("resources.list")());
Functions
| Name | Description |
|---|---|
attrValue(item, attrname, attrname2)
|
|
createColorDrawable(s)
|
decode solid color / gradient / border drawable from string like #AARRGGBB, e.g. #5599AA |
decodeAngle(s)
|
decode angle; only Ndeg format for now |
decodeDimension(s)
|
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 |
embedStandardDCanvasResources()
|
|
extractStateFlag(item, attrName, attrName2, state, stateMask, stateValue)
|
|
extractStateFlags(item, stateMask, stateValue)
|
converts XML attribute name to State (see http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList) |
imageCache()
|
image cache singleton |
loadResourceBytes(filename)
|
load resource bytes from embedded resource or file |
loadTextResource(resourceId)
|
load text resource |
resDirName(fullname)
|
Classes
| Name | Description |
|---|---|
BorderDrawable
|
solid borders (may be of different width) and, optionally, solid inner area |
BoxShadowDrawable
|
box shadows, can be blurred |
CombinedDrawable
|
Drawable which allows to combine together background image, gradient, borders, box shadows, etc. |
Drawable
|
Base class for all drawables |
DrawableCache
|
|
EmptyDrawable
|
|
GradientDrawable
|
|
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 |
|---|---|---|
_drawableCache
|
DrawableCache
|
|
_imageCache
|
ImageCache
|
|
EMBEDDED_RESOURCE_PREFIX
|
immutable(char[])
|
filename prefix for embedded resources |
embeddedResourceList
|
EmbeddedResourceList
|
Aliases
| Name | Type | Description |
|---|---|---|
DrawableRef
|
Ref!(dcanvas.graphics.resources.Drawable)
|
|
FrameDrawable
|
BorderDrawable
|