@@ -126,10 +126,7 @@ u32 random_number(u32 min, u32 max) {
126
126
return uniform_dist (re);
127
127
}
128
128
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) {
133
130
for (auto & pair : timezones) {
134
131
u32 color = random_number (255 , UINT32_MAX);
135
132
color |= 0xff ;
@@ -138,35 +135,40 @@ bool load_timezones(std::filesystem::path const& filename, world_clock_t& clock)
138
135
}
139
136
return true ;
140
137
}
138
+
141
139
u32 hex_to_int (std::string_view const & hex_value) {
142
140
u32 assigned_color;
143
141
std::stringstream ss;
144
142
ss << std::hex << hex_value;
145
143
ss >> assigned_color;
146
144
return assigned_color;
147
145
}
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);
155
152
return clock_color;
156
153
}
154
+
157
155
int main () {
158
156
misc::context_t ctx (" World Clock" );
159
157
ctx.setVerticalSyncEnabled (true );
160
158
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 );
162
164
std::cout << clock << ' \n ' ;
163
165
input_t input;
164
166
delta_time_t dt;
165
167
clock_ticker_t tick{&input, &clock };
166
168
while (ctx.running ()) {
167
169
input.update (ctx.poll ());
168
170
tick (++dt);
169
- if (auto drawer = ctx.drawer (generate_color (" src/ colors.pini " , clock ))) {
171
+ if (auto drawer = ctx.drawer (generate_color (colors, clock ))) {
170
172
world_clock_drawer_t ::in_t in;
171
173
in.blink = tick.blink ();
172
174
in.mouse_pos = ctx.mouse_pos ();
0 commit comments