]> Shamusworld >> Repos - architektonas/blobdiff - src/painter.cpp
Fixed Container loading, informative display.
[architektonas] / src / painter.cpp
index 6cfd91f8ef62641d6584158631c6a3834866532a..6145638c8a022080a30aab44122498ff0fcd9eb1 100644 (file)
@@ -15,6 +15,7 @@
 #include "painter.h"
 
 #include "mathconstants.h"
+#include "object.h"
 
 
 // Set class variable defaults
@@ -208,6 +209,7 @@ void Painter::DrawPoint(int x, int y)
 }
 
 
+// The rect passed in is in Qt coordinates...
 void Painter::DrawRoundedRect(QRectF rect, double radiusX, double radiusY)
 {
        if (!painter)
@@ -217,6 +219,21 @@ void Painter::DrawRoundedRect(QRectF rect, double radiusX, double radiusY)
 }
 
 
+// The rect passed in is in Cartesian but we want to pad it by a set number of
+// pixels (currently set at 8), so the pad looks the same regardless of zoom.
+void Painter::DrawPaddedRect(QRectF rect)
+{
+       if (!painter)
+               return;
+
+       Vector v1 = CartesianToQtCoords(Vector(rect.x(), rect.y()));
+       Vector v2 = CartesianToQtCoords(Vector(rect.right(), rect.bottom()));
+       QRectF screenRect(QPointF(v1.x, v1.y), QPointF(v2.x, v2.y));
+       screenRect.adjust(-8, 8, 8, -8);        // Left/top, right/bottom
+       painter->drawRect(screenRect);
+}
+
+
 void Painter::DrawRect(QRectF rect)
 {
        if (!painter)
@@ -240,6 +257,9 @@ void Painter::DrawText(QRectF rect, int type, QString text)
 
 void Painter::DrawArrowhead(Vector head, Vector tail, double size)
 {
+       if (!painter)
+               return;
+
        QPolygonF arrow;
 
        // We draw the arrowhead aligned along the line from tail to head
@@ -261,3 +281,34 @@ void Painter::DrawArrowhead(Vector head, Vector tail, double size)
        painter->drawPolygon(arrow);
 }
 
+
+// Point is given in Cartesian coordinates
+void Painter::DrawCrosshair(Vector point)
+{
+       if (!painter)
+               return;
+
+       Vector screenPoint = CartesianToQtCoords(point);
+       painter->drawLine(0, screenPoint.y, screenSize.x, screenPoint.y);
+       painter->drawLine(screenPoint.x, 0, screenPoint.x, screenSize.y);
+}
+
+
+void Painter::DrawInformativeText(QString text)
+{
+       painter->setFont(*Object::font);
+       QRectF bounds = painter->boundingRect(QRectF(), Qt::AlignVCenter, text);
+       bounds.moveTo(17.0, 17.0);
+       QRectF textRect = bounds;
+       textRect.adjust(-7.0, -7.0, 7.0, 7.0);
+
+       QPen pen = QPen(QColor(0x00, 0xFF, 0x00), 1.0, Qt::SolidLine);
+       painter->setPen(pen);
+       painter->setBrush(QBrush(QColor(0x40, 0xFF, 0x40, 0x9F)));
+       painter->drawRoundedRect(textRect, 7.0, 7.0);
+
+       pen = QPen(QColor(0x00, 0x5F, 0xDF));
+       painter->setPen(pen);
+       painter->drawText(bounds, Qt::AlignVCenter, text);
+}
+