Jump to content

Fix for MoveNubRenderer selection in the LineTool.


Recommended Posts

I was getting annoyed when I was dealing with small lines, that it would select the wrong nub. So I changed the OnStylusDown method in the LineTool. Now it works perfectly.

Because instead of stopping at the first nub that passes the IsPointTouching method, it also checks all the nubs and picks the one closer to the mouse.

Here is the changed method:

        protected override void OnStylusDown(StylusEventArgs e)
       {
           bool callBase = false;
           if (!this.inCurveMode)
           {
               callBase = true;
           }
           else
           {
               PointF mousePt = new PointF(e.Fx, e.Fy);
               //start of change
               Single mindistance = Single.MaxValue;
               for (int i = 0; i < this.moveNubs.Length; ++i)
               {
                   if (this.moveNubs[i].IsPointTouching(Point.Truncate(mousePt), true))
                   {
                       PointF[] points = new PointF[]{this.moveNubs[i].Location};
                       this.moveNubs[i].Transform.TransformPoints(points);
                       Single distX = points[0].X - mousePt.X;
                       Single distY = points[0].Y - mousePt.Y;
                       Single distance = (Single)Math.Sqrt(distX * distX + distY * distY);
                       if (distance < mindistance)
                       {
                           mindistance = distance;
                           this.draggingNubIndex = i;
                           this.Cursor = this.handCursorMouseDown;
                           if (this.curveType == CurveType.NotDecided)
                           {
                               if (e.Button == MouseButtons.Right)
                               {
                                   this.curveType = CurveType.Bezier;
                               }
                               else
                               {
                                   this.curveType = CurveType.Spline;
                               }
                           }
                       }
                   }
               }
               //end of change
               if (this.draggingNubIndex == -1)
               {
                   callBase = true;
               }
               else
               {
                   for (int i = 0; i < this.moveNubs.Length; ++i)
                   {
                       this.moveNubs[i].Visible = false;
                   }
                   string helpText2 = PdnResources.GetString("LineTool.CurvingHelpText");
                   SetStatus(null, helpText2);
                   OnStylusMove(e);
               }
           }
           if (callBase)
           {
               base.OnStylusDown(e);
           }
       }

the original method is from 2.61

Link to comment
Share on other sites

I'm planning on making some changes to the way Tools handle this type of stuff anyway, I'll make sure this type of proximity association is implemented in 3.0.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...