예제 #1
0
        //Method mainly for the copy paste function, make a clone of the
        //poly that way when you change a point in one you don't change it for every
        //copied poly.
        public Polygon ClonePolygon(Polygon toClone)
        {
            var poly = new Polygon();
            poly.Name = toClone.Name;
            foreach (PolyPoint child in toClone.Children)
            {
                var point = new PolyPoint(child.X, child.Y);
                poly.AddChild(point);
            }
            poly.Parent = toClone.Parent;

            return poly;
        }
예제 #2
0
        public ImageViewer()
        {
            _instance = this;

            _mode = Mode.Center;
            _paused = false;
            _poly = null;
            _polyGroup = null;
            _moving = null;
            if (!DesignMode)
            {
                _arrowNormCursor = new Cursor("Cursors/ArrowNorm.cur");
                _arrowOverCursor = new Cursor("Cursors/ArrowOver.cur");
                _penCursor = new Cursor("Cursors/Pen.cur");
                _penOverCursor = new Cursor("Cursors/PenOver.cur");
                _movingCursor = Cursors.Hand;
            }

            Timer refreshTimer = new Timer();
            refreshTimer.Interval = (int)(1000 * 1 / 30.0f);
            refreshTimer.Tick += Refresh;
            refreshTimer.Start();
        }
예제 #3
0
 public PolyPointExport(PolyPoint point)
 {
     X = point.MappedX;
     Y = point.MappedY;
 }
예제 #4
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            // update CenterPoint
            if (_mode == Mode.Center && _centerMoving)
            {
                _centerMoving = false;
            }
            // update PolygonPoint
            else if (_mode == Mode.Polygon && _poly != null)
            {
                _moving = null;
                if (_poly == null || _poly.Children.Count <= 1) return;

                // Double check points for doubles on the same spot
                var removal = new List<int>();
                for (int i = 0; i < _poly.Children.Count; ++i)
                {
                    foreach (var node in _poly.Children)
                    {
                        var child = (PolyPoint) node;
                        var polyPoint = _poly.Children[i] as PolyPoint;
                        if (polyPoint == null || (child.X != polyPoint.X || child.Y != polyPoint.Y)) continue;

                        // Check to make sure that the point isn't actually the exact same one index wise etc.
                        if (child == _poly.Children[i]) continue;
                        if (!removal.Contains(i))
                        {
                            removal.Add(i);
                        }
                    }
                }

                if (removal.Count == 0) return;
                removal.Reverse();
                foreach (var i in removal)
                {
                    _poly.Children.RemoveAt(i);
                }
                MessageBox.Show(@"Removed duplicate vertices. Try not to do this... it breaks things.");
            }
                //Set OriginalPoint to null so we don't keep moving the polygon forever.
            else if (_mode == Mode.Moving && _originalPoint != null)
            {
                _originalPoint = null;
            }
        }
예제 #5
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            //if right button held - pan
            if (e.Button == MouseButtons.Right)
            {
                var panVector = new Vector2((e.X - _currentX), (e.Y - _currentY));
                // panVector = _camera2D.GetWorldCoordinates(panVector);
                _camera2D.Move(-panVector);
               // _camera2D.Pos -= panVector;
                _currentX = e.X;
                _currentY = e.Y;
            }

            //if mode center and left button is held - still move center
            if (_mode == Mode.Center && _centerMoving)
            {
                Vector2 centerPoint = _camera2D.GetWorldCoordinates(new Vector2(e.X, e.Y));

                _image.CenterPointX = (int)centerPoint.X;
                _image.CenterPointY = (int)centerPoint.Y;
            }
            //if mode polygon and left button is held - still move polygon point
            else if (_mode == Mode.Polygon && _moving != null)
            {
                Vector2 polyWorldCenter = _camera2D.GetWorldCoordinates(new Vector2(e.X, e.Y));

                _moving.X = (int) polyWorldCenter.X;
                _moving.Y = (int) polyWorldCenter.Y;
            }
            //Move some Polygons
            else if (_mode == Mode.Moving && _originalPoint != null)
            {
                //Get the coords of the mouse in image space
                var polyWorldCenter = _camera2D.GetWorldCoordinates(new Vector2(e.X, e.Y));
                var p = new PolyPoint
                {
                    X = (int)polyWorldCenter.X,
                    Y = (int)polyWorldCenter.Y,
                };

                //Get the distance between the original Click point and the mouse currently.
                var dist = _originalPoint - p;
                dist *= -1;
                if (dist.X != 0 || dist.Y != 0 && MouseIsInPolygon(_poly.Children, p))
                {
                    var clone = _poly.ClonePolygon(_poly);
                    for (int i = 0; i < _poly.Children.Count; i++)
                    {
                        var child = (clone.Children[i] as PolyPoint);
                        child += dist;
                        _poly.Children[i] = child;
                    }
                }
                //set the _origianl point to the new mouse point.
                _originalPoint = p;

            }

            //Indicate Cursor
            bool overCenter = false;
            bool overPoly = false;
            if ((_mode == Mode.Center) && CheckifMouseIsInCenter(e.X, e.Y))
            {
                overCenter = true;
            }
            else if (_poly != null && (_mode == Mode.Polygon))
            {
                PolyPoint polygon = CheckIfMouseIsInPolygon(e.X, e.Y);
                if (polygon != null)
                    overPoly = true;
            }

            if (_mode == Mode.Center)
            {
                if (overCenter)
                    Cursor = _arrowOverCursor;
                else
                {
                    Cursor = _arrowNormCursor;
                }
            }
            else if (_mode == Mode.Moving)
            {
                Cursor = _movingCursor;
            }
            else
            {
                if (overPoly)
                    Cursor = _penOverCursor;
                else
                {
                    Cursor = _penCursor;
                }
            }
        }
예제 #6
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            //if right down, get current mouse location
            if (e.Button == MouseButtons.Right)
            {
                _currentX = e.X;
                _currentY = e.Y;
            }

            //if left down
            if (e.Button == MouseButtons.Left)
            {
                //end center mode - move center point
                if (_mode == Mode.Center)
                {
                    _centerMoving = true;

                    Vector2 centerPoint = _camera2D.GetWorldCoordinates(new Vector2(e.X, e.Y));

                    _image.CenterPointX = (int)centerPoint.X;
                    _image.CenterPointY = (int)centerPoint.Y;
                }
                else if (_poly != null && _mode == Mode.Polygon && _moving == null)
                {
                    //check if selecting existing point
                    _moving = CheckIfMouseIsInPolygon(e.X, e.Y);

                    // if not add point
                    if (_moving == null && _poly.Children.Count < Settings.Default.MaxVerts)
                    {
                        var polyWorldCenter = _camera2D.GetWorldCoordinates(new Vector2(e.X, e.Y));
                        var p = new PolyPoint
                        {
                            X = (int) polyWorldCenter.X,
                            Y = (int) polyWorldCenter.Y,
                            Parent = _poly
                        };
                        _poly.Children.Add(p);
                        //added point, now dirty.
                        Glue.Instance.DocumentIsSaved = false;
                        _moving = p;
                    }
                    else if( _poly.Children.Count >= Settings.Default.MaxVerts && _moving == null)
                    {
                        MessageBox.Show(
                            string.Format("Max Amount of Verts hit! The Max amount of verts for a polygon is {0}.",
                                Settings.Default.MaxVerts));
                    }
                }
                    //Movement start.
                else if (_poly != null && _moving == null && _mode == Mode.Moving)
                {
                    var polyWorldCenter = _camera2D.GetWorldCoordinates(new Vector2(e.X, e.Y));
                    var p = new PolyPoint
                    {
                        X = (int)polyWorldCenter.X,
                        Y = (int)polyWorldCenter.Y,
                    };
                    if (!CanMoveAnyPolygon)
                    {
                        //check if mouse is inside a polygon
                        if (MouseIsInPolygon(_poly.Children, p))
                        {
                            //store the original point then we'll check later to see how much we have to offset all the other points by
                            _originalPoint = p;
                        }
                    }
                    //if it wasn't inside the selected polygon see if it's inside another of the same polygroup
                    else
                    {
                        foreach (Polygon polygon in _polyGroup.Children)
                        {
                            if (MouseIsInPolygon(polygon.Children, p))
                            {
                                _originalPoint = p;
                                _poly = polygon;
                                _poly.IsSelected = true;
                                Mode = Mode.Moving;
                                break;
                            }
                        }
                    }
                }
            }
        }
예제 #7
0
        //A More exact Mouse In PolygonCheck
        public static bool MouseIsInPolygon(FastObservableCollection<INode> poly, PolyPoint point)
        {
            Vector3 vecPoint = new Vector3(point.X, point.Y,0);

            var tempList = new FastObservableCollection<INode>();
            foreach (var node in poly)
            {
                tempList.Add(node);
            }
            //Copy the list so we can add the last two verts into the start so we can get a full circle check easy.
            tempList.Insert(0,tempList[tempList.Count-2]);
            tempList.Insert(0,tempList[tempList.Count-1]);

            for (int i = 1; i < tempList.Count - 2; i++)
            {
                //we'll feed 3 verts at a time to PointInTriangle to see if it returns true or not. If one time returns true then we can stop calculating
                Vector3 A = new Vector3((tempList[0] as PolyPoint).X, (tempList[0] as PolyPoint).Y ,0);
                Vector3 B = new Vector3((tempList[i + 1] as PolyPoint).X, (tempList[i + 1] as PolyPoint).Y,0);
                Vector3 C = new Vector3((tempList[i + 2] as PolyPoint).X, (tempList[i + 2] as PolyPoint).Y,0);

                if (PointInTriangle(ref A, ref B, ref C, ref vecPoint))
                {
                    return true;
                }
            }
            return false;
        }
예제 #8
0
        private static void AddDefaultFootBox(ImageFrame frame)
        {
            var footGroup = new PolygonGroup { Name = "Foot", Parent = frame };
            footGroup.Initialize();

            frame.AddChild(footGroup);
            var foot = new Polygon { Name = "Foot", Parent = footGroup };

            var bottom = frame.TrimRectangle.Bottom - 1;
            var left = frame.TrimRectangle.Left;
            var right = frame.TrimRectangle.Right;
            var width = frame.TrimRectangle.Width;

            var tl = new PolyPoint(left + (int)(width * 0.25f), bottom - 2) { Parent = foot };
            var tr = new PolyPoint(right - (int)(width * 0.25f), bottom - 2) { Parent = foot };
            var br = new PolyPoint(right - (int)(width * 0.25f), bottom) { Parent = foot };
            var bl = new PolyPoint(left + (int)(width * 0.25f), bottom) { Parent = foot };

            foot.AddChild(tl);
            foot.AddChild(tr);
            foot.AddChild(br);
            foot.AddChild(bl);

            footGroup.AddChild(foot);
        }
예제 #9
0
        private static void AddDefaultDepthBox(ImageFrame frame)
        {
            var depthGroup = new PolygonGroup { Name = "Depth", Parent = frame };
            depthGroup.Initialize();

            frame.AddChild(depthGroup);
            var depth = new Polygon { Name = "Depth", Parent = depthGroup };

            var bottom = frame.TrimRectangle.Bottom - 1;
            var left = frame.TrimRectangle.Left;
            var right = frame.TrimRectangle.Right;
            var width = frame.TrimRectangle.Width;

            var defaultDepthPercentage = (int)(frame.TrimRectangle.Height * 0.125f);
            const float defaultWidthBorder = 0.9f; // 10% on each side = 80%

            var tl = new PolyPoint(left + (int)(width * defaultWidthBorder), bottom - defaultDepthPercentage) { Parent = depth };
            var tr = new PolyPoint(right - (int)(width * defaultWidthBorder), bottom - defaultDepthPercentage) { Parent = depth };
            var br = new PolyPoint(right - (int)(width * defaultWidthBorder), bottom) { Parent = depth };
            var bl = new PolyPoint(left + (int)(width * defaultWidthBorder), bottom) { Parent = depth };
            depth.AddChild(tl);
            depth.AddChild(tr);
            depth.AddChild(br);
            depth.AddChild(bl);

            depthGroup.AddChild(depth);
        }