Ejemplo n.º 1
0
        public static Event BuildButton(this ImGui gui, Rect rect, SchemeColor normal, SchemeColor over, SchemeColor down = SchemeColor.None, uint button = SDL.SDL_BUTTON_LEFT)
        {
            if (button == 0)
            {
                button = (uint)InputSystem.Instance.mouseDownButton;
            }
            switch (gui.action)
            {
            case ImGuiAction.MouseMove:
                var wasOver = gui.IsMouseOver(rect);
                return(gui.ConsumeMouseOver(rect, RenderingUtils.cursorHand) && !wasOver ? Event.MouseOver : Event.None);

            case ImGuiAction.MouseDown:
                return(gui.actionParameter == button && gui.ConsumeMouseDown(rect, button) ? Event.MouseDown : Event.None);

            case ImGuiAction.MouseUp:
                return(gui.actionParameter == button && gui.ConsumeMouseUp(rect, true, button) ? Event.Click : Event.None);

            case ImGuiAction.Build:
                var color = gui.IsMouseOver(rect) ? (down != SchemeColor.None && gui.IsMouseDown(rect, button)) ? down : over : normal;
                gui.DrawRectangle(rect, color);
                return(Event.None);

            default:
                return(Event.None);
            }
        }
Ejemplo n.º 2
0
        public static bool BuildLink(this ImGui gui, string text)
        {
            gui.BuildText(text, color: SchemeColor.Link);
            var rect = gui.lastRect;

            switch (gui.action)
            {
            case ImGuiAction.MouseMove:
                gui.ConsumeMouseOver(rect, RenderingUtils.cursorHand);
                break;

            case ImGuiAction.MouseDown:
                if (gui.actionParameter == SDL.SDL_BUTTON_LEFT)
                {
                    gui.ConsumeMouseDown(rect);
                }
                break;

            case ImGuiAction.MouseUp:
                if (gui.ConsumeMouseUp(rect))
                {
                    return(true);
                }
                break;

            case ImGuiAction.Build:
                if (gui.IsMouseOver(rect))
                {
                    gui.DrawRectangle(new Rect(rect.X, rect.Bottom - 0.2f, rect.Width, 0.1f), SchemeColor.Link);
                }
                break;
            }

            return(false);
        }
Ejemplo n.º 3
0
        public static Event BuildRedButton(this ImGui gui, Icon icon, float size = 1.5f)
        {
            Rect iconRect;

            using (gui.EnterGroup(new Padding(0.3f)))
                iconRect = gui.AllocateRect(size, size, RectAlignment.Middle);
            var evt = gui.BuildButton(gui.lastRect, SchemeColor.None, SchemeColor.Error);

            if (gui.isBuilding)
            {
                gui.DrawIcon(iconRect, icon, gui.IsMouseOver(gui.lastRect) ? SchemeColor.ErrorText : SchemeColor.Error);
            }
            return(evt);
        }
Ejemplo n.º 4
0
        public static Event BuildRedButton(this ImGui gui, string text)
        {
            Rect      textRect;
            TextCache cache;

            using (gui.EnterGroup(DefaultButtonPadding))
                textRect = gui.AllocateTextRect(out cache, text, align: RectAlignment.Middle);
            var evt = gui.BuildButton(gui.lastRect, SchemeColor.None, SchemeColor.Error);

            if (gui.isBuilding)
            {
                gui.DrawRenderable(textRect, cache, gui.IsMouseOver(gui.lastRect) ? SchemeColor.ErrorText : SchemeColor.Error);
            }
            return(evt);
        }
Ejemplo n.º 5
0
        public static bool BuildSlider(this ImGui gui, float value, out float newValue, float width = 10f)
        {
            var sliderRect  = gui.AllocateRect(width, 2f, RectAlignment.Full);
            var handleStart = (sliderRect.Width - 1f) * value;
            var handleRect  = new Rect(sliderRect.X + handleStart, sliderRect.Y, 1f, sliderRect.Height);
            var update      = false;

            newValue = value;

            switch (gui.action)
            {
            case ImGuiAction.Build:
                gui.DrawRectangle(handleRect, gui.IsMouseOverOrDown(sliderRect) ? SchemeColor.Background : SchemeColor.PureBackground, RectangleBorder.Thin);
                sliderRect.Y     += (sliderRect.Height - 0.3f) / 2f;
                sliderRect.Height = 0.3f;
                gui.DrawRectangle(sliderRect, SchemeColor.Grey);
                break;

            case ImGuiAction.MouseMove:
                if (gui.IsMouseDown(sliderRect))
                {
                    update = true;
                }
                else
                {
                    gui.ConsumeMouseOver(sliderRect, RenderingUtils.cursorHand);
                }
                break;

            case ImGuiAction.MouseDown:
                if (gui.IsMouseOver(sliderRect))
                {
                    gui.ConsumeMouseDown(sliderRect);
                    update = true;
                }
                break;
            }

            if (!update)
            {
                return(false);
            }
            var positionX = (gui.mousePosition.X - sliderRect.X - 0.5f) / (sliderRect.Width - 1f);

            newValue = MathUtils.Clamp(positionX, 0f, 1f);
            gui.Rebuild();
            return(true);
        }