@@ -126,10 +126,7 @@ u32 random_number(u32 min, u32 max) {
126126 return uniform_dist (re);
127127}
128128
129- bool load_timezones (std::filesystem::path const & filename, world_clock_t & clock) {
130- pn::pini timezones;
131- if (!timezones.load_file (filename)) { return false ; }
132-
129+ bool load_timezones (pn::pini const & timezones, world_clock_t & clock) {
133130 for (auto & pair : timezones) {
134131 u32 color = random_number (255 , UINT32_MAX);
135132 color |= 0xff ;
@@ -138,35 +135,40 @@ bool load_timezones(std::filesystem::path const& filename, world_clock_t& clock)
138135 }
139136 return true ;
140137}
138+
141139u32 hex_to_int (std::string_view const & hex_value) {
142140 u32 assigned_color;
143141 std::stringstream ss;
144142 ss << std::hex << hex_value;
145143 ss >> assigned_color;
146144 return assigned_color;
147145}
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);
146+
147+ sf::Color generate_color (pn::pini const & colors, world_clock_t const & clock) {
148+ if (colors.empty ()) { return sf::Color::White; }
149+ world_hour_t const primary_hour = clock.begin ()->hour ;
150+ u32 const assigned_color = hex_to_int (colors.get_string (std::to_string (static_cast <int >(primary_hour.hour ()))));
151+ sf::Color const clock_color (assigned_color);
155152 return clock_color;
156153}
154+
157155int main () {
158156 misc::context_t ctx (" World Clock" );
159157 ctx.setVerticalSyncEnabled (true );
160158 world_clock_t clock;
161- load_timezones (" src/timezones.pini" , clock);
159+ pn::pini colors;
160+ colors.load_file (" src/colors.pini" );
161+ pn::pini timezones;
162+ timezones.load_file (" src/timezones.pini" );
163+ load_timezones (timezones, clock);
162164 std::cout << clock << ' \n ' ;
163165 input_t input;
164166 delta_time_t dt;
165167 clock_ticker_t tick{&input, &clock};
166168 while (ctx.running ()) {
167169 input.update (ctx.poll ());
168170 tick (++dt);
169- if (auto drawer = ctx.drawer (generate_color (" src/ colors.pini " , clock))) {
171+ if (auto drawer = ctx.drawer (generate_color (colors, clock))) {
170172 world_clock_drawer_t ::in_t in;
171173 in.blink = tick.blink ();
172174 in.mouse_pos = ctx.mouse_pos ();
0 commit comments