Graphics Class
Layer for loading (and subsequently caching) graphical resources.
Full description:
The Graphics class handles loading and caching of graphics resources. It can adapt as the API to C changes, and hide these changes from most of the other Lua code.
Method Index
- _adjustWindowDisplayScale(scale)
- _isLanguageSupportedByTHAssets()
- _loadPalette(dir, name, transparent_255, pal8bit)
- _loadPalettes(gfx_set)
- _loadTrueTypeFont(name, sprite_table, font_options)
- _onChangeUIScale()
- allPalettes()
- arabicNumerals()
- drawNumbersFromUnicode()
- getPalette(name)
- getUIScale()
- getWindowDisplayScale()
- hasLanguageFont(font)
- loadAnimations(dir, prefix)
- loadBuiltinFont()
- loadCursor(sheet, index, hot_x, hot_y)
- loadFont(sprite_table, font_options, y_sep, ttf_color, force_bitmap)
- loadFontAndSpriteTable(dir, name, complex, palette, font_options)
- loadFontFile()
- loadGhost(dir, name, index)
- loadLanguageFont(name, sprite_table, font_options, y_sep, ttf_color, force_bitmap)
- loadMainCursor(name)
- loadMenuFont()
- loadPalette(_, name)
- loadRaw(name, width, height, dir, _paldir, pal, _transparent_255, flags)
- loadSpriteTable(dir, name, complex, palette)
- onChangeLanguage()
- onChangeResolution()
- onChangeUIScale()
- onChangeWindowDisplayScale(scale)
- updateTarget(target)
Member Index
- actual_ui_scale
- app
- builtin_font
- cache
- custom_graphics
- custom_graphics_folder
- display_scale
- language_font
- load_info
- reload_functions
- reload_functions_last
- target
- th_charset
- ttf_font_data
function Graphics:Graphics(app, gfx_set, charset)
Parameters:
| Name | Type | Description |
|---|---|---|
| app | ? | ? |
| gfx_set | ? | ? |
| charset | ? | ? |
Declared on: line 68 of Lua/graphics.lua.
function Graphics:_adjustWindowDisplayScale(scale)
Parameters:
| Name | Type | Description |
|---|---|---|
| scale | ? | ? |
Declared on: line 493 of Lua/graphics.lua.
function Graphics:_loadPalette(dir, name, transparent_255, pal8bit)
Load a palette file
Parameters:
| Name | Type | Description |
|---|---|---|
| dir | string | The directory of the palette relative to the HOSPITAL directory |
| name | string | The name of the palette file |
| transparent_255 | boolean | Whether the 255th entry in the palette should be transparent |
| pal8bit | ? | ? |
Declared on: line 313 of Lua/graphics.lua.
function Graphics:_loadPalettes(gfx_set)
Parameters:
| Name | Type | Description |
|---|---|---|
| gfx_set | ? | ? |
Declared on: line 129 of Lua/graphics.lua.
function Graphics:_loadTrueTypeFont(name, sprite_table, font_options)
Load a true type font
Parameters:
| Name | Type | Description |
|---|---|---|
| name | string | The name of the font from the language file. Always 'unicode'. |
| sprite_table | userdata | The sprite table of the font this font is replacing. Used for default colour and metrics. |
| font_options | table | A table of font options: x_sep (integer) The horizontal separation of the font. Defaults to 0. y_sep (integer) The vertical separation of the font. Defaults to 0. ttf_color (table) The colour of the font in form .red, .green and .blue. If nil, the colour will be detected from the sprite table. ttf_width (integer) The nominal width of the font, in pixels. If nil, the width will be detected from the sprite table. ttf_height (integer) The nominal height of the font, in pixels. If nil, the height will be detected from the sprite table. ttf_shadow (table|boolean) table with fields offset_x, offset_y and color. The color field has the same format as ttf_color. If this field is present, the font will be drawn with a shadow of the specified colour and offset. color is optional and defaults to opaque black. offset_x and offset_y are optional and default to 1. If the field is omitted entirely, no shadow is drawn. Alternately ttf_shadow can be set to true to draw a shadow with default parameters, or false to disable any shadow. apply_ui_scale (boolean) Whether to apply the UI scale factor to the font size. |
Declared on: line 645 of Lua/graphics.lua.
function Graphics:_onChangeUIScale()
Reload any assets that depend on the actual ui scale
Declared on: line 519 of Lua/graphics.lua.
function Graphics:allPalettes()
Declared on: line 354 of Lua/graphics.lua.
function Graphics:getPalette(name)
Parameters:
| Name | Type | Description |
|---|---|---|
| name | ? | ? |
Declared on: line 346 of Lua/graphics.lua.
function Graphics:getUIScale()
Declared on: line 1109 of Lua/graphics.lua.
function Graphics:hasLanguageFont(font)
Parameters:
| Name | Type | Description |
|---|---|---|
| font | ? | ? |
Declared on: line 434 of Lua/graphics.lua.
function Graphics:loadAnimations(dir, prefix)
Parameters:
| Name | Type | Description |
|---|---|---|
| dir | ? | ? |
| prefix | ? | ? |
Declared on: line 816 of Lua/graphics.lua.
function Graphics:loadCursor(sheet, index, hot_x, hot_y)
Parameters:
| Name | Type | Description |
|---|---|---|
| sheet | ? | ? |
| index | ? | ? |
| hot_x | ? | ? |
| hot_y | ? | ? |
Declared on: line 246 of Lua/graphics.lua.
function Graphics:loadFont(sprite_table, font_options, y_sep, ttf_color, force_bitmap)
Load a font for the given sprite table.
Parameters:
| Name | Type | Description |
|---|---|---|
| sprite_table | userdata | The sprite table of the font this font is replacing. Used for default colour and metrics. |
| font_options | table | A table of font options: x_sep (integer) The horizontal separation of the font. Defaults to 0. y_sep (integer) The vertical separation of the font. Defaults to 0. ttf_color (table) The colour of the font in form .red, .green and .blue. If nil, the colour will be detected from the sprite table. force_bitmap (boolean) Whether to force the font to be a bitmap font. If nil, this will be set to true for Font05V if the language uses Arabic numerals. ttf_width (integer) The nominal width of the font, in pixels. If nil, the width will be detected from the sprite table. ttf_height (integer) The nominal height of the font, in pixels. If nil, the height will be detected from the sprite table. ttf_shadow (table|boolean) table with fields offset_x, offset_y and color. The color field has the same format as ttf_color. If this field is present, the font will be drawn with a shadow of the specified colour and offset. color is optional and defaults to opaque black. offset_x and offset_y are optional and default to 1. If the field is omitted entirely, no shadow is drawn. Alternately ttf_shadow can be set to true to draw a shadow with default parameters, or false to disable any shadow. apply_ui_scale (boolean) Whether to apply the UI scale factor to the font size. |
| y_sep | ? | ? |
| ttf_color | ? | ? |
| force_bitmap | ? | ? |
Declared on: line 740 of Lua/graphics.lua.
function Graphics:loadFontAndSpriteTable(dir, name, complex, palette, font_options)
This is the same as calling loadFont(Graphics:loadSpriteTable(dir, name, complex, palette), font_options)
except that force_bitmap is set to true automatically for some sprite tables.
Parameters:
| Name | Type | Description |
|---|---|---|
| dir | string | The directory of the sprite table relative to the HOSPITAL directory. |
| name | string | The name of the sprite table file without the .dat extension. |
| complex | boolean | Whether the sprite table is complex or not. |
| palette | string | The name of the palette file. If nil, the default palette will be used. |
| font_options | table | A table of font options: x_sep (integer) The horizontal separation of the font. Defaults to 0. y_sep (integer) The vertical separation of the font. Defaults to 0. ttf_color (table) The colour of the font in form .red, .green and .blue. If nil, the colour will be detected from the sprite table. force_bitmap (boolean) Whether to force the font to be a bitmap font. If nil, this will be set to true for Font05V if the language uses Arabic numerals. ttf_width (integer) The nominal width of the font, in pixels. If nil, the width will be detected from the sprite table. ttf_height (integer) The nominal height of the font, in pixels. If nil, the height will be detected from the sprite table. ttf_shadow (table|boolean) table with fields offset_x, offset_y and color. The color field has the same format as ttf_color. If this field is present, the font will be drawn with a shadow of the specified colour and offset. color is optional and defaults to opaque black. offset_x and offset_y are optional and default to 1. If the field is omitted entirely, no shadow is drawn. Alternately ttf_shadow can be set to true to draw a shadow with default parameters, or false to disable any shadow. apply_ui_scale (boolean) Whether to apply the UI scale factor to the font size. |
Declared on: line 699 of Lua/graphics.lua.
function Graphics:loadFontFile()
If it is not found it tries to use the font file from the compile setting WITH_FONT,
or look for one in the CorsixTH folder, the grandparent of this file.
Declared on: line 175 of Lua/graphics.lua.
function Graphics:loadGhost(dir, name, index)
Parameters:
| Name | Type | Description |
|---|---|---|
| dir | ? | ? |
| name | ? | ? |
| index | ? | ? |
Declared on: line 358 of Lua/graphics.lua.
function Graphics:loadLanguageFont(name, sprite_table, font_options, y_sep, ttf_color, force_bitmap)
Load a true type font
Parameters:
| Name | Type | Description |
|---|---|---|
| name | string | The name of the font from the language file. Always 'unicode'. |
| sprite_table | userdata | The sprite table of the font this font is replacing. Used for default colour and metrics. |
| font_options | table | A table of font options: x_sep (integer) The horizontal separation of the font. Defaults to 0. y_sep (integer) The vertical separation of the font. Defaults to 0. ttf_color (table) The colour of the font in form .red, .green and .blue. If nil, the colour will be detected from the sprite table. force_bitmap (boolean) Whether to force the font to be a bitmap font. If nil, this will be set to true for Font05V if the language uses Arabic numerals. ttf_width (integer) The nominal width of the font, in pixels. If nil, the width will be detected from the sprite table. ttf_height (integer) The nominal height of the font, in pixels. If nil, the height will be detected from the sprite table. ttf_shadow (table|boolean) table with fields offset_x, offset_y and color. The color field has the same format as ttf_color. If this field is present, the font will be drawn with a shadow of the specified colour and offset. color is optional and defaults to opaque black. offset_x and offset_y are optional and default to 1. If the field is omitted entirely, no shadow is drawn. Alternately ttf_shadow can be set to true to draw a shadow with default parameters, or false to disable any shadow. apply_ui_scale (boolean) Whether to apply the UI scale factor to the font size. |
| y_sep | int | Deprecated: use font_options.y_sep instead. |
| ttf_color | table | Deprecated: use font_options.ttf_color instead. |
| force_bitmap | boolean | Deprecated: use font_options.force_bitmap instead. |
Declared on: line 588 of Lua/graphics.lua.
function Graphics:loadMainCursor(name)
Parameters:
| Name | Type | Description |
|---|---|---|
| name | ? | ? |
Declared on: line 227 of Lua/graphics.lua.
function Graphics:loadMenuFont()
Utility function to return preferred font for main menu ui
Declared on: line 538 of Lua/graphics.lua.
function Graphics:loadPalette(_, name)
Kept for load compatibility
Parameters:
| Name | Type | Description |
|---|---|---|
| _ | ? | ? |
| name | ? | ? |
Declared on: line 1100 of Lua/graphics.lua.
function Graphics:loadRaw(name, width, height, dir, _paldir, pal, _transparent_255, flags)
Load a bitmap from a dat file and palette
Parameters:
| Name | Type | Description |
|---|---|---|
| name | string | The file name of the bitmap without the .dat extension |
| width | int | The width of the bitmap. Defaults to 640 |
| height | int | The height of the bitmap. Defaults to 480 |
| dir | string | The directory of the bitmap. Defaults to QData |
| _paldir | string | ignored |
| pal | string | The name of the palette |
| _transparent_255 | boolean | ignored |
| flags | table | Additional flags for loading the bitmap |
Declared on: line 368 of Lua/graphics.lua.
function Graphics:loadSpriteTable(dir, name, complex, palette)
Parameters:
| Name | Type | Description |
|---|---|---|
| dir | ? | ? |
| name | ? | ? |
| complex | ? | ? |
| palette | ? | ? |
Declared on: line 862 of Lua/graphics.lua.
function Graphics:onChangeResolution()
Call when the render size changes
Declared on: line 509 of Lua/graphics.lua.
function Graphics:onChangeUIScale()
Call when the configured ui_scale is changed
Declared on: line 504 of Lua/graphics.lua.
function Graphics:onChangeWindowDisplayScale(scale)
Parameters:
| Name | Type | Description |
|---|---|---|
| scale | ? | ? |
Declared on: line 485 of Lua/graphics.lua.
function Graphics:updateTarget(target)
Parameters:
| Name | Type | Description |
|---|---|---|
| target | ? | ? |
Declared on: line 888 of Lua/graphics.lua.