summaryrefslogtreecommitdiff
path: root/html/examples/iupcdaux.lua
diff options
context:
space:
mode:
authorscuri <scuri>2009-06-26 17:22:45 +0000
committerscuri <scuri>2009-06-26 17:22:45 +0000
commitfeab2c247a73bffa2cba7833e05b6b4f92351e41 (patch)
treefa81b2e5b56dcf09d67dd845f2bbb2cbe8675605 /html/examples/iupcdaux.lua
parent6571550c067af0bb8579d892ab2cf2b8e4543c6e (diff)
*** empty log message ***
Diffstat (limited to 'html/examples/iupcdaux.lua')
-rw-r--r--html/examples/iupcdaux.lua45
1 files changed, 45 insertions, 0 deletions
diff --git a/html/examples/iupcdaux.lua b/html/examples/iupcdaux.lua
new file mode 100644
index 0000000..18ae23c
--- /dev/null
+++ b/html/examples/iupcdaux.lua
@@ -0,0 +1,45 @@
+require"cdlua"
+require"iuplua"
+require"iupluacd"
+
+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