#include "drawingview.h"
#include <stdint.h>
-#include "mathconstants.h"
-
-//#include "arc.h"
-//#include "circle.h"
-//#include "dimension.h"
-//#include "geometry.h"
-//#include "line.h"
#include "global.h"
+#include "mathconstants.h"
#include "painter.h"
+#include "structs.h"
#define BACKGROUND_MAX_SIZE 512
// Alternate way to do the above...
line->SetDimensionOnLine();
#endif
+#else
+ Line * line = new Line;//(Vector(5, 5), Vector(50, 40), &document);
+ line->p1 = Vector(5, 5);
+ line->p2 = Vector(50, 40);
+ line->type = OTLine;
+ line->thickness = 1.0;
+ document.objects.push_back(line);
+ document.objects.push_back(new Line(Vector(50, 40), Vector(10, 83)));
+ document.objects.push_back(new Line(Vector(10, 83), Vector(17, 2)));
+ document.objects.push_back(new Circle(Vector(100, 100), 36));
+ document.objects.push_back(new Circle(Vector(50, 150), 49));
+ document.objects.push_back(new Arc(Vector(300, 300), 32, PI / 4.0, PI * 1.3)),
+ document.objects.push_back(new Arc(Vector(200, 200), 60, PI / 2.0, PI * 1.5));
#endif
/*
The drawing enforces the grid spacing through the drawing->gridSpacing variable.
- drawing->gridSpacing = 12.0 / Painter::zoom;
+ drawing->gridSpacing = 12.0 / Global::zoom;
-Painter::zoom is the zoom factor for the drawing, and all mouse clicks are
-translated to Cartesian coordinates through this. (Initially, Painter::zoom is
+Global::zoom is the zoom factor for the drawing, and all mouse clicks are
+translated to Cartesian coordinates through this. (Initially, Global::zoom is
set to 1.0. SCREEN_ZOOM is set to 1.0/4.0.)
Really, the 100% zoom level can be set at *any* zoom level, it's more of a
this. Maybe this is the case for having a base unit and basing point sizes off
of that.
-Here's what's been figured out. Painter::zoom is simply the ratio of pixels to
+Here's what's been figured out. Global::zoom is simply the ratio of pixels to
base units. What that means is that if you have a 12px grid with a 6" grid size
-(& base unit of "inches"), Painter::zoom becomes 12px / 6" = 2.0 px/in.
+(& base unit of "inches"), Global::zoom becomes 12px / 6" = 2.0 px/in.
Dimensions now have a "size" parameter to set their absolute size in relation
to the base unit. ATM, the arrows are drawn in pixels, but also scaled by
-Painter::zoom *and* size. Same with the dimension text; it's drawn at 10pt and
+Global::zoom *and* size. Same with the dimension text; it's drawn at 10pt and
scaled the same way as the arrowheads.
Need a way to scale line widths as well. :-/ Shouldn't be too difficult, just
// Set up new BG brush & zoom level (pixels per base unit)
// Painter::zoom = gridPixels / gridSpacing;
- Painter::zoom = gridPixels / Global::gridSpacing;
+ Global::zoom = gridPixels / Global::gridSpacing;
UpdateGridBackground();
}
// The top level document takes care of rendering for us...
// document.Draw(&painter);
+ // Not any more it doesn't...
+ RenderObjects(&painter, &document);
#if 0
if (toolAction)
}
+void DrawingView::RenderObjects(Painter * p, Container * c)
+{
+ std::vector<void *>::iterator i;
+
+ for(i=c->objects.begin(); i!=c->objects.end(); i++)
+ {
+ Object * obj = (Object *)(*i);
+ p->SetPen(QPen(Qt::black, 1.0 * Global::zoom * obj->thickness, Qt::SolidLine));
+
+ switch (obj->type)
+ {
+ case OTLine:
+ {
+ Line * l = (Line *)obj;
+ p->DrawLine(l->p1, l->p2);
+ break;
+ }
+ case OTCircle:
+ {
+ Circle * ci = (Circle *)obj;
+ p->DrawEllipse(ci->p1, ci->radius, ci->radius);
+ break;
+ }
+ case OTArc:
+ {
+ Arc * a = (Arc *)obj;
+ p->DrawArc(a->p1, a->radius, a->angle1, a->angle2);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+}
+
+
void DrawingView::resizeEvent(QResizeEvent * /*event*/)
{
- Painter::screenSize = Vector(size().width(), size().height());
+ Global::screenSize = Vector(size().width(), size().height());
UpdateGridBackground();
}
// Since we're using Qt coords for scrolling, we have to adjust them here to
// conform to Cartesian coords, since the origin is using Cartesian. :-)
Vector delta(oldPoint, point);
- delta /= Painter::zoom;
+ delta /= Global::zoom;
delta.y = -delta.y;
- Painter::origin -= delta;
+ Global::origin -= delta;
UpdateGridBackground();
update();
// This is not centering for some reason. Need to figure out why. :-/
if (event->delta() > 0)
{
- Vector newOrigin = center - ((center - Painter::origin) / zoomFactor);
- Painter::origin = newOrigin;
- Painter::zoom *= zoomFactor;
+ Vector newOrigin = center - ((center - Global::origin) / zoomFactor);
+ Global::origin = newOrigin;
+ Global::zoom *= zoomFactor;
}
else
{
- Vector newOrigin = center + ((-center + Painter::origin) * zoomFactor);
- Painter::origin = newOrigin;
- Painter::zoom /= zoomFactor;
+ Vector newOrigin = center + ((-center + Global::origin) * zoomFactor);
+ Global::origin = newOrigin;
+ Global::zoom /= zoomFactor;
}
#if 1
// Global::gridSpacing = gridPixels / Painter::zoom;
// UpdateGridBackground();
- SetGridSize(Global::gridSpacing * Painter::zoom);
+ SetGridSize(Global::gridSpacing * Global::zoom);
update();
// zoomIndicator->setText(QString("Grid: %1\", BU: Inch").arg(Global::gridSpacing));
#endif