示例#1
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (_Matrix == null)
            {
                return;
            }
            int x  = e.X / mGridSize;
            int sy = e.Y / mGridSize;
            int y  = TRANSPOSE(sy);
            var POINTS_PER_METER = PathStore.POINTS_PER_METER;

            if (x >= PathStore.MAPSPACE || x < 0 || y < 0 || y >= PathStore.MAPSPACE)
            {
                return;
            }

            // For times that tooltips are not working
            if (e.Button == MouseButtons.Right)
            {
                if (tipForm == null || tipForm.IsDisposed)
                {
                    tipForm = new WaypointProperties();
                }
                tipForm.SetWaypoint(PathStore.GetCollisionIndex(x, y), CurrentPlane);
                tipForm.Show();
                tipForm.Activate();
                return;
            }

            if (e.Button == MouseButtons.None || mDrawMode == DrawModeSetup.None)
            {
                string         str;
                CollisionIndex o = PathStore.GetCollisionIndexNoSideEffect(x, y);
                if (o != null)
                {
                    byte  before = Matrix[x, y];
                    float fbef   = CurrentPlane.HeightMap[o.PX, o.PY];
                    float low    = _CurrentPlane == null ? 0 : CurrentPlane.MinZ;
                    float high   = _CurrentPlane == null ? float.MaxValue : CurrentPlane.MaxZ;
                    str = "";
                    if (_CurrentPlane != null)
                    {
                        str += o.OccupiedString(_CurrentPlane);
                    }
                    if (_Matrix != null)
                    {
                        str += String.Format(" matrix={0}", Matrix[x, y]);
                    }
                    if (_CurrentPlane != null)
                    {
                        str += String.Format(" GL={0}", CurrentPlane.HeightMap[o.PX, o.PY]);
                    }
                    if (_Matrix != null)
                    {
                        if (Matrix[x, y] != before)
                        {
                            Matrix[x, y] = before;
                        }
                    }
                    if (_CurrentPlane != null)
                    {
                        if (CurrentPlane.HeightMap[o.PX, o.PY] != fbef)
                        {
                            CurrentPlane.HeightMap[o.PX, o.PY] = fbef;
                        }
                    }
                }
                else
                {
                    str = "" + Matrix[x, y];
                }
                tip.SetToolTip(this, str + " at " + x / POINTS_PER_METER + "/" + y / POINTS_PER_METER + "/" + CurrentPlane.MinZ);
                return;
            }

            byte[,] mMatrix = Matrix;
            switch (mDrawMode)
            {
            case DrawModeSetup.Start:
                this.Invalidate(new Rectangle(mStart.X * mGridSize, mStart.Y * mGridSize, mGridSize, mGridSize));
                mStart = new Point(x, y);
                PathStore.SetPassable(x / POINTS_PER_METER, y / POINTS_PER_METER, ZLevel);    // mMatrix[x, y] = 1;
                break;

            case DrawModeSetup.End:
                this.Invalidate(new Rectangle(mEnd.X * mGridSize, mEnd.Y * mGridSize, mGridSize, mGridSize));
                mEnd = new Point(x, y);
                PathStore.SetPassable(x / POINTS_PER_METER, y / POINTS_PER_METER, ZLevel);    // mMatrix[x, y] = 1;
                break;

            case DrawModeSetup.Block:
                if (e.Button == (MouseButtons.Left | MouseButtons.Right))
                {
                    SetMatrix(x, y, ((byte)(mMatrix[x, y] - mNodeWeight > 1 ? mMatrix[x, y] - mNodeWeight : 1)));
                }
                else if (e.Button == MouseButtons.Left)
                {
                    SetMatrix(x, y, mNodeWeight);
                }
                else if (e.Button == MouseButtons.Right)
                {
                    SetMatrix(x, y, (byte)(mMatrix[x, y] + mNodeWeight < 256 ? mMatrix[x, y] + mNodeWeight : 255));
                }
                break;
            }

            this.Invalidate(new Rectangle(x * mGridSize, sy * mGridSize, mGridSize, mGridSize));
            base.OnMouseMove(e);
        }