diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index cb4141b..2384ca2 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -574,6 +574,7 @@ void Engine::DrawOption() void Engine::DisplayAudioMenu(float centerX, float centerY) { float minBar = centerX - Width() * 0.15; float maxBar = centerX + Width() * 0.3; + float percentPosX = centerX + Width() * 0.31f; glColor4f(1.0f, 0.5f, 0.0f, 1.0f); m_texturePrincipal.Bind(); @@ -589,6 +590,11 @@ void Engine::DisplayAudioMenu(float centerX, float centerY) { DrawSliderBackground(centerX, centerY, minBar, maxBar, principalBottom, principalTop); RedrawSlider(centerX, centerY, m_volPrincipal, minBar, maxBar, principalBottom, principalTop); + DisplayBarPercentValue(centerX, centerY, percentPosX, principalBottom, minBar, maxBar, m_volPrincipal); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); glColor4f(1.0f, 0.5f, 0.0f, 1.0f); m_textureMusique.Bind(); @@ -604,6 +610,11 @@ void Engine::DisplayAudioMenu(float centerX, float centerY) { DrawSliderBackground(centerX, centerY, minBar, maxBar, musiqueBottom, musiqueTop); RedrawSlider(centerX, centerY, m_volMusique, minBar, maxBar, musiqueBottom, musiqueTop); + DisplayBarPercentValue(centerX, centerY, percentPosX, musiqueBottom, minBar, maxBar, m_volMusique); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); glColor4f(1.0f, 0.5f, 0.0f, 1.0f); m_textureEffets.Bind(); @@ -619,6 +630,7 @@ void Engine::DisplayAudioMenu(float centerX, float centerY) { DrawSliderBackground(centerX, centerY, minBar, maxBar, effectsBottom, effectsTop); RedrawSlider(centerX, centerY, m_volEffets, minBar, maxBar, effectsBottom, effectsTop); + DisplayBarPercentValue(centerX, centerY, percentPosX, effectsBottom, minBar, maxBar, m_volEffets); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } @@ -697,6 +709,7 @@ void Engine::DisplayGraphicsMenu(float centerX, float centerY) { void Engine::DisplayGameplayMenu(float centerX, float centerY) { float minBar = centerX - Width() * 0.15; float maxBar = centerX + Width() * 0.3; + float percentPosX = centerX + Width() * 0.31f; glColor4f(1.0f, 0.5f, 0.0f, 1.0f); m_textureSensibilite.Bind(); @@ -712,6 +725,7 @@ void Engine::DisplayGameplayMenu(float centerX, float centerY) { DrawSliderBackground(centerX, centerY, minBar, maxBar, sensibleBottom, sensibleTop); RedrawSlider(centerX, centerY, m_volSensible, minBar, maxBar, sensibleBottom, sensibleTop); + DisplayBarPercentValue(centerX, centerY, percentPosX, sensibleBottom, minBar, maxBar, m_volSensible); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } @@ -727,6 +741,30 @@ void Engine::DrawSliderBackground(float centerX, float centerY, float minVal, fl glEnd(); } +void Engine::DisplayBarPercentValue(float centerX, float centerY, float posX, float posY, float minVal, float maxVal, float value) { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + + float percentage = (value / (maxVal - minVal)) * 100; + + if (percentage < 0.0f) { + percentage = 0.0f; + } + else if (percentage > 100.0f) { + percentage = 100.0f; + } + + m_textureFont.Bind(); + std::ostringstream ss; + ss.str(""); + ss << std::fixed << std::setprecision(2); + ss << percentage << "%"; + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + PrintText(posX, posY, ss.str(), 2.0f); + + glDisable(GL_BLEND); +} + void Engine::RedrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue) { if (value < 0.0f) { value = 0.0f; @@ -1253,6 +1291,7 @@ void Engine::PrintText(float x, float y, const std::string& t, float charSizeMul float baseCharSize = 20 + (24 - 20) * (windowWidth - 1600) / (1920 - 1600); float charSize = baseCharSize * charSizeMultiplier; + glPushMatrix(); glLoadIdentity(); glTranslated(x, y, 0); @@ -1270,6 +1309,7 @@ void Engine::PrintText(float x, float y, const std::string& t, float charSizeMul glTranslated(0.5555f * charSize, 0, 0); } + glPopMatrix(); } int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; } diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index cfe5c47..b80cd64 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -65,6 +65,7 @@ private: void DisplayGraphicsMenu(float centerX, float centerY); void DisplayGameplayMenu(float centerX, float centerY); void DrawSliderBackground(float centerX, float centerY, float minVal, float maxVal, float bottomSideValue, float topSideValue); + void DisplayBarPercentValue(float centerX, float centerY, float posX, float posY, float minVal, float maxVal, float value); void RedrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue); void DrawHud(float elapsedTime, BlockType bloc); void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f);