Exemplo n.º 1
0
        private void ScrollTick(object sender, EventArgs e)
        {
            if (_scrollViewport != null)
            {
                if (_scrollViewport.ScrollPosition.X + _xRate < 0)
                {
                    _xRate = Math.Max(0, _scrollViewport.ScrollPosition.X + _xRate);
                }
                if (_scrollViewport.ScrollPosition.Y + _yRate < 0)
                {
                    _yRate = Math.Max(0, _scrollViewport.ScrollPosition.Y + _yRate);
                }

                if (_scrollViewport.VisibleBounds.Right + _xRate >= _scrollViewport.LevelBounds.Width)
                {
                    _xRate = Math.Max(0, Math.Min(_scrollViewport.LevelBounds.Width - _scrollViewport.VisibleBounds.Right, _xRate));
                }
                if (_scrollViewport.VisibleBounds.Bottom + _yRate >= _scrollViewport.LevelBounds.Height)
                {
                    _yRate = Math.Max(0, Math.Min(_scrollViewport.LevelBounds.Height - _scrollViewport.VisibleBounds.Bottom, _yRate));
                }

                _scrollViewport.ScrollPosition = new Point(_scrollViewport.ScrollPosition.X + (int)_xRate, _scrollViewport.ScrollPosition.Y + (int)_yRate);

                _prevX = _prevX + _xRate;
                _prevY = _prevY + _yRate;
                PointerEventInfo info = new PointerEventInfo(PointerEventType.None, _prevX, _prevY);
                AutoScrollTick(info, _scrollViewport);
            }
        }
Exemplo n.º 2
0
        private void ShowPreviewMarker(PointerEventInfo info)
        {
            if (ActiveObjectClass == null)
                return;

            if (ActiveObjectClass != _activeClass) {
                HidePreviewMarker();
                _previewMarker = null;
                _activeClass = ActiveObjectClass;
            }

            if (!_previewMarkerVisible) {
                if (_previewMarker == null) {
                    _previewMarker = new ImageAnnot() {
                        Image = ActiveObjectClass.Image,
                        BlendColor = new Color(255, 255, 255, 128),
                    };
                }

                _annots.Add(_previewMarker);
                _previewMarkerVisible = true;
            }

            Point xlat = new Point((int)info.X - _activeClass.ImageBounds.Width / 2, (int)info.Y - _activeClass.ImageBounds.Height / 2);
            if (SnapManager != null)
                xlat = SnapManager.Translate(xlat, SnappingTarget);

            _previewMarker.Position = xlat;
        }
Exemplo n.º 3
0
 public void PointerPosition(PointerEventInfo info, ILevelGeometry viewport)
 {
     if (IsCancelled)
     {
         return;
     }
     PointerPositionCore(info, viewport);
 }
Exemplo n.º 4
0
 public void EndPointerSequence(PointerEventInfo info, ILevelGeometry viewport)
 {
     if (IsCancelled)
     {
         return;
     }
     EndPointerSequenceCore(info, viewport);
 }
Exemplo n.º 5
0
 protected override void EndPointerSequenceCore(PointerEventInfo info, ILevelGeometry viewport)
 {
     switch (info.Type) {
         case PointerEventType.Primary:
             EndSelectTilesSequence(info, viewport);
             break;
     }
 }
Exemplo n.º 6
0
        protected override void EndPointerSequenceCore(PointerEventInfo info, ILevelGeometry viewport)
        {
            _state = _state.EndPointerSequence(info, viewport);

            /*switch (info.Type) {
                case PointerEventType.Primary:
                    EndSelectObjectSequence(info, viewport);
                    break;
            }*/
        }
Exemplo n.º 7
0
        protected override void StartPointerSequenceCore(PointerEventInfo info, ILevelGeometry viewport)
        {
            switch (info.Type) {
                case PointerEventType.Primary:
                    StartFillSequence(info);
                    break;
            }

            UpdatePointerSequence(info, viewport);
        }
Exemplo n.º 8
0
        protected override void PointerPositionCore(PointerEventInfo info, ILevelGeometry viewport)
        {
            TileCoord location = TileLocation(info);
            if (!TileInRange(location) || _inAreaSequence) {
                HidePreviewMarker();
                return;
            }

            ShowPreviewMarker(location);
        }
Exemplo n.º 9
0
 protected override void EndPointerSequenceCore(PointerEventInfo info, ILevelGeometry viewport)
 {
     switch (info.Type) {
         case PointerEventType.Primary:
             EndErasePathSequence(info);
             break;
         case PointerEventType.Secondary:
             EndEraseAreaSequence(info, viewport);
             break;
     }
 }
Exemplo n.º 10
0
        protected void StartAutoScroll(PointerEventInfo info, ILevelGeometry viewport)
        {
            _prevX          = info.X;
            _prevY          = info.Y;
            _scrollViewport = viewport;

            if (_scrollTimer.Interval != 50)
            {
                _scrollTimer.Interval = 50;
                _scrollTimer.Tick    += new System.EventHandler(ScrollTick);
            }
            _scrollTimer.Enabled = true;
        }
Exemplo n.º 11
0
        protected override void StartPointerSequenceCore(PointerEventInfo info, ILevelGeometry viewport)
        {
            switch (info.Type) {
                case PointerEventType.Primary:
                    StartDrawObjectSequence(info);
                    break;
                case PointerEventType.Secondary:
                    Cancel();
                    break;
            }

            UpdatePointerSequence(info, viewport);
        }
Exemplo n.º 12
0
        protected override void StartPointerSequenceCore(PointerEventInfo info, ILevelGeometry viewport)
        {
            switch (info.Type) {
                case PointerEventType.Primary:
                    StartSelectTilesSequence(info, viewport);
                    break;
                case PointerEventType.Secondary:
                    DefloatSelection();
                    break;
            }

            UpdatePointerSequence(info, viewport);
        }
Exemplo n.º 13
0
        protected override void StartPointerSequenceCore(PointerEventInfo info, ILevelGeometry viewport)
        {
            _state = _state.StartPointerSequence(info, viewport);

            /*switch (info.Type) {
                case PointerEventType.Primary:
                    StartSelectObjectSequence(info, viewport);
                    break;
                case PointerEventType.Secondary:
                    _selectionManager.ClearSelection();
                    if (_rotationAnnot != null) {
                        _annots.Remove(_rotationAnnot);
                        _rotationAnnot = null;
                    }
                    UpdatePropertyProvider();
                    break;
            }*/

            UpdatePointerSequence(info, viewport);
        }
Exemplo n.º 14
0
        protected void UpdateAutoScroll(PointerEventInfo info, ILevelGeometry viewport)
        {
            double deltaX = info.X - _prevX;
            double deltaY = info.Y - _prevY;

            double diffLeft   = info.X - viewport.VisibleBounds.Left;
            double diffRight  = viewport.VisibleBounds.Right - info.X;
            double diffTop    = info.Y - viewport.VisibleBounds.Top;
            double diffBottom = viewport.VisibleBounds.Bottom - info.Y;

            double threshold  = 50 / viewport.ZoomFactor;
            double multiplier = 5;

            _xRate = 0;
            _yRate = 0;

            if (diffLeft < threshold)
            {
                _xRate = multiplier * (diffLeft - threshold) / threshold;
            }

            if (diffRight < threshold)
            {
                _xRate = multiplier * (threshold - diffRight) / threshold;
            }

            if (diffTop < threshold)
            {
                _yRate = multiplier * (diffTop - threshold) / threshold;
            }

            if (diffBottom < threshold)
            {
                _yRate = multiplier * (threshold - diffBottom) / threshold;
            }

            _prevX          = info.X;
            _prevY          = info.Y;
            _scrollViewport = viewport;
        }
Exemplo n.º 15
0
        private void EndEraseAreaSequence(PointerEventInfo info, ILevelGeometry viewport)
        {
            Rectangle selection = _band.Selection;
            int xmin = Math.Max(Layer.TileOriginX, selection.Left);
            int ymin = Math.Max(Layer.TileOriginY, selection.Top);
            int xmax = Math.Min(Layer.TileOriginX + Layer.TilesWide, selection.Right);
            int ymax = Math.Min(Layer.TileOriginY + Layer.TilesHigh, selection.Bottom);

            TileReplace2DCommand command = new TileReplace2DCommand(Layer);
            for (int x = xmin; x < xmax; x++) {
                for (int y = ymin; y < ymax; y++) {
                    command.QueueReplacement(new TileCoord(x, y), (TileStack)null);
                    Layer[new TileCoord(x, y)] = null;
                }
            }

            History.Execute(command);

            _annots.Remove(_selection);
            _inAreaSequence = false;

            EndAutoScroll(info, viewport);
        }
Exemplo n.º 16
0
 protected void EndAutoScroll(PointerEventInfo info, ILevelGeometry viewport)
 {
     _scrollViewport      = null;
     _scrollTimer.Enabled = false;
 }
Exemplo n.º 17
0
        private void StartFillSequence(PointerEventInfo info)
        {
            if (!SourceValid)
                return;

            TileCoord location = TileLocation(info);
            if (!TileInRange(location))
                return;

            if (SourceType == TileSourceType.Brush) {
                Layer.TileAdding += TileAddingHandler;
                Layer.TileRemoving += TileRemovingHandler;
            }

            _fillLayer = Layer;
            _sourceStack = new TileStack();
            _sourceStack.Add(ActiveTile);

            _fillCommand = new TileReplace2DCommand(Layer);
            FloodFill(location.X, location.Y);

            if (SourceType == TileSourceType.Brush) {
                Layer.TileAdding -= TileAddingHandler;
                Layer.TileRemoving -= TileRemovingHandler;
            }

            History.Execute(_fillCommand);
        }
Exemplo n.º 18
0
 protected virtual void PointerPositionCore(PointerEventInfo info, ILevelGeometry viewport)
 {
 }
Exemplo n.º 19
0
        private void UpdateEraseAreaSequenceCommon(PointerEventInfo info, ILevelGeometry viewport)
        {
            TileCoord location = TileLocation(info);

            int x = Math.Max(0, Math.Min(Layer.TilesWide - 1, location.X)) * Layer.TileWidth;
            int y = Math.Max(0, Math.Min(Layer.TilesHigh - 1, location.Y)) * Layer.TileHeight;

            _band.End = new Point(location.X, location.Y);
            Rectangle selection = _band.Selection;

            _selection.Start = new Point(selection.Left * Layer.TileWidth, selection.Top * Layer.TileHeight);
            _selection.End = new Point(selection.Right * Layer.TileWidth, selection.Bottom * Layer.TileHeight);
        }
Exemplo n.º 20
0
 private void StartErasePathSequence(PointerEventInfo info)
 {
     _drawCommand = new TileReplace2DCommand(Layer);
 }
Exemplo n.º 21
0
 protected virtual void AutoScrollTick(PointerEventInfo info, ILevelGeometry viewport)
 {
 }
Exemplo n.º 22
0
            public override void HandlePointerPosition(PointerEventInfo info)
            {
                if (_form._tileController == null || _form._layer == null)
                    return;

                TileCoord location = TileLocation(info);
                if (!TileInRange(location))
                    return;

                if (_form._tileController.SelectedTile != null) {
                    if (_form._tileController.SelectedTile.Width != _form._layer.TileWidth ||
                        _form._tileController.SelectedTile.Height != _form._layer.TileHeight) {
                        MessageBox.Show("Selected tile not compatible with brush tile dimensions.", "Incompatible Tile", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (!_erase)
                        _form._layer.AddTile(location.X, location.Y, _form._tileController.SelectedTile);
                    else
                        _form._layer.ClearTile(location.X, location.Y);
                }
            }
Exemplo n.º 23
0
 protected override void PointerPositionCore(PointerEventInfo info, ILevelGeometry viewport)
 {
     if (_snapManager == null)
         _snapManager = new SnappingManager(GetSnappingSourceOrigin(), GetSnappingSourceBounds(), GridSize);
 }
Exemplo n.º 24
0
        private void UpdateDrawPathSequence(PointerEventInfo info)
        {
            if (ActiveTile == null && _activeBrush == null)
                return;

            TileCoord location = TileLocation(info);
            if (!TileInRange(location))
                return;

            if (_activeBrush != null) {
                Layer.TileAdding += TileAddingHandler;
                Layer.TileRemoving += TileRemovingHandler;

                _activeBrush.ApplyBrush(Layer, location.X, location.Y);

                Layer.TileAdding -= TileAddingHandler;
                Layer.TileRemoving -= TileRemovingHandler;

                /*foreach (LocatedTile tile in _anonBrush.Tiles) {
                    TileCoord tileloc = new TileCoord(location.X + tile.X, location.Y + tile.Y);
                    if (Layer[tileloc] == null || Layer[tileloc].Top != tile.Tile) {
                        _drawCommand.QueueAdd(tileloc, tile.Tile);
                        Layer.AddTile(tileloc.X, tileloc.Y, tile.Tile);
                    }
                }*/
            }
            else if (Layer[location] == null || Layer[location].Top != ActiveTile) {
                if (Layer.CanAddTile(location.X, location.Y, ActiveTile)) {
                    _drawCommand.QueueAdd(location, ActiveTile);
                    Layer.AddTile(location.X, location.Y, ActiveTile);
                }
            }
        }
Exemplo n.º 25
0
        private void UpdateDrag(PointerEventInfo info, ILevelGeometry viewport)
        {
            TileCoord location = TileLocation(info);

            _band.End = new Point(location.X, location.Y);
            Rectangle selection = _band.Selection;

            _selectionAnnot.Start = new Point(selection.Left * Layer.TileWidth, selection.Top * Layer.TileHeight);
            _selectionAnnot.End = new Point(selection.Right * Layer.TileWidth, selection.Bottom * Layer.TileHeight);

            //UpdateAutoScroll(info, viewport);
        }
Exemplo n.º 26
0
 protected virtual void EndPointerSequenceCore(PointerEventInfo info, ILevelGeometry viewport)
 {
 }
Exemplo n.º 27
0
 private void EndErasePathSequence(PointerEventInfo info)
 {
     History.Execute(_drawCommand);
 }
Exemplo n.º 28
0
        private void StartEraseAreaSequence(PointerEventInfo info, ILevelGeometry viewport)
        {
            HidePreviewMarker();

            TileCoord location = TileLocation(info);

            int x = (int)(location.X * Layer.TileWidth);
            int y = (int)(location.Y * Layer.TileHeight);

            _band = new RubberBand(new Point(location.X, location.Y));
            _selection = new SelectionAnnot(new Point(x, y))
            {
                Fill = new SolidColorBrush(new Color(192, 0, 0, 128)),
                //Outline = new Pen(new SolidColorBrush(new Color(192, 0, 0, 200))),
            };

            _annots.Add(_selection);
            _inAreaSequence = true;

            StartAutoScroll(info, viewport);
        }
Exemplo n.º 29
0
 public virtual void HandlePointerPosition(PointerEventInfo info)
 {
 }
Exemplo n.º 30
0
 private void UpdateEraseAreaSequence(PointerEventInfo info, ILevelGeometry viewport)
 {
     UpdateEraseAreaSequenceCommon(info, viewport);
     UpdateAutoScroll(info, viewport);
 }
Exemplo n.º 31
0
 public virtual void HandleStartPointerSequence(PointerEventInfo info)
 {
 }
Exemplo n.º 32
0
        private void UpdateErasePathSequence(PointerEventInfo info)
        {
            TileCoord location = TileLocation(info);
            if (!TileInRange(location))
                return;

            if (Layer[location] != null && Layer[location].Count > 0) {
                _drawCommand.QueueReplacement(location, (TileStack)null);
                Layer[location] = null;
            }
        }
Exemplo n.º 33
0
 public virtual void HandleUpdatePointerSequence(PointerEventInfo info)
 {
 }
Exemplo n.º 34
0
 public virtual void HandlePointerPosition(PointerEventInfo info)
 {
     if (_parent != null)
         _parent.HandlePointerPosition(info);
 }
Exemplo n.º 35
0
 public virtual void HandleEndPointerSequence(PointerEventInfo info)
 {
     if (_parent != null)
         _parent.HandleEndPointerSequence(info);
 }
Exemplo n.º 36
0
 protected override void StartPointerSequenceCore(PointerEventInfo info, ILevelGeometry viewport)
 {
     _snapManager = new SnappingManager(GetSnappingSourceOrigin(), GetSnappingSourceBounds(), GridSize);
 }
Exemplo n.º 37
0
        public void TargetMouseDown(object sender, MouseEventArgs e)
        {
            PointerEventType type = GetPointerType(e.Button);
            if (_responder == null || type == PointerEventType.None)
                return;

            Point position = TranslatePosition(e.Location);
            PointerEventInfo info = new PointerEventInfo(type, position.X, position.Y);

            // Ignore event if a sequence is active
            if (_sequenceOpen.Count(kv => { return kv.Value; }) == 0) {
                _sequenceOpen[info.Type] = true;
                _responder.HandleStartPointerSequence(info);
            }
        }
Exemplo n.º 38
0
 private TileCoord TileLocation(PointerEventInfo info)
 {
     return new TileCoord((int)Math.Floor(info.X / _form._layer.TileWidth), (int)Math.Floor(info.Y / _form._layer.TileHeight));
 }
Exemplo n.º 39
0
        public void TargetMouseUp(object sender, MouseEventArgs e)
        {
            PointerEventType type = GetPointerType(e.Button);
            if (_responder == null || type == PointerEventType.None)
                return;

            Point position = TranslatePosition(e.Location);
            PointerEventInfo info = new PointerEventInfo(type, position.X, position.Y);

            if (_sequenceOpen[info.Type]) {
                _sequenceOpen[info.Type] = false;
                _responder.HandleEndPointerSequence(info);
            }
        }