mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[kandinsky] Explicit color constructors
Change-Id: Ifd4a0c281a7c6aded225d06295f4d79039e4e848
This commit is contained in:
committed by
Émilie Feral
parent
d9216522dc
commit
d6e96fe143
@@ -23,9 +23,9 @@ private:
|
||||
const KDColor firstAvailableColor();
|
||||
static constexpr int k_numberOfDefaultColors = 10;
|
||||
static constexpr KDColor k_defaultColors[k_numberOfDefaultColors] = {
|
||||
KDColor(0xE5473E), KDColor(0x57B1D9), KDColor(0xE49832), KDColor(0x6DBE51),
|
||||
KDColor(0x199B99), KDColor(0xF2A37C), KDColor(0x37C995), KDColor(0x6759D0),
|
||||
KDColor(0xEF7138), KDColor(0x1774C5)
|
||||
KDColor::RGB24(0xE5473E), KDColor::RGB24(0x57B1D9), KDColor::RGB24(0xE49832), KDColor::RGB24(0x6DBE51),
|
||||
KDColor::RGB24(0x199B99), KDColor::RGB24(0xF2A37C), KDColor::RGB24(0x37C995), KDColor::RGB24(0x6759D0),
|
||||
KDColor::RGB24(0xEF7138), KDColor::RGB24(0x1774C5)
|
||||
};
|
||||
static constexpr const char * k_functionNames[k_maxNumberOfFunctions] = {
|
||||
"f", "g", "h", "p", "q", "r", "s", "t"
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
namespace Graph {
|
||||
|
||||
constexpr KDColor kAxisColor = KDColor(0x000000);
|
||||
constexpr KDColor kMainGridColor = KDColor(0xCCCCCC);
|
||||
constexpr KDColor kSecondaryGridColor = KDColor(0xEEEEEE);
|
||||
constexpr KDColor kAxisColor = KDColor::RGB24(0x000000);
|
||||
constexpr KDColor kMainGridColor = KDColor::RGB24(0xCCCCCC);
|
||||
constexpr KDColor kSecondaryGridColor = KDColor::RGB24(0xEEEEEE);
|
||||
constexpr int kNumberOfMainGridLines = 5;
|
||||
constexpr int kNumberOfSecondaryGridLines = 4;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
private:
|
||||
static constexpr KDCoordinate k_verticalFunctionMargin = 50-12;
|
||||
static constexpr KDCoordinate k_emptyRowHeight = 50;
|
||||
constexpr static KDColor k_separatorColor = KDColor(0xEFF2F4);
|
||||
constexpr static KDColor k_separatorColor = KDColor::RGB24(0xEFF2F4);
|
||||
constexpr static KDCoordinate k_separatorThickness = 1;
|
||||
Function * m_function;
|
||||
ExpressionView m_expressionView;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Probability::ParametersController::ParametersController(Responder * parentResponder) :
|
||||
ViewController(parentResponder),
|
||||
m_view(SolidColorView(KDColor(0xF3619B)))
|
||||
m_view(SolidColorView(KDColor::RGB24(0xF3619B)))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ public:
|
||||
virtual KDColor backgroundColor() const;
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
|
||||
static constexpr KDColor k_evenLineBackgroundColor = KDColor(0xF7F9FA);
|
||||
static constexpr KDColor k_evenLineBackgroundColor = KDColor::RGB24(0xF7F9FA);
|
||||
static constexpr KDColor k_oddLineBackgroundColor = KDColorWhite;
|
||||
static constexpr KDColor k_selectedLineBackgroundColor = KDColor(0xC0D3EA);
|
||||
static constexpr KDColor k_selectedLineBackgroundColor = KDColor::RGB24(0xC0D3EA);
|
||||
|
||||
protected:
|
||||
bool m_even;
|
||||
|
||||
@@ -33,8 +33,8 @@ private:
|
||||
int selectedButton();
|
||||
private:
|
||||
constexpr static KDCoordinate k_headerHeight = 20;
|
||||
constexpr static KDColor k_separatorHeaderColor = KDColor(0xDEE0E2);
|
||||
constexpr static KDColor k_selectedBackgroundColor = KDColor(0x426DA7);
|
||||
constexpr static KDColor k_separatorHeaderColor = KDColor::RGB24(0xDEE0E2);
|
||||
constexpr static KDColor k_selectedBackgroundColor = KDColor::RGB24(0x426DA7);
|
||||
View * m_mainView;
|
||||
bool m_visibleHeader;
|
||||
int m_selectedButton;
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
class Palette {
|
||||
public:
|
||||
constexpr static KDColor LineColor = KDColor(0xB4B7B9);
|
||||
constexpr static KDColor BackgroundColor = KDColor(0xF0F3F5);
|
||||
constexpr static KDColor CellBackgroundColor = KDColor(0xFCFCFC);
|
||||
constexpr static KDColor FocusCellBackgroundColor = KDColor(0xBFD3EB);
|
||||
constexpr static KDColor DesactiveTextColor = KDColor(0x646464);
|
||||
constexpr static KDColor BoxTitleBackgroundColor = KDColor(0x656976);
|
||||
constexpr static KDColor LineColor = KDColor::RGB24(0xB4B7B9);
|
||||
constexpr static KDColor BackgroundColor = KDColor::RGB24(0xF0F3F5);
|
||||
constexpr static KDColor CellBackgroundColor = KDColor::RGB24(0xFCFCFC);
|
||||
constexpr static KDColor FocusCellBackgroundColor = KDColor::RGB24(0xBFD3EB);
|
||||
constexpr static KDColor DesactiveTextColor = KDColor::RGB24(0x646464);
|
||||
constexpr static KDColor BoxTitleBackgroundColor = KDColor::RGB24(0x656976);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -17,9 +17,9 @@ protected:
|
||||
void logAttributes(std::ostream &os) const override;
|
||||
#endif
|
||||
private:
|
||||
constexpr static KDColor k_defaultTabColor = KDColor(0x426DA7);
|
||||
constexpr static KDColor k_selectedTabColor = KDColor(0xC0D3EB);
|
||||
constexpr static KDColor k_separatorTabColor = KDColor(0x567AA7);
|
||||
constexpr static KDColor k_defaultTabColor = KDColor::RGB24(0x426DA7);
|
||||
constexpr static KDColor k_selectedTabColor = KDColor::RGB24(0xC0D3EB);
|
||||
constexpr static KDColor k_separatorTabColor = KDColor::RGB24(0x567AA7);
|
||||
bool m_active;
|
||||
bool m_selected;
|
||||
const char * m_name;
|
||||
|
||||
@@ -7,24 +7,30 @@ class KDColor {
|
||||
public:
|
||||
constexpr KDColor() : m_value(0) {}
|
||||
// FIXME: This should not be needed, and is probably wasting CPU cycles
|
||||
static constexpr KDColor RGB16(uint16_t rgb) {
|
||||
return KDColor(rgb);
|
||||
}
|
||||
static constexpr KDColor RGB24(uint32_t rgb) {
|
||||
return KDColor(((rgb&0xF80000)>>8)|((rgb&0x00FC00)>>5)|((rgb&0x0000F8)>>3));
|
||||
}
|
||||
static constexpr KDColor RGB888(uint8_t r, uint8_t g, uint8_t b) {
|
||||
return KDColor((r>>3)<<11 | (g>>2) << 5 | (b>>3));
|
||||
}
|
||||
|
||||
constexpr KDColor(uint32_t rgb)
|
||||
: m_value(((rgb&0xF80000)>>8)|((rgb&0x00FC00)>>5)|((rgb&0x0000F8)>>3)) {}
|
||||
constexpr KDColor(uint8_t r, uint8_t g, uint8_t b)
|
||||
: m_value((r>>3)<<11 | (g>>2) << 5 | (b>>3)) {}
|
||||
uint8_t red();
|
||||
uint8_t green();
|
||||
uint8_t blue();
|
||||
static KDColor blend(KDColor first, KDColor second, uint8_t alpha);
|
||||
operator uint16_t() const { return m_value; }
|
||||
private:
|
||||
constexpr KDColor(uint16_t value) : m_value(value) {}
|
||||
uint16_t m_value;
|
||||
};
|
||||
|
||||
constexpr KDColor KDColorBlack = KDColor(0x000000);
|
||||
constexpr KDColor KDColorWhite = KDColor(0xFFFFFF);
|
||||
constexpr KDColor KDColorRed = KDColor(0xFF0000);
|
||||
constexpr KDColor KDColorGreen = KDColor(0x00FF00);
|
||||
constexpr KDColor KDColorBlue = KDColor(0x0000FF);
|
||||
constexpr KDColor KDColorBlack = KDColor::RGB24(0x000000);
|
||||
constexpr KDColor KDColorWhite = KDColor::RGB24(0xFFFFFF);
|
||||
constexpr KDColor KDColorRed = KDColor::RGB24(0xFF0000);
|
||||
constexpr KDColor KDColorGreen = KDColor::RGB24(0x00FF00);
|
||||
constexpr KDColor KDColorBlue = KDColor::RGB24(0x0000FF);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -19,7 +19,7 @@ KDColor KDColor::blend(KDColor first, KDColor second, uint8_t alpha) {
|
||||
uint16_t red = first.red()*alpha + second.red()*oneMinusAlpha;
|
||||
uint16_t green = first.green()*alpha + second.green()*oneMinusAlpha;
|
||||
uint16_t blue = first.blue()*alpha + second.blue()*oneMinusAlpha;
|
||||
return KDColor(red>>8, green>>8, blue>>8);
|
||||
return RGB888(red>>8, green>>8, blue>>8);
|
||||
|
||||
|
||||
// Blend White + black, ask for white
|
||||
|
||||
@@ -5,20 +5,20 @@
|
||||
QUIZ_CASE(kandinsky_color_rgb) {
|
||||
assert(sizeof(KDColor) == 2); // We really want KDColor to be packed
|
||||
|
||||
assert(KDColor(0xFF0000) == 0xF800);
|
||||
assert(KDColor(0x00FF00) == 0x07E0);
|
||||
assert(KDColor(0x0000FF) == 0x1F);
|
||||
assert(KDColor::RGB24(0xFF0000) == 0xF800);
|
||||
assert(KDColor::RGB24(0x00FF00) == 0x07E0);
|
||||
assert(KDColor::RGB24(0x0000FF) == 0x1F);
|
||||
/* R = 0x12 = 0b 0001 0010. 5 most important bits are 00010.
|
||||
* G = 0x34 = 0b 0011 0100. 6 most important bits are 001101.
|
||||
* B = 0x56 = 0b 0101 0110. 5 most important bits are 01010.
|
||||
* KDColor = 0b 00010 001101 01010
|
||||
* = 0b 0001 0001 1010 1010
|
||||
* = 0x 1 1 A A */
|
||||
assert(KDColor(0x123456) == 0x11AA);
|
||||
assert(KDColor::RGB24(0x123456) == 0x11AA);
|
||||
}
|
||||
|
||||
QUIZ_CASE(kandinsky_color_blend) {
|
||||
KDColor midGray = KDColor(0x7F7F7F);
|
||||
KDColor midGray = KDColor::RGB24(0x7F7F7F);
|
||||
KDColor res = KDColor::blend(KDColorWhite, KDColorBlack, 0xFF);
|
||||
assert(res == KDColorWhite);
|
||||
assert(KDColor::blend(KDColorWhite, KDColorBlack, 0) == KDColorBlack);
|
||||
|
||||
@@ -7,7 +7,7 @@ void print(const char * message) {
|
||||
static int line_y = 0;
|
||||
KDContext * ctx = KDIonContext::sharedContext();
|
||||
int line_height = KDText::stringSize("M").height();
|
||||
ctx->drawString(message, KDPoint(0, line_y), 0);
|
||||
ctx->drawString(message, KDPoint(0, line_y), KDColorBlack);
|
||||
line_y += line_height;
|
||||
if (line_y > Ion::Display::Height) {
|
||||
line_y = 0;
|
||||
|
||||
Reference in New Issue
Block a user