コード例 #1
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            // initiate drawing process
            Point mousep = overlay.Rasterizer.RasterizePixel(p);

            origin = new Point(mousep.X, overlay.Height - mousep.Y);

            if (IsReferenceable(item))
            {
                originRef = item;
            }
            else
            {
                originRef = null;
            }

            PreviewRect.SetPosition(origin.X, origin.Y, 0, 0);

            // adjust rotation in case we are in a rotated frame
            double angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform) * 180 / Math.PI;

            PreviewRect.Rotation = angle;

            ////if (!overlay.canvas.Children.Contains(PreviewRect))
            ////    overlay.canvas.Children.Add(PreviewRect);
            /////PreviewRect.Visibility = Visibility.Visible;
            PreviewRect.Visible = true;

            overlay.MouseCaptured = true;
        }
コード例 #2
0
        public void MarkObject(OverlayShapeVM vv)
        {
            // Find the shape (view)
            Shape v = canvas1.Children.OfType <OverlayShapeView>().FirstOrDefault(osv => osv.TheUnderlyingShape == vv) as Shape;

            if (v == null)
            {
                return;
            }

            MarkerCenter        = new Point(Canvas.GetLeft(v) + v.Width / 2, Canvas.GetBottom(v) + v.Height / 2);
            MarkerEllipse.Width = Math.Max(v.Width, v.Height);
            //MarkerEllipse.Width = Math.Max(ols.ActualWidth, ols.ActualHeight);
            //da.KeyFrames.Add(new DoubleKeyFrame());
            Canvas.SetBottom(MarkerEllipse, MarkerCenter.Y - MarkerEllipse.ActualHeight / 2);
            Canvas.SetLeft(MarkerEllipse, MarkerCenter.X - MarkerEllipse.ActualWidth / 2);

            if (!canvas1.Children.Contains(MarkerEllipse))
            {
                canvas1.Children.Add(MarkerEllipse);
            }
            Storyboard anim = (Storyboard)FindResource("MarkerAnimation");

            anim.Begin(this);
            MarkerEllipse.Visibility = System.Windows.Visibility.Visible;
        }
コード例 #3
0
        private void CreateContextMenu()
        {
            var m = TheContextMenu = new ContextMenu();
            var i = new MenuItem("Jump to source");

            i.Click += (s, e) => { JumpToSourceDoIt(PopupSource); };
            m.MenuItems.Add(i);
            var ieditscope = i = new MenuItem("Edit this scope");

            i.Click += (s, e) => { TheOverlayModel.CurEditing = PopupSource as OverlayScope; };
            m.MenuItems.Add(i);

            var mm           = new MenuItem("Assign style");
            var massignstyle = mm;

            i        = new MenuItem("Assign new style...");
            i.Click += (s, e) => TheOverlayModel.AssignStyle(PdfOverlayModel.AssignStyleType.AssignNewStyle);
            mm.MenuItems.Add(i);
            i        = new MenuItem("Assign current node style");
            i.Click += (s, e) => TheOverlayModel.AssignStyle(PdfOverlayModel.AssignStyleType.AssignCurrentNodeStyle);
            mm.MenuItems.Add(i);
            i        = new MenuItem("Change style to new style...");
            i.Click += (s, e) => TheOverlayModel.AssignStyle(PdfOverlayModel.AssignStyleType.ChangeToNewStyle);
            mm.MenuItems.Add(i);
            i        = new MenuItem("Change style to current node style");
            i.Click += (s, e) => TheOverlayModel.AssignStyle(PdfOverlayModel.AssignStyleType.ChangeToCurrentNodeStyle);
            mm.MenuItems.Add(i);
            m.MenuItems.Add(mm);

            var mselection = mm = new MenuItem("Selection");

            i        = new MenuItem("Copy");
            i.Click += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.Copy);
            mm.MenuItems.Add(i);
            i        = new MenuItem("Copy enscoped");
            i.Click += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.CopyEnscoped);
            mm.MenuItems.Add(i);
            i        = new MenuItem("Cut");
            i.Click += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.Cut);
            mm.MenuItems.Add(i);
            i        = new MenuItem("Cut enscoped");
            i.Click += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.CutEnscoped);
            mm.MenuItems.Add(i);
            i        = new MenuItem("Delete");
            i.Click += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.Delete);
            mm.MenuItems.Add(i);
            i        = new MenuItem("Collect");
            i.Click += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.Collect);
            mm.MenuItems.Add(i);
            i        = new MenuItem("Collect and enscope");
            i.Click += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.CollectEnscoped);
            mm.MenuItems.Add(i);
            m.MenuItems.Add(mm);

            m.Popup += (s, e) => {
                PopupSource          = ObjectAtCursor;
                massignstyle.Enabled = mselection.Enabled = TheOverlayModel.selectionTool.SelItems.Count() > 0;
                ieditscope.Enabled   = (PopupSource is OverlayScope);
            };
        }
コード例 #4
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            // initiate drawing process
            Point mousep = overlay.Rasterizer.RasterizePixel(p);

            origin = new Point(mousep.X, overlay.Height - mousep.Y);

            if (IsReferenceable(item))
            {
                originRef = item;
            }
            else
            {
                originRef = null;
            }

            PreviewEllipse.SetPosition(origin.X, origin.Y, 0, 0);

            double angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform) * 180 / Math.PI;

            PreviewEllipse.Rotation = angle;

            PreviewEllipse.Visible = true;

            overlay.MouseCaptured = true;
        }
コード例 #5
0
ファイル: SelectionTool.cs プロジェクト: wilsoc5/tikzedt
 void RemoveItem(OverlayShapeVM o)
 {
     if (SelectedItems.Contains(o))
     {
         SelectedItems.Remove(o);
         o.IsSelected = false;
     }
 }
コード例 #6
0
ファイル: RasterControl.cs プロジェクト: wilsoc5/tikzedt
        private void CreateContextMenu()
        {
            var m = TheContextMenu = new Gtk.Menu();
            var i = new Gtk.MenuItem("Jump to source");

            i.Activated += (s, e) => { JumpToSourceDoIt(PopupSource); };
            m.Add(i);
            i            = new Gtk.MenuItem("Edit this scope");
            i.Activated += (s, e) => { };
            m.Add(i);

            var mm = new Gtk.MenuItem("Assign style");

            i            = new Gtk.MenuItem("Assign new style...");
            i.Activated += (s, e) => TheOverlayModel.AssignStyle(PdfOverlayModel.AssignStyleType.AssignNewStyle);
            var mmm = new Gtk.Menu();

            mm.Submenu = mmm;
            mmm.Add(i);
            i            = new Gtk.MenuItem("Assign current node style");
            i.Activated += (s, e) => TheOverlayModel.AssignStyle(PdfOverlayModel.AssignStyleType.AssignCurrentNodeStyle);
            mmm.Add(i);
            i            = new Gtk.MenuItem("Change style to new style...");
            i.Activated += (s, e) => TheOverlayModel.AssignStyle(PdfOverlayModel.AssignStyleType.ChangeToNewStyle);
            mmm.Add(i);
            i            = new Gtk.MenuItem("Change style to current node style");
            i.Activated += (s, e) => TheOverlayModel.AssignStyle(PdfOverlayModel.AssignStyleType.ChangeToCurrentNodeStyle);
            mmm.Add(i);
            m.Add(mm);

            mm           = new Gtk.MenuItem("Selection");
            mmm          = new Gtk.Menu();
            mm.Submenu   = mmm;
            i            = new Gtk.MenuItem("Copy");
            i.Activated += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.Copy);
            mmm.Add(i);
            i            = new Gtk.MenuItem("Copy enscoped");
            i.Activated += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.CopyEnscoped);
            mmm.Add(i);
            i            = new Gtk.MenuItem("Cut");
            i.Activated += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.Cut);
            mmm.Add(i);
            i            = new Gtk.MenuItem("Cut enscoped");
            i.Activated += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.CutEnscoped);
            mmm.Add(i);
            i            = new Gtk.MenuItem("Delete");
            i.Activated += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.Delete);
            mmm.Add(i);
            i            = new Gtk.MenuItem("Collect");
            i.Activated += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.Collect);
            mmm.Add(i);
            i            = new Gtk.MenuItem("Collect and enscope");
            i.Activated += (s, e) => TheOverlayModel.PerformCodeBlockOperation(PdfOverlayModel.CodeBlockAction.CollectEnscoped);
            mmm.Add(i);
            m.Add(mm);

            m.PopupMenu += (s, e) => { PopupSource = ObjectAtCursor; };
        }
コード例 #7
0
ファイル: PdfOverlay.cs プロジェクト: wilsoc5/tikzedt
 public void MarkObject(OverlayShapeVM v)
 {
     MarkObject_Timer.Stop();
     MarkObject_BlinkCount = 0;
     MarkObject_Marked     = v;
     MarkObject_ShowMarker = true;
     MarkObject_Timer.Start();
     Invalidate();
 }
コード例 #8
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            if (item != null)
            {
                // initiate a drag/drop operation
                curDragged = (OverlayShapeVM)item;
                DragOrigin = (new Point(item.Center.X, item.Center.Y)) - (Vector)p;
                ////DragOrigin = e.GetPosition(item);
                ////DragOrigin = new Point(DragOrigin.X, (item as OverlayShape).Height - DragOrigin.Y);
                DragOriginC = p;
                DragOriginO = new Point(curDragged.Center.X, curDragged.Center.Y);
                movedenough = false;
                //MessageBox.Show(o.ToString());

                // select the clicked shape

                /*          if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
                 *        {
                 *            if (!ToggleItem(curDragged))
                 *            {
                 *                // unselected -> start no drag operation
                 *                curDragged = null;
                 *            }
                 *        }
                 *        else
                 *        {
                 *            AddItem(curDragged, !IsItemSelected(curDragged));
                 *        }*/

                // adjust raster origin/scale/polar/cartesian
                overlay.SetCorrectRaster(curDragged);

                // for an arc, display preview
                //if (curDragged.item is Tikz_Arc)
                //{
                FillNodesOnArc();
                //check whether starting moving arc was successful
                if (PreviewArc.Spokes == null)
                {
                    SetCursorNo();
                    curDragged = null;
                    return;
                }
                AdjustPreviewPos(p);
                PreviewArc.Visible = true;
                //}

                // capture mouse. this is important if the user drags sth. outside canvas1's bounds
                if (curDragged != null)
                {
                    overlay.MouseCaptured = true;
                }
            }
        }
コード例 #9
0
ファイル: SelectionTool.cs プロジェクト: wilsoc5/tikzedt
 /// <summary>
 /// Adds an item to the list of selected items.
 /// </summary>
 /// <param name="o">The item to add.</param>
 /// <param name="Exclusive">If Exclusive is set, all other items are unselected.</param>
 public void AddItem(OverlayShapeVM o, bool Exclusive = false)
 {
     if (Exclusive)
     {
         Clear(o);
     }
     if (!SelectedItems.Contains(o))
     {
         o.IsSelected = true;
         SelectedItems.Add(o);
     }
 }
コード例 #10
0
ファイル: SelectionTool.cs プロジェクト: wilsoc5/tikzedt
 /// <summary>
 /// Clears the list, except possibly the item "except".
 /// </summary>
 /// <param name="except">The thing not to remove.</param>
 void Clear(OverlayShapeVM except = null)
 {
     foreach (OverlayShapeVM o in SelectedItems)
     {
         if (o != except)
         {
             o.IsSelected = false;
         }
     }
     SelectedItems.RemoveWhere(o => (o != except));
     //SelectedItems.Clear();
 }
コード例 #11
0
ファイル: OverlayShapeViews.cs プロジェクト: wilsoc5/tikzedt
 public OverlayShapeView(OverlayShapeVM osv)
 {
     TheUnderlyingShape = osv;
     MyBindings.Add(BindingFactory.CreateBinding(osv, "BB", vm => { Canvas.SetLeft(this, vm.BB.X); Canvas.SetBottom(this, vm.BB.Y); }, null, false));
     MyBindings.Add(BindingFactory.CreateBinding(osv, "IsSelected", vm => { if (vm.IsSelected)
                                                                            {
                                                                                SetSelColor();
                                                                            }
                                                                            else
                                                                            {
                                                                                SetStdColor();
                                                                            } }, null, false));
 }
コード例 #12
0
ファイル: SelectionTool.cs プロジェクト: wilsoc5/tikzedt
 /// <summary>
 /// Toggles selection state, returns new selection state.
 /// </summary>
 /// <param name="o"></param>
 /// <returns></returns>
 public bool ToggleItem(OverlayShapeVM o)
 {
     if (SelectedItems.Contains(o))
     {
         RemoveItem(o);
         return(false);
     }
     else
     {
         AddItem(o);
         return(true);
     }
 }
コード例 #13
0
ファイル: PdfOverlay.cs プロジェクト: wilsoc5/tikzedt
 public void JumpToSourceDoIt(OverlayShapeVM o)
 {
     if (o != null)
     {
         if (JumpToSource != null)
         {
             JumpToSource(this, new JumpToSourceEventArgs()
             {
                 JumpToPos = o.item.StartPosition(), SelectionLength = o.item.text.Length
             });
         }
     }
 }
コード例 #14
0
 void IPdfOverlayView.JumpToSourceDoIt(OverlayShapeVM o)
 {
     if (JumpToSource != null)
     {
         TikzParseItem tpi = o.item;
         if (tpi != null)
         {
             JumpToSource(this, new JumpToSourceEventArgs()
             {
                 JumpToPos = tpi.StartPosition(), SelectionLength = tpi.Length
             });
         }
     }
 }
コード例 #15
0
 public static void Draw(this OverlayShapeVM os, Graphics dc, int Height)
 {
     if (os is OverlayScope)
     {
         (os as OverlayScope).Draw(dc, Height);
     }
     else if (os is OverlayControlPoint)
     {
         (os as OverlayControlPoint).Draw(dc, Height);
     }
     else if (os is OverlayNode)
     {
         (os as OverlayNode).Draw(dc, Height);
     }
 }
コード例 #16
0
ファイル: SelectionTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonUp(Point p, TEMouseArgs e)
        {
            if (SelectionRect.Visible)
            {
                SelectionRect.Visible = false;
            }

            // adjust position of dragged item (in parsetree)
            if (curDragged != null && movedenough)
            {
                overlay.BeginUpdate();
                // determine the relative shift
                Vector relshift      = curDragged.Center - DragOriginO;
                Vector relshift_tikz = relshift / overlay.Resolution;
                ShiftSelItemsInParseTree(relshift_tikz, overlay.DisplayTree.TopLevelItems);

                /*
                 * Point pp = new Point(Canvas.GetLeft(curDragged) + curDragged.Width / 2, Canvas.GetBottom(curDragged) + curDragged.Height / 2);
                 * pp = ScreenToTikz(pp);
                 * if (curDragged is OverlayNode)
                 * {
                 *  (curDragged as OverlayNode).tikzitem.SetAbsPos(pp);
                 *  (curDragged as OverlayNode).tikzitem.UpdateText();
                 *
                 * }
                 * else if (curDragged is OverlayScope)
                 * {
                 *  Point pdiff = new Point(e.GetPosition(canvas1).X - DragOriginC.X, e.GetPosition(canvas1).Y - DragOriginC.Y);
                 *  pdiff = rasterizer.RasterizePixel(pdiff);
                 *
                 *  double xs = pdiff.X / Resolution, ys = -pdiff.Y / Resolution;
                 *
                 *  curDragged.ShiftItemRelative(pdiff);
                 * }*/
                // update all item's positions
                overlay.DisplayTree.AdjustPositions();

                // update raster in case it has changed
                overlay.SetCorrectRaster(curDragged);

                curDragged = null;

                overlay.EndUpdate();
            }
        }
コード例 #17
0
        /// <summary>
        /// Tests whether the point p (in TL centric coordinates) lies within the object.
        /// If yes returns a "distance", based on which the object is selected. (smallest distance wins)
        /// If no returns a large value (1000000)
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public static double HitTest(this OverlayShapeVM os, double x, double y, double Height)
        {
            // no overloading for extensions in c# -> we have to forward the call
            if (os is OverlayScope)
            {
                return((os as OverlayScope).HitTest(x, y, Height));
            }

            var lBB = os.BB.UpsideDown(Height);

            if (lBB.Contains(x, y))
            {
                return((new System.Windows.Point(x, y) - lBB.Center()).Length);
            }
            else
            {
                return(1000000);
            }
        }
コード例 #18
0
        Tikz_Option smoothOption; // this has to be changed to smooth cycle for closed curve

        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
            {
                return;
            }

            p = overlay.Rasterizer.RasterizePixelToTikz(p);
            if (ContinueWithBigImage(p) == false)
            {
                return;
            }

            overlay.BeginUpdate();

            overlay.SetCorrectRaster(overlay.CurEditing, true);

            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);


            // find tikzpicture and add
            bool lcreated;

            if (EnsureCurAddToExists(out lcreated))
            {
                // on double click -> close path
                if (e.ClickCount == 2)
                {
                    if (!lcreated)
                    {
                        smoothOption.key = "smooth cycle";
                        smoothOption.UpdateText();
                    }
                }
                else
                {
                    if (!lcreated)
                    {
                        // for prettier formatting
                        curAddTo.AddChild(new Parser.Tikz_Something(" "));
                    }

                    // create new coordinate
                    Parser.Tikz_Coord tc = new Parser.Tikz_Coord();
                    tc.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                    curAddTo.AddChild(tc);
                    if (item is OverlayNode && IsReferenceable(item))
                    {
                        Tikz_Node tn = MakeReferenceableNode((item as OverlayNode).tikzitem);
                        tc.type    = Tikz_CoordType.Named;
                        tc.nameref = tn.name;
                    }
                    else
                    {
                        // do it here since the coordinate calculation needs the parents' coord. transform
                        tc.SetAbsPos(new Point(p.X, p.Y));
                    }

                    //tn.UpdateText();
                    curAddTo.UpdateText();
                    //tpict.UpdateText();

                    // draw the added object in the overlay
                    //       overlay.AddToDisplayTree(tc);
                }
            }

            overlay.EndUpdate();

            // doubleclick also stops path drawing
            if (e.ClickCount == 2)
            {
                overlay.ActivateDefaultTool();
            }
        }
コード例 #19
0
        public override void OnLeftMouseButtonUp(Point p, TEMouseArgs e)
        {
            if (PreviewArc.Spokes == null)
            {
                SetCursorDefault();
                return;
            }

            PreviewArc.Visible = false;
            // adjust position of dragged item (in parsetree)
            if (curDragged != null && movedenough && curDragged.item is Tikz_XYItem)
            {
                overlay.BeginUpdate();
                // determine the relative shift
                Vector relshift      = new Vector(curDragged.Center.X - DragOriginO.X, curDragged.Center.Y - DragOriginO.Y);
                Vector relshift_tikz = relshift / overlay.Resolution;

                // compute new radius
                Point pold;
                (curDragged.item as Tikz_XYItem).GetAbsPos(out pold);
                Point  pnew = pold + relshift_tikz;
                double Rnew = (pnew - center_tikz).Length;

                // adjust all position accordingly...
                for (int i = 0; i < nodesOnArc.Count; i++)
                {
                    Point newp = center_tikz + Rnew * (new Vector(Math.Cos(PreviewArc.Spokes[i]), Math.Sin(PreviewArc.Spokes[i])));

                    if (i == 0)
                    {
                        nodesOnArc[i].SetAbsPos(newp);
                    }
                    else
                    {
                        //if (nodesOnArc[i] == curDragged.item)
                        //(nodesOnArc[i] as Tikz_Arc).SetAbsPosRandPhi2(Rnew, PreviewArc.Spokes[i]);
                        (nodesOnArc[i] as Tikz_Arc).SetFromPoints(center_tikz, newp, PreviewArc.Spokes[i - 1], PreviewArc.Spokes[i]);
                        //else
                        //    (nodesOnArc[i] as Tikz_Arc).SetAbsPosOnlyR(newp);
                    }

                    nodesOnArc[i].UpdateText();
                }



                // set first angle of arc segment directly after curDragged
                //if (curDraggedInd + 1 < nodesOnArc.Count)
                //{
                //    (nodesOnArc[curDraggedInd + 1] as Tikz_Arc).SetAbsPosRandPhi1(pnew);
                //}

                // ShiftSelItemsInParseTree(relshift_tikz, overlay.TopLevelItems);

                /*
                 * Point pp = new Point(Canvas.GetLeft(curDragged) + curDragged.Width / 2, Canvas.GetBottom(curDragged) + curDragged.Height / 2);
                 * pp = ScreenToTikz(pp);
                 * if (curDragged is OverlayNode)
                 * {
                 *  (curDragged as OverlayNode).tikzitem.SetAbsPos(pp);
                 *  (curDragged as OverlayNode).tikzitem.UpdateText();
                 *
                 * }
                 * else if (curDragged is OverlayScope)
                 * {
                 *  Point pdiff = new Point(e.GetPosition(canvas1).X - DragOriginC.X, e.GetPosition(canvas1).Y - DragOriginC.Y);
                 *  pdiff = rasterizer.RasterizePixel(pdiff);
                 *
                 *  double xs = pdiff.X / Resolution, ys = -pdiff.Y / Resolution;
                 *
                 *  curDragged.ShiftItemRelative(pdiff);
                 * }*/
                // update all item's positions
                overlay.DisplayTree.AdjustPositions();

                curDragged        = null;
                PreviewArc.Spokes = null;

                overlay.EndUpdate();
            }
            else if (curDragged != null && curDragged.item is Tikz_XYItem)
            { //if not movedenough, reset all "moving variables" anyways
                curDragged        = null;
                PreviewArc.Spokes = null;
            }
        }
コード例 #20
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
 /// <summary>
 /// Set e.Handled if you want to turn off the default handling... like opening the context menu etc.
 /// </summary>
 /// <param name="item">The item on which the event occurred.</param>
 /// <param name="p">The cursor position, in BOTTOM LEFT CENTERED pixel coordinates.</param>
 ///
 public virtual void OnRightMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
 {
 }
コード例 #21
0
ファイル: SelectionTool.cs プロジェクト: wilsoc5/tikzedt
 public bool IsItemSelected(OverlayShapeVM o)
 {
     return(SelectedItems.Contains(o));
 }
コード例 #22
0
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
            {
                return;
            }

            Point ptikz = overlay.Rasterizer.RasterizePixelToTikz(p);

            p = overlay.Rasterizer.RasterizePixel(p);
            if (ContinueWithBigImage(ptikz) == false)
            {
                return;
            }

            if (pointcount == 0)
            {
                //overlay.SetCorrectRaster(overlay.CurEditing, true);
                center = ptikz;

                // set raster to polar, and such that origin is at center
                overlay.Rasterizer.View.IsCartesian = false;
                TikzMatrix M = overlay.Rasterizer.View.CoordinateTransform;
                M.m[0, 2] = center.X;
                M.m[1, 2] = center.Y;
                overlay.Rasterizer.View.CoordinateTransform = M;
                pointcount = 1;

                PreviewPie.center = PreviewArc.center = new Point(p.X, overlay.Height - p.Y);
            }
            else if (pointcount == 1)
            {
                p1            = ptikz;
                pointcount    = 2;
                PreviewPie.p1 = PreviewArc.p2 = new Point(p.X, overlay.Height - p.Y);

                // compute radius
                TikzMatrix M    = overlay.Rasterizer.View.CoordinateTransform;
                Point      ploc = M.Inverse().Transform(p1);
                overlay.Rasterizer.View.ForceRadiusTo = (ploc - (new Point(0, 0))).Length;
            }
            else if (pointcount == 2)
            {
                // **** create arc / pie ****
                overlay.BeginUpdate();
                // find next tikzpicture and add
                if (AddNewCurAddTo()) //(EnsureCurAddToExists(out lcreated))
                {
                    // Pie?
                    if (IsPie)
                    {
                        // create new coordinate
                        Tikz_Coord tc = new Parser.Tikz_Coord();
                        tc.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                        curAddTo.AddChild(tc);
                        tc.SetAbsPos(center);
                        curAddTo.AddChild(new Parser.Tikz_Something(" -- "));
                    }

                    Tikz_Coord tc1 = new Parser.Tikz_Coord();
                    if (IsPie)
                    {
                        tc1.type = Tikz_CoordType.Polar;
                        tc1.deco = "++";
                    }
                    curAddTo.AddChild(tc1);
                    tc1.SetAbsPos(p1);
                    curAddTo.AddChild(new Parser.Tikz_Something(" "));

                    // create arc
                    Tikz_Arc ta = new Tikz_Arc();
                    curAddTo.AddChild(ta);
                    ta.SetFromPoints(center, ptikz, IsLargeArc);

                    if (IsPie)
                    {
                        curAddTo.AddChild(new Parser.Tikz_Something(" -- cycle"));
                    }

                    //tn.UpdateText();
                    curAddTo.UpdateText();
                    //tpict.UpdateText();

                    // draw the added object in the overlay
                    //          overlay.AddToDisplayTree(curAddTo);
                }

                overlay.EndUpdate();

                // reset everything
                pointcount = 0;
                overlay.Rasterizer.View.ForceRadiusTo = -1;
                overlay.SetCorrectRaster(overlay.CurEditing, true);
            }
            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);
            UpdatePreviewDisplay(p);
        }
コード例 #23
0
ファイル: SelectionTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            if (e.ClickCount == 2 && (item is OverlayScope)) // Select for editing
            {
                overlay.CurEditing = item as OverlayScope;
            }
            else if (e.ClickCount == 2 && (item is OverlayNode))
            {
                overlay.JumpToSourceDoIt(item);
            }
            else if (item is OverlayShapeVM)
            {
                // initiate a drag/drop operation
                curDragged = (OverlayShapeVM)item;
                DragOrigin = (Point)(item.Center - p); ////e.GetPosition(item);
                ////DragOrigin = new Point(DragOrigin.X, (item as OverlayShape).Height - DragOrigin.Y);
                DragOriginC = p;
                DragOriginO = curDragged.Center;
                movedenough = false;
                //MessageBox.Show(o.ToString());

                // select the clicked shape
                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                {
                    if (!ToggleItem(curDragged))
                    {
                        // unselected -> start no drag operation
                        curDragged = null;
                    }
                }
                else
                {
                    AddItem(curDragged, !IsItemSelected(curDragged));
                }

                // adjust raster origin/scale/polar/cartesian
                overlay.SetCorrectRaster(curDragged);

                // capture mouse. this is important if the user drags sth. outside canvas1's bounds
                if (curDragged != null)
                {
                    overlay.MouseCaptured = true;
                }
            }
            else if (item == null)
            {
                BeginSelectionChange(overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control));

                // display selection rectangle
                SelectionRectOrigin = overlay.CursorPosition;
                //SelectionRect.RenderTransform = new TranslateTransform(SelectionRectOrigin.X, SelectionRectOrigin.Y);
                SelectionRect.SetPosition(SelectionRectOrigin.X, SelectionRectOrigin.Y, 0, 0);
                ////Canvas.SetLeft(SelectionRect, SelectionRectOrigin.X);
                ////Canvas.SetTop(SelectionRect, SelectionRectOrigin.Y);
                ////SelectionRect.Width = 0;
                ////SelectionRect.Height = 0;
                ////Canvas.SetZIndex(SelectionRect, overlay.canvas.Children.Count);
                ////if (!overlay.canvas.Children.Contains(SelectionRect))
                ////    overlay.canvas.Children.Add(SelectionRect);
                ////SelectionRect.Visibility = System.Windows.Visibility.Visible;
                SelectionRect.Visible = true;
                overlay.MouseCaptured = true;
            }
        }
コード例 #24
0
        public override void OnLeftMouseButtonUp(Point p, TEMouseArgs e)
        {
            // add the rectangle
            if (PreviewRect.Visible)
            {
                if (!EnsureParseTreeExists())
                {
                    return;
                }

                Point firstpoint  = overlay.ScreenToTikz(origin, true);
                Point secondpoint = overlay.Rasterizer.RasterizePixelToTikz(p);

                double     angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform);
                TikzMatrix R     = TikzMatrix.RotationMatrix(angle);
                TikzMatrix RI    = R.Inverse();

                Point firstpointR = R.Transform(firstpoint), secondpointR = R.Transform(secondpoint);

                if (ForcePointsBLTR)
                {
                    // ensure first pt is bottom left, second top right
                    Rect r = new Rect(firstpointR, secondpointR);
                    firstpointR  = r.TopLeft; // note that we use upside down coordinates, so the c# notations are different
                    secondpointR = r.BottomRight;
                    firstpoint   = RI.Transform(firstpointR);
                    secondpoint  = RI.Transform(secondpointR);
                }

                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                {
                    // both sides the same
                    double sidelength = Math.Max(Math.Abs(firstpointR.X - secondpointR.X), Math.Abs(firstpointR.Y - secondpointR.Y));
                    secondpointR = new Point(
                        firstpointR.X + Math.Sign(secondpointR.X - firstpointR.X) * sidelength,
                        firstpointR.Y + Math.Sign(secondpointR.Y - firstpointR.Y) * sidelength);
                    secondpoint = RI.Transform(secondpointR);
                }

                overlay.BeginUpdate();

                if (AddNewCurAddTo())
                {
                    Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord();
                    tc1.type = overlay.UsePolarCoordinates? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                    Parser.Tikz_Coord tc2 = new Parser.Tikz_Coord();
                    tc2.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;

                    curAddTo.AddChild(new Parser.Tikz_Something(" "));
                    curAddTo.AddChild(tc1);
                    curAddTo.AddChild(new Parser.Tikz_Something(codeToInsert));
                    curAddTo.AddChild(tc2);

                    if (originRef == null)
                    {
                        tc1.SetAbsPos(firstpoint);
                    }
                    else
                    {
                        Tikz_Node tn = MakeReferenceableNode((originRef as OverlayNode).tikzitem);
                        tc1.type    = Tikz_CoordType.Named;
                        tc1.nameref = tn.name;
                    }

                    OverlayShapeVM hit = overlay.ObjectAtCursor;
                    if ((hit is OverlayNode) && IsReferenceable(hit as OverlayNode))
                    {
                        Tikz_Node tn = MakeReferenceableNode((hit as OverlayNode).tikzitem);
                        tc2.type    = Tikz_CoordType.Named;
                        tc2.nameref = tn.name;
                    }
                    else
                    {
                        tc2.SetAbsPos(secondpoint);
                    }

                    //           overlay.AddToDisplayTree(tc1);
                    //           overlay.AddToDisplayTree(tc2);

                    curAddTo.UpdateText();
                }

                overlay.EndUpdate();

                PreviewRect.Visible = false;
            }
        }
コード例 #25
0
ファイル: BezierTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShapeVM item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
            {
                return;
            }

            Point prast = overlay.Rasterizer.RasterizePixel(p);

            p = overlay.Rasterizer.RasterizePixelToTikz(p);
            if (ContinueWithBigImage(p) == false)
            {
                return;
            }

            overlay.BeginUpdate();

            overlay.SetCorrectRaster(overlay.CurEditing, true);

            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);


            // find next tikzpicture and add
            bool lcreated;

            if (EnsureCurAddToExists(out lcreated))
            {
                {
                    // there are three states:  (i)   new path -> add coordinate
                    //                          (ii)  add controlpoints
                    //                          (iii) 2 cps's added -> add bezier segment
                    if (CPCount == 2)
                    {
                        // add controls
                        Tikz_Controls tcont = new Tikz_Controls();
                        tcont.starttag = " .. controls ";
                        tcont.endtag   = " ..";
                        Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord(), tc2 = new Parser.Tikz_Coord(); // control points
                        tc1.type = tc2.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;

                        tcont.AddChild(tc1);
                        tcont.AddChild(new Tikz_Something(" and "));
                        tcont.AddChild(tc2);

                        curAddTo.AddChild(tcont);

                        // the endpoint
                        Parser.Tikz_Coord tcend = new Parser.Tikz_Coord();
                        tcend.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                        curAddTo.AddChild(new Tikz_Something(" "));
                        curAddTo.AddChild(tcend);

                        // do it here since the coordinate calculation needs the parents' coord. transform, and the second added point
                        tcend.SetAbsPos(p);
                        tc1.SetAbsPos(CP1);
                        tc2.SetAbsPos(CP2);

                        tcont.UpdateText();
                        tcend.UpdateText();

                        // draw the added objects in the overlay
                        //       overlay.AddToDisplayTree(tcend);
                        //       overlay.AddToDisplayTree(tcont);

                        CPCount             = 0;
                        Preview_CP1.Visible = Preview_CP2.Visible = false;
                    }
                    else if (lcreated)
                    {
                        // add starting point
                        // create new coordinate
                        Parser.Tikz_Coord tc = new Parser.Tikz_Coord();
                        tc.type = overlay.UsePolarCoordinates ? Parser.Tikz_CoordType.Polar : Parser.Tikz_CoordType.Cartesian;
                        curAddTo.AddChild(tc);
                        // do it here since the coordinate calculation needs the parents' coord. transform
                        tc.SetAbsPos(new Point(p.X, p.Y)); //hack
                        curAddTo.UpdateText();
                        // draw the added object in the overlay
                        //        overlay.AddToDisplayTree(tc);

                        CPCount = 0;
                    }
                    else
                    {
                        // remember control points
                        if (CPCount == 0)
                        {
                            CP1 = p;

                            Preview_CP1.SetCenter(prast.X, prast.Y);
                            ////Canvas.SetLeft(Preview_CP1, prast.X - Preview_CP1.Width / 2);
                            ////Canvas.SetBottom(Preview_CP1, prast.Y - Preview_CP1.Height / 2);
                            ////if (!overlay.canvas.Children.Contains(Preview_CP1))
                            ////    overlay.canvas.Children.Add(Preview_CP1);
                            ////Preview_CP1.Visibility = Visibility.Visible;
                            Preview_CP1.Visible = true;
                        }
                        else if (CPCount == 1)
                        {
                            CP2 = p;
                            Preview_CP2.SetCenter(prast.X, prast.Y);
                            ////Canvas.SetLeft(Preview_CP2, prast.X - Preview_CP2.Width / 2);
                            ////Canvas.SetBottom(Preview_CP2, prast.Y - Preview_CP2.Height / 2);
                            ////if (!overlay.canvas.Children.Contains(Preview_CP2))
                            ////    overlay.canvas.Children.Add(Preview_CP2);
                            ////Preview_CP2.Visibility = Visibility.Visible;
                            Preview_CP2.Visible = true;
                        }
                        CPCount++;
                    }
                }
            }

            overlay.EndUpdate();
        }