Skip to content

Commit 235da00

Browse files
authored
Merge pull request #10 from cpp-gamedev/pini
change backrgound color
2 parents 76effd2 + 31b51ff commit 235da00

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

src/colors.pini

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
0=1A2A6CFF
2+
1=232967FF
3+
2=302861FF
4+
3=39285CFF
5+
4=3D275AFF
6+
5=492754FF
7+
6=4E2652FF
8+
7=5C254AFF
9+
8=6B2443FF
10+
9=72243FFF
11+
10=832237FF
12+
11=912130FF
13+
12=AA2023FF
14+
13=B82C20FF
15+
14=C64823FF
16+
15=CA5023FF
17+
16=D36425FF
18+
17=C03D22FF
19+
18=B4221FFF
20+
19=872235FF
21+
20=76233EFF
22+
21=54264FFF
23+
22=3C285BFF
24+
23=262966FF
25+
24=1A2A6CFF

src/main.cpp

+30-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
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

1420
using namespace misc;
1521

@@ -120,10 +126,7 @@ u32 random_number(u32 min, u32 max) {
120126
return uniform_dist(re);
121127
}
122128

123-
bool load_timezones(std::filesystem::path const& filename, world_clock_t& clock) {
124-
pn::pini timezones;
125-
if (!timezones.load_file(filename)) { return false; }
126-
129+
bool load_timezones(pn::pini const& timezones, world_clock_t& clock) {
127130
for (auto& pair : timezones) {
128131
u32 color = random_number(255, UINT32_MAX);
129132
color |= 0xff;
@@ -132,19 +135,40 @@ bool load_timezones(std::filesystem::path const& filename, world_clock_t& clock)
132135
}
133136
return true;
134137
}
138+
139+
u32 hex_to_int(std::string_view const& hex_value) {
140+
u32 assigned_color;
141+
std::stringstream ss;
142+
ss << std::hex << hex_value;
143+
ss >> assigned_color;
144+
return assigned_color;
145+
}
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);
152+
return clock_color;
153+
}
154+
135155
int main() {
136156
misc::context_t ctx("World Clock");
137157
ctx.setVerticalSyncEnabled(true);
138158
world_clock_t clock;
139-
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);
140164
std::cout << clock << '\n';
141165
input_t input;
142166
delta_time_t dt;
143167
clock_ticker_t tick{&input, &clock};
144168
while (ctx.running()) {
145169
input.update(ctx.poll());
146170
tick(++dt);
147-
if (auto drawer = ctx.drawer()) {
171+
if (auto drawer = ctx.drawer(generate_color(colors, clock))) {
148172
world_clock_drawer_t::in_t in;
149173
in.blink = tick.blink();
150174
in.mouse_pos = ctx.mouse_pos();

0 commit comments

Comments
 (0)