private void Do_Draw(int x, int y)
        {
            Map map = Model.Instance.ActiveMap;

            if (map != null && x >= 0 && x < map.Width && y >= 0 && y < map.Height)
            {
                string layer = this.ActivePrimaryLayer;
                string detail = this.ActiveDetailLayer;
                int    left, right, top, bottom;
                switch (this.ActiveTool)
                {
                case Tool.IdMarker:
                    AddId addid = new AddId(x, y, this.ActivePrimaryLayer);
                    if (addid.ShowDialog() ?? false)
                    {
                        this.UpdateIdHighlights();
                    }
                    this.mouse_is_down = false;

                    break;

                case Tool.Tile:
                    if (this.ActiveTile != null)
                    {
                        map.SetTile(layer, detail, x, y, this.ActiveTile);
                        this.RefreshTile(layer, detail, x, y);
                    }
                    break;

                case Tool.Rectangle:
                    if (this.ActiveTile != null)
                    {
                        left   = Math.Min(this.start_drag_x, this.end_drag_x);
                        right  = Math.Max(this.start_drag_x, this.end_drag_x);
                        top    = Math.Min(this.start_drag_y, this.end_drag_y);
                        bottom = Math.Max(this.start_drag_y, this.end_drag_y);

                        for (int tx = left; tx <= right; ++tx)
                        {
                            for (int ty = top; ty <= bottom; ++ty)
                            {
                                map.SetTile(layer, detail, tx, ty, this.ActiveTile);
                                this.RefreshTile(layer, detail, tx, ty);
                            }
                        }
                    }
                    break;

                case Tool.EraserDetail:
                    left   = Math.Min(this.start_drag_x, this.end_drag_x);
                    right  = Math.Max(this.start_drag_x, this.end_drag_x);
                    top    = Math.Min(this.start_drag_y, this.end_drag_y);
                    bottom = Math.Max(this.start_drag_y, this.end_drag_y);

                    for (int tx = left; tx <= right; ++tx)
                    {
                        for (int ty = top; ty <= bottom; ++ty)
                        {
                            map.SetTile(layer, detail, tx, ty, null);
                            this.RefreshTile(layer, detail, tx, ty);
                        }
                    }
                    break;

                case Tool.EraserLayer:
                    left   = Math.Min(this.start_drag_x, this.end_drag_x);
                    right  = Math.Max(this.start_drag_x, this.end_drag_x);
                    top    = Math.Min(this.start_drag_y, this.end_drag_y);
                    bottom = Math.Max(this.start_drag_y, this.end_drag_y);

                    for (int tx = left; tx <= right; ++tx)
                    {
                        for (int ty = top; ty <= bottom; ++ty)
                        {
                            foreach (string det in "Base BaseAdorn BaseDetail Doodad DoodadAdorn Excessive".Split(' '))
                            {
                                map.SetTile(layer, det, tx, ty, null);
                                this.RefreshTile(layer, det, tx, ty);
                            }
                        }
                    }
                    break;

                case Tool.EraserDeep:
                    left   = Math.Min(this.start_drag_x, this.end_drag_x);
                    right  = Math.Max(this.start_drag_x, this.end_drag_x);
                    top    = Math.Min(this.start_drag_y, this.end_drag_y);
                    bottom = Math.Max(this.start_drag_y, this.end_drag_y);

                    for (int tx = left; tx <= right; ++tx)
                    {
                        for (int ty = top; ty <= bottom; ++ty)
                        {
                            foreach (string det in "Base BaseAdorn BaseDetail Doodad DoodadAdorn Excessive".Split(' '))
                            {
                                foreach (string lay in "A B C D E F Stairs".Split(' '))
                                {
                                    map.SetTile(lay, det, tx, ty, null);
                                    this.RefreshTile(lay, det, tx, ty);
                                }
                            }
                        }
                    }
                    break;

                default: break;
                }
            }
        }
        private void Do_Draw(int x, int y)
        {
            Map map = Model.Instance.ActiveMap;

            if (map != null && x >= 0 && x < map.Width && y >= 0 && y < map.Height)
            {
                string layer = this.ActivePrimaryLayer;
                string detail = this.ActiveDetailLayer;
                int left, right, top, bottom;
                switch (this.ActiveTool)
                {
                    case Tool.IdMarker:
                        AddId addid = new AddId(x, y, this.ActivePrimaryLayer);
                        if (addid.ShowDialog() ?? false)
                        {
                            this.UpdateIdHighlights();
                        }
                        this.mouse_is_down = false;

                        break;
                    case Tool.Tile:
                        if (this.ActiveTile != null)
                        {
                            map.SetTile(layer, detail, x, y, this.ActiveTile);
                            this.RefreshTile(layer, detail, x, y);
                        }
                        break;
                    case Tool.Rectangle:
                        if (this.ActiveTile != null)
                        {
                            left = Math.Min(this.start_drag_x, this.end_drag_x);
                            right = Math.Max(this.start_drag_x, this.end_drag_x);
                            top = Math.Min(this.start_drag_y, this.end_drag_y);
                            bottom = Math.Max(this.start_drag_y, this.end_drag_y);

                            for (int tx = left; tx <= right; ++tx)
                            {
                                for (int ty = top; ty <= bottom; ++ty)
                                {
                                    map.SetTile(layer, detail, tx, ty, this.ActiveTile);
                                    this.RefreshTile(layer, detail, tx, ty);
                                }
                            }
                        }
                        break;
                    case Tool.EraserDetail:
                        left = Math.Min(this.start_drag_x, this.end_drag_x);
                        right = Math.Max(this.start_drag_x, this.end_drag_x);
                        top = Math.Min(this.start_drag_y, this.end_drag_y);
                        bottom = Math.Max(this.start_drag_y, this.end_drag_y);

                        for (int tx = left; tx <= right; ++tx)
                        {
                            for (int ty = top; ty <= bottom; ++ty)
                            {
                                map.SetTile(layer, detail, tx, ty, null);
                                this.RefreshTile(layer, detail, tx, ty);
                            }
                        }
                        break;
                    case Tool.EraserLayer:
                        left = Math.Min(this.start_drag_x, this.end_drag_x);
                        right = Math.Max(this.start_drag_x, this.end_drag_x);
                        top = Math.Min(this.start_drag_y, this.end_drag_y);
                        bottom = Math.Max(this.start_drag_y, this.end_drag_y);

                        for (int tx = left; tx <= right; ++tx)
                        {
                            for (int ty = top; ty <= bottom; ++ty)
                            {
                                foreach (string det in "Base BaseAdorn BaseDetail Doodad DoodadAdorn Excessive".Split(' '))
                                {
                                    map.SetTile(layer, det, tx, ty, null);
                                    this.RefreshTile(layer, det, tx, ty);
                                }
                            }
                        }
                        break;
                    case Tool.EraserDeep:
                        left = Math.Min(this.start_drag_x, this.end_drag_x);
                        right = Math.Max(this.start_drag_x, this.end_drag_x);
                        top = Math.Min(this.start_drag_y, this.end_drag_y);
                        bottom = Math.Max(this.start_drag_y, this.end_drag_y);

                        for (int tx = left; tx <= right; ++tx)
                        {
                            for (int ty = top; ty <= bottom; ++ty)
                            {
                                foreach (string det in "Base BaseAdorn BaseDetail Doodad DoodadAdorn Excessive".Split(' '))
                                {
                                    foreach (string lay in "A B C D E F Stairs".Split(' '))
                                    {
                                        map.SetTile(lay, det, tx, ty, null);
                                        this.RefreshTile(lay, det, tx, ty);
                                    }
                                }
                            }
                        }
                        break;
                    default: break;
                }
            }
        }