1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00
vcmi/client/mapView/MapOverlayLogVisualizer.cpp

99 lines
2.2 KiB
C++
Raw Normal View History

2024-08-06 21:29:04 +02:00
/*
* MapOverlayLogVisualizer.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "MapOverlayLogVisualizer.h"
#include "MapViewModel.h"
#include "../../lib/logging/VisualLogger.h"
#include "../render/Canvas.h"
#include "../render/Colors.h"
#include "../render/EFont.h"
2024-08-10 18:13:09 +02:00
#include "../render/IFont.h"
#include "../render/IRenderHandler.h"
2024-08-10 18:13:09 +02:00
#include "../render/Graphics.h"
2024-08-06 21:29:04 +02:00
#include "../gui/TextAlignment.h"
#include "../gui/CGuiHandler.h"
2024-08-06 21:29:04 +02:00
MapOverlayLogVisualizer::MapOverlayLogVisualizer(Canvas & target, std::shared_ptr<MapViewModel> model)
: target(target), model(model)
{
}
void MapOverlayLogVisualizer::drawLine(int3 start, int3 end)
{
const Point offset = Point(30, 30);
auto level = model->getLevel();
if(start.z != level || end.z != level)
return;
auto pStart = model->getTargetTileArea(start).topLeft();
auto pEnd = model->getTargetTileArea(end).topLeft();
auto viewPort = target.getRenderArea();
pStart.x += 3;
pEnd.x -= 3;
pStart += offset;
pEnd += offset;
if(viewPort.isInside(pStart) && viewPort.isInside(pEnd))
{
target.drawLine(pStart, pEnd, ColorRGBA(255, 255, 0), ColorRGBA(255, 0, 0));
}
}
2024-08-10 18:13:09 +02:00
void MapOverlayLogVisualizer::drawText(
int3 tile,
int lineNumber,
const std::string & text,
const std::optional<ColorRGBA> & background)
2024-08-06 21:29:04 +02:00
{
2024-08-10 18:13:09 +02:00
const Point offset = Point(6, 6);
2024-08-06 21:29:04 +02:00
auto level = model->getLevel();
if(tile.z != level)
return;
auto pStart = offset + model->getTargetTileArea(tile).topLeft();
auto viewPort = target.getRenderArea();
2024-08-10 18:13:09 +02:00
ColorRGBA color = Colors::YELLOW;
if(background)
{
color = ((background->b + background->r + background->g) < 300)
? Colors::WHITE
: Colors::BLACK;
}
2024-08-06 21:29:04 +02:00
if(viewPort.isInside(pStart))
{
const auto & font = GH.renderHandler().loadFont(FONT_TINY);
int w = font->getStringWidth(text);
int h = font->getLineHeight();
2024-08-10 18:13:09 +02:00
pStart.y += h * lineNumber;
if(background)
{
target.drawColor(Rect(pStart, Point(w + 4, h)), *background);
pStart.x += 2;
}
target.drawText(pStart, EFonts::FONT_TINY, color, ETextAlignment::TOPLEFT, text);
2024-08-06 21:29:04 +02:00
}
}