// STILL TO BE DONE:
//
// - Lots of stuff
+// - Layer locking (hiding works)
//
// Uncomment this for debugging...
line->thickness = 2.0;
line->style = LSDash;
line->color = 0xFF7F00;
+ line->layer = 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)));
}
-void DrawingView::SetCurrentLayer(int layer)
+void DrawingView::SetCurrentLayer(int /*layer*/)
{
- Global::currentLayer = layer;
+//Not needed anymore...
+// Global::currentLayer = layer;
//printf("DrawingView::CurrentLayer = %i\n", layer);
}
+//
+// Basically, we just make a single pass through the Container. If the layer #
+// is less than the layer # being deleted, then do nothing. If the layer # is
+// equal to the layer # being deleted, then delete the object. If the layer #
+// is greater than the layer # being deleted, then set the layer # to its layer
+// # - 1.
+//
+void DrawingView::DeleteCurrentLayer(int layer)
+{
+//printf("DrawingView::DeleteCurrentLayer(): currentLayer = %i\n", layer);
+ std::vector<void *>::iterator i = document.objects.begin();
+
+ while (i != document.objects.end())
+ {
+ Object * obj = (Object *)(*i);
+
+ if (obj->layer < layer)
+ i++;
+ else if (obj->layer == layer)
+ {
+ document.objects.erase(i);
+ delete obj;
+ }
+ else
+ {
+ obj->layer--;
+ i++;
+ }
+ }
+
+ // We've just done a destructive action, so update the screen!
+ update();
+}
+
+
+void DrawingView::HandleLayerToggle(void)
+{
+ // A layer's visibility was toggled, so update the screen...
+ update();
+}
+
+
+//
+// A layer was moved up or down in the layer list, so we have to swap the
+// document's object's layer numbers in the layers that were swapped.
+//
+void DrawingView::HandleLayerSwap(int layer1, int layer2)
+{
+//printf("DrawingView: Swapping layers %i and %i.\n", layer1, layer2);
+ std::vector<void *>::iterator i;
+
+ for(i=document.objects.begin(); i!=document.objects.end(); i++)
+ {
+ Object * obj = (Object *)(*i);
+
+ if (obj->layer == layer1)
+ obj->layer = layer2;
+ else if (obj->layer == layer2)
+ obj->layer = layer1;
+ }
+}
+
+
QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event)
{
// This is undoing the transform, e.g. going from client coords to local coords.
painter.DrawLine(-16384, 0, 16384, 0);
// Do object rendering...
- RenderObjects(&painter, document.objects);
+ for(int i=0; i<Global::numLayers; i++)
+ {
+ if (Global::layerHidden[i] == false)
+ RenderObjects(&painter, document.objects, i);
+ }
// Do tool rendering, if any...
if (Global::tool)
//
// Renders objects in the passed in vector
//
-void DrawingView::RenderObjects(Painter * painter, std::vector<void *> & v)
+void DrawingView::RenderObjects(Painter * painter, std::vector<void *> & v, int layer)
{
std::vector<void *>::iterator i;
Object * obj = (Object *)(*i);
float scaledThickness = Global::scale * obj->thickness;
+ // If the object isn't on the current layer being drawn, skip it
+ if (obj->layer != layer)
+ continue;
+
if ((Global::tool == TTRotate) && ctrlDown && obj->selected)
{
painter->SetPen(0x00FF00, 2.0, LSSolid);
else
{
Line * l = new Line(toolPoint[0], toolPoint[1]);
+ l->layer = Global::activeLayer;
document.objects.push_back(l);
toolPoint[0] = toolPoint[1];
}
{
double length = Vector::Magnitude(toolPoint[0], toolPoint[1]);
Circle * c = new Circle(toolPoint[0], length);
+ c->layer = Global::activeLayer;
document.objects.push_back(c);
toolPoint[0] = toolPoint[1];
Global::toolState = TSNone;
span += PI_TIMES_2;
Arc * arc = new Arc(toolPoint[0], toolPoint[1].x, toolPoint[2].x, span);
+ arc->layer = Global::activeLayer;
document.objects.push_back(arc);
Global::toolState = TSNone;
}