protected override void OnMouseMoved(int x, int y, int dx, int dy)
{
if (null == m_Target) return;
if (!m_Held) return;
Rectangle oldBounds = m_Target.Bounds;
Rectangle bounds = m_Target.Bounds;
Vector2i min = m_Target.MinimumSize;
Vector2i pCursorPos = m_Target.CanvasPosToLocal(new Vector2i(x, y));
Vector2i delta = m_Target.LocalPosToCanvas(m_HoldPos);
delta.X -= x;
delta.Y -= y;
if (0 != (m_ResizeDir & Pos.Left))
{
bounds.X -= delta.X;
bounds.Width += delta.X;
// Conform to minimum size here so we don't
// go all weird when we snap it in the base conrt
if (bounds.Width < min.X)
{
int diff = min.X - bounds.Width;
bounds.Width += diff;
bounds.X -= diff;
}
}
if (0 != (m_ResizeDir & Pos.Top))
{
bounds.Y -= delta.Y;
bounds.Height += delta.Y;
// Conform to minimum size here so we don't
// go all weird when we snap it in the base conrt
if (bounds.Height < min.Y)
{
int diff = min.Y - bounds.Height;
bounds.Height += diff;
bounds.Y -= diff;
}
}
if (0 != (m_ResizeDir & Pos.Right))
{
// This is complicated.
// Basically we want to use the HoldPos, so it doesn't snap to the edge of the control
// But we need to move the HoldPos with the window movement. Yikes.
// I actually think this might be a big hack around the way this control works with regards
// to the holdpos being on the parent panel.
int woff = bounds.Width - m_HoldPos.X;
int diff = bounds.Width;
bounds.Width = pCursorPos.X + woff;
if (bounds.Width < min.X) bounds.Width = min.X;
diff -= bounds.Width;
m_HoldPos.X -= diff;
}
if (0 != (m_ResizeDir & Pos.Bottom))
{
int hoff = bounds.Height - m_HoldPos.Y;
int diff = bounds.Height;
bounds.Height = pCursorPos.Y + hoff;
if (bounds.Height < min.Y) bounds.Height = min.Y;
diff -= bounds.Height;
m_HoldPos.Y -= diff;
}
m_Target.SetBounds(bounds);
if (Resized != null)
Resized.Invoke(this);
}