예제 #1
0
        public void Window(SGroup group)
        {
            Vector2 position = group.Position;

            PreparePosition(group, ref position);
            Rect bounds = new Rect(
                position.x, position.y,
                group.Size.x + group.Border * 2f,
                group.Size.y + group.Border * 2f + group.WindowTitleBar.Size.y * 0.5f
                );

            GUI.backgroundColor = _Transparent;
            RegisterNextComponentIn(group);
            RegisterOperation(EGUIOperation.Start, EGUIComponent.Group, bounds);
            GUI.BeginGroup(bounds);
            _ClipScopeTypes.Push(EClipScopeType.CustomWindow);
            _ClipScopeRects.Push(bounds);

            group.RenderGroup(CurrentComponentID);

            RegisterOperation(EGUIOperation.End, EGUIComponent.Group, NULLRECT);
            GUI.EndGroup();
            _ClipScopeTypes.Pop();
            _ClipScopeRects.Pop();
        }
예제 #2
0
        public void StartGroup(SGroup group)
        {
            Vector2 position = group.InnerOrigin;

            PreparePosition(group, ref position);
            Rect bounds = new Rect(position, group.Size);

            GUI.backgroundColor = _Transparent;
            RegisterNextComponentIn(group);
            if (group.ScrollDirection == SGroup.EDirection.None)
            {
                RegisterOperation(EGUIOperation.Start, EGUIComponent.Group, bounds);
                GUI.BeginGroup(bounds);
                _ClipScopeTypes.Push(EClipScopeType.Group);
            }
            else
            {
                Rect viewBounds = new Rect(Vector2.zero, group.ContentSize);
                RegisterOperation(EGUIOperation.Start, EGUIComponent.Scroll, bounds, group.ScrollPosition, viewBounds,
                                  (group.ScrollDirection & SGroup.EDirection.Horizontal) == SGroup.EDirection.Horizontal,
                                  (group.ScrollDirection & SGroup.EDirection.Vertical) == SGroup.EDirection.Vertical
                                  );
                GUI.BeginScrollView(
                    bounds, group.ScrollPosition, viewBounds,
                    (group.ScrollDirection & SGroup.EDirection.Horizontal) == SGroup.EDirection.Horizontal,
                    (group.ScrollDirection & SGroup.EDirection.Vertical) == SGroup.EDirection.Vertical
                    );
                _ClipScopeTypes.Push(EClipScopeType.Scroll);
            }

            _ClipScopeRects.Push(bounds);
        }
예제 #3
0
        public void EndWindow(SGroup group)
        {
            if (group.WindowID == -1)
            {
                return;
            }

            if (group.ScrollDirection != SGroup.EDirection.None)
            {
                RegisterOperation(EGUIOperation.End, EGUIComponent.Scroll, NULLRECT);
                GUI.EndScrollView();
            }
            else
            {
                RegisterOperation(EGUIOperation.End, EGUIComponent.Clip, NULLRECT);
                GUI.EndClip();
            }

            _ClipScopeTypes.Pop();
            _ClipScopeRects.Pop();

            group.WindowTitleBar.Root   = group.Root;
            group.WindowTitleBar.Parent = group;
            group.WindowTitleBar.Render();
        }
예제 #4
0
        private void _ScrollBar(SGroup group)
        {
            Rect bounds = !group.IsWindow ? new Rect(group.InnerOrigin, group.InnerSize) : new Rect(
                group.Border,
                group.WindowTitleBar.Size.y + group.Border,
                group.Size.x, group.Size.y
                );

            if (bounds.height <= group.ContentSize.y)
            {
                float   width    = 2f; // TODO Grow on mouse-over.
                Vector2 position = new Vector2(
                    bounds.x + bounds.width - width,
                    bounds.y + bounds.height * group.ScrollPosition.y / group.ContentSize.y
                    );
                Vector2 size = new Vector2(
                    width,
                    Mathf.Max(0f, Mathf.Min(bounds.height, bounds.height * bounds.height / group.ContentSize.y + position.y) - position.y)
                    );

                Rect(group, position, size, group.Foreground * 0.8f);

                // TODO Mouse input.
            }

            // TODO Horizontal scroll.
        }
예제 #5
0
        public int HandleMouseEvent(Event e)
        {
            // Console.WriteLine();
            // Console.WriteLine("SGUI-IM: Handling mouse event " + e);
            SGroup lastWindowDragging = _WindowDragging;

            EventType    type   = e.type;
            EMouseStatus status = EMouseStatus.Outside;

            switch (type)
            {
            case EventType.MouseUp: status = EMouseStatus.Up; break;

            case EventType.MouseDown: status = EMouseStatus.Down; break;

            case EventType.MouseDrag: status = EMouseStatus.Drag; break;
            }
            Vector2 pos = e.mousePosition;

            int handled = HandleMouseEventIn(e, null);

            if (handled != -1)
            {
                if (type != EventType.MouseMove)
                {
                    _RegisteredNextElement = false;
                    for (int i = 0; i < _OPs.Count; i++)
                    {
                        _RecreateOperation(i, handled);
                    }

                    _ComponentElements[handled]?.SetMouseStatus(_Secret, status, pos);
                }
                else
                {
                    for (int i = 0; i < _Elements.Count; i++)
                    {
                        SElement elem = _Elements[i];
                        if (elem == null)
                        {
                            continue;
                        }
                        // TODO replace GetFirstComponentID with possible future HasComponentID
                        elem.SetMouseStatus(_Secret, GetFirstComponentID(elem) == handled ? EMouseStatus.Inside : EMouseStatus.Outside, pos);
                    }
                }
            }

            if (lastWindowDragging == null && _WindowDragging != null)
            {
                IList <SElement> children = _WindowDragging.Parent?.Children ?? _WindowDragging.Root.Children;
                children.Remove(_WindowDragging);
                children.Insert(children.Count, _WindowDragging);
            }

            // Console.WriteLine("SGUI-IM: Mouse event handled: " + handled);
            // Console.WriteLine();
            return(handled);
        }
예제 #6
0
        public override void Update()
        {
            SGroup group = (SGroup)Elem;

            if (group.ContentSize.y < group.Size.y)
            {
                group.ContentSize = new Vector2(group.ContentSize.x, group.Size.y + group.GrowExtra.y);
            }
        }
        public override void UpdateStyle()
        {
            SGroup group = (SGroup)Elem;

            group.ContentSize = Vector2.zero;
            for (int i = group.Children.Count - 1; i > -1; --i)
            {
                group.GrowToFit(group[i]);
            }
        }
예제 #8
0
        public void StartWindow(SGroup group)
        {
            if (group.WindowID == -1)
            {
                return;
            }

            Rect(
                new Vector2(0f, group.WindowTitleBar.Size.y),
                new Vector2(
                    group.Size.x + group.Border * 2f,
                    group.Size.y + group.Border * 2f
                    ), group.Background
                );

            Rect bounds = new Rect(
                group.Border,
                group.WindowTitleBar.Size.y + group.Border,
                group.Size.x, group.Size.y
                );

            GUI.backgroundColor = _Transparent;
            RegisterNextComponentIn(group);
            if (group.ScrollDirection == SGroup.EDirection.None)
            {
                RegisterOperation(EGUIOperation.Start, EGUIComponent.Clip, bounds);
                GUI.BeginClip(
                    bounds,
                    Vector2.zero,
                    new Vector2(0f, group.WindowTitleBar.Size.y),
                    true
                    );
                _ClipScopeTypes.Push(EClipScopeType.Clip);
            }
            else
            {
                Rect viewBounds = new Rect(Vector2.zero, group.ContentSize);
                RegisterOperation(EGUIOperation.Start, EGUIComponent.Scroll, bounds, group.ScrollPosition, viewBounds,
                                  (group.ScrollDirection & SGroup.EDirection.Horizontal) == SGroup.EDirection.Horizontal,
                                  (group.ScrollDirection & SGroup.EDirection.Vertical) == SGroup.EDirection.Vertical
                                  );
                GUI.BeginScrollView(
                    bounds, group.ScrollPosition, viewBounds,
                    (group.ScrollDirection & SGroup.EDirection.Horizontal) == SGroup.EDirection.Horizontal,
                    (group.ScrollDirection & SGroup.EDirection.Vertical) == SGroup.EDirection.Vertical
                    );
                _ClipScopeTypes.Push(EClipScopeType.Scroll);
            }

            _ClipScopeRects.Push(bounds);
        }
예제 #9
0
        public void WindowTitleBar(SWindowTitleBar bar)
        {
            Rect bounds = new Rect(Vector2.zero, bar.Size);

            SGroup group = (SGroup)bar.Parent;
            string title = group.WindowTitle;

            Rect(bar, Vector2.zero, bar.Size, group.Background);

            if (!string.IsNullOrEmpty(title))
            {
                Text(bar, new Vector2(group.Border, 0f), bar.InnerSize, title);
            }

            // TODO Window header buttons.
        }
예제 #10
0
        public void EndGroup(SGroup group)
        {
            if (group.ScrollDirection != SGroup.EDirection.None)
            {
                RegisterOperation(EGUIOperation.End, EGUIComponent.Scroll, NULLRECT);
                GUI.EndScrollView();
            }
            else
            {
                RegisterOperation(EGUIOperation.End, EGUIComponent.Group, NULLRECT);
                GUI.EndGroup();
            }

            _ClipScopeTypes.Pop();
            _ClipScopeRects.Pop();
        }
예제 #11
0
        private bool _RecreateOperation(int opID, int handledComponentID = -1)
        {
            if (opID < 0)
            {
                opID = _OPs.Count + opID;
            }
            Event e = Event.current;

            EGUIOperation op      = _OPs[opID];
            int           elemID  = _OPElementIDs[opID];
            int           compID  = _OPComponentIDs[opID];
            EGUIComponent elemGUI = _OPComponents[opID];
            Rect          bounds  = _OPBounds[opID];

            object[] data = _OPData[opID];

            // Console.WriteLine("SGUI-IM: Recreating operation for E" + elemID + "C" + compID + ": " + op + " " + elemGUI);

            SElement elem = _Elements[elemID];

            if (op == EGUIOperation.Draw && handledComponentID != -1)
            {
                if (e.type == EventType.Used)
                {
                    // Console.WriteLine("SGUI-IM: Current event used - recreating operation @ NULLRECT");
                    bounds = NULLRECT;
                }

                if (compID < handledComponentID)
                {
                    // Console.WriteLine("SGUI-IM: Current component before handled component (" + handledComponentID + ") - recreating operation @ NULLRECT");
                    bounds = NULLRECT;
                }

                if (elem == null || !elem.Visible || !elem.Enabled)
                {
                    // Console.WriteLine("SGUI-IM: Current component element not interactable - recreating operation @ NULLRECT");
                    bounds = NULLRECT;
                }
            }

            switch (op)
            {
            case EGUIOperation.Draw:
                switch (elemGUI)
                {
                case EGUIComponent.Label:
                    RegisterNextComponent();
                    GUI.Label(bounds, (string)data[0]);
                    break;

                case EGUIComponent.Button:
                    RegisterNextComponent();
                    GUI.Button(bounds, (string)data[0]);
                    break;

                case EGUIComponent.TextField:
                    RegisterNextComponent();
                    // TextField and Button use mouse input by themselves.
                    if (elemGUI == EGUIComponent.TextField)
                    {
                        if (e.isMouse && bounds.Contains(e.mousePosition))
                        {
                            // ... although the TextField mouse input requires some help with the cursor placement.
                            string    text          = (string)data[0];
                            Vector2   mousePosition = e.mousePosition;
                            EventType type          = e.type;
                            Event.current.Use();
                            GUI.TextField(bounds, text);
                            // Focus(compID); // Actually kills focus.
                            TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
#pragma warning disable CS0618
                            // TextEditor.content is obsolete, yet it must be accessed.
                            // Alternatively access TextEditor.m_Content via reflection.
                            GUIContent content = editor.content;
#pragma warning restore CS0618

                            // editor.style.GetCursorStringIndex(this.position, this.m_Content, cursorPosition + this.scrollOffset);
                            // GetCursorStringIndex seems broken.
                            int     index    = 0;
                            Vector2 position = -editor.scrollOffset;
                            PreparePosition(elem, ref position);
                            Rect boundsScrolled = new Rect(position.x, position.y, bounds.size.x, bounds.size.y);
                            for (; index < text.Length; index++)
                            {
                                if (mousePosition.x < editor.style.GetCursorPixelPosition(boundsScrolled, content, index).x - LineHeight * 0.5f)
                                {
                                    break;
                                }
                            }

                            if (type == EventType.MouseDown)
                            {
                                editor.cursorIndex = index;
                                editor.selectIndex = index;
                            }
                            else if (type == EventType.MouseDrag)
                            {
                                editor.cursorIndex = index;
                            }

                            editor.UpdateScrollOffsetIfNeeded();
                            return(true);
                        }
                        else
                        {
                            GUI.TextField(bounds, (string)data[0]);
                        }
                    }

                    if (e.isMouse && bounds.Contains(e.mousePosition))
                    {
                        // Still need to know whether mouse is in it or not, though
                        return(true);
                    }
                    break;
                }
                break;

            case EGUIOperation.Start:
                RegisterNextComponent();
                switch (elemGUI)
                {
                case EGUIComponent.Clip:
                    GUI.BeginClip(bounds, Vector2.zero, Vector2.zero, true);
                    _ClipScopeTypes.Push(EClipScopeType.Clip);
                    _ClipScopeRects.Push(bounds);
                    break;

                case EGUIComponent.Group:
                    GUI.BeginGroup(bounds);
                    _ClipScopeTypes.Push(EClipScopeType.Group);
                    _ClipScopeRects.Push(bounds);
                    break;

                case EGUIComponent.Scroll:
                    data[0] = GUI.BeginScrollView(bounds, (Vector2)data[0], (Rect)data[1], (bool)data[2], (bool)data[3]);
                    SGroup group = elem as SGroup;
                    if (group != null)
                    {
                        group.ScrollPosition = (Vector2)data[0];
                    }
                    _ClipScopeTypes.Push(EClipScopeType.Scroll);
                    _ClipScopeRects.Push(bounds);
                    break;
                }
                break;

            case EGUIOperation.End:
                switch (elemGUI)
                {
                case EGUIComponent.Clip:
                    GUI.EndClip();
                    break;

                case EGUIComponent.Group:
                    GUI.EndGroup();
                    break;

                case EGUIComponent.Scroll:
                    GUI.EndScrollView();
                    break;
                }
                _ClipScopeTypes.Pop();
                _ClipScopeRects.Pop();
                break;
            }

            return(false);
        }
예제 #12
0
        public int HandleMouseEventInGroup(Event e, SGroup group)
        {
            int  handled;
            int  groupFirstComponent = GetFirstComponentID(group);
            bool containsMouse       = new Rect(
                group.AbsoluteOffset.x + group.Position.x,
                group.AbsoluteOffset.y + group.Position.y,
                group.Size.x + group.Border * 2f,
                group.Size.y + (group.IsWindow ? group.WindowTitleBar.Size.y : 0f) + group.Border * 2f
                ).Contains(e.mousePosition);

            if (group.IsWindow)
            {
                SWindowTitleBar bar = group.WindowTitleBar;

                Rect bounds = (_ClipScopeRects.Count == 0 || !IsOnGUIRepainting) ?
                              new Rect(group.AbsoluteOffset + group.Position, bar.Size) :
                              new Rect(Vector2.zero, bar.Size);
                if (e.type == EventType.MouseDown && bounds.Contains(e.mousePosition))
                {
                    bar.Dragging    = true;
                    _WindowDragging = group;
                    e.Use();
                    return(groupFirstComponent);
                }

                if (bar.Dragging)
                {
                    if (e.type == EventType.MouseDrag)
                    {
                        group.Position += e.delta;
                    }
                    else if (e.type == EventType.MouseUp)
                    {
                        bar.Dragging    = false;
                        _WindowDragging = null;
                    }
                    e.Use();
                    return(groupFirstComponent);
                }

                bar.Dragging = false;
            }

            if (!containsMouse)
            {
                return(-1);
            }

            IList <SElement> children = group.Children;

            for (int i = children.Count - 1; 0 <= i; i--)
            {
                if ((handled = HandleMouseEventIn(e, children[i])) != -1)
                {
                    return(handled);
                }
            }

            // Window background would be click-through otherwise.
            if (!new Rect(group.AbsoluteOffset + group.Position, group.InnerSize).Contains(e.mousePosition))
            {
                e.Use();
                return(groupFirstComponent);
            }
            return(-1);
        }