home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / UIFlow 1.0.1 / UIFlow Source / CFDFront / TDragCommand.cp < prev    next >
Encoding:
Text File  |  1992-02-21  |  17.0 KB  |  490 lines  |  [TEXT/MPS ]

  1. #pragma segment Boundry
  2. // **********************************************************************
  3. //    TDragCommand - Methods
  4. // **********************************************************************
  5. //        drag directions (in info structure: dLeft & dRight
  6. //            true is toward the selected point (point we are dragging
  7. //            false is away from the point being dragged
  8. // --------------------------------------------------------------------------------------------------
  9. //    Initializing the dragger command .....
  10. // --------------------------------------------------------------------------------------------------
  11. short TDragCommand::IDragCommand(TGeomView * geom, TPoint * pt, Point * theMouse)
  12.     {
  13.     fGeom                = geom;                                                                        // save the geometry
  14.     fCDocument        = (TCFDFrontDocument *)fGeom->fCDocument;                // get the document
  15.     fMatrix            = fCDocument->fPointMatrix;                                        // overseer matrix
  16.     fPoint                = pt;                                                                                // save this segment
  17.     fMouse.h            = theMouse->h;                                                                // save the mouse location
  18.     fMouse.v            = theMouse->v;
  19.         
  20.     lastTrack = fPoint->GetStart();                                                            // save location of this segment
  21.     fPoint->RememberPoint();                                                                    // remember yourselft
  22.     HLock((Handle) this);
  23.     if (fMatrix->SetCornors(fPoint,&dInfo) == 1)                                        // get the surrounding points
  24.         {
  25.         HUnlock((Handle) this);
  26.         return 1;
  27.         }
  28.     HUnlock((Handle) this);
  29.     if (dInfo.lrc != NULL)
  30.         dInfo.lrc->RememberPoint();
  31.         
  32.     if (fGeom->fSSide != NULL)
  33.         fSide = fGeom->fSSide->GetSide();
  34.     else
  35.         fSide = cNotOnBoundry;
  36.     fGeom->SetDragging(false);                                                                    // init dragging to false
  37.     ICommand (cDragPointCommand,fCDocument,fGeom,fGeom->GetScroller(true));
  38.     fConstrainsMouse = true;                                                                        // constrain the mouse
  39.     return 0;
  40.     }
  41.  
  42. // --------------------------------------------------------------------------------------------------
  43. //    Display the Lines
  44. // --------------------------------------------------------------------------------------------------
  45. void TDragCommand::DisplayIt(Point trans, Point temp)
  46.     {
  47.     fGeom->Focus();                                                                                    // focus on geometry
  48.     PenMode(srcXor);                                                                                    // xor drawing
  49.     
  50.     if (!fPoint->IsBoundryPt())                                                                    // a grid point
  51.         {
  52.         fPoint->Draw();                                                                                // erase point
  53.         fPoint->DrawGrid(dInfo.above->fTrans);                                            // erase old lines
  54.         fPoint->DrawGrid(dInfo.right->fTrans);
  55.         fPoint->DrawGrid(dInfo.below->fTrans);
  56.         fPoint->DrawGrid(dInfo.left->fTrans);
  57.         
  58.         fPoint->SetStart(temp.v,temp.h);                                                        // set the point to the new point
  59.         
  60.         fPoint->DrawGrid(dInfo.above->fTrans);                                            // draw new lines
  61.         fPoint->DrawGrid(dInfo.right->fTrans);
  62.         fPoint->DrawGrid(dInfo.below->fTrans);
  63.         fPoint->DrawGrid(dInfo.left->fTrans);
  64.         fPoint->Draw();                                                                                // redraw the point    
  65.         }
  66.     else if (fPoint->IsCornor())
  67.         {
  68.         fPoint->Draw();                                                                                // erase point
  69.         if (dInfo.lrc != NULL)
  70.             dInfo.lrc->DrawSection(dInfo.left->fTrans);
  71.         else if (dInfo.dLeft)
  72.             dInfo.left->DrawSection(fPoint->fTrans);
  73.         else
  74.             fPoint->DrawSection(dInfo.left->fTrans);                                        // redraw boundry line
  75.         if (dInfo.dRight)
  76.             dInfo.right->DrawSection(fPoint->fTrans);                                    // erase boundry line
  77.         else
  78.             fPoint->DrawSection(dInfo.right->fTrans);                                    // redraw boundry line
  79.         
  80.         if (dInfo.above != NULL)                                                                        // is there a grid line?
  81.             fPoint->DrawGrid(dInfo.above->fTrans);                                        // erase it
  82.         
  83.         fPoint->SetStart(temp.v,temp.h);                                                        // set the point to the new point
  84.         if (dInfo.lrc != NULL)
  85.             dInfo.lrc->SetStart(temp.v,temp.h);
  86.  
  87.         if (dInfo.lrc != NULL)
  88.             dInfo.lrc->DrawSection(dInfo.left->fTrans);
  89.         else if (dInfo.dLeft)
  90.             dInfo.left->DrawSection(fPoint->fTrans);
  91.         else
  92.             fPoint->DrawSection(dInfo.left->fTrans);                                        // redraw boundry line
  93.         if (dInfo.dRight)
  94.             dInfo.right->DrawSection(fPoint->fTrans);                                    // erase boundry line
  95.         else
  96.             fPoint->DrawSection(dInfo.right->fTrans);                                    // redraw boundry line
  97.  
  98.         if (dInfo.above != NULL)                                                                        // is there a grid line?
  99.             fPoint->DrawGrid(dInfo.above->fTrans);                                        // redraw it
  100.         fPoint->Draw();                                                                                // redraw the point    
  101.         }
  102.     else        
  103.         {
  104.         fPoint->DrawHold();
  105.         fPoint->DrawTemp(trans,dInfo.left->fTrans);                                    // redraw boundry line
  106.         dInfo.right->DrawTemp(trans,dInfo.right->fTrans);                            // erase boundry line
  107.  
  108.         fPoint->SetHold(temp.v,temp.h);
  109.         fMatrix->MovePoints(temp,fLength);                                                // move selected row / column
  110.         fPoint->DrawHold();
  111.         }
  112.     return;
  113.     }
  114.  
  115. // --------------------------------------------------------------------------------------------------
  116. //    Display the Obstacles
  117. // --------------------------------------------------------------------------------------------------
  118. void TDragCommand::DisplayObstacles(void)
  119.     {
  120.     if (fPoint->fObsUpLeft != NULL)
  121.         ((TObstacle *) ((TPoint * ) fPoint)->fObsUpLeft)->Draw();
  122.     if (fPoint->fObsUpRight != NULL)
  123.         ((TObstacle *) ((TPoint * ) fPoint)->fObsUpRight)->Draw();
  124.     if (fPoint->fObsLwLeft != NULL)
  125.         ((TObstacle *) ((TPoint * ) fPoint)->fObsLwLeft)->Draw();
  126.     if (fPoint->fObsLwRight != NULL)
  127.         ((TObstacle *) ((TPoint * ) fPoint)->fObsLwRight)->Draw();
  128.  
  129.     if (fPoint->fBaffAbove != NULL)
  130.         ((TBaffle *) ((TPoint * ) fPoint)->fBaffAbove)->Draw();
  131.     if (fPoint->fBaffBelow != NULL)
  132.         ((TBaffle *) ((TPoint * ) fPoint)->fBaffBelow)->Draw();
  133.     if (fPoint->fBaffLeft != NULL)
  134.         ((TBaffle *) ((TPoint * ) fPoint)->fBaffLeft)->Draw();
  135.     if (fPoint->fBaffRight != NULL)
  136.         ((TBaffle *) ((TPoint * ) fPoint)->fBaffRight)->Draw();
  137.     }
  138.  
  139. // --------------------------------------------------------------------------------------------------
  140. //    Do the command
  141. // --------------------------------------------------------------------------------------------------
  142. pascal void TDragCommand::DoIt(void)
  143.     {
  144.     if (fPoint->IsBoundryPt() && !fPoint->IsCornor())
  145.         {
  146.         fPoint->SetStart(fPt.v,fPt.h);                                        // set the point to the new point
  147.         fMatrix->FixHold();
  148.         if (fMatrix->IsShown())
  149.             fMatrix->DrawHold(false);
  150.         else
  151.             {
  152.             fPoint->DrawSection(dInfo.left->fTrans);                        // redraw boundry line
  153.             dInfo.right->DrawSection(fPoint->fTrans);                        // erase boundry line
  154.             }
  155.         fMatrix->DoHighlight();                                                // rehighlight the point
  156.         ((TInformationView *) fCDocument->fInfoView)->StatusString(fPoint->fStart);    // display the status string
  157.         return;
  158.         }
  159.         
  160.     this->DisplayObstacles();
  161.     fMatrix->DoHighlight();                                                    // rehighlight the point
  162.     ((TInformationView *) fCDocument->fInfoView)->StatusString(fPoint->fStart);    // display the status string
  163.     fGeom->Focus();
  164.     }
  165.     
  166. // --------------------------------------------------------------------------------------------------
  167. //    UnDo the command
  168. // --------------------------------------------------------------------------------------------------
  169. pascal void TDragCommand::UndoIt(void)
  170.     {
  171.     Point temp,trans;
  172.     
  173.     if (!fPoint->IsBoundryPt() || fPoint->IsCornor())
  174.         {
  175.         fMatrix->DoHighlight();                                                // rehighlight the point
  176.         this->DisplayObstacles();
  177.         temp        = fPoint->RetrievePoint();
  178.         trans    = fPoint->fTrans;
  179.         fPoint->RememberPoint();
  180.         if (dInfo.lrc != NULL)
  181.             dInfo.lrc->RememberPoint();
  182.         this->DisplayIt(trans,temp);
  183.         lastTrack = temp;
  184.  
  185.         this->DisplayObstacles();
  186.         fMatrix->DoHighlight();                                                                            // rehighlight the point
  187.         ((TInformationView *) fCDocument->fInfoView)->StatusString(fPoint->fStart);    // display the status string
  188.         return;
  189.         }
  190.     
  191.     fMatrix->DoHighlight();                                                                                // rehighlight the point
  192.     if (fMatrix->IsShown())
  193.         fMatrix->DrawHold(true);    
  194.     else
  195.         {
  196.         fPoint->DrawSection(dInfo.left->fTrans);                                                    // redraw boundry line
  197.         dInfo.right->DrawSection(fPoint->fTrans);                                                // erase boundry line
  198.         fPoint->Draw();
  199.         }
  200.  
  201.     fMatrix->RetrieveAndFix2Hold();                                                                    // gets old pt back into hold & fixes it
  202.     if (fMatrix->IsShown())
  203.         fMatrix->DrawHold(true);    
  204.     else
  205.         {
  206.         fPoint->DrawSection(dInfo.left->fTrans);                                                    // redraw boundry line
  207.         dInfo.right->DrawSection(fPoint->fTrans);                                                // erase boundry line
  208.         fPoint->Draw();
  209.         }
  210.  
  211.     fMatrix->DoHighlight();                                                                                // rehighlight the point
  212.     ((TInformationView *) fCDocument->fInfoView)->StatusString(fPoint->fStart);    // display the status string
  213.     
  214.     return;
  215.     }
  216.     
  217. // --------------------------------------------------------------------------------------------------
  218. //    UnDo the command
  219. // --------------------------------------------------------------------------------------------------
  220. pascal void TDragCommand::RedoIt(void)
  221.     {
  222.     Point temp,trans;
  223.  
  224.     if (!fPoint->IsBoundryPt() || fPoint->IsCornor())
  225.         {
  226.         fMatrix->DoHighlight();                                                                        // rehighlight the point
  227.         this->DisplayObstacles();
  228.         temp        = fPoint->RetrievePoint();
  229.         trans    = fPoint->fTrans;
  230.         fPoint->RememberPoint();
  231.         if (dInfo.lrc != NULL)
  232.             dInfo.lrc->RememberPoint();
  233.         this->DisplayIt(trans,temp);
  234.         lastTrack = temp;
  235.     
  236.         this->DisplayObstacles();
  237.         fMatrix->DoHighlight();                                                                        // rehighlight the point
  238.         ((TInformationView *) fCDocument->fInfoView)->StatusString(fPoint->fStart);    // display the status string
  239.         return;
  240.         }
  241.  
  242.     fMatrix->DoHighlight();                                                                                // rehighlight the point
  243.     if (fMatrix->IsShown())
  244.         fMatrix->DrawHold(true);    
  245.     else
  246.         {
  247.         fPoint->DrawSection(dInfo.left->fTrans);                                                    // redraw boundry line
  248.         dInfo.right->DrawSection(fPoint->fTrans);                                                // erase boundry line
  249.         fPoint->Draw();
  250.         }
  251.  
  252.     fMatrix->RetrieveAndFix2Hold();                                                                    // gets old pt back into hold & fixes it
  253.     if (fMatrix->IsShown())
  254.         fMatrix->DrawHold(true);    
  255.     else
  256.         {
  257.         fPoint->DrawSection(dInfo.left->fTrans);                                                    // redraw boundry line
  258.         dInfo.right->DrawSection(fPoint->fTrans);                                                // erase boundry line
  259.         fPoint->Draw();
  260.         }
  261.  
  262.     fMatrix->DoHighlight();                                                                                // rehighlight the point
  263.     ((TInformationView *) fCDocument->fInfoView)->StatusString(fPoint->fStart);    // display the status string
  264.     
  265.     return;
  266.     }
  267.     
  268.     
  269. // --------------------------------------------------------------------------------------------------
  270. //    Track the Mouse
  271. // --------------------------------------------------------------------------------------------------
  272. pascal TCommand * TDragCommand::TrackMouse(TrackPhase thePhase, VPoint * /*anchorPoint*/,
  273.     VPoint * /*previousPoint*/, VPoint * nextPoint, Boolean mouseDidMove)
  274.     {
  275.     PointInfo     sInfo;
  276.     
  277.     fGeom->Focus();
  278.         
  279.     if (thePhase == trackRelease)                                                                    // mouse button released?
  280.         {
  281.         if (fGeom->IsDragging())                                                                        // done dragging reselect & highlight point
  282.             {
  283.             fGeom->SetDragging(false);                                                                // set dragging off
  284.             if (fMatrix->IsShown())
  285.                 {
  286.                 fPoint->DrawHold();
  287.                 fGeom->Focus();
  288.                 sInfo.gridOnly = false;                                                                    // assign opposite of fShown
  289.                 if (!fPoint->IsCornor())
  290.                     {
  291.                     if (fSide == cRight || fSide == cLeft)
  292.                         {
  293.                         HLock((Handle) this);
  294.                         sInfo.row = (fMatrix->GetRow()-1);
  295.                         fMatrix->OneRowDo(DrawAllPoints,&sInfo);
  296.                         sInfo.row = (fMatrix->GetRow()+1);
  297.                         fMatrix->OneRowDo(DrawAllPoints,&sInfo);
  298.                         HUnlock((Handle) this);
  299.                         }
  300.                     else if (fSide == cTop || fSide == cBottom)
  301.                         {
  302.                         HLock((Handle) this);
  303.                         sInfo.column = (fMatrix->GetColumn()-1);
  304.                         fMatrix->OneColumnDo(DrawPoint,&sInfo);
  305.                         sInfo.column = (fMatrix->GetColumn()+1);
  306.                         fMatrix->OneColumnDo(DrawPoint,&sInfo);
  307.                         HUnlock((Handle) this);
  308.                         }
  309.                     }
  310.                 }                    
  311.             }
  312.         else                                                                                                        // wasn't dragging in the first place
  313.             return gNoChanges;                                                                            // do nothing
  314.         }
  315.     else if (!fGeom->IsDragging())                                                                    // starting to drag point unselect & unhighlight
  316.         {
  317.         fGeom->lastCmd = 1;
  318.         fGeom->SetDragging(true);                                                                    // set dragging on
  319.         fMatrix->DoHighlight();                                                                        // unhighlight point
  320.         fPoint->RememberPoint();                                                                    // remember starting location
  321.         if (!fPoint->IsCornor() && fPoint->IsBoundryPt())
  322.             {
  323.             if (fSide == cRight || fSide  == cLeft)
  324.                 {
  325.                 TRow * tRow;
  326.                 short      r;
  327.                 r = fMatrix->GetRow();
  328.                 tRow = (TRow *) fMatrix->At(r);
  329.                 fLength = tRow->GetLength(NULL);                                                // the cumulative length of the row
  330.                 tRow->RememberRow();                                                                // all points in row remember self
  331.                 }
  332.             else if (fSide == cTop || fSide == cBottom)
  333.                 {
  334.                 short c;
  335.                 c = fMatrix->GetColumn();
  336.                 fLength = fMatrix->GetColumnLength(c);
  337.                 fMatrix->RememberColumn();                                                        // all points in column remember self
  338.                 }
  339.             if (fMatrix->IsShown())
  340.                 fMatrix->DrawHold(true);
  341.             else
  342.                 {
  343.                 fPoint->DrawSection(dInfo.left->fTrans);                                        // redraw boundry line
  344.                 dInfo.right->DrawSection(fPoint->fTrans);                                    // erase boundry line
  345.                 fPoint->Draw();
  346.                 }
  347.             }
  348.         else
  349.             this->DisplayObstacles();
  350.         }
  351.         
  352.     if (mouseDidMove)                                                                                    // did the mouse move?
  353.         {
  354.         Point tmp, tmp1; 
  355.         tmp1 = VPtToPt (nextPoint);                                                                    // convert nextpoint to view point
  356.         tmp = AntiTransform(tmp1,fGeom->fMagnify);
  357.         
  358.         ((TInformationView *) fCDocument->fInfoView)->StatusString(tmp);    // display the status string
  359.         }
  360.     return this;                                                                                                // return this command to MacApp
  361.     }
  362.  
  363. // -------------------------------------------------------------------------------------------------
  364. //    tracking feedback. limit the mouse motion to the geometry not including the border.
  365. // -------------------------------------------------------------------------------------------------
  366. pascal void TDragCommand::TrackConstrain (VPoint * /*ancorPoint*/, 
  367.             VPoint * /*previousPoint*/, VPoint * nextPoint)    
  368.     {
  369.     if (nextPoint->v <= 5)                                                                                // limit the verticle dimension
  370.         nextPoint->v = 5;
  371.     else
  372.         if (nextPoint->v >= fGeom->fSize.v - 5)
  373.             nextPoint->v = fGeom->fSize.v - 5;
  374.  
  375.     if (nextPoint->h <= 5)                                                                                // limit the horizontal dimension
  376.         nextPoint->h = 5;
  377.     else
  378.         if (nextPoint->h >= fGeom->fSize.h - 5)
  379.             nextPoint->h = fGeom->fSize.h - 5;
  380. }
  381.  
  382. // --------------------------------------------------------------------------------------------------
  383. //    Give user feedback on the mouse drag
  384. // --------------------------------------------------------------------------------------------------
  385. pascal void TDragCommand::TrackFeedback(VPoint * /*anchorPoint*/,VPoint * nextPoint, 
  386.     Boolean /*turnItOn*/, Boolean mouseDidMove)
  387.     {
  388. //
  389. //    lastTrack is thisPoint the last time through this method.  It is initialized to the fStart point
  390. //    of the selected segment in IDragPointCommand Method.
  391. //
  392.     fGeom->Focus();                                                                                        // focus on geomview
  393.     if (mouseDidMove)                                                                                    // did the mouse move
  394.         {
  395.         Point tmp, thisPoint;
  396.         
  397.         tmp = fGeom->ViewToQDPt(nextPoint);                                                    // get quick draw coordinates
  398.         thisPoint = AntiTransform(tmp,fGeom->fMagnify);
  399.         fPt = thisPoint;
  400.         this->DisplayIt(tmp,thisPoint);                                                                // display the lines.        
  401.         lastTrack = thisPoint;                                                                            // reset tracking point
  402.         }
  403.     return;                                                                                                        // return
  404.     }
  405.     
  406. // --------------------------------------------------------------------------------------------------
  407. //    Move the Point (called from TInformationView::DoChoice)
  408. // --------------------------------------------------------------------------------------------------
  409.  void TDragCommand::MovePoint(void)
  410.     {
  411.     Point tmp;
  412.     PointInfo     sInfo;
  413.     tmp = fPoint->fTrans;
  414.     
  415.     fGeom->Focus();                                                                                    // focus on geometry
  416.     fPoint->RememberPoint();                                                                    // remember starting location
  417.     if (!fPoint->IsCornor() && fPoint->IsBoundryPt())
  418.         {
  419.         if (fSide == cRight || fSide  == cLeft)
  420.             {
  421.             TRow * tRow;
  422.             short      r;
  423.             r = fMatrix->GetRow();
  424.             tRow = (TRow *) fMatrix->At(r);
  425.             fLength = tRow->GetLength(NULL);                                                // the cumulative length of the row
  426.             tRow->RememberRow();                                                                // all points in row remember self
  427.             }
  428.         else if (fSide == cTop || fSide == cBottom)
  429.             {
  430.             short c;
  431.             c = fMatrix->GetColumn();
  432.             fLength = fMatrix->GetColumnLength(c);
  433.             fMatrix->RememberColumn();                                                        // all points in column remember self
  434.             }
  435.         if (fMatrix->IsShown())
  436.             fMatrix->DrawHold(true);
  437.         else
  438.             {
  439.             fPoint->DrawSection(dInfo.left->fTrans);                                        // redraw boundry line
  440.             dInfo.right->DrawSection(fPoint->fTrans);                                    // erase boundry line
  441.             fPoint->Draw();
  442.             }
  443.         fPoint->SetHold(fMouse.v,fMouse.h);
  444.         fMatrix->MovePoints(fMouse,fLength);
  445.         }
  446.     else
  447.         {
  448.         Point tmp, thisPoint;
  449.         VPoint t;
  450.         t.h = fMouse.h;
  451.         t.v = fMouse.v;
  452.         tmp = fGeom->ViewToQDPt(&t);
  453.         thisPoint = AntiTransform(tmp,fGeom->fMagnify);
  454.         this->DisplayIt(tmp,thisPoint);
  455.         this->DisplayObstacles();
  456.         }
  457.     
  458.     this->DoIt();
  459.     fGeom->Focus();
  460.  
  461.     if (fMatrix->IsShown())
  462.         {
  463.         if (!fPoint->IsCornor())
  464.             {
  465.             sInfo.gridOnly = false;                                                                        // assign opposite of fShown
  466.  
  467.             if (fSide == cRight || fSide == cLeft)
  468.                 {
  469.                 HLock((Handle) this);
  470.                 sInfo.row = (fMatrix->GetRow()-1);
  471.                 fMatrix->OneRowDo(DrawAllPoints,&sInfo);
  472.                 sInfo.row = (fMatrix->GetRow()+1);
  473.                 fMatrix->OneRowDo(DrawAllPoints,&sInfo);
  474.                 HUnlock((Handle) this);
  475.                 }
  476.             else if (fSide == cTop || fSide == cBottom)
  477.                 {
  478.                 HLock((Handle) this);
  479.                 sInfo.column = (fMatrix->GetColumn()-1);
  480.                 fMatrix->OneColumnDo(DrawPoint,&sInfo);
  481.                 sInfo.column = (fMatrix->GetColumn()+1);
  482.                 fMatrix->OneColumnDo(DrawPoint,&sInfo);
  483.                 HUnlock((Handle) this);
  484.                 }
  485.             } 
  486.         }                
  487.     return;                                                                                                        // return;
  488.     }
  489.     
  490.