X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fpainter.cpp;h=61ee9b6c0ffa6f1e28a26231dc6ee118acd50d13;hb=f507d97c1b1118834a70332f5f79d8479a6964c0;hp=35528faf9887ce5930306cb6f6d2c26465392c9a;hpb=84afe881653a02a16b19d4da37435b8701b1a826;p=architektonas diff --git a/src/painter.cpp b/src/painter.cpp index 35528fa..61ee9b6 100644 --- a/src/painter.cpp +++ b/src/painter.cpp @@ -79,6 +79,26 @@ void Painter::SetRenderHint(int hint) } +void Painter::SetPen(QPen pen) +{ + if (!painter) + return; + + painter->setPen(pen); +} + + +void Painter::SetPen(uint32_t color, float size/*= 0*/, int style/*= 0*/) +{ + if (!painter) + return; + + // We can cast style as Qt:PenStyle because they line up 1-to-1 + painter->setPen(QPen(QColor(color >> 16, (color >> 8) & 0xFF, color & 0xFF, 255), + size, (Qt::PenStyle)style)); +} + + void Painter::SetBrush(QBrush brush) { if (!painter) @@ -88,21 +108,21 @@ void Painter::SetBrush(QBrush brush) } -void Painter::SetFont(QFont font) +void Painter::SetBrush(uint32_t color) { if (!painter) return; - painter->setFont(font); + painter->setBrush(QBrush(QColor(color >> 16, (color >> 8) & 0xFF, color & 0xFF, 255))); } -void Painter::SetPen(QPen pen) +void Painter::SetFont(QFont font) { if (!painter) return; - painter->setPen(pen); + painter->setFont(font); } @@ -145,6 +165,30 @@ void Painter::DrawAngledText(Vector center, double angle, QString text, double s } +// +// Draw angled text. Draws text using point p as the upper left corner. +// Size is point size, angle is in radians (defaults to 0). +// +void Painter::DrawTextObject(Point p, QString text, double size, double angle/*= 0*/) +{ + if (!painter) + return; + + p = CartesianToQtCoords(p); + painter->setFont(QFont("Arial", Global::zoom * size)); + int textWidth = QFontMetrics(painter->font()).width(text); + int textHeight = QFontMetrics(painter->font()).height(); + + QRectF textBox(0, 0, textWidth, textHeight); + painter->save(); + painter->translate(p.x, p.y); + // Angles are backwards in the Qt coord system, so we flip ours... + painter->rotate(-angle * RADIANS_TO_DEGREES); + painter->drawText(textBox, Qt::AlignLeft | Qt::AlignTop , text); + painter->restore(); +} + + void Painter::DrawArc(Vector center, double radius, double startAngle, double span) { center = CartesianToQtCoords(center);