예제 #1
0
 public void MouseDown(DTkViewer dv, DMouseButton btn, DPoint pt)
 {
     IGlyph glyph;
     if (editing && HitTest(pt, null, out glyph) == DHitTest.Body)
     {
         DRect r = GetClockRect();
         DPoint fhp = FirstHandPoint(r);
         DPoint shp = SecondHandPoint(r);
         if (DGeom.DistBetweenTwoPts(pt, fhp) <= DGeom.DistBetweenTwoPts(pt, shp))
         {
             editingFirstHand = true;
             firstHandAngle.Value = DGeom.AngleBetweenPoints(r.Center, pt);
         }
         else
         {
             editingSecondHand = true;
             secondHandAngle.Value = DGeom.AngleBetweenPoints(r.Center, pt);
         }
         dv.Update(r);
     }
     else
         DoEditFinished();
 }
예제 #2
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoDrawingLineMouseMove(DTkViewer dv, DPoint pt)
 {
     // initial update rect
     DRect updateRect = currentFigure.GetSelectRect();
     // bound pt to canvas
     BoundPtToPage(pt);
     // add point
     if (currentFigure is IPolyline)
     {
         if (!(currentFigure is IRepositionPoint))
             ((IPolyline)currentFigure).AddPoint(pt);
         else
             ((IPolyline)currentFigure).LastPoint = pt;
     }
     // update drawing
     dv.Update(updateRect.Union(currentFigure.GetSelectRect()));
 }
예제 #3
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoDrawingLineMouseUp(DTkViewer dv, DMouseButton btn, DPoint pt)
 {
     if (currentFigure is IPolyline)
     {
         if (!(currentFigure is IRepositionPoint))
         {
             // test for finished line
             bool lineNotFinished = false;
             if (((IPolyline)currentFigure).Points.Count < 2)
             {
                 if (UsePolylineDots)
                 {
                     DPoint currentPt = ((IPolyline)currentFigure).Points[0];
                     DPoint newPt = new DPoint(currentPt.X + 0.01, currentPt.Y + 0.01);
                     ((IPolyline)currentFigure).Points.Add(newPt);
                 }
                 else
                     lineNotFinished = true;
             }
             if (!lineNotFinished)
             {
                 // simplify polyline
                 if (SimplifyPolylines && currentFigure is IPolyline)
                 {
                     ((IPolyline)currentFigure).Points = DGeom.SimplifyPolyline(((IPolyline)currentFigure).Points, simplifyPolylinesTolerance);
                     dv.Update(currentFigure.GetSelectRect());
                 }
                 // auto group
                 if (autoGroupPolylineTimeoutMet)
                 {
                     autoGroupPolylineXLimitMet = DGeom.DistXBetweenRects(autoGroupPolylineFigure.GetEncompassingRect(),
                         currentFigure.GetEncompassingRect()) < autoGroupPolylinesXLimit;
                     autoGroupPolylineYLimitMet = DGeom.DistYBetweenRects(autoGroupPolylineFigure.GetEncompassingRect(),
                         currentFigure.GetEncompassingRect()) < autoGroupPolylinesYLimit;
                     if (autoGroupPolylineXLimitMet && autoGroupPolylineYLimitMet)
                     {
                         if (autoGroupPolylineFigure is GroupFigure)
                         {
                             figureHandler.Remove(currentFigure);
                             IChildFigureable cf = (IChildFigureable)autoGroupPolylineFigure;
                             cf.ChildFigures.Add(currentFigure);
                             cf.ChildFigures = cf.ChildFigures;
                         }
                         else if (autoGroupPolylineFigure is IPolyline)
                         {
                             figureHandler.Remove(autoGroupPolylineFigure);
                             figureHandler.Remove(currentFigure);
                             GroupFigure gf = new GroupFigure(new List<Figure>(new Figure[] { autoGroupPolylineFigure, currentFigure }));
                             figureHandler.Add(gf, false);
                             autoGroupPolylineFigure = gf;
                         }
                     }
                     else
                         autoGroupPolylineFigure = currentFigure;
                 }
             }
             autoGroupPolylineStart = Environment.TickCount;
         }
     }
     // commit to undo/redo
     CommitOrRollback(false);
     // transition
     TransitionTo(DrawLineDefault);
 }
예제 #4
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoDragFigureMouseMove(DTkViewer dv, DPoint pt)
 {
     // rectangular area to update with paint event
     DRect updateRect = new DRect();
     // move selected figures
     switch (mouseHitTest)
     {
         case DHitTest.Body:
             System.Diagnostics.Trace.Assert(currentFigure != null, "currentFigure is null");
             // drag figure event
             if (DragFigureEvt != null)
                 DragFigureEvt(null, currentFigure, dv.EngineToClient(pt));
             // if figure drag op is cancelled then quit this function
             if (cancelledFigureDrag)
             {
                 cancelledFigureDrag = false;
                 return;
             }
             // bound pt to canvas
             BoundPtToPage(pt);
             // initial update rect
             updateRect = GetBoundingBox(currentFigure);
             foreach (Figure f in figureHandler.SelectedFigures)
                 updateRect = updateRect.Union(GetBoundingBox(f));
             // apply x/y delta to figures
             DPoint dPos = CalcDragDelta(pt);
             if (gridSnapPosition && grid > 0)
             {
                 DPoint o = GridSnapOffset(currentFigure.X + dPos.X, currentFigure.Y + dPos.Y);
                 dPos.X += o.X;
                 dPos.Y += o.Y;
                 pt.X += o.X;
                 pt.Y += o.Y;
             }
             if (dPos.X != 0 || dPos.Y != 0)
                 foreach (Figure f in figureHandler.SelectedFigures)
                     if (!f.Locked)
                     {
                         f.X += dPos.X;
                         f.Y += dPos.Y;
                     }
             // store drag pt for reference later (eg. next mousemove event)
             dragPt = pt;
             // final update rect
             foreach (Figure f in figureHandler.SelectedFigures)
                 updateRect = updateRect.Union(GetBoundingBox(f));
             break;
         case DHitTest.SelectRect:
             goto case DHitTest.Body;
         case DHitTest.Resize:
             System.Diagnostics.Trace.Assert(currentFigure != null, "currentFigure is null");
             // bound pt to canvas
             BoundPtToPage(pt);
             // alert figure we are going to resize it
             currentFigure.BeforeResize();
             // inital update rect
             updateRect = GetBoundingBox(currentFigure);
             // translate point onto the same rotated plane as the figure
             pt = currentFigure.RotatePointToFigure(pt);
             // apply width/height delta to figure
             DPoint dSize = CalcSizeDelta(pt, currentFigure, LockingAspectRatio || currentFigure.LockAspectRatio);
             if (lockInitialAspectRatio && !(figureLockAspectRatioMode == DHsmLockAspectRatioMode.Always || currentFigure.LockAspectRatio))
             {
                 DPoint dSizeUnlocked = CalcSizeDelta(pt, currentFigure, false);
                 if (figureLockAspectRatioMode == DHsmLockAspectRatioMode.Never ||
                     Math.Abs(dSizeUnlocked.X - dSize.X) >= unlockInitalAspectRatioThreshold ||
                     Math.Abs(dSizeUnlocked.Y - dSize.Y) >= unlockInitalAspectRatioThreshold)
                 {
                      lockInitialAspectRatio = false;
                     dSize = dSizeUnlocked;
                 }
             }
             if (currentFigure.Width > 0 && currentFigure.Width + dSize.X < currentFigure.MinSize)
             {
                 dSize.X = currentFigure.MinSize - currentFigure.Width;
                 if (LockingAspectRatio || currentFigure.LockAspectRatio)
                     dSize.Y = (currentFigure.Height / currentFigure.Width) * dSize.X;
             }
             if (currentFigure.Height > 0 && currentFigure.Height + dSize.Y < currentFigure.MinSize)
             {
                 dSize.Y = currentFigure.MinSize - currentFigure.Height;
                 if (LockingAspectRatio || currentFigure.LockAspectRatio)
                     dSize.X = (currentFigure.Width / currentFigure.Height) * dSize.Y;
             }
             DRect oldRect = currentFigure.Rect;
             currentFigure.Width += dSize.X;
             currentFigure.Height += dSize.Y;
             // snap resize
             if (gridSnapResize && grid > 0)
             {
                 DPoint o2 = GridSnapOffset(currentFigure.Width, currentFigure.Height);
                 currentFigure.Width += o2.X;
                 currentFigure.Height += o2.Y;
             }
             DGeom.UpdateRotationPosition(currentFigure, oldRect, currentFigure.Rect);
             // final update rect
             updateRect = updateRect.Union(GetBoundingBox(currentFigure));
             // alert figure we have finished resizing
             currentFigure.AfterResize();
             // debug message
     #if DEBUG
             DoDebugMessage(string.Format("{0} {1}", dSize.X, dSize.Y));
     #endif
             break;
         case DHitTest.RepositionPoint:
             System.Diagnostics.Trace.Assert(currentFigure != null, "currentFigure is null");
             // bound pt to canvas
             BoundPtToPage(pt);
             // inital update rect
             updateRect = GetBoundingBox(currentFigure);
             // get our reposition point interface
             IRepositionPoint rp = (IRepositionPoint)currentFigure;
             // setup points
             DPoint newPoint;
             newPoint = new DPoint(pt.X, pt.Y);
             SetPointDelegate setPoint = delegate(DPoint point)
             {
                 // snap point to grid
                 if (gridSnapLines && grid > 0)
                 {
                     DPoint o3 = GridSnapOffset(point.X, point.Y);
                     point.X += o3.X;
                     point.Y += o3.Y;
                 }
                 // now set point
                 rp.RepositionPoint = point;
             };
             GetRotationalSnapDelegate getRotationalSnap = delegate(double angleRemainder)
             {
                 if (angleRemainder < figureSnapRange)
                     return -angleRemainder;
                 else if (angleRemainder > figureSnapAngle - figureSnapRange)
                     return figureSnapAngle - angleRemainder;
                 else
                     return 0;
             };
             if (rp.AnglePoint != null)
             {
                 // find the current angle of the line and the remainder when divided by the snap angle
                 double currentAngle = DGeom.AngleBetweenPoints(rp.RepositionPoint, rp.AnglePoint);
                 double ar = currentAngle % figureSnapAngle;
                 // reposition line
                 double newAngle;
                 switch (FigureSnapAngleMode)
                 {
                     case DHsmSnapAngleMode.Always:
                         // slide point along snap angle
                         newAngle = DGeom.AngleBetweenPoints(newPoint, rp.AnglePoint);
                         ar = newAngle % figureSnapAngle;
                         if (ar < figureSnapAngle / 2)
                             setPoint(DGeom.RotatePoint(newPoint, rp.AnglePoint, -ar));
                         else
                             setPoint(DGeom.RotatePoint(newPoint, rp.AnglePoint, figureSnapAngle - ar));
                         break;
                     case DHsmSnapAngleMode.Default:
                         if (ar == 0)
                         {
                             // line is snapped, test if new angle will unsnap the line
                             newAngle = DGeom.AngleBetweenPoints(newPoint, rp.AnglePoint);
                             ar = newAngle % figureSnapAngle;
                             if (ar > figureSnapRange && ar < figureSnapAngle - figureSnapRange)
                                 // unsnapped, set new point
                                 setPoint(newPoint);
                             else
                             {
                                 // slide point along snap angle
                                 newPoint = DGeom.RotatePoint(newPoint, rp.AnglePoint, getRotationalSnap(ar));
                                 setPoint(newPoint);
                             }
                         }
                         else
                         {
                             // set new point
                             setPoint(newPoint);
                             // test whether to snap our line
                             newAngle = DGeom.AngleBetweenPoints(newPoint, rp.AnglePoint);
                             ar = newAngle % figureSnapAngle;
                             double rotationalSnap = getRotationalSnap(ar);
                             // snap it
                             if (rotationalSnap != 0)
                                 setPoint(DGeom.RotatePoint(newPoint, rp.AnglePoint, rotationalSnap));
                         }
                         break;
                     case DHsmSnapAngleMode.Never:
                         // set new point
                         setPoint(newPoint);
                         break;
                 }
             }
             else
                 setPoint(newPoint);
             // final update rect
             updateRect = updateRect.Union(GetBoundingBox(currentFigure));
             break;
         case DHitTest.Rotate:
             System.Diagnostics.Trace.Assert(currentFigure != null, "currentFigure is null");
             // initial update rect
             updateRect = GetBoundingBox(currentFigure);
             // apply rotation to figure
             double newRot = GetRotationOfPointComparedToFigure(currentFigure, pt) - dragRot;
             double r = newRot % figureSnapAngle;
             switch (figureSnapAngleMode)
             {
                 case DHsmSnapAngleMode.Always:
                     if (r < figureSnapAngle / 2)
                         currentFigure.Rotation = newRot - r;
                     else
                         currentFigure.Rotation = newRot + figureSnapAngle - r;
                     break;
                 case DHsmSnapAngleMode.Default:
                     if (r < figureSnapRange)
                         currentFigure.Rotation = newRot - r;
                     else if (r > figureSnapAngle - figureSnapRange)
                         currentFigure.Rotation = newRot + figureSnapAngle - r;
                     else
                         currentFigure.Rotation = newRot;
                     break;
                 case DHsmSnapAngleMode.Never:
                     currentFigure.Rotation = newRot;
                     break;
             }
             // final update rect
             updateRect = updateRect.Union(GetBoundingBox(currentFigure));
     #if DEBUG
             // debug message
             DoDebugMessage((currentFigure.Rotation * 180 / Math.PI).ToString());
     #endif
             break;
     }
     // update drawing
     dv.Update(updateRect);
 }
예제 #5
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoDragSelectMouseMove(DTkViewer dv, DPoint pt)
 {
     // rectangular area to update with paint event
     DRect updateRect = new DRect();
     // initial update rect
     updateRect = figureHandler.SelectionFigure.Rect;
     // drag select figure
     figureHandler.SelectionFigure.TopLeft = dragPt;
     figureHandler.SelectionFigure.BottomRight = pt;
     if (figureHandler.SelectionFigure.Width < 0)
     {
         figureHandler.SelectionFigure.X += figureHandler.SelectionFigure.Width;
         figureHandler.SelectionFigure.Width = -figureHandler.SelectionFigure.Width;
     }
     if (figureHandler.SelectionFigure.Height < 0)
     {
         figureHandler.SelectionFigure.Y += figureHandler.SelectionFigure.Height;
         figureHandler.SelectionFigure.Height = -figureHandler.SelectionFigure.Height;
     }
     // final update rect
     updateRect = updateRect.Union(figureHandler.SelectionFigure.Rect);
     // update drawing
     dv.Update(updateRect);
 }
예제 #6
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoDrawingRectMouseUp(DTkViewer dv, DMouseButton btn, DPoint pt)
 {
     CommitOrRollback(true);
     // transition
     TransitionTo(DrawRectDefault);
     // update drawing
     dv.Update(figureHandler.SelectionFigure.Rect);
 }
예제 #7
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoTextEditMouseMove(DTkViewer dv, DPoint pt)
 {
     TextEditFigure tef = (TextEditFigure)currentFigure;
     if (textEditMouseDown)
     {
         if (textEditChangeTextWrap)
         {
             dv.Update(GetBoundingBox(tef));
             if (!tef.WrapText)
             {
                 tef.WrapFontSize = tef.FontSize;
                 tef.WrapThreshold = tef.Width - tef.BorderWidth * 2;
                 tef.WrapText = true;
                 textEditDragWrapOffset = tef.X + tef.BorderWidth + tef.WrapLength - pt.X;
             }
             const int threshBase = 200;
             tef.WrapThreshold = threshBase * ((pt.X - (tef.X + tef.BorderWidth) + textEditDragWrapOffset) /
                 (threshBase * tef.FontSize / tef.WrapFontSize));
             dv.Update(GetBoundingBox(tef));
         }
         else if (textEditMove)
         {
             // bound pt to canvas
             BoundPtToPage(pt);
             // initial update rect
             DRect updateRect = GetBoundingBox(tef);
             // move text edit figure
             tef.X += pt.X - dragPt.X;
             tef.Y += pt.Y - dragPt.Y;
             dragPt = pt;
             // update
             dv.Update(updateRect.Union(GetBoundingBox(tef)));
         }
         else
         {
             tef.SetCursorPoint(pt, true);
             dv.Update(currentFigure.Rect);
         }
     }
     else
     {
         IGlyph glyph;
         if (currentFigure.HitTest(pt, null, out glyph) == DHitTest.Body)
         {
             if (tef.HitTestTextWrapHandle(pt))
                 dv.SetCursor(DCursor.MoveWE);
             else if (tef.HitTestBorder(pt))
                 dv.SetCursor(DCursor.MoveAll);
             else
                 dv.SetCursor(DCursor.IBeam);
         }
         else
             DoSelectDefaultMouseMove(dv, pt);
     }
 }
예제 #8
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoTextEditDoubleClick(DTkViewer dv, DMouseButton b, DPoint pt)
 {
     ((TextEditFigure)currentFigure).DoubleClick(pt);
     dv.Update(currentFigure.Rect);
 }
예제 #9
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoTextEditKeyPress(DTkViewer dv, int k)
 {
     if (currentFigure != null && currentFigure is TextEditFigure)
     {
         TextEditFigure te = (TextEditFigure)currentFigure;
         DRect updateRect = te.Rect;
         switch ((DKeys)k)
         {
             case DKeys.Backspace:
                 te.BackspaceAtCursor();
                 break;
             case DKeys.Enter:
                 te.InsertAtCursor('\n');
                 break;
             case DKeys.Escape:
                 TransitionTo(SelectDefault);
                 return;
             case DKeys.Delete:
                 te.DeleteAtCursor();
                 break;
             case DKeys.Left:
                 te.MoveCursor((DKeys)k, textEditKey.Ctrl, textEditKey.Shift);
                 break;
             case DKeys.Right: goto case DKeys.Left;
             case DKeys.Up: goto case DKeys.Left;
             case DKeys.Down: goto case DKeys.Left;
             case DKeys.Home: goto case DKeys.Left;
             case DKeys.End: goto case DKeys.Left;
             case DKeys.PageUp: break;
             case DKeys.PageDown: break;
             default:
                 te.InsertAtCursor((char)k);
                 break;
         }
         dv.Update(updateRect.Union(te.Rect));
     }
 }
예제 #10
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoSelectDefaultMouseMove(DTkViewer dv, DPoint pt)
 {
     // set cursor
     DHitTest hitTest;
     List<Figure> children = new List<Figure>();
     IGlyph glyph;
     Figure f = figureHandler.HitTestFigures(pt, out hitTest, children, out glyph);
     // set mouseover
     if (f != null && !f.MouseOver)
     {
         f.MouseOver = true;
         dv.Update(GetBoundingBox(f));
     }
     foreach (Figure otherFig in figureHandler.Figures)
         if (otherFig != f && otherFig.MouseOver)
         {
             otherFig.MouseOver = false;
             dv.Update(GetBoundingBox(otherFig));
         }
     // set cursor
     switch (hitTest)
     {
         case DHitTest.None:
             dv.SetCursor(DCursor.Default);
             break;
         case DHitTest.Body:
             if (f.Locked)
                 dv.SetCursor(DCursor.Default);
             else
                 dv.SetCursor(DCursor.MoveAll);
             if (f.ClickEvent)
                 dv.SetCursor(DCursor.Hand);
             else
                 foreach (Figure child in children)
                     if (child.ClickEvent)
                     {
                         dv.SetCursor(DCursor.Hand);
                         break;
                     }
             break;
         case DHitTest.SelectRect:
             goto case DHitTest.Body;
         case DHitTest.Resize:
             dv.SetCursor(DCursor.MoveNWSE);
             break;
         case DHitTest.RepositionPoint:
             goto case DHitTest.Resize;
         case DHitTest.Rotate:
             dv.SetCursor(DCursor.Rotate);
             break;
         case DHitTest.Context:
             dv.SetCursor(DCursor.Hand);
             break;
         case DHitTest.Lock:
             goto case DHitTest.Context;
         case DHitTest.Glyph:
             dv.SetCursor(glyph.Cursor);
             break;
     }
     #if DEBUG
     DoDebugMessage(string.Format("{0}, {1}", pt.X, pt.Y));
     #endif
 }
예제 #11
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoSelectDefaultMouseUp(DTkViewer dv, DMouseButton btn, DPoint pt)
 {
     DHitTest hitTest;
     List<Figure> children = new List<Figure>();
     IGlyph glyph;
     if (btn == DMouseButton.Left)
     {
         Figure f = figureHandler.HitTestFigures(pt, out hitTest, children, out glyph);
         if (hitTest == DHitTest.Glyph)
         {
             if (children.Count > 0)
                 glyph.CallClicked(children[0], dv.EngineToClient(pt));
             else
                 glyph.CallClicked(f, dv.EngineToClient(pt));
         }
         else if ((hitTest == DHitTest.Body || hitTest == DHitTest.SelectRect) && FigureClick != null)
         {
             foreach (Figure child in children)
                 if (child.ClickEvent)
                     FigureClick(null, child, dv.EngineToClient(pt));
             if (f.ClickEvent)
                 FigureClick(null, f, dv.EngineToClient(pt));
             if (FiguresDeselectOnSingleClick && !FigureSelectToggleToSelection)
             {
                 figureHandler.SelectFigures(new List<Figure>(new Figure[] { f }), false);
                 dv.Update();
             }
         }
     }
     else if (btn == DMouseButton.Right)
     {
         Figure f = figureHandler.HitTestSelect(pt, out hitTest, null, out glyph, figureSelectToggleToSelection);
         dv.SetCursor(DCursor.Default);
         dv.Update();
         if (ContextClick != null)
             ContextClick(null, f, dv.EngineToClient(pt));
     }
     // nullify current figure for DoSelectDefault -> DHsmSignals.MouseMove:
     currentFigure = null;
 }
예제 #12
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
        void DoSelectDefaultMouseDown(DTkViewer dv, DMouseButton btn, DPoint pt)
        {
            if (btn == DMouseButton.Left)
            {
                // find and select clicked figure
                List<Figure> children = new List<Figure>();
                IGlyph glyph;
                Figure f = figureHandler.HitTestSelect(pt, out mouseHitTest, children, out glyph, figureSelectToggleToSelection);
                // update selected figures
                if (glyph != null)
                {

                }
                else if (f != null)
                {
                    // set drag infomation
                    currentFigure = f;
                    switch (mouseHitTest)
                    {
                        case DHitTest.Body:
                            // store drag point
                            dragPt = pt;
                            if (!f.Locked)
                            {
                                // drag figure start event
                                if (DragFigureStart != null)
                                    DragFigureStart(null, f, dv.EngineToClient(pt));
                            }
                            break;
                        case DHitTest.SelectRect:
                            goto case DHitTest.Body;
                        case DHitTest.Resize:
                            dragPt = new DPoint(0, 0);
                            dragPt = CalcSizeDelta(f.RotatePointToFigure(pt), f, LockingAspectRatio || f.LockAspectRatio);
                            lockInitialAspectRatio = figureLockAspectRatioMode == DHsmLockAspectRatioMode.Default;
                            break;
                        case DHitTest.RepositionPoint:
                            break;
                        case DHitTest.Rotate:
                            dragRot = GetRotationOfPointComparedToFigure(f, pt) - f.Rotation;
                            if (dragRot > Math.PI)
                                dragRot = dragRot - (Math.PI * 2);
                            break;
                        case DHitTest.Context:
                            if (FigureContextClick != null)
                                FigureContextClick(null, f, dv.EngineToClient(pt));
                            break;
                        case DHitTest.Lock:
                            if (FigureLockClick != null)
                                FigureLockClick(null, f, dv.EngineToClient(pt));
                            break;
                    }
                }
                else
                {
                    if (!figureSelectToggleToSelection)
                        figureHandler.ClearSelected();
                    dragPt = pt; // mouseHitTest = DHitTest.None
                    // transition
                    TransitionTo(DragSelect);
                }
                // update drawing
                dv.Update();
            }
        }
예제 #13
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoSelectDefaultKeyPress(DTkViewer dv, int k)
 {
     int dx = 0, dy = 0;
     switch (k)
     {
         case (int)DKeys.Left:
             dx = -keyMovementRate;
             break;
         case (int)DKeys.Right:
             dx = keyMovementRate;
             break;
         case (int)DKeys.Up:
             dy = -keyMovementRate;
             break;
         case (int)DKeys.Down:
             dy = keyMovementRate;
             break;
     }
     if (dx != 0 || dy != 0)
     {
         undoRedoArea.Start(moveName, this);
         foreach (Figure f in figureHandler.SelectedFigures)
         {
             f.X += dx;
             f.Y += dy;
         }
         undoRedoArea.Commit();
         dv.Update();
     }
 }
예제 #14
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoDrawTextMouseDown(DTkViewer dv, DMouseButton btn, DPoint pt)
 {
     if (btn == DMouseButton.Left)
     {
         undoRedoArea.Start(addTextName);
         // bound pt to canvas
         BoundPtToPage(pt);
         // create TextFigure
         currentFigure = new TextFigure(pt, "", 0);
         // add to list of figures
         figureHandler.Add(currentFigure, true);
         // update DViewer
         dv.Update();
         // transition
         TransitionTo(TextEdit);
     }
 }
예제 #15
0
 public void MouseMove(DTkViewer dv, DPoint pt)
 {
     IGlyph glyph;
     if (editingFirstHand)
     {
         firstHandAngle.Value = DGeom.AngleBetweenPoints(GetClockRect().Center, pt);
         dv.Update(GetClockRect());
     }
     else if (editingSecondHand)
     {
         secondHandAngle.Value = DGeom.AngleBetweenPoints(GetClockRect().Center, pt);
         dv.Update(GetClockRect());
     }
     else if (editing && HitTest(pt, null, out glyph) == DHitTest.Body)
         dv.SetCursor(DCursor.Crosshair);
     else
         dv.SetCursor(DCursor.Default);
 }
예제 #16
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoTextEditMouseDown(DTkViewer dv, DMouseButton btn, DPoint pt)
 {
     if (btn == DMouseButton.Left)
     {
         TextEditFigure tef = (TextEditFigure)currentFigure;
         IGlyph glyph;
         if (currentFigure.HitTest(pt, null, out glyph) == DHitTest.Body)
         {
             textEditMouseDown = true;
             textEditChangeTextWrap = tef.HitTestTextWrapHandle(pt);
             textEditMove = tef.HitTestBorder(pt);
             if (textEditChangeTextWrap)
                 textEditDragWrapOffset = tef.X + tef.BorderWidth + tef.WrapLength - pt.X;
             if (textEditMove)
                 dragPt = pt;
             else
             {
                 tef.SetCursorPoint(pt, false);
                 dv.Update(currentFigure.Rect);
             }
         }
         else
         {
             // find and select clicked figure
             Figure f = figureHandler.HitTestSelect(pt, out mouseHitTest, null, out glyph, false);
             // select the TextFigure from the TextEditFigure
             if (f == tef)
             {
                 if (tef.HasText)
                 {
                     f = tef.Figure;
                     figureHandler.SelectFigures(new List<Figure>(new Figure[] { f }), false);
                 }
             }
             // setup for select mouse move
             dragPt = pt;
             // transition to select state
             TransitionTo(DragFigure);
             currentFigure = f;
         }
     }
     else if (btn == DMouseButton.Right)
         TransitionTo(Select);
 }
예제 #17
0
 public static void PreviewFigure(DEngine de, DTkViewer dv, Type figureClass, DAuthorProperties dap, DPoint viewerSize)
 {
     // add figure de so it shows on the viewer
     de.UndoRedo.Start("blah");
     de.ClearPage();
     Figure f = (Figure)Activator.CreateInstance(figureClass);
     dap.ApplyPropertiesToFigure(f);
     if (f is PolylineFigure)
     {
         DPoints pts = new DPoints();
         pts.Add(new DPoint(viewerSize.X / 4.0, viewerSize.Y / 4.0));
         pts.Add(new DPoint(viewerSize.X * 1.25 / 4.0, viewerSize.Y * 1.10 / 4.0));
         pts.Add(new DPoint(viewerSize.X * 1.50 / 4.0, viewerSize.Y * 1.25 / 4.0));
         pts.Add(new DPoint(viewerSize.X * 1.75 / 4.0, viewerSize.Y * 1.50 / 4.0));
         pts.Add(new DPoint(viewerSize.X * 2.00 / 4.0, viewerSize.Y * 1.75 / 4.0));
         pts.Add(new DPoint(viewerSize.X * 2.25 / 4.0, viewerSize.Y * 2.00 / 4.0));
         pts.Add(new DPoint(viewerSize.X * 2.50 / 4.0, viewerSize.Y * 2.25 / 4.0));
         pts.Add(new DPoint(viewerSize.X * 2.75 / 4.0, viewerSize.Y * 2.50 / 4.0));
         pts.Add(new DPoint(viewerSize.X * 3 / 4.0, viewerSize.Y * 3 / 4.0));
         ((PolylineFigure)f).Points = pts;
     }
     else if (f is ITextable)
         ((ITextable)f).Text = "Aa";
     f.Left = viewerSize.X / 4.0;
     f.Top = viewerSize.Y / 4.0;
     f.Width = viewerSize.X / 2.0;
     f.Height = viewerSize.Y / 2.0;
     if (f is TextFigure)
     {
         f.Left = viewerSize.X / 8.0;
         f.Width = viewerSize.X * 3 / 4.0;
     }
     de.AddFigure(f);
     de.UndoRedo.Commit();
     dv.Update();
 }
예제 #18
0
파일: DHsm.cs 프로젝트: djpnewton/ddraw
 void DoDrawingRectMouseMove(DTkViewer dv, DPoint pt)
 {
     // initial update rect
     DRect updateRect = currentFigure.GetSelectRect();
     // bound pt to canvas
     BoundPtToPage(pt);
     // change dimensions
     if (pt.X >= dragPt.X)
         currentFigure.Right = pt.X;
     else
     {
         currentFigure.Left = pt.X;
         currentFigure.Right = dragPt.X;
     }
     if ((figureLockAspectRatioMode == DHsmLockAspectRatioMode.Always) || currentFigure.LockAspectRatio)
     {
         currentFigure.Height = currentFigure.Width;
         if (pt.Y >= dragPt.Y)
             currentFigure.Top = dragPt.Y;
         else
             currentFigure.Top = dragPt.Y - currentFigure.Height;
     }
     else
     {
         if (pt.Y >= dragPt.Y)
             currentFigure.Bottom = pt.Y;
         else
         {
             currentFigure.Top = pt.Y;
             currentFigure.Bottom = dragPt.Y;
         }
     }
     // set selection rectangle
     figureHandler.SelectionFigure.Rect = currentFigure.GetSelectRect();
     // update drawing
     dv.Update(updateRect.Union(currentFigure.GetSelectRect()));
 }