void mouse_MouseMoved(float x, float y) { mouseX = x; mouseY = y; if ((_downButtons & MouseButtons.Left) != 0 && _downControl != null) { _hoverControl.OnMouseMove(mouseX - _hoverControl.GetAbsX(), mouseY - _hoverControl.GetAbsY()); } else { Control c = GetControlByPosition(_controls, null, 0, 0, (int)mouseX, (int)mouseY); if (_hoverControl != c) { if (_hoverControl != null) _hoverControl.OnMouseLeave(); _hoverControl = c; if (_hoverControl != null) _hoverControl.OnMouseHover(); } if (_hoverControl != null) _hoverControl.OnMouseMove(mouseX - _hoverControl.GetAbsX(), mouseY - _hoverControl.GetAbsY()); } }
private static Control GetControlByPosition(IList<Control> controls, Control def, float totalX, float totalY, float x, float y) { Control c = def; for (int i = controls.Count - 1; i >= 0; --i) { Control ctl = controls[i]; if (x >= (totalX + ctl.Position.X) && y > (totalY + ctl.Position.Y) && x < (totalX + ctl.Position.X + ctl.Size.X) && y < (totalY + ctl.Position.Y + ctl.Size.Y)) { c = GetControlByPosition(ctl.Controls, ctl, totalX + ctl.Position.X, totalY + ctl.Position.Y, x, y); break; } } return c; }
void mouse_MouseButtonPressed(MouseButtons buttons) { SetActiveControl(GetControlByPosition(_controls, null, 0, 0, (int)mouseX, (int)mouseY)); if (_activeControl != null) _activeControl.OnMouseDown(buttons, mouseX - _activeControl.GetAbsX(), mouseY - _activeControl.GetAbsY()); _downControl = _activeControl; _downButtons |= buttons; }
public void SetActiveControl(Control c) { _activeControl = c; Control tmp = _activeControl; while (tmp != null && tmp.Parent != null) { tmp = tmp.Parent; } if (tmp != null) { if (_controls.Contains(tmp)) { _controls.Remove(tmp); _controls.Add(tmp); } } }