Files
Lua-compilateur/Demo/gui/scene.lua
T
BlackAngelTV 9587d1ed49 feat(gui): draw windowed apps through a batched SDL2 surface
Compiled programs could only write to the terminal, so the demo editor had no
real window. When CMake finds SDL2 the runtime now exposes a `gui` table and
Demo/guipaint.lua builds a 960x640 editor on top of it.

Frames are collected in Lua, merged into horizontal runs and sent with a single
`gui.rects` call: a full scene goes from 15071 draw calls and 42.9 ms per frame
to 1522 calls and 2.1 ms, and the rendered screenshot stays pixel-identical.
2026-11-18 10:18:44 +01:00

61 lines
1.6 KiB
Lua

-- The picture drawn by `guipaint shot` and by the tests: same canvas primitives
-- as the interactive tools, so the capture shows the real application state.
local palette = require("paint.palette")
local M = {}
local function index_of(name)
local slot = palette.slot_of(name)
if slot == nil then
return 0
end
return palette.index_of_slot(slot)
end
local function solid(app, name, x1, y1, x2, y2)
app.canvas:rect(x1, y1, x2, y2, index_of(name), true)
end
function M.picture(app)
local canvas = app.canvas
local width = canvas.width
local height = canvas.height
local ground = height - 24
canvas:fill(1, 1, index_of("nuit"))
local stars = {
{ 14, 6 }, { 28, 12 }, { 52, 5 }, { 71, 9 }, { 120, 7 }, { 134, 13 },
}
for position = 1, #stars do
canvas:set(stars[position][1], stars[position][2], index_of("blanc"))
end
canvas:ellipse(math.floor(width * 0.85), 13, 9, 6, index_of("jaune"), true)
solid(app, "gris", 20, 17, 40, 19)
solid(app, "gris", 24, 15, 36, 17)
solid(app, "vert", 1, ground, width, height)
solid(app, "brun", 24, 34, 72, ground)
for row = 16, 34 do
local half = math.floor((row - 16) * 1.8)
solid(app, "brun", 48 - half, row, 48 + half, row)
end
solid(app, "nuit", 38, 50, 46, ground)
solid(app, "cyan", 54, 44, 64, 52)
solid(app, "brun", 100, 50, 106, ground)
canvas:ellipse(103, 40, 14, 12, index_of("vert"), true)
app.slot = palette.slot_of("jaune")
app.tool = 4
app.cursor_x = math.floor(width * 0.85)
app.cursor_y = 13
app.cursor_in_canvas = true
app.message = "PAYSAGE - CLIC POUR DESSINER"
return app
end
return M