From 13bfe28c2588ab9ffdfb21d33f6ee42b7ed2daf5 Mon Sep 17 00:00:00 2001 From: johndoe6345789 Date: Mon, 5 Jan 2026 14:19:58 +0000 Subject: [PATCH] feat: Add cursor rendering function to GUI and integrate it into demo --- scripts/gui.lua | 34 ++++++++++++++++++++++++++++++++++ scripts/gui_demo.lua | 6 ++++++ 2 files changed, 40 insertions(+) diff --git a/scripts/gui.lua b/scripts/gui.lua index b2ba518..dfd7cf7 100644 --- a/scripts/gui.lua +++ b/scripts/gui.lua @@ -326,6 +326,40 @@ function Gui.svg(context, rectDef, svgPath, opts) context:pushSvg(svgPath, rect, opts) end +function Gui.cursor(context, inputState, opts) + opts = opts or {} + if not context or not inputState then + return + end + local size = opts.size or 14 + local thickness = opts.thickness or 2 + local half = size / 2 + local halfThickness = thickness / 2 + local color = opts.color or {1.0, 0.95, 0.2, 1.0} + if inputState.mouseDown and opts.activeColor then + color = opts.activeColor + end + + local x = inputState.mouseX or 0 + local y = inputState.mouseY or 0 + context:pushRect({ + x = x - half, + y = y - halfThickness, + width = size, + height = thickness, + }, { + color = color, + }) + context:pushRect({ + x = x - halfThickness, + y = y - half, + width = thickness, + height = size, + }, { + color = color, + }) +end + function Gui.textbox(context, widgetId, rectDef, state, opts) opts = opts or {} state = state or {} diff --git a/scripts/gui_demo.lua b/scripts/gui_demo.lua index 3d0d254..8803293 100644 --- a/scripts/gui_demo.lua +++ b/scripts/gui_demo.lua @@ -125,6 +125,12 @@ end function get_gui_commands() ctx:beginFrame(input) drawTestButtons() + Gui.cursor(ctx, input, { + size = 16, + thickness = 2, + color = {1.0, 0.9, 0.2, 1.0}, + activeColor = {1.0, 0.35, 0.15, 1.0}, + }) ctx:endFrame() return ctx:getCommands() end