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.

More...

Members

Aliases

DrawableRef
alias DrawableRef = Ref!Drawable
Undocumented in source.
FrameDrawable
deprecated alias FrameDrawable = BorderDrawable
Undocumented in source.

Classes

BorderDrawable
class BorderDrawable

solid borders (may be of different width) and, optionally, solid inner area

BoxShadowDrawable
class BoxShadowDrawable

box shadows, can be blurred

CombinedDrawable
class CombinedDrawable

Drawable which allows to combine together background image, gradient, borders, box shadows, etc.

ConsoleDrawBuf
class ConsoleDrawBuf

Text image drawable. Resource file extension: .tim Image format is JSON based. Sample: { text: [ "╔═╗", "║ ║", "╚═╝"], backgroundColor: [0x000080], textColor: [0xFF0000], ninepatch: [1,1,1,1] }

Drawable
class Drawable

Base class for all drawables

DrawableCache
class DrawableCache
Undocumented in source.
EmptyDrawable
class EmptyDrawable
Undocumented in source.
GradientDrawable
class GradientDrawable
Undocumented in source.
ImageCache
class ImageCache

decoded raster images cache (png, jpeg) -- access by filenames

ImageDrawable
class ImageDrawable
Undocumented in source.
OpenGLDrawable
class OpenGLDrawable

Custom drawing inside openGL

SolidFillDrawable
class SolidFillDrawable
Undocumented in source.
StateDrawable
class StateDrawable

Drawable which is drawn depending on state (see http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList)

TextDrawable
class TextDrawable
Undocumented in source.

Enums

DimensionUnits
enum DimensionUnits
Undocumented in source.

Functions

attrValue
string attrValue(Element item, string attrname, string attrname2)
Undocumented in source. Be warned that the author may not have intended to support it.
attrValue
string attrValue(string[string] attr, string attrname, string attrname2)
Undocumented in source. Be warned that the author may not have intended to support it.
embedResource
EmbeddedResource[] embedResource()
Undocumented in source. Be warned that the author may not have intended to support it.
embedResources
EmbeddedResource[] embedResources()

embed all resources from list

embedResourcesFromList
EmbeddedResource[] embedResourcesFromList()

embed all resources from list

embedStandardDlangUIResources
void embedStandardDlangUIResources()
Undocumented in source. Be warned that the author may not have intended to support it.
extractStateFlag
void extractStateFlag(string[string] attr, string attrName, string attrName2, State state, uint stateMask, uint stateValue)
Undocumented in source. Be warned that the author may not have intended to support it.
extractStateFlags
void extractStateFlags(string[string] attr, uint stateMask, uint stateValue)

converts XML attribute name to State (see http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList)

loadResourceBytes
immutable(ubyte[]) loadResourceBytes(string filename)

load resource bytes from embedded resource or file

loadTextResource
string loadTextResource(string resourceId)

load text resource

resDirName
string resDirName(string fullname)
Undocumented in source. Be warned that the author may not have intended to support it.

Properties

drawableCache
DrawableCache drawableCache [@property getter]

drawable cache singleton

drawableCache
void drawableCache [@property getter]

drawable cache singleton

imageCache
ImageCache imageCache [@property getter]

image cache singleton

imageCache
void imageCache [@property getter]

image cache singleton

Static functions

createColorDrawable
Drawable createColorDrawable(string s)

decode solid color / gradient / border drawable from string like #AARRGGBB, e.g. #5599AA

createTextDrawable
Drawable createTextDrawable(string s)

Sample format: { text: [ "╔═╗", "║ ║", "╚═╝"], backgroundColor: [0x000080], // put more values for individual colors of cells textColor: [0xFF0000], // put more values for individual colors of cells ninepatch: [1,1,1,1] }

decodeAngle
uint decodeAngle(string s)

decode angle; only Ndeg format for now

decodeDimension
uint decodeDimension(string s)

decode size string, e.g. 1px or 2 or 3pt

Static variables

_drawableCache
DrawableCache _drawableCache;
Undocumented in source.
_imageCache
ImageCache _imageCache;
Undocumented in source.
embeddedResourceList
EmbeddedResourceList embeddedResourceList;
Undocumented in source.

Structs

EmbeddedResource
struct EmbeddedResource
Undocumented in source.
EmbeddedResourceList
struct EmbeddedResourceList
Undocumented in source.

Variables

EMBEDDED_RESOURCE_PREFIX
string EMBEDDED_RESOURCE_PREFIX;

filename prefix for embedded resources

Detailed Description

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")());

Meta

License

Boost License 1.0

Authors

Vadim Lopatin, coolreader.org@gmail.com