protected override void OnMouseMove(MouseEventArgs e) { if (m_movingCell != null) { Rectangle oldRect = m_movingCell.CellRectangle; Rectangle rect = oldRect; rect.Offset(e.X - mousePos.X, e.Y - mousePos.Y); m_movingCell.SetCellRectangle(rect); mousePos = new Point(e.X, e.Y); Invalidate(PaintUtils.Union(oldRect, rect)); } base.OnMouseMove(e); }
/// <summary> /// Нужно рассчитать положения шашек в точных пикселах. /// Пока ничего не двигается, специальный флажок "запирает" пересчёт, /// то есть насчитанные прямоугольники используются. /// При изменении пересчёт вызывается один раз для всего поля. /// </summary> internal void NeedCellRectangle() { if (IsCellRectangleValid) { return; } Rectangle tableRect = new Rectangle( Point.Empty, Pool.ClientRectangle.Size); tableRect.Inflate(-6, -6); Size cellSize = new Size( tableRect.Width / Width, tableRect.Height / Height); int adjX = tableRect.Width - cellSize.Width * Width; int adjY = tableRect.Height - cellSize.Height * Height; tableRect.Offset(adjX / 2, adjY / 2); tableRect.Width -= adjX - adjX / 2; tableRect.Height -= adjY - adjY / 2; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { CellPlate cell = this[x, y]; Rectangle rect = new Rectangle( tableRect.X + cellSize.Width * x, tableRect.Y + cellSize.Height * y, cellSize.Width, cellSize.Height); if (cell != null) { cell.SetCellRectangle(rect); } else { emptyRect = rect; } } } }