Skip to content

color_util

Source: base/tealdef/gui/main/color_util.d.tl

Notes

Colour types of GUI resource files (*.gres) and helpers that turn them into Vec3f/Vec4f values, add transparency, mix colours and derive hover/active shades.

GResColor

record global base/tealdef/gui/main/color_util.d.tl:3

global record GResColor is {number}

{number} is expected to have length 3 or 4

GResColorRange

record global base/tealdef/gui/main/color_util.d.tl:4

global record GResColorRange

Notes

A pair of GUI resource colours (minimum and maximum), e.g. for a colour gradient.

Fields

Name Type Description
min GResColor Colour at the lower end of the range.
max GResColor Colour at the upper end of the range.

GResColorArray

record global base/tealdef/gui/main/color_util.d.tl:8

global record GResColorArray is {GResColor}

Notes

A list of GUI resource colours.

GResTransparency

record global base/tealdef/gui/main/color_util.d.tl:10

global record GResTransparency

Notes

Standard alpha values of the GUI, from the resource ::/gui/main/transparency.gres.

Details

Read it with api.gui.genericRep.get(api.gui.genericRep.find("::/gui/main/transparency.gres")).data and pass the values as alpha to color_util.withTransparency.

Fields

Name Type Description
VeryLow number Alpha 0.9 (almost opaque).
Low number Alpha 0.75.
Medium number Alpha 0.5.
High number Alpha 0.25.
VeryHigh number Alpha 0.1 (almost transparent).

Functions

metamethod __index(GResTransparency, string) : number base/tealdef/gui/main/color_util.d.tl:11

Notes

Lookup of the alpha values by name (transparency["Low"]).

Returns number

ColorUtil

record global base/tealdef/gui/main/color_util.d.tl:20

global record ColorUtil

Load: local color_util = require "::/gui/main/color_util.tl" as ColorUtil

Notes

Conversion and mixing helpers for GUI resource colours (GResColor, a list of 3 or 4 numbers in 0..1).

Functions

toVec3(color : GResColor) : Vec3f base/tealdef/gui/main/color_util.d.tl:21

Call as color_util.toVec3(…)

Notes

Converts a colour to a Vec3f (red, green, blue); alpha is dropped.

Returns Vec3f

Used in the base game: 5 times in 2 files

base/content/gui/gui/main/particle_react_util.tl:19

api.type.ParticleParamCurveVec3f.CurvePoint.new(0.0, color_util.toVec3(colors.LevelUpStars)),
base/content/mission/mission/mission_sim.script.tl:1191
api.gui.byId.setHighlighted(k, true, style, color_util.toVec3(mission_colors.Highlight))

toVec4(color : GResColor) : Vec4f base/tealdef/gui/main/color_util.d.tl:22

Call as color_util.toVec4(…)

Notes

Converts a colour to a Vec4f; a missing alpha becomes 1.0.

Returns Vec4f

Used in the base game: 163 times in 49 files

base/content/game_mechanics/game_mechanics/finance/finances_charts.tl:199

colors = { color_util.toVec4(defaultColorsRef:get().Positive), color_util.toVec4(defaultColorsRef:get().Negative) },
base/content/game_mechanics/game_mechanics/finance/finances_react_util.tl:141
backgroundColor1 = color_util.toVec4(colorDefault.BaseLightMedium),
base/content/gui/gui/construction/construction_desc_layers.script.tl:19
contour.color = color_util.toVec4(contourConfig.color)
base/content/gui/gui/construction/construction_react_util.tl:43
modifierColor.inProgress = color_util.toVec4(constructionColors.Modifier.InProgress)
base/content/gui/gui/entity_window/double_slip_switch.tl:70
local redPhaseColor = color_util.toVec4(defaultColors.Error)
base/content/gui/gui/entity_window/industry/industry_eow.script.tl:807
color_util.toVec4(defaultColors.Indifferent),
… and 43 more files.

toRange3(colorRange : GResColorRange) : {Vec3f, Vec3f} base/tealdef/gui/main/color_util.d.tl:24

Call as color_util.toRange3(…)

{min, max}

Returns {Vec3f, Vec3f}

toRange4(colorRange : GResColorRange) : {Vec4f, Vec4f} base/tealdef/gui/main/color_util.d.tl:25

Call as color_util.toRange4(…)

{min, max}

Returns {Vec4f, Vec4f}

Used in the base game: 11 times in 5 files

base/content/gui/gui/entity_window/town/town.tl:54

local passengerTransportColor = color_util.toRange4(layerColors.PassengerFlow.PublicTransport)
base/content/gui/gui/layers/layer_cargo_flow.tl:37
local playerTransportColor = color_util.toRange4(layerColors.CargoFlow.PlayerTransport)
base/content/gui/gui/layers/layer_noise.tl:20
local impactMinMaxColor = color_util.toRange4(layerColors.Noise.Impact)
base/content/gui/gui/layers/layer_passenger_flow.tl:16
local originColor = color_util.toRange4(layerColors.PassengerFlow.Origin)
base/content/gui/gui/layers/layer_pollution.tl:19
local emitterMinMaxColor = color_util.toRange4(layerColors.Pollution.Emission)

toArray3(colorArray : GResColorArray) : {Vec3f} base/tealdef/gui/main/color_util.d.tl:27

Call as color_util.toArray3(…)

Notes

Converts each colour of the list with toVec3.

Returns {Vec3f}

Used in the base game: 7 times in 6 files

base/content/gui/gui/construction/construction_react_util.tl:3326

laneModifier.lineColors = color_util.toArray3(api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).data as GResColorArra
base/content/gui/gui/entity_window/vehicle/vehicle_eow.script.tl:139
local colorPalette = color_util.toArray3(table_util.concatenate((api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).da
base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:601
local colorPalette = color_util.toArray3(table_util.concatenate((api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).da
base/content/gui/gui/line_vehicle_mgmt/line_util.tl:40
local lineColors = color_util.toArray3(api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).data as GResColorArray)
base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:3600
local colorPalette = color_util.toArray3(table_util.concatenate((api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).da
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_window.tl:4866
local colorChooserColorsStaticData = color_util.toArray3(table_util.concatenate((api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_c

toArray4(colorArray : GResColorArray) : {Vec4f} base/tealdef/gui/main/color_util.d.tl:28

Call as color_util.toArray4(…)

Notes

Converts each colour of the list with toVec4.

Returns {Vec4f}

Used in the base game: 16 times in 14 files

base/content/game_mechanics/game_mechanics/finance/finances_charts.tl:233

local chartColorsRef = react.useRef(color_util.toArray4(api.gui.genericRep.get(api.gui.genericRep.find("::/gui/main/chart_colors.gres")).data as GResColorArray)
base/content/game_mechanics/game_mechanics/subventions/deliver_cargo/deliver_cargo.script.tl:408
local actualColors = color_util.toArray4(layerColors.CargoFlow.Consumers3D.Actual)
base/content/game_mechanics/game_mechanics/subventions/deliver_cargo_town/deliver_cargo_town.script.tl:506
local actualColors = color_util.toArray4(layerColors.CargoFlow.Consumers3D.Actual)
base/content/game_mechanics/game_mechanics/subventions/deliver_passengers/deliver_passengers.script.tl:461
local actualColors = color_util.toArray4(layerColors.CargoFlow.Consumers3D.Actual)
base/content/game_mechanics/game_mechanics/subventions/deliver_workers/deliver_workers.script.tl:295
local actualColors = color_util.toArray4(layerColors.CargoFlow.Consumers3D.Actual)
base/content/gui/gui/construction/construction_react_util.tl:549
layerConfig.voronoiRenderableConfig.colors = color_util.toArray4(layerColors.Construction.Voronoi)
… and 8 more files.

toArray4WithTransparency(colorArray : GResColorArray, alpha : number) : {Vec4f} base/tealdef/gui/main/color_util.d.tl:29

Call as color_util.toArray4WithTransparency(…)

Notes

Converts each colour of the list to a Vec4f with the given alpha (the colour's own alpha is replaced).

Returns {Vec4f}

Used in the base game: 6 times in 3 files

base/content/gui/gui/entity_window/industry/industry.tl:332

local potentialColors = color_util.toArray4WithTransparency(layerColors.CargoFlow.Suppliers3D.Potential, transparency.VeryLow)
base/content/gui/gui/entity_window/town/town.tl:1024
local actualColors = color_util.toArray4WithTransparency(layerColors.CargoFlow.Suppliers3D.Actual, transparency.VeryLow)
base/content/gui/gui/layers/layer_infrastructure.tl:37
edgeRenderableConfig.speedColor = color_util.toArray4WithTransparency(layerColors.Infrastructure.Speed, transparency.Low)

withTransparency(gResColor : GResColor, alpha : number) : Vec4f base/tealdef/gui/main/color_util.d.tl:31

Call as color_util.withTransparency(…)

Notes

Returns the colour as Vec4f with its alpha replaced by alpha.

Returns Vec4f

Used in the base game: 30 times in 8 files

base/content/gui/gui/construction/construction_desc_layers.script.tl:38

mapColors.water = color_util.withTransparency(layerColors.Terrain.Water, transparency.Low)
base/content/gui/gui/construction/construction_react_util.tl:37
modifierColor.validSubtle = color_util.withTransparency(constructionColors.Modifier.Valid, transparency.Medium)
base/content/gui/gui/entity_window/double_slip_switch.tl:76
color_util.withTransparency(defaultColors.Error, transparency.VeryHigh)
base/content/gui/gui/layers/layer_infrastructure.tl:39
edgeRenderableConfig.tunnelOutlineColor = color_util.withTransparency(layerColors.Infrastructure.Tunnel, transparency.Low)
base/content/gui/gui/layers/layer_terrain.tl:20
local waterColor = color_util.withTransparency(layerColors.Terrain.Water, transparency.Low)
base/content/gui/gui/layers/layer_traffic.tl:34
color_util.withTransparency(layerColors.Traffic.Jammed, transparency.Medium),
… and 2 more files.

withTransparencyRaw(gResColor : GResColor, alpha : number) : GResColor base/tealdef/gui/main/color_util.d.tl:32

Call as color_util.withTransparencyRaw(…)

Notes

Returns a new GResColor with its alpha replaced by alpha.

Returns GResColor

Used in the base game: 323 times in 37 files

base/content/game_mechanics/game_mechanics/achievements/achievements.css.lua:103

backgroundColor1 = color_util.withTransparencyRaw(
base/content/game_mechanics/game_mechanics/company/company.css.lua:14
local cardColor = color_util.withTransparencyRaw(colorDefault.BaseVeryLight, transparency.Medium)
base/content/game_mechanics/game_mechanics/finance/finances.css.lua:28
local financesTableHoverColor = color_util.withTransparencyRaw(colorDefault.AccentLight, transparency.Medium)
base/content/game_mechanics/game_mechanics/notifications/gui/notifications.css.lua:16
local notificationCautionTransparent = color_util.withTransparencyRaw(notificationCautionSolid, transparency.High)
base/content/game_mechanics/game_mechanics/towns/town_react_util.css.lua:23
backgroundColor1 = color_util.withTransparencyRaw(
base/content/gui/gui/camera_tool/camera_tool.css.lua:12
local borderColor = color_util.withTransparencyRaw(colorDefault.BaseVeryLight, transparency.Medium)
… and 31 more files.

mixColors(colorA : GResColor, colorB : GResColor, amount : number) : Vec4f base/tealdef/gui/main/color_util.d.tl:34

Call as color_util.mixColors(…)

Notes

Linearly interpolates between two colours (including alpha) and returns a Vec4f.

Parameter Type Description
colorA GResColor
colorB GResColor
amount number 0 gives colorA, 1 gives colorB.

Returns Vec4f

mixColorsRaw(colorA : GResColor, colorB : GResColor, amount : number) : GResColor base/tealdef/gui/main/color_util.d.tl:35

Call as color_util.mixColorsRaw(…)

Notes

Like mixColors, but returns a GResColor.

Returns GResColor

Used in the base game: 3 times in 2 files

base/content/gui/gui/line_vehicle_mgmt/line_vehicle_mgmt.css.lua:37

color = color_util.mixColorsRaw(
base/content/gui/gui/main/internal.css.lua:22
backgroundColor1 = color_util.mixColorsRaw(

getHoverFrom(enabledColor : GResColor) : Vec4f base/tealdef/gui/main/color_util.d.tl:37

Call as color_util.getHoverFrom(…)

Notes

Derives the hover shade of a colour (brightness +0.2, slightly less saturation, in HSV) as Vec4f.

Returns Vec4f

Used in the base game: 1 time in 1 file

base/content/game_mechanics/game_mechanics/finance/finances_react_util.tl:133

backgroundColor1 = color_util.getHoverFrom({color.x, color.y, color.z, color.w}),

getHoverFromRaw(enabledColor : GResColor) : GResColor base/tealdef/gui/main/color_util.d.tl:38

Call as color_util.getHoverFromRaw(…)

Notes

Like getHoverFrom, but returns a GResColor.

Returns GResColor

Used in the base game: 54 times in 8 files

base/content/game_mechanics/game_mechanics/company/company.css.lua:139

color_util.getHoverFromRaw(colorDefault.AccentLight),
base/content/game_mechanics/game_mechanics/notifications/gui/notifications.css.lua:130
backgroundColor1 = color_util.getHoverFromRaw(notificationProblemSolid),
base/content/gui/gui/game_bar/game_bar.css.lua:132
borderColor = color_util.getHoverFromRaw(colorDefault.AccentDark),
base/content/gui/gui/line_vehicle_mgmt/line_vehicle_mgmt.css.lua:1930
backgroundColor1 = color_util.getHoverFromRaw(colorDefault.NeutralDark),
base/content/gui/gui/main/builtin.css.lua:207
borderColor = color_util.getHoverFromRaw(colorDefault.AccentMedium),
base/content/gui/gui/main/default.css.lua:84
backgroundColor1 = color_util.getHoverFromRaw(colorDefault.AccentDark),
… and 2 more files.

getActiveFrom(enabledColor : GResColor) : Vec4f base/tealdef/gui/main/color_util.d.tl:40

Call as color_util.getActiveFrom(…)

Notes

Derives the pressed/active shade of a colour (brightness +0.1, slightly less saturation, in HSV) as Vec4f.

Returns Vec4f

Used in the base game: 2 times in 1 file

base/content/game_mechanics/game_mechanics/finance/finances_react_util.tl:125

backgroundColor1 = color_util.getActiveFrom({color.x, color.y, color.z, color.w}),

getActiveFromRaw(enabledColor : GResColor) : GResColor base/tealdef/gui/main/color_util.d.tl:41

Call as color_util.getActiveFromRaw(…)

Notes

Like getActiveFrom, but returns a GResColor.

Returns GResColor

Used in the base game: 57 times in 9 files

base/content/game_mechanics/game_mechanics/company/company.css.lua:146

color_util.getActiveFromRaw(colorDefault.AccentLight),
base/content/game_mechanics/game_mechanics/notifications/gui/notifications.css.lua:134
backgroundColor1 = color_util.getActiveFromRaw(notificationProblemSolid),
base/content/gui/gui/game_bar/game_bar.css.lua:137
borderColor = color_util.getActiveFromRaw(colorDefault.AccentDark),
base/content/gui/gui/line_vehicle_mgmt/line_vehicle_mgmt.css.lua:409
backgroundColor1 = color_util.getActiveFromRaw(colorDefault.BaseVeryLight),
base/content/gui/gui/main/builtin.css.lua:224
borderColor = color_util.getActiveFromRaw(colorDefault.AccentMedium),
base/content/gui/gui/main/content_card.css.lua:80
backgroundColor1 = color_util.getActiveFromRaw(colorDefault.BaseDark),
… and 3 more files.