|
@@ -9,6 +9,7 @@
|
|
|
*/
|
|
|
#include "StdInc.h"
|
|
|
#include "GameEngine.h"
|
|
|
+#include "GameLibrary.h"
|
|
|
|
|
|
#include "gui/CIntObject.h"
|
|
|
#include "gui/CursorHandler.h"
|
|
@@ -35,6 +36,8 @@
|
|
|
|
|
|
#include "../lib/AsyncRunner.h"
|
|
|
#include "../lib/CConfigHandler.h"
|
|
|
+#include "../lib/texts/TextOperations.h"
|
|
|
+#include "../lib/texts/CGeneralTextHandler.h"
|
|
|
|
|
|
#include <SDL_render.h>
|
|
|
|
|
@@ -125,8 +128,8 @@ void GameEngine::updateFrame()
|
|
|
handleEvents();
|
|
|
windows().simpleRedraw();
|
|
|
|
|
|
- if (settings["video"]["showfps"].Bool())
|
|
|
- drawFPSCounter();
|
|
|
+ if (settings["video"]["performanceOverlay"]["show"].Bool())
|
|
|
+ drawPerformanceOverlay();
|
|
|
|
|
|
screenHandlerInstance->updateScreenTexture();
|
|
|
|
|
@@ -184,14 +187,47 @@ Point GameEngine::screenDimensions() const
|
|
|
return screenHandlerInstance->getLogicalResolution();
|
|
|
}
|
|
|
|
|
|
-void GameEngine::drawFPSCounter()
|
|
|
+void GameEngine::drawPerformanceOverlay()
|
|
|
{
|
|
|
+ auto font = EFonts::FONT_SMALL;
|
|
|
+ const auto & fontPtr = ENGINE->renderHandler().loadFont(font);
|
|
|
+
|
|
|
Canvas target = screenHandler().getScreenCanvas();
|
|
|
- Rect targetArea(0, screenDimensions().y - 20, 48, 11);
|
|
|
+
|
|
|
+ auto powerState = ENGINE->input().getPowerState();
|
|
|
+ std::string powerSymbol = ""; // add symbol if emoji are supported (e.g. VCMI extras)
|
|
|
+ if(powerState.powerState == PowerStateMode::ON_BATTERY)
|
|
|
+ powerSymbol = fontPtr->canRepresentCharacter("🔋") ? "🔋 " : (LIBRARY->generaltexth->translate("vcmi.overlay.battery") + " ");
|
|
|
+ else if(powerState.powerState == PowerStateMode::CHARGING)
|
|
|
+ powerSymbol = fontPtr->canRepresentCharacter("🔌") ? "🔌 " : (LIBRARY->generaltexth->translate("vcmi.overlay.charging") + " ");
|
|
|
+
|
|
|
std::string fps = std::to_string(framerate().getFramerate())+" FPS";
|
|
|
+ std::string time = TextOperations::getFormattedTimeLocal(std::time(nullptr));
|
|
|
+ std::string power = powerState.powerState == PowerStateMode::UNKNOWN ? "" : powerSymbol + std::to_string(powerState.percent) + "%";
|
|
|
+
|
|
|
+ std::string textToDisplay = time + (power.empty() ? "" : " | " + power) + " | " + fps;
|
|
|
+
|
|
|
+ maxPerformanceOverlayTextWidth = std::max(maxPerformanceOverlayTextWidth, static_cast<int>(fontPtr->getStringWidth(textToDisplay))); // do not get smaller (can cause graphical glitches)
|
|
|
+
|
|
|
+ Rect targetArea;
|
|
|
+ std::string edge = settings["video"]["performanceOverlay"]["edge"].String();
|
|
|
+ int marginTopBottom = settings["video"]["performanceOverlay"]["marginTopBottom"].Integer();
|
|
|
+ int marginLeftRight = settings["video"]["performanceOverlay"]["marginLeftRight"].Integer();
|
|
|
+
|
|
|
+ Point boxSize(maxPerformanceOverlayTextWidth + 6, fontPtr->getLineHeight() + 2);
|
|
|
+
|
|
|
+ if (edge == "topleft")
|
|
|
+ targetArea = Rect(marginLeftRight, marginTopBottom, boxSize.x, boxSize.y);
|
|
|
+ else if (edge == "topright")
|
|
|
+ targetArea = Rect(screenDimensions().x - marginLeftRight - boxSize.x, marginTopBottom, boxSize.x, boxSize.y);
|
|
|
+ else if (edge == "bottomleft")
|
|
|
+ targetArea = Rect(marginLeftRight, screenDimensions().y - marginTopBottom - boxSize.y, boxSize.x, boxSize.y);
|
|
|
+ else if (edge == "bottomright")
|
|
|
+ targetArea = Rect(screenDimensions().x - marginLeftRight - boxSize.x, screenDimensions().y - marginTopBottom - boxSize.y, boxSize.x, boxSize.y);
|
|
|
|
|
|
- target.drawColor(targetArea, ColorRGBA(10, 10, 10));
|
|
|
- target.drawText(targetArea.center(), EFonts::FONT_SMALL, Colors::WHITE, ETextAlignment::CENTER, fps);
|
|
|
+ target.drawColor(targetArea.resize(1), Colors::BRIGHT_YELLOW);
|
|
|
+ target.drawColor(targetArea, ColorRGBA(0, 0, 0));
|
|
|
+ target.drawText(targetArea.center(), font, Colors::WHITE, ETextAlignment::CENTER, textToDisplay);
|
|
|
}
|
|
|
|
|
|
bool GameEngine::amIGuiThread()
|