コード例 #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;
            }

            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;
        }
コード例 #2
0
        public override void OnMouseMove(Point p, TEMouseArgs e)
        {
            base.OnMouseMove(p, e);

            //Point mousep = e.GetPosition(overlay.canvas);
            Point mousep = overlay.Rasterizer.RasterizePixel(p);

            ////mousep = new Point(mousep.X, overlay.canvas.ActualHeight - mousep.Y);
            mousep = new Point(mousep.X, overlay.Height - mousep.Y);
            if (PreviewEllipse.Visible)
            {
                // compute rotated diagonal
                double angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform);
                //TikzMatrix R
                TikzMatrix R       = TikzMatrix.RotationMatrix(-angle);
                Vector     newdiag = R.Transform(mousep - origin);

                double width  = Math.Abs(newdiag.X),  // actually half the width/height!
                       height = Math.Abs(newdiag.Y);
                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                {
                    width = height = Math.Max(width, height);
                }

                R = R.Inverse();
                Point topleft = origin + R.Transform(new Vector(-width, -height));

                PreviewEllipse.SetPosition(topleft.X, topleft.Y, 2 * width, 2 * height);
            }
        }
コード例 #3
0
        /// <summary>
        /// Packages the Mouse event arguments into UI framework independent format.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public static TEMouseArgs ToTEMouseArgs(this MouseButtonEventArgs e)
        {
            TEMouseArgs ee = (e as MouseEventArgs).ToTEMouseArgs();

            ee.ClickCount = e.ClickCount;
            return(ee);
        }
コード例 #4
0
        /// <summary>
        /// The standard handling of right click is as follows (with this priority):
        ///   1. The current tool uses the click.
        ///   2. Set the tool to the standard tool (move)
        ///   3. Deselect the CurEditing item.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void canvas1_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            // call right down-method in the current tool
            Point       mousep = e.GetPosition(canvas1);
            var         oo     = ObjectAtPosition(mousep);
            TEMouseArgs ee     = e.ToTEMouseArgs();

            TheModel.CurrentTool.OnRightMouseButtonDown(oo, new Point(mousep.X, Height - mousep.Y), ee);
            e.Handled = ee.Handled;

            // if the tool didn't use the click-> proceed with standard handling
            if (!e.Handled)
            {
                if (Tool == OverlayToolType.move)
                {
                    //canvas1.ContextMenu.IsEnabled = true;
                    if (TheModel.CurEditing != null)
                    {
                        TheModel.CurEditing       = null;
                        PreventContextMenuOpening = true;
                    }
                }
                else
                {
                    Tool = OverlayToolType.move;
                    PreventContextMenuOpening = true;
                }
            }
            else
            {
                PreventContextMenuOpening = true;
            }
        }
コード例 #5
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;
        }
コード例 #6
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            if (!EnsureParseTreeExists())
            {
                return;
            }

            overlay.BeginUpdate();

            overlay.SetCorrectRaster(overlay.CurEditing, true);

            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);
            p = overlay.Rasterizer.RasterizePixelToTikz(p);
            if (ContinueWithBigImage(p) == false)
            {
                return;
            }

            // find next tikzpicture and add
            Parser.Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture();
            if (tpict != null)
            {
                Parser.Tikz_Node tn = new Parser.Tikz_Node();
                tn.label = "";
                tn.coord = new Parser.Tikz_Coord();
                if (overlay.NodeStyle != "")
                {
                    tn.options = "[" + overlay.NodeStyle + "]";
                }

                Parser.Tikz_Path tp = new Parser.Tikz_Path();
                tp.starttag = @"\node ";
                tp.endtag   = ";";

                tp.AddChild(tn);
                if (overlay.CurEditing != null)
                {
                    overlay.CurEditing.tikzitem.AddChild(tp);
                    overlay.CurEditing.tikzitem.AddChild(new Parser.Tikz_Something("\r\n"));
                }
                else
                {
                    tpict.AddChild(tp);
                    tpict.AddChild(new Parser.Tikz_Something("\r\n"));
                }
                // do it here since the coordinate calculation needs the parents' coord. transform
                tn.SetAbsPos(new Point(p.X, p.Y)); //hack

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

                //RedrawObjects();
                overlay.AddToDisplayTree(tp);
            }

            overlay.EndUpdate();
        }
コード例 #7
0
ファイル: ArcTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnMouseMove(Point p, TEMouseArgs e)
        {
            base.OnMouseMove(p, e);
            p = overlay.Rasterizer.RasterizePixel(p);

            if (pointcount > 0)
                UpdatePreviewDisplay(p);

        }
コード例 #8
0
ファイル: SelectionTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnMouseMove(Point p, TEMouseArgs e)
        {
            Point mousep = overlay.CursorPosition;

            if (SelectionRect.Visible)
            {
                // update the size of the selection rect
                double x = Math.Min(mousep.X, SelectionRectOrigin.X),
                       y = Math.Min(mousep.Y, SelectionRectOrigin.Y);
                //SelectionRect.RenderTransform = new TranslateTransform(x, y);
                ////Canvas.SetLeft(SelectionRect, x);
                ////Canvas.SetTop(SelectionRect, y);
                ////SelectionRect.Width = Math.Abs(mousep.X - SelectionRectOrigin.X);
                ////SelectionRect.Height = Math.Abs(mousep.Y - SelectionRectOrigin.Y);
                SelectionRect.SetPosition(x, y, Math.Abs(mousep.X - SelectionRectOrigin.X), Math.Abs(mousep.Y - SelectionRectOrigin.Y));

                // update current selection
                Rect selr = SelectionRect.GetBB();////System.Windows.Controls.Primitives.LayoutInformation.GetLayoutSlot(SelectionRect); // this is BB of selection rect
                UpdateSelection(selr, overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control));
            }

            // start a drag operation only after the mouse moved at least xx pixels to avoid accidental moving
            if ((DragOriginC - p).Length > 5)
            {
                movedenough = true;
            }
            // for a dragged scope, the relative movement gets rasterized
            // for a dragged node, the center of the node gets rasterized
            if (curDragged != null && e.LeftButtonPressed && movedenough)
            {
                if (curDragged is OverlayScope)
                {
                    // total shift
                    Point relshift_pixel = new Point(p.X - DragOriginC.X, p.Y - DragOriginC.Y);
                    relshift_pixel = overlay.Rasterizer.RasterizePixelRelative(relshift_pixel);
                    // shift yet to be done
                    Vector relshift_tobedone = (Vector)(DragOriginO + (relshift_pixel - curDragged.Center));

                    ShiftSelItemsOnScreen(relshift_tobedone);
                }
                else if (curDragged is OverlayNode)
                {
                    // use width instead actual width
                    ////Point center_pixel = new Point(p.X - DragOrigin.X + curDragged.Width / 2,
                    ////                               p.Y - DragOrigin.Y + curDragged.Height / 2);
                    Point center_pixel = new Point(p.X - DragOrigin.X,
                                                   p.Y - DragOrigin.Y);
                    // the center pixel of the node should go here
                    center_pixel = overlay.Rasterizer.RasterizePixel(center_pixel);

                    // shift yet to be done
                    Vector relshift_tobedone = center_pixel - curDragged.Center;
                    ShiftSelItemsOnScreen(relshift_tobedone);
                }
            }
        }
コード例 #9
0
ファイル: ArcTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnMouseMove(Point p, TEMouseArgs e)
        {
            base.OnMouseMove(p, e);
            p = overlay.Rasterizer.RasterizePixel(p);

            if (pointcount > 0)
            {
                UpdatePreviewDisplay(p);
            }
        }
コード例 #10
0
ファイル: ArcEditTool.cs プロジェクト: JoeyEremondi/tikzedt
        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;
            }
            


        }
コード例 #11
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;
                }
            }
        }
コード例 #12
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnRightMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            //base.OnRightMouseButtonDown(item, p, e);

            // if a node is selected, unselect it
            if (curSel != null)
            {
                curSel    = null;
                e.Handled = true;   // we don't want anything else to happen (contextmenu opening etc)
            }
        }
コード例 #13
0
        private void canvas1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (canvas1.IsMouseCaptured)
            {
                canvas1.ReleaseMouseCapture();  // release mouse capture here to make sure the tools cannot forget
            }
            Point       mousep = e.GetPosition(canvas1);
            TEMouseArgs ee     = e.ToTEMouseArgs();

            TheModel.CurrentTool.OnLeftMouseButtonUp(new Point(mousep.X, Height - mousep.Y), ee);
            e.Handled = ee.Handled;
        }
コード例 #14
0
        private void canvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // for some unknown reason the focus has to be set using the dispatcher...
            Dispatcher.BeginInvoke(new Action(delegate() { Keyboard.Focus(canvas1); }));

            // call left down-method in the current tool
            Point       mousep = e.GetPosition(canvas1);
            var         oo     = ObjectAtPosition(mousep);
            TEMouseArgs ee     = e.ToTEMouseArgs();

            TheModel.CurrentTool.OnLeftMouseButtonDown(oo, new Point(mousep.X, Height - mousep.Y), ee);
            e.Handled = ee.Handled;
        }
コード例 #15
0
        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
                Point relshift      = new Point(curDragged.View.GetLeft() - DragOriginO.X, curDragged.View.GetBottom() - DragOriginO.Y);
                Point relshift_tikz = new Point(relshift.X / overlay.Resolution, relshift.Y / overlay.Resolution);
                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
                foreach (OverlayShape o in overlay.TopLevelItems)
                {
                    o.AdjustPosition(overlay.Resolution);
                }

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

                curDragged = null;

                overlay.EndUpdate();
            }
        }
コード例 #16
0
        public override void OnMouseMove(Point p, TEMouseArgs e)
        {
            base.OnMouseMove(p, e);

            //Point mousep = e.GetPosition(overlay.canvas);
            Point mousep = overlay.Rasterizer.RasterizePixel(p);

            ////mousep = new Point(mousep.X, overlay.canvas.ActualHeight - mousep.Y);
            mousep = new Point(mousep.X, overlay.Height - mousep.Y);
            if (PreviewRect.Visible)
            {
                // compute rotated diagonal
                double     angle   = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform);
                TikzMatrix R       = TikzMatrix.RotationMatrix(-angle);
                Vector     newdiag = R.Transform(mousep - origin);

                // update the size and position of the preview rect
                double width, height;
                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                {
                    // both sides the same
                    width   = height = Math.Max(Math.Abs(newdiag.X), Math.Abs(newdiag.Y));
                    newdiag = new Vector(Math.Sign(newdiag.X) * width, Math.Sign(newdiag.Y) * height);
                }
                else
                {
                    width  = Math.Abs(newdiag.X);
                    height = Math.Abs(newdiag.Y);
                }

                R = R.Inverse();
                Point topleft = origin + R.Transform(new Vector(Math.Min(0, newdiag.X), Math.Min(0, newdiag.Y)));

                //double x = (newdiag.X<0 ?  mousep.X : origin.X),
                //       y = (newdiag.Y<0 ?  mousep.Y : origin.Y);
                //SelectionRect.RenderTransform = new TranslateTransform(x, y);
                PreviewRect.SetPosition(topleft.X, topleft.Y, width, height);
            }
        }
コード例 #17
0
        /*
         * /// <summary>
         * /// Sets the current parsetree and updates the overlay.
         * /// </summary>
         * /// <param name="t">The new parsetree.</param>
         * /// <param name="tBB">The new bounding box.</param>
         * public void SetParseTree(Tikz_ParseTree t, Rect tBB)
         * {
         *  BB = tBB;
         *  ParseTree = t;
         *  //curSel = null; //curDragged = null;
         *  Resolution = Resolution; // to recalc size
         *  ActivateDefaultTool(); // to reset current tool
         *  RedrawObjects();
         * } */


        #region Events forwarded to Current tool
        private void canvas1_MouseMove(object sender, MouseEventArgs e)
        {
            Point mousep = e.GetPosition(canvas1);
            // convert to bottom left coordinates
            Point p = new Point(mousep.X, Height - mousep.Y);

            TEMouseArgs ee = e.ToTEMouseArgs();

            TheModel.CurrentTool.OnMouseMove(p, ee);
            e.Handled = ee.Handled;


            // display the current mouse position

            /*   p.Y /= Resolution;
             * p.X /= Resolution;
             * p.X += BB.X;
             * p.Y += BB.Y;
             *
             * String s = "(" + String.Format("{0:f1}", p.X) + "; " + String.Format("{0:f1}", p.Y) + ")";
             * ((MainWindow)Application.Current.Windows[0]).AddStatusBarCoordinate(s);
             */
        }
コード例 #18
0
        public override void OnMouseMove(Point p, TEMouseArgs e)
        {
            Point mousep = overlay.CursorPosition;

            // start a drag operation only after the mouse moved at least xx pixels to avoid accidental moving
            if ((DragOriginC - p).Length > 5)
            {
                movedenough = true;
            }
            // for a dragged scope, the relative movement gets rasterized
            // for a dragged node, the center of the node gets rasterized
            if (curDragged != null && e.LeftButtonPressed && movedenough)
            {
                if (curDragged is OverlayScope)
                {
                }
                else if (curDragged is OverlayNode)
                {
                    // use width instead actual width
                    Point center_pixel = new Point(p.X - DragOrigin.X,
                                                   p.Y - DragOrigin.Y);
                    // the center pixel of the node should go here
                    center_pixel = overlay.Rasterizer.RasterizePixel(center_pixel);

                    // shift yet to be done
                    Point relshift_tobedone = new Point(
                        center_pixel.X - curDragged.Center.X,
                        center_pixel.Y - curDragged.Center.Y
                        );
                    //ShiftSelItemsOnScreen(relshift_tobedone);

                    curDragged.Center = center_pixel;

                    AdjustPreviewPos(center_pixel);
                }
            }
        }
コード例 #19
0
        public override void OnLeftMouseButtonDown(OverlayShape 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;
        }
コード例 #20
0
        public override void OnLeftMouseButtonDown(OverlayShape 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 OverlayShape)
            {
                // initiate a drag/drop operation
                curDragged = (OverlayShape)item;
                DragOrigin = (Point)((new Point(item.View.GetLeft(), item.View.GetBottom())) - p); ////e.GetPosition(item);
                ////DragOrigin = new Point(DragOrigin.X, (item as OverlayShape).Height - DragOrigin.Y);
                DragOriginC = p;
                DragOriginO = new Point(curDragged.View.GetLeft(), curDragged.View.GetBottom());
                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;
            }
        }
コード例 #21
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/tikzedt
 /// <summary>
 /// LeftMouseButtonUp event, forwarded from the overlay control.
 /// </summary>
 /// <param name="p"></param>
 /// <param name="e"></param>
 public virtual void OnLeftMouseButtonUp(Point p, TEMouseArgs e) { }
コード例 #22
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)
 {
 }
コード例 #23
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
 /// <summary>
 /// MouseMove event, forwarded from the overlay control.
 /// </summary>
 /// <param name="p"></param>
 ///
 public virtual void OnMouseMove(Point p, TEMouseArgs e)
 {
 }
コード例 #24
0
ファイル: BezierTool.cs プロジェクト: JoeyEremondi/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();
        }
コード例 #25
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnRightMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            //base.OnRightMouseButtonDown(item, p, e);

            // if a node is selected, unselect it
            if (curSel != null)
            {
                curSel = null;
                e.Handled = true;   // we don't want anything else to happen (contextmenu opening etc)
            }
        }
コード例 #26
0
ファイル: ArcEditTool.cs プロジェクト: JoeyEremondi/tikzedt
        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;
            }
        }
コード例 #27
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e) 
        {

            if (!(item is OverlayNode))
            {
                curSel = null;
                return;
            }
            OverlayNode n = item as OverlayNode;

            // make sure a referenceable item is selected... otherwise we cannot add an edge
            if (!IsReferenceable(item))
            {
                MainWindow.AddStatusLine("Only items that are referenceable (=can be given names) can be connected with the edge tool.");
                return;
            }

            if (curSel == null)
            {
                curSel = n;
                return;
            }

            // make sure both nodes involved are nodes
          /*  if (!(curSel.tikzitem is Tikz_Node) || !(n.tikzitem is Tikz_Node))
            {
                String which = ""; String verb = "is";
                if (!(curSel.tikzitem is Tikz_Node) && !(n.tikzitem is Tikz_Node))
                { which = "Both"; verb = "are"; }
                else if (!(curSel.tikzitem is Tikz_Node))
                    which = "The first";
                else if (!(n.tikzitem is Tikz_Node))
                    which = "The second";
                MainWindow.AddStatusLine(which + " of the selected coordinates " + verb + " not a node (i.e. not defined with \\node but rather with \\draw or \\path)", true);
                curSel = null;
                return; // hack
            } */

            //the return from above must not interfere with BeginModify()
            overlay.BeginUpdate();

            // add an edge curSel to n
            //bool lcreated;
            //if (EnsureCurAddToExists(out lcreated))

            //always create new \draw command. otherwise it can happen that the \draw-command
            //is above the \node-definition which causes an error while compiling the latex code.
            if (AddNewCurAddTo())
            {
                // make sure both nodes involved have names
                Parser.Tikz_Node t1 = MakeReferenceableNode(curSel.tikzitem ),
                                 t2 = MakeReferenceableNode(n.tikzitem );

                Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord();
                tc1.type = Parser.Tikz_CoordType.Named;
                Parser.Tikz_Coord tc2 = new Parser.Tikz_Coord();
                tc2.type = Parser.Tikz_CoordType.Named;

                curAddTo.AddChild(new Parser.Tikz_Something(" "));
                curAddTo.AddChild(tc1);
                if (t1 == t2)                
                    curAddTo.AddChild(new Parser.Tikz_Something(" edge[loop, looseness=20] "));                
                else
                    curAddTo.AddChild(new Parser.Tikz_Something(" edge "));
                curAddTo.AddChild(tc2);
                //tpict.AddChild(tp);                    

                // make sure both nodes have names
  /*              Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture();
                if (t1.name == "")
                {
                    t1.SetName(tpict.GetUniqueName());
                    t1.UpdateText();
                }
                if (t2.name == "")
                {
                    t2.SetName(tpict.GetUniqueName());
                    t2.UpdateText();
                }
                */
                tc1.nameref = t1.name;
                tc2.nameref = t2.name;
                //tc1.UpdateText();
                curAddTo.UpdateText();
                //tpict.UpdateText();
                //                    txtCode_TextChanged

                //RedrawObjects();
                //if (OnModified != null)
                //    OnModified.Invoke();

                //edge was drawn. release currently selected node.
                curSel = null;

                //will neither want to path tool to start from this last select nodes.
                curAddTo = null;
            }
            //forgetting to call EndModify causes weird "No undo group should be open at this point"-message.
            overlay.EndUpdate();
        }
コード例 #28
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
        {
            if (!(item is OverlayNode))
            {
                curSel = null;
                return;
            }
            OverlayNode n = item as OverlayNode;

            // make sure a referenceable item is selected... otherwise we cannot add an edge
            if (!IsReferenceable(item))
            {
                MainWindow.AddStatusLine("Only items that are referenceable (=can be given names) can be connected with the edge tool.");
                return;
            }

            if (curSel == null)
            {
                curSel = n;
                return;
            }

            // make sure both nodes involved are nodes

            /*  if (!(curSel.tikzitem is Tikz_Node) || !(n.tikzitem is Tikz_Node))
             * {
             *    String which = ""; String verb = "is";
             *    if (!(curSel.tikzitem is Tikz_Node) && !(n.tikzitem is Tikz_Node))
             *    { which = "Both"; verb = "are"; }
             *    else if (!(curSel.tikzitem is Tikz_Node))
             *        which = "The first";
             *    else if (!(n.tikzitem is Tikz_Node))
             *        which = "The second";
             *    MainWindow.AddStatusLine(which + " of the selected coordinates " + verb + " not a node (i.e. not defined with \\node but rather with \\draw or \\path)", true);
             *    curSel = null;
             *    return; // hack
             * } */

            //the return from above must not interfere with BeginModify()
            overlay.BeginUpdate();

            // add an edge curSel to n
            //bool lcreated;
            //if (EnsureCurAddToExists(out lcreated))

            //always create new \draw command. otherwise it can happen that the \draw-command
            //is above the \node-definition which causes an error while compiling the latex code.
            if (AddNewCurAddTo())
            {
                // make sure both nodes involved have names
                Parser.Tikz_Node t1 = MakeReferenceableNode(curSel.tikzitem),
                                 t2 = MakeReferenceableNode(n.tikzitem);

                Parser.Tikz_Coord tc1 = new Parser.Tikz_Coord();
                tc1.type = Parser.Tikz_CoordType.Named;
                Parser.Tikz_Coord tc2 = new Parser.Tikz_Coord();
                tc2.type = Parser.Tikz_CoordType.Named;

                curAddTo.AddChild(new Parser.Tikz_Something(" "));
                curAddTo.AddChild(tc1);
                if (t1 == t2)
                {
                    curAddTo.AddChild(new Parser.Tikz_Something(" edge[loop, looseness=20] "));
                }
                else
                {
                    curAddTo.AddChild(new Parser.Tikz_Something(" edge "));
                }
                curAddTo.AddChild(tc2);
                //tpict.AddChild(tp);

                // make sure both nodes have names

                /*              Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture();
                 *            if (t1.name == "")
                 *            {
                 *                t1.SetName(tpict.GetUniqueName());
                 *                t1.UpdateText();
                 *            }
                 *            if (t2.name == "")
                 *            {
                 *                t2.SetName(tpict.GetUniqueName());
                 *                t2.UpdateText();
                 *            }
                 */
                tc1.nameref = t1.name;
                tc2.nameref = t2.name;
                //tc1.UpdateText();
                curAddTo.UpdateText();
                //tpict.UpdateText();
                //                    txtCode_TextChanged

                //RedrawObjects();
                //if (OnModified != null)
                //    OnModified.Invoke();

                //edge was drawn. release currently selected node.
                curSel = null;

                //will neither want to path tool to start from this last select nodes.
                curAddTo = null;
            }
            //forgetting to call EndModify causes weird "No undo group should be open at this point"-message.
            overlay.EndUpdate();
        }
コード例 #29
0
ファイル: SelectionTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnMouseMove(Point p, TEMouseArgs e)
        {
            Point mousep = overlay.CursorPosition;
            if (SelectionRect.Visible)
            {
                // update the size of the selection rect
                double x = Math.Min(mousep.X, SelectionRectOrigin.X),
                       y = Math.Min(mousep.Y, SelectionRectOrigin.Y);
                //SelectionRect.RenderTransform = new TranslateTransform(x, y);
                ////Canvas.SetLeft(SelectionRect, x);
                ////Canvas.SetTop(SelectionRect, y);
                ////SelectionRect.Width = Math.Abs(mousep.X - SelectionRectOrigin.X);
                ////SelectionRect.Height = Math.Abs(mousep.Y - SelectionRectOrigin.Y);
                SelectionRect.SetPosition(x, y, Math.Abs(mousep.X - SelectionRectOrigin.X), Math.Abs(mousep.Y - SelectionRectOrigin.Y));

                // update current selection
                Rect selr = SelectionRect.GetBB();////System.Windows.Controls.Primitives.LayoutInformation.GetLayoutSlot(SelectionRect); // this is BB of selection rect
                UpdateSelection(selr, overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control));

            }

            // start a drag operation only after the mouse moved at least xx pixels to avoid accidental moving
            if ((DragOriginC - p).Length > 5)
                movedenough = true;
            // for a dragged scope, the relative movement gets rasterized
            // for a dragged node, the center of the node gets rasterized
            if (curDragged != null && e.LeftButtonPressed && movedenough)
            {
                if (curDragged is OverlayScope)
                {
                    // total shift
                    Point relshift_pixel = new Point(p.X - DragOriginC.X, p.Y - DragOriginC.Y);
                    relshift_pixel = overlay.Rasterizer.RasterizePixelRelative(relshift_pixel);
                    // shift yet to be done
                    Vector relshift_tobedone = (Vector)(DragOriginO + (relshift_pixel - curDragged.Center));

                    ShiftSelItemsOnScreen(relshift_tobedone);
                }
                else if (curDragged is OverlayNode)
                {
                    // use width instead actual width
                    ////Point center_pixel = new Point(p.X - DragOrigin.X + curDragged.Width / 2,
                    ////                               p.Y - DragOrigin.Y + curDragged.Height / 2);
                    Point center_pixel = new Point(p.X - DragOrigin.X,
                                                   p.Y - DragOrigin.Y);
                    // the center pixel of the node should go here
                    center_pixel = overlay.Rasterizer.RasterizePixel(center_pixel);

                    // shift yet to be done
                    Vector relshift_tobedone = center_pixel - curDragged.Center;
                    ShiftSelItemsOnScreen(relshift_tobedone);

                }
            }
        }
コード例 #30
0
ファイル: SelectionTool.cs プロジェクト: JoeyEremondi/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;

            }


        }
コード例 #31
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/tikzedt
 /// <summary>
 /// MouseMove event, forwarded from the overlay control.
 /// </summary>
 /// <param name="p"></param>
 /// 
 public virtual void OnMouseMove(Point p, TEMouseArgs e) { }
コード例 #32
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/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) { }
コード例 #33
0
ファイル: ArcTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape 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);

                ////if (!overlay.canvas.Children.Contains(PreviewArc))
                ////    overlay.canvas.Children.Add(PreviewArc);
                ////if (!overlay.canvas.Children.Contains(PreviewPie))
                ////    overlay.canvas.Children.Add(PreviewPie);
            }
            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);

        }
コード例 #34
0
ファイル: ArcEditTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnMouseMove(Point p, TEMouseArgs e)
        {
            Point mousep = overlay.CursorPosition;

            // start a drag operation only after the mouse moved at least xx pixels to avoid accidental moving
            if ((DragOriginC - p).Length > 5)
                movedenough = true;
            // for a dragged scope, the relative movement gets rasterized
            // for a dragged node, the center of the node gets rasterized
            if (curDragged != null && e.LeftButtonPressed && movedenough)
            {
                if (curDragged is OverlayScope)
                {
                }
                else if (curDragged is OverlayNode)
                {
                    // use width instead actual width
                    Point center_pixel = new Point(p.X - DragOrigin.X ,
                                                   p.Y - DragOrigin.Y );
                    // the center pixel of the node should go here
                    center_pixel = overlay.Rasterizer.RasterizePixel(center_pixel);

                    // shift yet to be done
                    Point relshift_tobedone = new Point(
                         center_pixel.X - curDragged.Center.X,
                         center_pixel.Y - curDragged.Center.Y 
                        );
                    //ShiftSelItemsOnScreen(relshift_tobedone);

                    curDragged.Center = center_pixel;

                    AdjustPreviewPos(center_pixel);
                    
                }
            }
        }
コード例 #35
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape 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);
            UpdateRaster();
            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);


            // find next tikzpicture and add
            bool lcreated;
            if (EnsureCurAddToExists(out lcreated))
            {
                // on double click -> close path
                if (e.ClickCount == 2)
                {
                    if (!lcreated)
                    {
                        //if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
                            curAddTo.AddChild(new Parser.Tikz_Something(" -- cycle"));
                        //else
                        //    curAddTo.AddChild(new Parser.Tikz_Something(" cycle"));
                    }
                }
                else
                {
                    if (!lcreated)
                    {
                        if (!overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                            // add an edge
                            curAddTo.AddChild(new Parser.Tikz_Something(" -- "));
                        else
                            curAddTo.AddChild(new Parser.Tikz_Something(" "));
                    }

                    // create new coordinate. If some node was clicked, set a reference to that node. Otherwise, just make new coordinates
                    Tikz_Coord tc = new Tikz_Coord();
                    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.type = overlay.UsePolarCoordinates ? Tikz_CoordType.Polar : Tikz_CoordType.Cartesian;
                        if (!lcreated) 
                            tc.deco = overlay.NewNodeModifier;  // first node should always be in absolute coordinates
                        tc.SetAbsPos(new Point(p.X, p.Y)); //hack

                        // if a nonempty node style is selected, also add a node with that style
                        if (overlay.NodeStyle.Trim() != "")
                        {
                            Tikz_Node tn = new Tikz_Node()
                            {
                                options = "["+overlay.NodeStyle+"]",
                                coord = null,
                                text = ""
                            };
                            curAddTo.AddChild(new Tikz_Something(" "));
                            curAddTo.AddChild(tn);
                        }
                    }
                    //tn.UpdateText();
                    curAddTo.UpdateText();
                    //tpict.UpdateText();

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

            overlay.EndUpdate();
            UpdateRaster();

            // doubleclick also stops path drawing
            if (e.ClickCount == 2)
                overlay.ActivateDefaultTool();
        }
コード例 #36
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/tikzedt
 /// <summary>
 /// This method is called when the tool is active and the appropriate mouse event occurs.
 /// 
 /// </summary>
 /// <param name="item">The item at cursor position.</param>
 /// <param name="p">The cursor position, in BOTTOM LEFT CENTERED pixel coordinates.</param>
 /// <param name="e"></param>
 public virtual void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e) { }
コード例 #37
0
        public override void OnLeftMouseButtonDown(OverlayShape 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;
        }
コード例 #38
0
ファイル: ArcTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape 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);

                ////if (!overlay.canvas.Children.Contains(PreviewArc))
                ////    overlay.canvas.Children.Add(PreviewArc);
                ////if (!overlay.canvas.Children.Contains(PreviewPie))
                ////    overlay.canvas.Children.Add(PreviewPie);
            }
            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);
        }
コード例 #39
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;
            }
        }
コード例 #40
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();
        }
コード例 #41
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape 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);
            UpdateRaster();
            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);


            // find next tikzpicture and add
            bool lcreated;

            if (EnsureCurAddToExists(out lcreated))
            {
                // on double click -> close path
                if (e.ClickCount == 2)
                {
                    if (!lcreated)
                    {
                        //if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
                        curAddTo.AddChild(new Parser.Tikz_Something(" -- cycle"));
                        //else
                        //    curAddTo.AddChild(new Parser.Tikz_Something(" cycle"));
                    }
                }
                else
                {
                    if (!lcreated)
                    {
                        if (!overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                        {
                            // add an edge
                            curAddTo.AddChild(new Parser.Tikz_Something(" -- "));
                        }
                        else
                        {
                            curAddTo.AddChild(new Parser.Tikz_Something(" "));
                        }
                    }

                    // create new coordinate. If some node was clicked, set a reference to that node. Otherwise, just make new coordinates
                    Tikz_Coord tc = new Tikz_Coord();
                    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.type = overlay.UsePolarCoordinates ? Tikz_CoordType.Polar : Tikz_CoordType.Cartesian;
                        if (!lcreated)
                        {
                            tc.deco = overlay.NewNodeModifier; // first node should always be in absolute coordinates
                        }
                        tc.SetAbsPos(new Point(p.X, p.Y));     //hack

                        // if a nonempty node style is selected, also add a node with that style
                        if (overlay.NodeStyle.Trim() != "")
                        {
                            Tikz_Node tn = new Tikz_Node()
                            {
                                options = "[" + overlay.NodeStyle + "]",
                                coord   = null,
                                text    = ""
                            };
                            curAddTo.AddChild(new Tikz_Something(" "));
                            curAddTo.AddChild(tn);
                        }
                    }
                    //tn.UpdateText();
                    curAddTo.UpdateText();
                    //tpict.UpdateText();

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

            overlay.EndUpdate();
            UpdateRaster();

            // doubleclick also stops path drawing
            if (e.ClickCount == 2)
            {
                overlay.ActivateDefaultTool();
            }
        }
コード例 #42
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
 /// <summary>
 /// LeftMouseButtonUp event, forwarded from the overlay control.
 /// </summary>
 /// <param name="p"></param>
 /// <param name="e"></param>
 public virtual void OnLeftMouseButtonUp(Point p, TEMouseArgs e)
 {
 }
コード例 #43
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;
                    }

                    OverlayShape 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;
            }
        }
コード例 #44
0
        public override void OnLeftMouseButtonUp(Point p, TEMouseArgs e)
        {
            // add the rectangle
            if (PreviewEllipse.Visible)
            {
                if (!EnsureParseTreeExists())
                    return;

                Point center = overlay.ScreenToTikz(origin, true); 
                Point secondpoint = overlay.Rasterizer.RasterizePixelToTikz(p); // in axis aligned (untranformed) tikz coordinates

                // compute rotated diagonal
                double angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform);
                TikzMatrix R = TikzMatrix.RotationMatrix(angle);
                Vector newdiag = R.Transform(secondpoint - center);

                double width = Math.Abs(newdiag.X),   // actually half the width/height!
                       height = Math.Abs(newdiag.Y);

                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                    width = height = Math.Max(width, height);
                
                overlay.BeginUpdate();

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

                    curAddTo.AddChild(new Parser.Tikz_Something(" "));
                    curAddTo.AddChild(tc1);
                    // since there might be a coordinate tranform, the width/height have to be transformed
                    // (note: rotates are not very well supported here) 
                    TikzMatrix M;
                    if (curAddTo.GetCurrentTransformAt(tc1, out M))
                    {
                        R = R.Inverse();
                        Point size_trans = M.Inverse().Transform(R.Transform(new Point(width, height)), true);
                        width = size_trans.X;
                        height = size_trans.Y;
                    }
                    else
                    {
                        MainWindow.AddStatusLine("Warning: Couldn't compute tranform at insertion position. Coordinates might be wrong.", true);
                    }

                    width = Math.Round(width, (int)Properties.Settings.Default.RoundToDecimals);
                    height = Math.Round(height, (int)Properties.Settings.Default.RoundToDecimals);

                    if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control) && width == height)
                        curAddTo.AddChild(new Parser.Tikz_Something(" circle (" + width + ")" ));
                    else
                        curAddTo.AddChild(new Parser.Tikz_Something(" ellipse (" + width + " and " + height + ")"));

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

                    curAddTo.UpdateText();
                }

                overlay.EndUpdate();

                PreviewEllipse.Visible = false;
            }
        }
コード例 #45
0
ファイル: OverlayTool.cs プロジェクト: wilsoc5/tikzedt
 /// <summary>
 /// This method is called when the tool is active and the appropriate mouse event occurs.
 ///
 /// </summary>
 /// <param name="item">The item at cursor position.</param>
 /// <param name="p">The cursor position, in BOTTOM LEFT CENTERED pixel coordinates.</param>
 /// <param name="e"></param>
 public virtual void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e)
 {
 }
コード例 #46
0
        public override void OnLeftMouseButtonUp(Point p, TEMouseArgs e)
        {
            // add the rectangle
            if (PreviewEllipse.Visible)
            {
                if (!EnsureParseTreeExists())
                {
                    return;
                }

                Point center      = overlay.ScreenToTikz(origin, true);
                Point secondpoint = overlay.Rasterizer.RasterizePixelToTikz(p); // in axis aligned (untranformed) tikz coordinates

                // compute rotated diagonal
                double     angle   = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform);
                TikzMatrix R       = TikzMatrix.RotationMatrix(angle);
                Vector     newdiag = R.Transform(secondpoint - center);

                double width  = Math.Abs(newdiag.X),  // actually half the width/height!
                       height = Math.Abs(newdiag.Y);

                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                {
                    width = height = Math.Max(width, height);
                }

                overlay.BeginUpdate();

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

                    curAddTo.AddChild(new Parser.Tikz_Something(" "));
                    curAddTo.AddChild(tc1);
                    // since there might be a coordinate tranform, the width/height have to be transformed
                    // (note: rotates are not very well supported here)
                    TikzMatrix M;
                    if (curAddTo.GetCurrentTransformAt(tc1, out M))
                    {
                        R = R.Inverse();
                        Point size_trans = M.Inverse().Transform(R.Transform(new Point(width, height)), true);
                        width  = size_trans.X;
                        height = size_trans.Y;
                    }
                    else
                    {
                        GlobalUI.UI.AddStatusLine(this, "Warning: Couldn't compute tranform at insertion position. Coordinates might be wrong.", true);
                    }

                    width  = Math.Round(width, (int)CompilerSettings.Instance.RoundToDecimals);
                    height = Math.Round(height, (int)CompilerSettings.Instance.RoundToDecimals);

                    if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control) && width == height)
                    {
                        curAddTo.AddChild(new Parser.Tikz_Something(" circle (" + width + ")"));
                    }
                    else
                    {
                        curAddTo.AddChild(new Parser.Tikz_Something(" ellipse (" + width + " and " + height + ")"));
                    }

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

                    //          overlay.AddToDisplayTree(tc1);

                    curAddTo.UpdateText();
                }

                overlay.EndUpdate();

                PreviewEllipse.Visible = false;
            }
        }
コード例 #47
0
        public override void OnMouseMove(Point p, TEMouseArgs e)
        {
            base.OnMouseMove(p, e);

            //Point mousep = e.GetPosition(overlay.canvas);
            Point mousep = overlay.Rasterizer.RasterizePixel(p);
            ////mousep = new Point(mousep.X, overlay.canvas.ActualHeight - mousep.Y);
            mousep = new Point(mousep.X, overlay.Height - mousep.Y);
            if (PreviewEllipse.Visible)
            {
                // compute rotated diagonal
                double angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform);
                //TikzMatrix R
                TikzMatrix R = TikzMatrix.RotationMatrix(-angle);
                Vector newdiag = R.Transform(mousep - origin);

                double width = Math.Abs(newdiag.X),   // actually half the width/height!
                       height = Math.Abs(newdiag.Y);
                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                    width = height = Math.Max(width, height);

                R = R.Inverse();
                Point topleft = origin + R.Transform(new Vector(-width, -height));

                PreviewEllipse.SetPosition(topleft.X, topleft.Y, 2 * width, 2 * height);
            }
        }
コード例 #48
0
ファイル: SelectionTool.cs プロジェクト: JoeyEremondi/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();
            }
        }
コード例 #49
0
ファイル: OverlayTool.cs プロジェクト: JoeyEremondi/tikzedt
        public override void OnLeftMouseButtonDown(OverlayShape item, Point p, TEMouseArgs e) 
        {
            if (!EnsureParseTreeExists())
                return;

            overlay.BeginUpdate();

            overlay.SetCorrectRaster(overlay.CurEditing, true);

            //Point p = new Point(e.GetPosition(canvas1).X, Height - e.GetPosition(canvas1).Y);
            p = overlay.Rasterizer.RasterizePixelToTikz(p);
            if (ContinueWithBigImage(p) == false)
                return;

            // find next tikzpicture and add
            Parser.Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture();
            if (tpict != null)
            {
                Parser.Tikz_Node tn = new Parser.Tikz_Node();
                tn.label = "";
                tn.coord = new Parser.Tikz_Coord();
                if (overlay.NodeStyle != "")
                    tn.options = "[" + overlay.NodeStyle + "]";

                Parser.Tikz_Path tp = new Parser.Tikz_Path();
                tp.starttag = @"\node ";
                tp.endtag = ";";

                tp.AddChild(tn);
                if (overlay.CurEditing != null)
                {
                    overlay.CurEditing.tikzitem.AddChild(tp);
                    overlay.CurEditing.tikzitem.AddChild(new Parser.Tikz_Something("\r\n"));
                }
                else
                {
                    tpict.AddChild(tp);
                    tpict.AddChild(new Parser.Tikz_Something("\r\n"));
                }
                // do it here since the coordinate calculation needs the parents' coord. transform
                tn.SetAbsPos(new Point(p.X, p.Y)); //hack

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

                //RedrawObjects();
                overlay.AddToDisplayTree(tp);
            }

            overlay.EndUpdate();
        }
コード例 #50
0
ファイル: SmoothCurveTool.cs プロジェクト: wilsoc5/tikzedt
        Tikz_Option smoothOption; // this has to be changed to smooth cycle for closed curve

        public override void OnLeftMouseButtonDown(OverlayShape 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();
            }
        }
コード例 #51
0
        public override void OnMouseMove(Point p, TEMouseArgs e)
        {
            base.OnMouseMove(p, e);

            //Point mousep = e.GetPosition(overlay.canvas);
            Point mousep = overlay.Rasterizer.RasterizePixel(p);
            ////mousep = new Point(mousep.X, overlay.canvas.ActualHeight - mousep.Y);
            mousep = new Point(mousep.X, overlay.Height - mousep.Y);
            if (PreviewRect.Visible)
            {
                // compute rotated diagonal
                double angle = -Helper.RotationFromMatrix(overlay.Rasterizer.View.CoordinateTransform);
                TikzMatrix R =TikzMatrix.RotationMatrix(-angle);
                Vector newdiag = R.Transform(mousep-origin);

                // update the size and position of the preview rect
                double width, height;
                if (overlay.KeyboardModifiers.HasFlag(TEModifierKeys.Control))
                {
                    // both sides the same
                    width = height = Math.Max(Math.Abs(newdiag.X), Math.Abs(newdiag.Y));
                    newdiag = new Vector(Math.Sign(newdiag.X) * width, Math.Sign(newdiag.Y) * height);
                }
                else
                {
                    width = Math.Abs(newdiag.X);
                    height = Math.Abs(newdiag.Y);
                }
               
                R = R.Inverse();
                Point topleft = origin + R.Transform( new Vector(Math.Min(0, newdiag.X), Math.Min(0, newdiag.Y)) );

                //double x = (newdiag.X<0 ?  mousep.X : origin.X),
                //       y = (newdiag.Y<0 ?  mousep.Y : origin.Y);
                //SelectionRect.RenderTransform = new TranslateTransform(x, y);
                PreviewRect.SetPosition(topleft.X, topleft.Y, width, height);

            }
        }
コード例 #52
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;
            }
        }
コード例 #53
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();
        }