Example #1
0
        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();
        }
Example #2
0
        protected virtual bool EnsureCurAddToExists(out bool created)
        {
            created = false;
            if (overlay.ParseTree == null)
            {
                return(false);
            }
            // find tikzpicture
            Parser.Tikz_Picture tpict = overlay.ParseTree.GetTikzPicture();
            if (tpict == null)
            {
                if (overlay.AllowEditing)
                {
                    // add a new tikzpicture
                    Tikz_Picture tp = new Tikz_Picture();
                    tp.starttag = "\\begin{tikzpicture}";
                    tp.AddChild(new Tikz_Something("\r\n"));
                    tp.endtag = "\\end{tikzpicture}";

                    //overlay.BeginUpdate();

                    overlay.ParseTree.AddChild(tp);
                    tp.UpdateText();

                    //overlay.EndUpdate();
                }
                else
                {
                    return(false);
                }
            }

            if (curAddTo == null || !(curAddTo is Parser.Tikz_Path))
            {
                created = AddNewCurAddTo();
            }

            return(true);
        }