+void DrawingView::RotateHandler(int mode, Point p)
+{
+ switch (mode)
+ {
+ case ToolMouseDown:
+ if (Global::toolState == TSNone)
+ {
+ toolPoint[0] = p;
+ toolObjects.clear();
+ CopyObjects(select, toolObjects);
+// ClearSelected(toolObjects);
+ Global::toolState = TSPoint1;
+ }
+ else if (Global::toolState == TSPoint1)
+ toolPoint[0] = p;
+ else
+ toolPoint[1] = p;
+
+ break;
+ case ToolMouseMove:
+/*
+There's two approaches to this that we can do:
+
+ -- Keep a copy of selected objects & rotate those (drawing rotated + selected)
+ -- Rotate the selected (drawing selected only)
+
+Either way, we need to have a copy of the points before we change them; we also need
+to know whether or not to discard any changes made--maybe with a ToolCleanup()
+function.
+*/
+ if ((Global::toolState == TSPoint1) || (Global::toolState == TSNone))
+ toolPoint[0] = p;
+ else if (Global::toolState == TSPoint2)
+ {
+// need to reset the selected points to their non-rotated state in this case...
+ if (shiftDown)
+ return;
+
+ toolPoint[1] = p;
+
+ double angle = Vector(toolPoint[1], toolPoint[0]).Angle();
+ std::vector<void *>::iterator j = select.begin();
+ std::vector<void *>::iterator i = toolObjects.begin();
+
+// for(; i!=select.end(); i++, j++)
+ for(; i!=toolObjects.end(); i++, j++)
+ {
+ Object * obj = (Object *)(*i);
+ Point p1 = Geometry::RotatePointAroundPoint(obj->p[0], toolPoint[0], angle);
+ Point p2 = Geometry::RotatePointAroundPoint(obj->p[1], toolPoint[0], angle);
+ Object * obj2 = (Object *)(*j);
+ obj2->p[0] = p1;
+ obj2->p[1] = p2;
+ }
+ }
+
+ break;
+ case ToolMouseUp:
+ if (Global::toolState == TSPoint1)
+ {
+ Global::toolState = TSPoint2;
+ // Prevent spurious line from drawing...
+ toolPoint[1] = toolPoint[0];
+ }
+ else if ((Global::toolState == TSPoint2) && shiftDown)
+ {
+ // Key override is telling us to make a new line, not continue the
+ // previous one.
+ toolPoint[0] = toolPoint[1];
+ }
+ else
+ {
+#if 0
+ Line * l = new Line(toolPoint[0], toolPoint[1]);
+ document.objects.push_back(l);
+ toolPoint[0] = toolPoint[1];
+#endif
+ }
+ }
+}
+
+