From 7b52cc13af4e85f1ca2deb6b6c77de9c95ea0dcf Mon Sep 17 00:00:00 2001 From: scuri Date: Fri, 17 Oct 2008 06:10:33 +0000 Subject: First commit - moving from LuaForge to SourceForge --- test/lua/iupcdaux.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/lua/iupcdaux.lua (limited to 'test/lua/iupcdaux.lua') diff --git a/test/lua/iupcdaux.lua b/test/lua/iupcdaux.lua new file mode 100644 index 0000000..a56ac1a --- /dev/null +++ b/test/lua/iupcdaux.lua @@ -0,0 +1,45 @@ +require"cdlua" +require"cdluaiup" +require"iuplua" + +iupcdaux = {} +iupcdaux.count = 0 + +-- Function to easy create a new IUP dialog with an IUP canvas, +-- and a CD canvas pointing to that IUP canvas + +function iupcdaux.new_dialog(w, h) + + -- defaul size + w = w or 300 + h = h or 200 + + cnv = iup.canvas { bgcolor="255 255 255", rastersize=w.."x"..h } + dlg = iup.dialog { cnv; title="canvas_"..(iupcdaux.count+1) } + + function cnv:map_cb() + canvas = cd.CreateCanvas(cd.IUP, self) + self.canvas = canvas -- store the CD canvas in a IUP attribute + end + + function cnv:action() + canvas = self.canvas -- retrieve the CD canvas from the IUP attribute + canvas:Activate() + canvas:Clear() + + if (self.Draw) then + self:Draw(canvas) + end + end + + function dlg:close_cb() + cnv = self[1] + canvas = cnv.canvas -- retrieve the CD canvas from the IUP attribute + canvas:Kill() + self:destroy() + return iup.IGNORE -- because we destroy the dialog + end + + iupcdaux.count = iupcdaux.count + 1 + return dlg +end -- cgit v1.2.3