Improve API text rendering speed
This commit is contained in:
parent
fbe5427c0b
commit
2b78330660
2 changed files with 8 additions and 6 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QStaticText>
|
||||||
|
|
||||||
class OverlayItem {
|
class OverlayItem {
|
||||||
public:
|
public:
|
||||||
|
@ -15,8 +16,9 @@ public:
|
||||||
|
|
||||||
class OverlayText : public OverlayItem {
|
class OverlayText : public OverlayItem {
|
||||||
public:
|
public:
|
||||||
OverlayText(QString text, int x, int y, QColor color, int fontSize) {
|
OverlayText(const QString inputText, int x, int y, QColor color, int fontSize) :
|
||||||
this->text = text;
|
text(QStaticText(inputText))
|
||||||
|
{
|
||||||
this->x = x;
|
this->x = x;
|
||||||
this->y = y;
|
this->y = y;
|
||||||
this->color = color;
|
this->color = color;
|
||||||
|
@ -25,7 +27,7 @@ public:
|
||||||
~OverlayText() {}
|
~OverlayText() {}
|
||||||
virtual void render(QPainter *painter, int x, int y);
|
virtual void render(QPainter *painter, int x, int y);
|
||||||
private:
|
private:
|
||||||
QString text;
|
const QStaticText text;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
QColor color;
|
QColor color;
|
||||||
|
@ -96,7 +98,7 @@ public:
|
||||||
void renderItems(QPainter *painter);
|
void renderItems(QPainter *painter);
|
||||||
QList<OverlayItem*> getItems();
|
QList<OverlayItem*> getItems();
|
||||||
void clearItems();
|
void clearItems();
|
||||||
void addText(QString text, int x, int y, QString color = "#000000", int fontSize = 12);
|
void addText(const QString text, int x, int y, QString color = "#000000", int fontSize = 12);
|
||||||
void addRect(int x, int y, int width, int height, QString color = "#000000", bool filled = false);
|
void addRect(int x, int y, int width, int height, QString color = "#000000", bool filled = false);
|
||||||
bool addImage(int x, int y, QString filepath, bool useCache = true, int width = -1, int height = -1, int xOffset = 0, int yOffset = 0, qreal hScale = 1, qreal vScale = 1, QList<QRgb> palette = QList<QRgb>(), bool setTransparency = false);
|
bool addImage(int x, int y, QString filepath, bool useCache = true, int width = -1, int height = -1, int xOffset = 0, int yOffset = 0, qreal hScale = 1, qreal vScale = 1, QList<QRgb> palette = QList<QRgb>(), bool setTransparency = false);
|
||||||
bool addImage(int x, int y, QImage image);
|
bool addImage(int x, int y, QImage image);
|
||||||
|
|
|
@ -7,7 +7,7 @@ void OverlayText::render(QPainter *painter, int x, int y) {
|
||||||
font.setPixelSize(this->fontSize);
|
font.setPixelSize(this->fontSize);
|
||||||
painter->setFont(font);
|
painter->setFont(font);
|
||||||
painter->setPen(this->color);
|
painter->setPen(this->color);
|
||||||
painter->drawText(this->x + x, this->y + y, this->text);
|
painter->drawStaticText(this->x + x, this->y + y, this->text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayRect::render(QPainter *painter, int x, int y) {
|
void OverlayRect::render(QPainter *painter, int x, int y) {
|
||||||
|
@ -113,7 +113,7 @@ void Overlay::move(int deltaX, int deltaY) {
|
||||||
this->y += deltaY;
|
this->y += deltaY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Overlay::addText(QString text, int x, int y, QString color, int fontSize) {
|
void Overlay::addText(const QString text, int x, int y, QString color, int fontSize) {
|
||||||
this->items.append(new OverlayText(text, x, y, QColor(color), fontSize));
|
this->items.append(new OverlayText(text, x, y, QColor(color), fontSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue