这基本上是Lua Canvas Draw演示之一。它从左下角绘制一个100x100的矩形 - 唯一的问题是,如果我将画布垂直调整为较小的尺寸,它会开始切除矩形的底部,而不是从新的原点绘制,但仅在某个点之后。有没有办法从左上角画画?
require "cdlua"
require "iuplua"
require "iupluacd"
function newWindow(w,h)
w = w or 300
h = h or 200
canvas = iup.canvas{rastersize=w.."x"..h,border="no"}
dialog = iup.dialog{canvas; title="canvas"}
function canvas:map_cb()
self.canvas = cd.CreateCanvas(cd.IUP, self)
end
function canvas:action()
self.canvas:Activate()
self.canvas:Clear()
if self.Draw then
self:Draw(self.canvas)
end
end
function dialog:close_cb()
self[1].canvas:Kill()
self:destroy()
return iup.IGNORE
end
return dialog
end
local dialog = newWindow(w, h)
local canvas = dialog[1]
function canvas:Draw()
canvas = self.canvas
canvas:Rect(0,100,0,100)
end
dialog:show()
iup.MainLoop()
此图描绘了右栏中当前效果的两个屏幕截图以及左栏中所需效果的两张图片。
答案 0 :(得分:0)
画在" y =画布高度 - 方形高度",即y = 300 - 100 = 200
。