Beispiel #1
0
        public Container(uint w, uint h)
        {
            SurfaceWidth = w;
            SurfaceHeight = h;
            Width = w;
            Height = h;

            _children = new LinkedList<Widget>();
            _focus = null;
        }
Beispiel #2
0
        // 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);
        }
Beispiel #3
0
        // 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;
        }
Beispiel #4
0
 public void Add(Widget widget)
 {
     widget.Initialize(this);
     _children.AddFirst(widget);
 }
Beispiel #5
0
 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);
 }
Beispiel #6
0
        public void Remove(Widget widget)
        {
            _children.Remove(widget);

            if (_focus == widget)
                _focus = null;
        }
Beispiel #7
0
        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;
        }