/// <summary> /// Clears user controls handled by this manager /// </summary> public void Clear() { if (mouseover != null) { mouseover.OnMouseLeave(); mouseover = null; } if (Focus != null) { Focus.OnFocusLost(); Focus = null; } controls.Clear(); }
/// <summary> /// Adds a user control to this manager /// </summary> /// <param id="control">New user control</param> public void AddControl(UserControl control) { controls.Add(control); }
/// <summary> /// Handles the mouse operations /// </summary> private void HandleMouseOperations() { if (UI.Instance.LMBHold() && mouseover.Enabled) { mouseover.OnLHold(); } if (UI.Instance.LMBClick()) { if (Focus != mouseover) { if (Focus != null) { Focus.OnFocusLost(); } mouseover.OnFocus(); Focus = mouseover; } if (mouseover.Enabled) { mouseover.OnLClick(); } } if (UI.Instance.RMBHold() && mouseover.Enabled) { mouseover.OnRHold(); } if (UI.Instance.RMBClick()) { if (mouseover.Enabled) { mouseover.OnRClick(); } if (Focus != null) { Focus.OnFocusLost(); Focus = null; } } }
/// <summary> /// Handles the user control focus operations /// </summary> private void HandleFocus() { if (UI.Instance.KeysPressed && Focus.Enabled) { Focus.OnKeyPress(); } if (!Focus.Focus) { Focus.OnFocusLost(); Focus = null; } else if (mouseover == null) { if (UI.Instance.LMBClick() || UI.Instance.RMBClick()) { Focus.OnFocusLost(); Focus = null; } } if (Focus == null) { HandleMouseover(); } }
/// <summary> /// Handles the mouseover events /// </summary> private void HandleMouseover() { UserControl newMouseover = null; // Prefer focused control if (Focus != null) { if (UI.Instance.MouseInArea(Focus.Position, Focus.Size)) { newMouseover = Focus; } } // Prefer already mouseovered control if (newMouseover == null && mouseover != null) { if (UI.Instance.MouseInArea(mouseover.Position, mouseover.Size)) { newMouseover = mouseover; } } // If neither focused nor mouseovered controls are under mouse, check the rest if (newMouseover == null) { foreach (var control in controls) { if (UI.Instance.MouseInArea(control.Position, control.Size)) { newMouseover = control; break; } } } // Handle new mouseovered control if (newMouseover == mouseover) { if (mouseover != null) { mouseover.OnMouseMove(); } } else if (newMouseover == null) { // Left control mouseover.OnMouseLeave(); } else if (mouseover == null) { // Entered control newMouseover.OnMouseEnter(); } else { // Switched control mouseover.OnMouseLeave(); newMouseover.OnMouseEnter(); } mouseover = newMouseover; }