mirror of
https://github.com/johndoe6345789/SDL3CPlusPlus.git
synced 2026-04-24 13:44:58 +00:00
feat: Add cursor rendering function to GUI and integrate it into demo
This commit is contained in:
@@ -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 {}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user