X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fpainter.cpp;h=bdac361f59b64d7f68b2aca874ac169c0d92837d;hb=db0a3d91f37031e155cc8eac7cfdec9889f233ee;hp=308cab6b7bd87ed587cb884ae52113f1173abaad;hpb=bb8d0671717bac2c5350e34024273381be1d8175;p=architektonas diff --git a/src/painter.cpp b/src/painter.cpp index 308cab6..bdac361 100644 --- a/src/painter.cpp +++ b/src/painter.cpp @@ -15,6 +15,8 @@ #include "painter.h" #include "mathconstants.h" +//#include "object.h" +#include "global.h" // Set class variable defaults @@ -176,6 +178,53 @@ void Painter::DrawHandle(Vector center) } +// This function is for drawing object handles without regard for zoom level; +// we don't want our object handle size to depend on the zoom level! +void Painter::DrawArrowHandle(Vector center, double angle) +{ + center = CartesianToQtCoords(center); + QPolygonF arrow; + + // Since we're drawing directly on the screen, the Y is inverted. So we use + // the mirror of the angle. + double orthoAngle = -angle + (PI / 2.0); + Vector orthogonal = Vector(cos(orthoAngle), sin(orthoAngle)); + Vector unit = Vector(cos(-angle), sin(-angle)); + + Point p0 = center + (unit * 6.0); + Point p1 = center + (unit * 21.0); + Point p1b = center + (unit * 11.0); + Point p2 = p1b + (orthogonal * 5.0); + Point p3 = p1b - (orthogonal * 5.0); + + painter->drawLine(p0.x, p0.y, p1.x, p1.y); + arrow << QPointF(p1.x, p1.y) << QPointF(p2.x, p2.y) << QPointF(p3.x, p3.y); + + painter->drawPolygon(arrow); +} + + +// This function is for drawing object handles without regard for zoom level; +// we don't want our object handle size to depend on the zoom level! +void Painter::DrawArrowToLineHandle(Vector center, double angle) +{ + DrawArrowHandle(center, angle); + center = CartesianToQtCoords(center); + + // Since we're drawing directly on the screen, the Y is inverted. So we use + // the mirror of the angle. + double orthoAngle = -angle + (PI / 2.0); + Vector orthogonal = Vector(cos(orthoAngle), sin(orthoAngle)); + Vector unit = Vector(cos(-angle), sin(-angle)); + + Point p1 = center + (unit * 21.0); + Point p2 = p1 + (orthogonal * 7.0); + Point p3 = p1 - (orthogonal * 7.0); + + painter->drawLine(p2.x, p2.y, p3.x, p3.y); +} + + void Painter::DrawLine(int x1, int y1, int x2, int y2) { if (!painter) @@ -208,7 +257,7 @@ void Painter::DrawPoint(int x, int y) } -// This is drawn in Qt coordinates... +// The rect passed in is in Qt coordinates... void Painter::DrawRoundedRect(QRectF rect, double radiusX, double radiusY) { if (!painter) @@ -218,9 +267,8 @@ void Painter::DrawRoundedRect(QRectF rect, double radiusX, double radiusY) } -// This is drawn partially in Cartesian coordinates, and partially in Qt -// coordinates. The rect itself is in Cartesian but we want to pad it by a set -// number of pixels. +// 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) @@ -257,6 +305,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 @@ -278,3 +329,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(*Global::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); +} +