Files
jeopardy/templates/one-image.lua
T

44 lines
1.3 KiB
Lua

--[[ Constants
* (all lua builtins that don't allow io/executing code)
color (interface)
gui (interface)
multi (interface bound to a processor) no thread module
callback true/false correct/wrong
]]
local label
local imageHolder
local function index(window, q, callback)
frame = window:newFrame(0,0,0,0,0,.2,1,.8)
frame.visibility = 0
label = window:newTextLabel(" " ..q.title.. " ",0,0,0,0,0,0,1,.2)
label.align = ALIGN_CENTER
label.textColor = color.white
label.color = color.new("#363ac8")
label:scaleFont(.4)
label:centerFont()
label.drawBorder = false
if not q.image or q.image == "" then
error("Missing 'image' field for question!")
end
imageHolder = frame:newImageLabel(q.image)
imageHolder:setAspectSize(imageHolder.imageWidth,imageHolder.imageHeight)
imageHolder:centerX(true)
imageHolder:centerY(true)
imageHolder:setDualDim(0,0,imageHolder.imageWidth,imageHolder.imageHeight)
useDefaultHandler(callback)
end
local function update(dt) -- time in seconds that has passed since
_,_,w,h = imageHolder.parent:getAbsolutes()
local x,y,w,h = imageHolder:GetSizeAdjustedToAspectRatio(w,h)
imageHolder:setDualDim(w,h,x,y)
end
return {
index = index,
update = update
}