From d3e01264b9bc08901d154079f4ce04d7a582b882 Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 23 Oct 2023 20:09:45 +0200 Subject: [PATCH] Ensure key highlighting color is bright enough to not blend too much with black keys --- src/Cfg.h | 11 +++++++++++ src/Score.cpp | 9 ++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Cfg.h b/src/Cfg.h index 6ead358..ad032cb 100644 --- a/src/Cfg.h +++ b/src/Cfg.h @@ -29,6 +29,8 @@ #ifndef __CFG_H__ #define __CFG_H__ +#include + #define OPTION_BENCHMARK_TEST 0 #if OPTION_BENCHMARK_TEST #define BENCHMARK_INIT() benchMarkInit() @@ -71,6 +73,15 @@ public: return red == color.red && green == color.green && blue == color.blue; } + constexpr void ensureBrightness(float v) + { + if (red < v && green < v && blue < v) { + red = std::max(red, v); + green = std::max(green, v); + blue = std::max(blue, v); + } + } + float red, green, blue; }; diff --git a/src/Score.cpp b/src/Score.cpp index 21438ba..64521f2 100644 --- a/src/Score.cpp +++ b/src/Score.cpp @@ -168,9 +168,12 @@ void CScore::drawPianoKeyboard(){ glScalef(1.0f, 1.4f, 1.0f); glTranslatef(Cfg::staveStartX() + xPlaceSize * static_cast(i++), yStart, 0.0f); - CDraw::drColor (CColor(1.0, 1.0, 1.0)); - if(state[k]==1) CDraw::drColor(stopped ? Cfg::colorTheme().playedStoppedColor : Cfg::colorTheme().noteColor); - if(state[k]==2) CDraw::drColor(Cfg::colorTheme().playedBadColor); + const auto &theme = Cfg::colorTheme(); + auto color = CColor(1.0, 1.0, 1.0); + if(state[k]==1) color = stopped ? theme.playedStoppedColor : theme.noteColor; + else if(state[k]==2) color = theme.playedBadColor; + color.ensureBrightness(0.4f); // ensure the color is bright enough to not blend too much with black keys + CDraw::drColor(color); glBegin(GL_QUADS); glVertex2f(0, ySize); glVertex2f(xKeySize, ySize);