Esempio n. 1
0
        public void MouseMoveTile(TileMouseState e)
        {
            if (e.Location.X >= 0 && e.Location.Y >= 0 && e.Location.X < CurrentWorld.TilesWide && e.Location.Y < CurrentWorld.TilesHigh)
            {
                if (e.Location != MouseOverTile.MouseState.Location)
                {
                    MouseOverTile.Tile = CurrentWorld.Tiles[e.Location.X, e.Location.Y];
                }

                MouseOverTile.MouseState = e;

                ActiveTool.MouseMove(e);
            }
        }
Esempio n. 2
0
 public Form1()
 {
     InitializeComponent();
     tool = ActiveTool.Pen;
     pictureBox1.BackColor = Color.White;
     bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
     gfx = Graphics.FromImage(bmp); // choosing a layer on which gfx will draw;
     //after this everything drawn by gfx will show up on bmp;
     //and then setting that picturebox will take picture from bmp;
     pictureBox1.Image = bmp;
     pen.StartCap      = System.Drawing.Drawing2D.LineCap.Round;
     eraser.StartCap   = System.Drawing.Drawing2D.LineCap.Round;
     pen.EndCap        = System.Drawing.Drawing2D.LineCap.Round;
     eraser.EndCap     = System.Drawing.Drawing2D.LineCap.Round;
 }
Esempio n. 3
0
        private void OnMouseUpPixel(TileMouseEventArgs e)
        {
            if ((e.Tile.X < _world.Header.WorldBounds.W &&
                 e.Tile.Y < _world.Header.WorldBounds.H &&
                 e.Tile.X >= 0 &&
                 e.Tile.Y >= 0) && (_world.Tiles[e.Tile.X, e.Tile.Y] != null))
            {
                MouseUpTile = e.Tile;

                if (ActiveTool != null)
                {
                    ActiveTool.ReleaseTool(e);
                }
            }
        }
Esempio n. 4
0
        public void OnMouseLeftDoubleClick(double mouseX, double mouseY, bool isShiftKey, bool isCtrlKey)
        {
            var worldPoint = CoordinateSystem.ToWorldSpace(mouseX, mouseY);

            if (ActiveTool != null)
            {
                ActiveTool.OnMouseLeftDoubleClick(this, worldPoint.X, worldPoint.Y, isShiftKey, isCtrlKey);
            }
            else
            {
                foreach (var policy in Policies.OfType <IMouseAware>())
                {
                    policy.OnMouseLeftDoubleClick(this, worldPoint.X, worldPoint.Y, isShiftKey, isCtrlKey);
                }
            }
        }
Esempio n. 5
0
        public void OnMouseMove(double x, double y, bool isShiftKey, bool isCtrlKey)
        {
            var worldPoint = CoordinateSystem.ToWorldSpace(x, y);

            if (ActiveTool != null)
            {
                ActiveTool.OnMouseMove(this, worldPoint.X, worldPoint.Y, isShiftKey, isCtrlKey);
                return;
            }

            if (!_leftMouseDown)
            {
                Policies.OfType <IMouseAware>().ToList().ForEach(p => p.OnMouseMove(this, worldPoint.X, worldPoint.Y, isShiftKey, isCtrlKey));
            }
            else
            {
                var dxSum = worldPoint.X - _lastMouseDownPosX;
                var dySum = worldPoint.Y - _lastMouseDownPosY;
                var dx    = worldPoint.X - _lastMousePosX;
                var dy    = worldPoint.Y - _lastMousePosY;

                if (!_isDragging)
                {
                    if (Math.Abs(dxSum) >= MinimalDragDistance || Math.Abs(dySum) >= MinimalDragDistance)
                    {
                        _isDragging = true;

                        Policies.OfType <IDragAware>()
                        .ToList()
                        .ForEach(
                            p =>
                            p.OnDragStart(this, _lastMouseDownPosX, _lastMouseDownPosY, dxSum, dySum, isShiftKey,
                                          isCtrlKey));
                    }
                }
                else
                {
                    Policies.OfType <IDragAware>()
                    .ToList()
                    .ForEach(
                        p =>
                        p.OnMouseDrag(this, dxSum, dySum, dx, dy, isShiftKey, isCtrlKey));
                }
            }
            _lastMousePosX = worldPoint.X;
            _lastMousePosY = worldPoint.Y;
        }
Esempio n. 6
0
        protected override void Draw()
        {
            Camera.Update();

            if (LightsEnabled)
            {
                _krypton.Matrix = Camera.View;
                this._krypton.LightMapPrepare();
            }

            GraphicsDevice.Clear(new Color(240, 240, 240));

            _spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Camera.View);

            foreach (var layer in Map.Layers.Where(p => p.Order <= ActiveLayer.Order).OrderBy(p => p.Order))
            {
                DrawLayer(layer);
            }

            _spriteBatch.End();

            if (LightsEnabled)
            {
                this._krypton.Draw();
            }

            _spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Camera.View);

            ActiveTool.Draw(_spriteBatch, Camera, _currentMousePosition, _pixel);

            if (!mouseDown && _movingLight != null)
            {
                _movingLight = null;
            }

            foreach (Light2D light in _krypton.Lights)
            {
                if (light == SelectedLight)
                {
                    _spriteBatch.Draw(_selectionTexture, light.Position + new Vector2(1, -1), Color.White);
                }

                _spriteBatch.Draw(_lightSymbolTexture, light.Position /* - new Vector2(_lightSymbolTexture.Width / 2, _lightSymbolTexture.Height / 2)*/, Color.White);
            }

            _spriteBatch.End();
        }
Esempio n. 7
0
        internal static bool CanEnter(int x, int y, int depth, ActiveTool tool)
        {
            long regKind = ErosionLevelCache(x, y, depth) % 3;

            if (regKind == 0)
            {
                return(tool != ActiveTool.Neither);
            }
            else if (regKind == 1)
            {
                return(tool != ActiveTool.Torch);
            }
            else
            {
                return(tool != ActiveTool.CGear);
            }
        }
Esempio n. 8
0
        public void OnMouseRightDown(double mouseX, double mouseY, bool isShiftKey, bool isCtrlKey)
        {
            var worldPoint = CoordinateSystem.ToWorldSpace(mouseX, mouseY);

            if (ActiveTool != null)
            {
                ActiveTool.OnMouseRightDown(this, worldPoint.X, worldPoint.Y, isShiftKey, isCtrlKey);
            }
            else
            {
                _rightMouseDownFigureHit = GetBestFigure(worldPoint.X, worldPoint.Y, new List <Type>(), new List <Type>());

                foreach (var policy in Policies.OfType <IMouseAware>())
                {
                    policy.OnMouseRightDown(this, worldPoint.X, worldPoint.Y, isShiftKey, isCtrlKey);
                }
            }
        }
Esempio n. 9
0
        public void OnMouseLeftDown(double x, double y, bool isShiftKey, bool isCtrlKey)
        {
            var worldPoint = CoordinateSystem.ToWorldSpace(x, y);

            _leftMouseDown     = true;
            _lastMouseDownPosX = worldPoint.X;
            _lastMouseDownPosY = worldPoint.Y;

            if (ActiveTool != null)
            {
                ActiveTool.OnMouseLeftDown(this, worldPoint.X, worldPoint.Y, isShiftKey, isCtrlKey);
            }
            else
            {
                Policies.OfType <IMouseAware>()
                .ToList()
                .ForEach(p => p.OnMouseLeftDown(this, worldPoint.X, worldPoint.Y, isShiftKey, isCtrlKey));
            }
        }
Esempio n. 10
0
        private void ImgPanelMouseClick(object sender, MouseEventArgs e)
        {
            if (!(ActiveTool is null))
            {
                var action = ActiveTool.ClickHandler(e);

                // if the tool is resetting or exiting, save the object
                if (action == ToolAction.RESET || action == ToolAction.EXIT)
                {
                    objectList.Items.Add(ActiveTool.ResetAndGetObject());
                }

                // if the tool is aborting or exiting, delete the object
                if (action == ToolAction.ABORT || action == ToolAction.EXIT)
                {
                    CancelTool();
                }
            }
        }
Esempio n. 11
0
    void Player_OnToolStateChanged(ActiveTool activeTool)
    {
        switch (activeTool)
        {
        case ActiveTool.None:
            _grabFunction.enabled     = false;
            _scanningFunction.enabled = false;
            break;

        case ActiveTool.ImpulseBeam:
            _scanningFunction.enabled = false;
            _grabFunction.enabled     = true;
            break;

        case ActiveTool.Scanner:
            _grabFunction.enabled     = false;
            _scanningFunction.enabled = true;
            break;
        }
    }
Esempio n. 12
0
        private void OnMouseDownPixel(TileMouseEventArgs e)
        {
            if ((e.Tile.X < _world.Header.WorldBounds.W &&
                 e.Tile.Y < _world.Header.WorldBounds.H &&
                 e.Tile.X >= 0 &&
                 e.Tile.Y >= 0) && (_world.Tiles[e.Tile.X, e.Tile.Y] != null))
            {
                MouseDownTile = e.Tile;

                if (ActiveTool != null)
                {
                    ActiveTool.PressTool(e);

                    if (ActiveTool.Name == "Paste")
                    {
                        ActiveTool = null;// Tools.FirstOrDefault(t => t.Value.Name == "Selection").Value;
                    }
                }
            }
        }
Esempio n. 13
0
        private void ImgPanelPaint(object sender, PaintEventArgs e)
        {
            var p = sender as BufferedPanel;
            var g = e.Graphics;

            if (p.ImageLoaded())
            {
                p.DrawPanelImage(g);

                ActiveTool?.PaintHandler(p.Layer, p.RelativeToPanel, g);

                var selectedIndexes = objectList.SelectedIndices;
                for (int i = 0; i < objectList.Items.Count; i++)
                {
                    AbstractObject obj = objectList.Items[i] as AbstractObject;
                    obj.DrawObject(p.Layer, p.RelativeToPanel, g, selectedIndexes.Contains(i));
                }

                p.DrawPanelCrosshair(g, crosshair);
            }
        }
Esempio n. 14
0
    public void SetActiveTool(string aString)
    {
        var newTool = (ActiveTool)Enum.Parse(typeof(ActiveTool), aString, true);

        if (newTool == _activeTool)
        {
            return;
        }

        switch (newTool)
        {
        case ActiveTool.Element:
            OnMouseNormal += CheckElementOnHover;
            OnMouseClick  += CheckElementOnInput;

            OnMouseNormal -= CheckLineOnHover;
            OnMouseClick  -= CheckLineOnInput;
            break;

        case ActiveTool.Line:
            OnMouseNormal += CheckLineOnHover;
            OnMouseClick  += CheckLineOnInput;

            OnMouseNormal -= CheckElementOnHover;
            OnMouseClick  -= CheckElementOnInput;
            break;

        case ActiveTool.NodeRotation:
            OnMouseNormal -= CheckLineOnHover;
            OnMouseNormal -= CheckElementOnHover;
            OnMouseClick  -= CheckLineOnInput;
            OnMouseClick  -= CheckElementOnInput;


            break;
        }

        _activeTool = newTool;
    }
Esempio n. 15
0
        protected void CheckAndClearButtonFlags(MouseEventArgs e)
        {
            if ((ActiveTool == null) || (DrawingCanvas == null))
            {
                return;
            }

            for (int i = 0; i < MouseButtonRecords.Length; i++)
            {
                MouseButtonEventArgs args = new MouseButtonEventArgs(e.MouseDevice,
                                                                     e.Timestamp, (MouseButton)i, e.StylusDevice);
                if (MouseButtonRecords[i].Flags.HasFlag(DDMouseButtonFlags.Clicked))
                {
                    ActiveTool.ReportMouseClick(DrawingCanvas, args);
                    MouseButtonRecords[i].Flags ^= DDMouseButtonFlags.Clicked;
                }
                if (MouseButtonRecords[i].Flags.HasFlag(DDMouseButtonFlags.StartedDrag))
                {
                    ActiveTool.ReportStartDrag(DrawingCanvas, args);
                    MouseButtonRecords[i].Flags ^= DDMouseButtonFlags.StartedDrag;
                }
                if (MouseButtonRecords[i].Flags.HasFlag(DDMouseButtonFlags.Dragging))
                {
                    ActiveTool.ReportMouseDrag(DrawingCanvas, args);
                    if (MouseButtonRecords[i].Flags.HasFlag(DDMouseButtonFlags.EndedDrag))
                    {
                        MouseButtonRecords[i].Flags ^= DDMouseButtonFlags.Dragging;
                    }
                }
                if (MouseButtonRecords[i].Flags.HasFlag(DDMouseButtonFlags.EndedDrag))
                {
                    ActiveTool.ReportEndDrag(DrawingCanvas, args);
                    MouseButtonRecords[i].Flags ^= DDMouseButtonFlags.EndedDrag;
                }
            }
        }