# HG changeset patch # User Teemu Piippo # Date 1655754853 -10800 # Node ID a41ccc6924e35138a653718d55735a38710869e8 # Parent 065db0753f05c276a33aae486bc7dfbfeef7606d improve text rendering diff -r 065db0753f05 -r a41ccc6924e3 src/document.cpp --- 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 EditTools::modelActions() const diff -r 065db0753f05 -r a41ccc6924e3 src/gl/axesprogram.cpp --- 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() diff -r 065db0753f05 -r a41ccc6924e3 src/gl/common.h --- 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 +#include +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(); +}