void MagicView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CView::OnLButtonDown(nFlags, point);
   SetCapture();

   // set focus to the view that was clicked:
   int index = GetWinIndexByPoint(point.x, point.y);
   SetFocusModelView(index);

   drag_start = point;
   drag_left  = true;
   drag_right = false;

   ModelView*  mv       = GetModelViewByIndex(index);
   MagicDoc*   pDoc     = GetDocument();
   Model*      model    = pDoc->GetSolid()->GetModel();
   Selector*   selector = pDoc->GetSelector();

   if (IsUVEdit()) {
      int select_mode = UVMapView::SELECT_APPEND;

      if (nFlags & MK_CONTROL)
         select_mode = UVMapView::SELECT_REMOVE;

      if (!uvmap_view->WillSelect(point)) {
         uvmap_view->Begin(select_mode);
         uvmap_view->AddMark(point);
      }
   }

   else if (mv && selector) {
      int select_mode = Selector::SELECT_APPEND;

      if (nFlags & MK_CONTROL)
         select_mode = Selector::SELECT_REMOVE;

      selector->Begin(model, mv->GetViewMode(), select_mode);
      selector->AddMark(point);
   }
}
void MagicView::OnMouseMove(UINT nFlags, CPoint point) 
{
   if (drag_right) {
      CPoint offset = point - drag_start;

      if (view_focus == VIEW_PERSPECTIVE) {
         ModelView* view = GetModelViewByIndex(view_focus);
         view->SpinBy(offset.x * 0.5 * DEGREES, 
                      offset.y * 0.5 * DEGREES);
      }

      else if (IsUVEdit()) {
         uvmap_view->MoveBy(offset.x, offset.y);
      }

      else {
         ModelView* view = GetModelViewByIndex(view_focus);
         view->MoveBy(offset.x, offset.y);
      }

      drag_start = point;
      Invalidate();
   }

   else if (drag_left) {
      CPoint      offset      = point - drag_start;
      MagicDoc*   pDoc        = GetDocument();
      Selector*   selector    = pDoc->GetSelector();

      if (IsUVEdit()) {
         if (uvmap_view->IsActive()) {
            uvmap_view->AddMark(point);
         }
         else {
            uvmap_view->DragBy(offset.x, offset.y);
            drag_start = point;
         }
      }

      else if (selector && selector->IsActive()) {
         selector->AddMark(point);
      }
   }

   // xy status message:
   if (view_focus != VIEW_PERSPECTIVE) {
      char        xy[80];
      CPoint      mouse    = LPtoWP(point);
      Selection*  seln     = GetDocument()->GetSelection();

      int nv = seln ? seln->GetVerts().size() : 0;
      int np = seln ? seln->GetPolys().size() : 0;

      if (np || nv)
         sprintf_s(xy, "(%05d,%05d)  Verts:%d Polys:%d", mouse.x, mouse.y, nv, np);
      else
         sprintf_s(xy, "(%05d,%05d)", mouse.x, mouse.y);
      MainFrame::StatusXY(xy);
   }

	CView::OnMouseMove(nFlags, point);
}