Project Alice
Loading...
Searching...
No Matches
color.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "system_state.hpp"
4#include <cstdint>
5
6namespace ogl {
7
8// borrowed from http://www.burtleburtle.net/bob/hash/doobs.html
9inline constexpr uint32_t color_from_hash(uint32_t color) {
10 uint32_t m1 = 0x1337CAFE;
11 uint32_t m2 = 0xDEADBEEF;
12 m1 -= m2;
13 m1 -= color;
14 m1 ^= (color >> 13);
15 m2 -= color;
16 m2 -= m1;
17 m2 ^= (m1 << 8);
18 color -= m1;
19 color -= m2;
20 color ^= (m2 >> 13);
21 m1 -= m2;
22 m1 -= color;
23 m1 ^= (color >> 12);
24 m2 -= color;
25 m2 -= m1;
26 m2 ^= (m1 << 16);
27 color -= m1;
28 color -= m2;
29 color ^= (m2 >> 5);
30 m1 -= m2;
31 m1 -= color;
32 m1 ^= (color >> 3);
33 m2 -= color;
34 m2 -= m1;
35 m2 ^= (m1 << 10);
36 color -= m1;
37 color -= m2;
38 color ^= (m2 >> 15);
39 return color;
40}
41
42inline uint32_t color_gradient(float percent, uint32_t top_color, uint32_t bot_color) {
43 uint32_t color = 0;
44 for(uint32_t i = 0; i <= 16; i += 8) {
45 auto diff = int32_t(top_color >> i & 0xFF) - int32_t(bot_color >> i & 0xFF);
46 color |= uint32_t(int32_t(bot_color >> i & 0xFF) + diff * percent) << i;
47 }
48 return color;
49}
50
51template<class T>
52inline uint32_t get_ui_color(sys::state& state, T id) {
53 return dcon::fatten(state.world, id).get_color();
54}
55template<>
56inline uint32_t get_ui_color(sys::state& state, dcon::political_party_id id) {
57 return dcon::fatten(state.world, id).get_ideology().get_color();
58}
59template<>
60inline uint32_t get_ui_color(sys::state& state, dcon::issue_option_id id) {
61 return ogl::color_from_hash(uint32_t(id.index()));
62}
63template<>
64inline uint32_t get_ui_color(sys::state& state, dcon::crime_id id) {
65 return ogl::color_from_hash(uint32_t(id.index()));
66}
67
68} // namespace ogl
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
Definition: color.hpp:6
uint32_t get_ui_color(sys::state &state, T id)
Definition: color.hpp:52
constexpr uint32_t color_from_hash(uint32_t color)
Definition: color.hpp:9
uint32_t color_gradient(float percent, uint32_t top_color, uint32_t bot_color)
Definition: color.hpp:42
uint uint32_t