Example #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);
            }
        }
Example #2
0
        private void BuildHeaderResizer(ImGui gui, DataColumn <TData> column, Rect rect)
        {
            switch (gui.action)
            {
            case ImGuiAction.Build:
                var center = rect.X + rect.Width * 0.5f;
                if (gui.IsMouseDown(rect, SDL.SDL_BUTTON_LEFT))
                {
                    var unclampedWidth = gui.mousePosition.X - rect.Center.X + column.width;
                    var clampedWidth   = MathUtils.Clamp(unclampedWidth, column.minWidth, column.maxWidth);
                    center = center - column.width + clampedWidth;
                }
                var viewRect = new Rect(center - 0.1f, rect.Y, 0.2f, rect.Height);
                gui.DrawRectangle(viewRect, SchemeColor.GreyAlt);
                break;

            case ImGuiAction.MouseMove:
                gui.ConsumeMouseOver(rect, RenderingUtils.cursorHorizontalResize);
                if (gui.IsMouseDown(rect, SDL.SDL_BUTTON_LEFT))
                {
                    gui.Rebuild();
                }
                break;

            case ImGuiAction.MouseDown:
                gui.ConsumeMouseDown(rect, cursor: RenderingUtils.cursorHorizontalResize);
                break;

            case ImGuiAction.MouseUp:
                if (gui.ConsumeMouseUp(rect, false))
                {
                    var unclampedWidth = gui.mousePosition.X - rect.Center.X + column.width;
                    column.width = MathUtils.Clamp(unclampedWidth, column.minWidth, column.maxWidth);
                    contentGui?.Rebuild();
                }
                break;
            }
        }
Example #3
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);
        }