Atalasoft
Welcome to Atalasoft Community Sign in | Join | Help
in

Custom Annotation Orientation

Last post 30 Dec 2007, 10:15 PM by Glenn. 1 replies.
Sort Posts: Previous Next
  •  27 Dec 2007, 11:48 AM 12917

    Custom Annotation Orientation

    I am making some custom annotations and I am having a problem getting them to stay oriented after I let go of the mouse button when creating them.  You can reproduce what I'm talking about through the Annotation Demo that comes with the Atalasoft toolkit.  Open the demo and load an image; click Annotations -> Add -> Triangle (Custom Example).  When you draw the triangle, draw it from the buttom up so that the triangle is pointed down - make sure you do this during the original creation of the annotation before you lift the mouse button up.  Once you lift the mouse button up, the triangle will flip so that the tip is pointed up.

    Does anybody have a suggestion of how to get the annotation to retain its orientation so that the tip is still pointing down when you let go of the mouse button?

    Thanks!

    -Richie

  •  30 Dec 2007, 10:15 PM 12921 in reply to 12917

    Re: Custom Annotation Orientation

    The main issue is that the annotation is considered in normal orientation when it's first created, so the annotation Size is "fixed" because there can't be a negative Size value.

    If you override the OnMouseUp method of your AnnotationUI object, you can check the Data.Size property to find out the orientation before the size is fixed.  If the height is negative, then it's vertically flipped.  Below is what I did to fix the TriangleAnnotation example:

    protected override bool OnMouseUp(AnnotationMouseEventArgs e)
    {
        if (this.State == AnnotationState.Creating)
        {
            SizeF sz = this.Data.Size;
            if (sz.Height < 0)
            {
                sz.Height *= -1;
                this.Data.Size = sz;
                this.Data.Location = new PointF(this.Data.Location.X, this.Data.Location.Y - sz.Height);
                this.Data.Mirror(MirrorDirection.Vertical, true);
            }
        }

        return base.OnMouseUp(e);
    }

     


    Glenn Chittenden Jr.
    Atalasoft Development Team
View as RSS news feed in XML