Exemple #1
0
        private void FullItem_Click(object sender, EventArgs e)
        {
            Point ul = Point.Empty;
            Point ur = new Point(_tile.Width - 1, 0);
            Point lr = new Point(_tile.Width - 1, _tile.Height - 1);
            Point ll = new Point(0, _tile.Height - 1);

            _tile.Obstructions.Clear();
            _tile.Obstructions.Add(new Line(ul, ur));
            _tile.Obstructions.Add(new Line(ur, lr));
            _tile.Obstructions.Add(new Line(ll, lr));
            _tile.Obstructions.Add(new Line(ul, ll));
            TileImage.Refresh();
        }
Exemple #2
0
 private void TileImage_MouseMove(object sender, MouseEventArgs e)
 {
     if (_paint)
     {
         last_x = cur_x;
         last_y = cur_y;
         cur_x  = e.X / _zoom;
         cur_y  = e.Y / _zoom;
         if (cur_x != last_x || cur_y != last_y)
         {
             _end_loc.X = e.X / _zoom;
             _end_loc.Y = e.Y / _zoom;
             TileImage.Refresh();
         }
     }
 }
Exemple #3
0
 private void ClearItem_Click(object sender, EventArgs e)
 {
     _tile.Obstructions.Clear();
     TileImage.Refresh();
 }
Exemple #4
0
 private void TileImage_MouseUp(object sender, MouseEventArgs e)
 {
     _paint = false;
     if (_tool == 0)
     {
         _tile.Obstructions.Add(new Line(_start_loc, _end_loc));
     }
     else if (_tool == 1)
     {
         Rectangle rect = Line.ToRectangle(new Line(_start_loc, _end_loc));
         short     x1 = (short)rect.X, y1 = (short)rect.Y;
         short     x2 = (short)(rect.X + rect.Width);
         short     y2 = (short)(rect.Y + rect.Height);
         if (rect.Width == 0)
         {
             _tile.Obstructions.Add(new Line(x1, y1, x1, y2)); // horizontal
         }
         else if (rect.Height == 0)
         {
             _tile.Obstructions.Add(new Line(x1, y1, x2, y1)); // vertical
         }
         else
         {
             _tile.Obstructions.Add(new Line(x1, y1, x1, y2)); // top
             _tile.Obstructions.Add(new Line(x1, y1, x2, y1)); // left
             _tile.Obstructions.Add(new Line(x1, y2, x2, y2)); // bottom
             _tile.Obstructions.Add(new Line(x2, y1, x2, y2)); // right
         }
     }
     else if (_tool == 2)
     {
         if (_tile.Obstructions.Count == 0)
         {
             return;
         }
         int index = 0;
         int cur   = 0;
         int dist  = _tile.Width;
         int c_x   = e.X / _zoom;
         int c_y   = e.Y / _zoom;
         foreach (Line l in _tile.Obstructions)
         {
             int m_x    = l.X1 + (l.X2 - l.X1) / 2;
             int m_y    = l.Y1 + (l.Y2 - l.Y1) / 2;
             int d_x    = m_x - c_x;
             int d_y    = m_y - c_y;
             int l_dist = (int)Math.Sqrt(d_x * d_x + d_y * d_y);
             if (l_dist < dist)
             {
                 dist = l_dist;
                 cur  = index;
             }
             index++;
         }
         _tile.Obstructions.RemoveAt(cur);
     }
     if (Modified != null)
     {
         Modified(this, new EventArgs());
     }
     TileImage.Refresh();
 }