22#include < cstdint>
33#include < iostream>
44#include < set>
5+ #include < sstream>
6+ #include < string>
7+ #include < string_view>
58#include < context.hpp>
69#include < delta_time.hpp>
710#include < gfx/follow_eye.hpp>
811#include < maths/maths.hpp>
912#include < pini/pini.hpp>
1013#include < world_clock/gui.hpp>
1114#include < world_clock/io.hpp>
15+ #include " SFML/Graphics/Color.hpp"
16+ #include " types.hpp"
1217#include " world_clock/world_clock.hpp"
18+ #include " world_clock/world_hour.hpp"
1319
1420using namespace misc ;
1521
@@ -132,6 +138,22 @@ bool load_timezones(std::filesystem::path const& filename, world_clock_t& clock)
132138 }
133139 return true ;
134140}
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+ }
135157int main () {
136158 misc::context_t ctx (" World Clock" );
137159 ctx.setVerticalSyncEnabled (true );
@@ -144,7 +166,7 @@ int main() {
144166 while (ctx.running ()) {
145167 input.update (ctx.poll ());
146168 tick (++dt);
147- if (auto drawer = ctx.drawer ()) {
169+ if (auto drawer = ctx.drawer (generate_color ( " src/colors.pini " , clock) )) {
148170 world_clock_drawer_t ::in_t in;
149171 in.blink = tick.blink ();
150172 in.mouse_pos = ctx.mouse_pos ();
0 commit comments