0.8
Resources

This chapter discusses resources and how to distribute and use them with EGT.

Resources are a way of cataloging, distributing, identifying, and using some asset data. For example, assets might include images, icons, audio files, and video files. Resources may be stored in the filesystem and loaded on demand, or they may be compiled into the application binary itself by using the EGT mresg command, or they may be installed by default by EGT.

Respath

Identifying a resource uses something referenced in the EGT API as a respath. This can take several different forms, including standard absolute or relative file paths. Consider this an over-simplified version of a Universal Resource Identifier (URI) and the purpose of a URI.

If an absolute file path is used, noting extra will happen. That file path will attempt to be accessed. However, if a relative path is given then a search will happened by calling detail::resolve_file_path(). This function will search any directory registered with detail::add_search_path(). The default path's setup is searched in the following order:

  • Data install path.
  • EXE directory.
  • EGT icon path.

Respath: File Path

To access a resource with a file path, specify an absolute or relative file path.

auto play = Image("/some/path/play.png");
auto forward = Image("forward.png");

Respath: Built-in EGT Icons and Images

EGT comes with a set of icons and images installed with EGT by default. To access these icons and images, prefix the filename with a @ symbol like so:

auto bug = Image("@bug.png");

In the above example, bug.png is picked from a EGT installed default icons directory (i.e. /usr/share/libegt/icons). If a user wants to pick a different icon from a different directory, use the following syntax:

auto bug = Image("@128px/bug.png");

The EGT installed default icons directory can be changed by setting an environment variable EGT_ICONS_DIRECTORY. This value can be an absolute path or directory name. If a directory name is set, then this directory name will be appended with an EGT installed default icon's directory path. See Environment Variables for more information.

Respath: Executable Compiled in Resources

EGT provides a tool used to generate a resource file that contains the data of binary blobs of data that can then in turn directly be used in an application when, for example, referring to an image. This tool is in the scripts directory of the EGT distribution and it's called mresg.

This tool is generally run by your application Makefile to create the resulting OUTPUT C++ file that can then be compiled into the application binary.

$ ./mresg --help
./mresg INPUT... -o OUTPUT

Instead of using a filesystem path to a file, prefix the path with a colon (":") to interpret the path as a resource. Periods are replaced with underscores.

auto play = Image(":play_png");