Skip to content

Commit 1d689bf

Browse files
committed
change backrgound color
1 parent b5ed3fd commit 1d689bf

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/colors.pini

Lines changed: 25 additions & 0 deletions
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

Lines changed: 23 additions & 1 deletion
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

@@ -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+
}
135157
int 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

Comments
 (0)