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 bool OnClick(this ImGui gui, Rect rect)
 {
     if (gui.action == ImGuiAction.MouseUp)
     {
         return(gui.ConsumeMouseUp(rect));
     }
     if (gui.action == ImGuiAction.MouseDown && gui.actionParameter == SDL.SDL_BUTTON_LEFT)
     {
         gui.ConsumeMouseDown(rect);
     }
     return(false);
 }
Ejemplo n.º 4
0
        public static bool BuildButtonClick(this ImGui gui, Rect rect, uint button = SDL.SDL_BUTTON_LEFT)
        {
            if (gui.actionParameter == button)
            {
                if (gui.action == ImGuiAction.MouseDown)
                {
                    gui.ConsumeMouseDown(rect);
                }
                else if (gui.action == ImGuiAction.MouseUp)
                {
                    return(gui.ConsumeMouseUp(rect));
                }
            }

            return(false);
        }
Ejemplo n.º 5
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;
            }
        }