Mon, 20 Jun 2022 22:54:13 +0300
improve text rendering
src/document.cpp | file | annotate | diff | comparison | revisions | |
src/gl/axesprogram.cpp | file | annotate | diff | comparison | revisions | |
src/gl/common.h | file | annotate | diff | comparison | revisions |
--- a/src/document.cpp Mon Jun 20 22:41:34 2022 +0300 +++ b/src/document.cpp Mon Jun 20 22:54:13 2022 +0300 @@ -170,6 +170,7 @@ { const QBrush pointBrush; const QPen pointPen; + const QPen textPen; const QPen polygonPen; const QPen badPolygonPen; const QBrush greenPolygonBrush; @@ -178,16 +179,18 @@ } static const Pens brightPens{ - .pointBrush = {Qt::white}, + .pointBrush = {Qt::black}, .pointPen = {QBrush{Qt::black}, 2.0}, + .textPen = {Qt::black}, .polygonPen = {QBrush{Qt::black}, 2.0, Qt::DashLine}, .greenPolygonBrush = {QColor{64, 255, 128, 192}}, .redPolygonBrush = {QColor{255, 96, 96, 192}}, }; static const Pens darkPens{ - .pointBrush = {Qt::black}, + .pointBrush = {Qt::white}, .pointPen = {QBrush{Qt::white}, 2.0}, + .textPen = {Qt::white}, .polygonPen = {QBrush{Qt::white}, 2.0, Qt::DashLine}, .greenPolygonBrush = {QColor{64, 255, 128, 192}}, .redPolygonBrush = {QColor{255, 96, 96, 192}}, @@ -195,17 +198,21 @@ void EditTools::overpaint(QPainter* painter) { + painter->save(); const Pens& pens = (this->renderer->isDark() ? darkPens : brightPens); this->renderPreview(painter, &pens); + QFont font; + font.setBold(true); if (this->worldPosition.has_value()) { painter->setRenderHint(QPainter::Antialiasing); - painter->setPen(Qt::white); - painter->setBrush(Qt::green); + painter->setPen(pens.pointPen); + painter->setBrush(pens.greenPolygonBrush); const QPointF pos = this->renderer->modelToScreenCoordinates(*this->worldPosition); painter->drawEllipse(pos, 5, 5); - painter->drawText(pos + QPointF{5, 5}, vectorToString(*this->worldPosition)); + drawBorderedText(painter, pos + QPointF{5, 5}, font, vectorToString(*this->worldPosition)); } + painter->restore(); } const std::vector<ModelAction> EditTools::modelActions() const
--- a/src/gl/axesprogram.cpp Mon Jun 20 22:41:34 2022 +0300 +++ b/src/gl/axesprogram.cpp Mon Jun 20 22:54:13 2022 +0300 @@ -90,19 +90,9 @@ this->shader.bufferData(&data[0], countof(data), sizeof data[0]); } -void drawBorderedText(QPainter* painter, const QPointF& point, const QFont& font, const QString& text) -{ - QPainterPath path; - path.addText(point, font, text); - painter->save(); - painter->setBrush(Qt::white); - painter->setPen({Qt::black, 0.1 * font.pointSizeF()}); - painter->drawPath(path); - painter->restore(); -} - void AxesLayer::overpaint(QPainter* painter) { + painter->save(); QFont font; font.setStyle(QFont::StyleItalic); font.setBold(true); @@ -154,6 +144,7 @@ renderText(axis.text, *intersection); } } + painter->restore(); } void AxesLayer::paintGL()
--- a/src/gl/common.h Mon Jun 20 22:41:34 2022 +0300 +++ b/src/gl/common.h Mon Jun 20 22:54:13 2022 +0300 @@ -146,3 +146,16 @@ { return stream >> enum_value_cast(style); } + +#include <QPainter> +#include <QPainterPath> +inline void drawBorderedText(QPainter* painter, const QPointF& point, const QFont& font, const QString& text) +{ + QPainterPath path; + path.addText(point, font, text); + painter->save(); + painter->setBrush(Qt::white); + painter->setPen({Qt::black, 0.1 * font.pointSizeF()}); + painter->drawPath(path); + painter->restore(); +}