Skip to content

Commit 8a544e1

Browse files
leroiviOlivier ROMAN
authored and
Olivier ROMAN
committed
Refactor Colors in unique place
1 parent c0638c6 commit 8a544e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+475
-471
lines changed

src/components/settings/Settings.h

+10-29
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "components/brightness/BrightnessController.h"
55
#include "components/fs/FS.h"
66
#include "displayapp/apps/Apps.h"
7+
#include "displayapp/Colors.h"
78

89
namespace Pinetime {
910
namespace Controllers {
@@ -14,33 +15,13 @@ namespace Pinetime {
1415
enum class Notification : uint8_t { On, Off, Sleep };
1516
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
1617
enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, Shake = 3, LowerWrist = 4 };
17-
enum class Colors : uint8_t {
18-
White,
19-
Silver,
20-
Gray,
21-
Black,
22-
Red,
23-
Maroon,
24-
Yellow,
25-
Olive,
26-
Lime,
27-
Green,
28-
Cyan,
29-
Teal,
30-
Blue,
31-
Navy,
32-
Magenta,
33-
Purple,
34-
Orange,
35-
Pink
36-
};
3718
enum class PTSGaugeStyle : uint8_t { Full, Half, Numeric };
3819
enum class PTSWeather : uint8_t { On, Off };
3920

4021
struct PineTimeStyle {
41-
Colors ColorTime = Colors::Teal;
42-
Colors ColorBar = Colors::Teal;
43-
Colors ColorBG = Colors::Black;
22+
Colors::Color ColorTime = Colors::Teal;
23+
Colors::Color ColorBar = Colors::Teal;
24+
Colors::Color ColorBG = Colors::Black;
4425
PTSGaugeStyle gaugeStyle = PTSGaugeStyle::Full;
4526
PTSWeather weatherEnable = PTSWeather::Off;
4627
};
@@ -82,33 +63,33 @@ namespace Pinetime {
8263
return settings.chimesOption;
8364
};
8465

85-
void SetPTSColorTime(Colors colorTime) {
66+
void SetPTSColorTime(Colors::Color colorTime) {
8667
if (colorTime != settings.PTS.ColorTime)
8768
settingsChanged = true;
8869
settings.PTS.ColorTime = colorTime;
8970
};
9071

91-
Colors GetPTSColorTime() const {
72+
Colors::Color GetPTSColorTime() const {
9273
return settings.PTS.ColorTime;
9374
};
9475

95-
void SetPTSColorBar(Colors colorBar) {
76+
void SetPTSColorBar(Colors::Color colorBar) {
9677
if (colorBar != settings.PTS.ColorBar)
9778
settingsChanged = true;
9879
settings.PTS.ColorBar = colorBar;
9980
};
10081

101-
Colors GetPTSColorBar() const {
82+
Colors::Color GetPTSColorBar() const {
10283
return settings.PTS.ColorBar;
10384
};
10485

105-
void SetPTSColorBG(Colors colorBG) {
86+
void SetPTSColorBG(Colors::Color colorBG) {
10687
if (colorBG != settings.PTS.ColorBG)
10788
settingsChanged = true;
10889
settings.PTS.ColorBG = colorBG;
10990
};
11091

111-
Colors GetPTSColorBG() const {
92+
Colors::Color GetPTSColorBG() const {
11293
return settings.PTS.ColorBG;
11394
};
11495

src/displayapp/Colors.cpp

+6-43
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,10 @@
11
#include "displayapp/Colors.h"
22

3-
using namespace Pinetime::Applications;
4-
using namespace Pinetime::Controllers;
3+
#include <limits>
54

6-
lv_color_t Pinetime::Applications::Convert(Pinetime::Controllers::Settings::Colors color) {
7-
switch (color) {
8-
case Pinetime::Controllers::Settings::Colors::White:
9-
return LV_COLOR_WHITE;
10-
case Pinetime::Controllers::Settings::Colors::Silver:
11-
return LV_COLOR_SILVER;
12-
case Pinetime::Controllers::Settings::Colors::Gray:
13-
return LV_COLOR_GRAY;
14-
case Pinetime::Controllers::Settings::Colors::Black:
15-
return LV_COLOR_BLACK;
16-
case Pinetime::Controllers::Settings::Colors::Red:
17-
return LV_COLOR_RED;
18-
case Pinetime::Controllers::Settings::Colors::Maroon:
19-
return LV_COLOR_MAKE(0xb0, 0x0, 0x0);
20-
case Pinetime::Controllers::Settings::Colors::Yellow:
21-
return LV_COLOR_YELLOW;
22-
case Pinetime::Controllers::Settings::Colors::Olive:
23-
return LV_COLOR_MAKE(0xb0, 0xb0, 0x0);
24-
case Pinetime::Controllers::Settings::Colors::Lime:
25-
return LV_COLOR_LIME;
26-
case Pinetime::Controllers::Settings::Colors::Green:
27-
return LV_COLOR_MAKE(0x0, 0xb0, 0x0);
28-
case Pinetime::Controllers::Settings::Colors::Cyan:
29-
return LV_COLOR_CYAN;
30-
case Pinetime::Controllers::Settings::Colors::Teal:
31-
return LV_COLOR_MAKE(0x0, 0xb0, 0xb0);
32-
case Pinetime::Controllers::Settings::Colors::Blue:
33-
return LV_COLOR_BLUE;
34-
case Pinetime::Controllers::Settings::Colors::Navy:
35-
return LV_COLOR_MAKE(0x0, 0x0, 0xb0);
36-
case Pinetime::Controllers::Settings::Colors::Magenta:
37-
return LV_COLOR_MAGENTA;
38-
case Pinetime::Controllers::Settings::Colors::Purple:
39-
return LV_COLOR_MAKE(0xb0, 0x0, 0xb0);
40-
case Pinetime::Controllers::Settings::Colors::Orange:
41-
return LV_COLOR_ORANGE;
42-
case Pinetime::Controllers::Settings::Colors::Pink:
43-
return LV_COLOR_MAKE(0xFF, 0xAE, 0xC9);
44-
default:
45-
return LV_COLOR_WHITE;
46-
}
5+
Colors::Color Colors::linear_gradient(Colors::Color startingColor, Colors::Color endingColor, uint8_t progress) {
6+
constexpr decltype(progress) maxProgress = std::numeric_limits<decltype(progress)>::max();
7+
return Colors::Color(((maxProgress - progress) * startingColor.red() + progress * endingColor.red()) / maxProgress,
8+
((maxProgress - progress) * startingColor.green() + progress * endingColor.green()) / maxProgress,
9+
((maxProgress - progress) * startingColor.blue() + progress * endingColor.blue()) / maxProgress);
4710
}

src/displayapp/Colors.h

+78-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,82 @@
11
#pragma once
22

33
#include <lvgl/src/lv_misc/lv_color.h>
4-
#include "components/settings/Settings.h"
54

6-
namespace Pinetime {
7-
namespace Applications {
8-
lv_color_t Convert(Controllers::Settings::Colors color);
9-
}
10-
}
5+
namespace Colors {
6+
7+
enum Named : uint32_t {
8+
White = 0xFFFFFF,
9+
Silver = 0xC0C0C0,
10+
LightGray = 0xB0B0B0,
11+
Gray = 0x808080,
12+
DarkGray = 0x1B1B1B,
13+
Black = 0x000000,
14+
Red = 0xFF0000,
15+
Maroon = 0xB00000,
16+
Yellow = 0xFFFF00,
17+
Olive = 0xB0B000,
18+
Lime = 0x00FF00,
19+
Green = 0x00B000,
20+
Cyan = 0x00FFFF,
21+
Teal = 0x00B0B0,
22+
Blue = 0x0000FF,
23+
Navy = 0x0000B0,
24+
Magenta = 0xFF00FF,
25+
Purple = 0xB000B0,
26+
Orange = 0xFFA500,
27+
DeepOrange = 0xFF4000,
28+
Pink = 0xFFAEC9,
29+
Platinum = 0xE5E5E2,
30+
Gold = 0xFFD700,
31+
Copper = 0xB87333,
32+
Violet = 0x6000FF,
33+
Aqua = 0x00FFFF
34+
};
35+
36+
class Color {
37+
public:
38+
constexpr Color(uint32_t color) {
39+
data.hexcode = color;
40+
}
41+
42+
operator uint32_t() const {
43+
return data.hexcode;
44+
}
45+
46+
constexpr Color(uint8_t r, uint8_t g, uint8_t b) {
47+
data.argb.red = r;
48+
data.argb.green = g;
49+
data.argb.blue = b;
50+
}
51+
52+
operator lv_color_t() const {
53+
return lv_color_hex(data.hexcode);
54+
}
55+
56+
uint8_t red() const {
57+
return data.argb.red;
58+
}
59+
60+
uint8_t green() const {
61+
return data.argb.green;
62+
}
63+
64+
uint8_t blue() const {
65+
return data.argb.blue;
66+
}
67+
68+
private:
69+
union {
70+
uint32_t hexcode = 0;
71+
72+
struct {
73+
uint8_t blue = 0;
74+
uint8_t green = 0;
75+
uint8_t red = 0;
76+
uint8_t alpha = 0;
77+
} argb;
78+
} data;
79+
};
80+
81+
Color linear_gradient(Color startingColor, Color endingColor, uint8_t progress);
82+
}

0 commit comments

Comments
 (0)