+++ /dev/null
-//
-// Graphics primitives
-//
-// Various graphic functions that are slightly more complex than those that
-// come with various widget libraries.
-//
-// by James L. Hammons
-// (C) 2005 Underground Software
-//
-// JLH = James L. Hammons <jlhamm@acm.org>
-//
-// Who When What
-// --- ---------- -------------------------------------------------------------
-// JLH 03/14/1998 Created this file
-// JLH 01/20/2005 Converted to use wxWidgets
-// JLH 08/30/2008 Repurposed file to handle more than just bezier curves
-//
-
-#include "graphicprimitives.h"
-
-double abs(double n) // Helper function
-{
- return (n < 0 ? -n : n);
-}
-
-
-//
-// This function takes three points and draws a curve using a second order
-// Bezier function.
-//
-void Bezier(QPainter &p, point p1, point p2, point p3)
-{
- double step = abs(p1.x - p3.x), tmp = abs(p1.y - p3.y);
- step = (tmp > step ? tmp : step); // Get the larger of the two...
- step = (step > 0 ? 1/step : 1); // & convert to valid step value
- step *= 2.0; // (double it to draw less...)
-
- int prevX = (int)p1.x, prevY = (int)p1.y;
-
- for(double u=0; u<=1; u+=step)
- {
- double _2u = 2*u, _uu = u*u, _2uu = 2*_uu;
- double x = (p1.x * (1 - _2u + _uu)) + (p2.x * (_2u - _2uu)) + (p3.x * _uu);
- double y = (p1.y * (1 - _2u + _uu)) + (p2.y * (_2u - _2uu)) + (p3.y * _uu);
-
- p.drawLine(prevX, prevY, (int)x, (int)y);
- prevX = (int)x, prevY = (int)y;
- }
-
- p.drawLine(prevX, prevY, (int)p3.x, (int)p3.y);
-}
-
-
-//
-// This is a convenience funtion, using IPoints :-)
-//
-void Bezier(QPainter &p, IPoint p1, IPoint p2, IPoint p3)
-{
- Bezier(p, point(p1.x, p1.y), point(p2.x, p2.y), point(p3.x, p3.y));
-}
-
-
-//
-// Draw a round dot (5x5, centered on [x, y])
-//
-void DrawRoundDot(QPainter &p, int32_t x, int32_t y)
-{
- QPoint pt[8];
-
- pt[0] = QPoint(x - 1, y - 2);
- pt[1] = QPoint(x + 1, y - 2);
- pt[2] = QPoint(x + 2, y - 1);
- pt[3] = QPoint(x + 2, y + 1);
- pt[4] = QPoint(x + 1, y + 2);
- pt[5] = QPoint(x - 1, y + 2);
- pt[6] = QPoint(x - 2, y + 1);
- pt[7] = QPoint(x - 2, y - 1);
-
- p.drawPolygon(pt, 8);
-}
-
-
-//
-// Draw a sqaure dot (5x5, centered on [x, y])
-//
-void DrawSquareDot(QPainter &p, int32_t x, int32_t y)
-{
- QPoint pt[4];
-
- pt[0] = QPoint(x - 2, y - 2);
- pt[1] = QPoint(x + 2, y - 2);
- pt[2] = QPoint(x + 2, y + 2);
- pt[3] = QPoint(x - 2, y + 2);
-
- p.drawPolygon(pt, 4);
-}
-
-
-//
-// Draw a sqaure dot (nxn, centered on [x, y])
-//
-void DrawSquareDotN(QPainter &p, int32_t x, int32_t y, uint32_t n)
-{
- QPoint pt[4];
- uint32_t offset = (n - 1) / 2;
-
- pt[0] = QPoint(x - offset, y - offset);
- pt[1] = QPoint(x + offset, y - offset);
- pt[2] = QPoint(x + offset, y + offset);
- pt[3] = QPoint(x - offset, y + offset);
-
- p.drawPolygon(pt, 4);
-}
-
-
-//
-// Draw a round dot (nxn, centered on [x, y])
-//
-void DrawRoundDotN(QPainter &p, int32_t x, int32_t y, uint32_t n)
-{
- int radius = (n / 2) + 1;
- p.drawEllipse(x - radius, y - radius, n, n);
-}