public Container(uint w, uint h) { SurfaceWidth = w; SurfaceHeight = h; Width = w; Height = h; _children = new LinkedList<Widget>(); _focus = null; }
// INTERNAL ONLY public void BringToFront(Widget widget) { var node = _children.Find(widget); if (node == null) return; _children.Remove(node); _children.AddFirst(widget); if (Parent != null) Parent.BringToFront(this); }
// INTERNAL ONLY public void Focus(Widget widget) { if (!_children.Contains(widget)) return; BringToFront(widget); if (_focus != null) _focus.Focussed = false; _focus = widget; if (Parent != null) Parent.Focus(this); widget.Focussed = true; }
public void Add(Widget widget) { widget.Initialize(this); _children.AddFirst(widget); }
private static bool ContainsPoint(Widget widget, int x, int y) { return x >= widget.Left && y >= widget.Top && x < (widget.Left + widget.Width) && y < (widget.Top + widget.Height); }
public void Remove(Widget widget) { _children.Remove(widget); if (_focus == widget) _focus = null; }
public override bool MousePressed(int x, int y, Mouse.Button button, bool pressed) { if (pressed) { if (_focus != null) { _focus.Focussed = false; _focus = null; } var node = _children.First; while (node != null) { var widget = node.Value; var next = node.Next; if (widget.Visible && ContainsPoint(widget, x, y)) { widget.Focus(); return widget.MousePressed(x - widget.Left, y - widget.Top, button, true); } node = next; } } else { var node = _children.First; while (node != null) { var widget = node.Value; var next = node.Next; widget.MousePressed(x - widget.Left, y - widget.Top, button, false); node = next; } } return false; }