Exemple #1
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);
            }
        }
Exemple #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 (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);
            }
        }
Exemple #3
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;
            }
        }
Exemple #4
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;
            }
        }
Exemple #5
0
        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);
        }