2
2
#include < cstdint>
3
3
#include < iostream>
4
4
#include < set>
5
+ #include < sstream>
6
+ #include < string>
7
+ #include < string_view>
5
8
#include < context.hpp>
6
9
#include < delta_time.hpp>
7
10
#include < gfx/follow_eye.hpp>
8
11
#include < maths/maths.hpp>
9
12
#include < pini/pini.hpp>
10
13
#include < world_clock/gui.hpp>
11
14
#include < world_clock/io.hpp>
15
+ #include " SFML/Graphics/Color.hpp"
16
+ #include " types.hpp"
12
17
#include " world_clock/world_clock.hpp"
18
+ #include " world_clock/world_hour.hpp"
13
19
14
20
using namespace misc ;
15
21
@@ -132,6 +138,22 @@ bool load_timezones(std::filesystem::path const& filename, world_clock_t& clock)
132
138
}
133
139
return true ;
134
140
}
141
+ u32 hex_to_int (std::string_view const & hex_value) {
142
+ u32 assigned_color;
143
+ std::stringstream ss;
144
+ ss << std::hex << hex_value;
145
+ ss >> assigned_color;
146
+ return assigned_color;
147
+ }
148
+ sf::Color generate_color (std::filesystem::path const & themefile, world_clock_t const & clock) {
149
+ pn::pini colors;
150
+ if (!colors.load_file (themefile)) { return sf::Color::White; }
151
+ world_hour_t primary_hour = clock.begin ()->hour ;
152
+ std::string hour_str = std::to_string (static_cast <int >(primary_hour.hour ()));
153
+ u32 assigned_color = hex_to_int (colors.get_string (hour_str));
154
+ sf::Color clock_color (assigned_color);
155
+ return clock_color;
156
+ }
135
157
int main () {
136
158
misc::context_t ctx (" World Clock" );
137
159
ctx.setVerticalSyncEnabled (true );
@@ -144,7 +166,7 @@ int main() {
144
166
while (ctx.running ()) {
145
167
input.update (ctx.poll ());
146
168
tick (++dt);
147
- if (auto drawer = ctx.drawer ()) {
169
+ if (auto drawer = ctx.drawer (generate_color ( " src/colors.pini " , clock) )) {
148
170
world_clock_drawer_t ::in_t in;
149
171
in.blink = tick.blink ();
150
172
in.mouse_pos = ctx.mouse_pos ();
0 commit comments