CorsixTH engine (the C++ part)
Open source implementation of Theme Hospital
Loading...
Searching...
No Matches
th_lua_ui.h
Go to the documentation of this file.
1#ifndef CORSIX_TH_TH_LUA_UI_H_
2#define CORSIX_TH_TH_LUA_UI_H_
3
4#include "config.h"
5
6#include <algorithm>
7#include <cassert>
8
10
21constexpr uint8_t map_color_channel(int low, int high, int val, int start,
22 int end) {
23 assert(low < high);
24 assert(start >= 0 && start <= 0xFF);
25 assert(end >= 0 && end <= 0xFF);
26
27 if (val <= low) {
28 return start;
29 }
30 if (val >= high) {
31 return end;
32 }
33
34 return static_cast<uint8_t>(start +
35 (end - start) * (val - low) / (high - low));
36}
37
38#endif // CORSIX_TH_TH_LUA_UI_H_
constexpr uint8_t map_color_channel(int low, int high, int val, int start, int end)
Remap a value between low and high to an output between start and end.
Definition th_lua_ui.h:21