summaryrefslogtreecommitdiff
path: root/html/examples/rubberband.wlua
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/rubberband.wlua
parent6571550c067af0bb8579d892ab2cf2b8e4543c6e (diff)
*** empty log message ***
Diffstat (limited to 'html/examples/rubberband.wlua')
-rw-r--r--html/examples/rubberband.wlua54
1 files changed, 54 insertions, 0 deletions
diff --git a/html/examples/rubberband.wlua b/html/examples/rubberband.wlua
new file mode 100644
index 0000000..595373a
--- /dev/null
+++ b/html/examples/rubberband.wlua
@@ -0,0 +1,54 @@
+require("iupcdaux") -- utility module used in some samples
+
+dlg = iupcdaux.new_dialog(w, h)
+cnv = dlg[1] -- retrieve the IUP canvas
+
+
+function cnv:button_cb(button,pressed,x,y,r)
+ canvas = self.canvas -- retrieve the CD canvas from the IUP attribute
+
+ -- start drag if button1 is pressed
+ if button ==iup.BUTTON1 and pressed == 1 then
+ y = canvas:UpdateYAxis(y)
+
+ -- prepare for XOR
+ canvas:Foreground(cd.WHITE)
+ canvas:WriteMode(cd.XOR)
+
+ xstart = x
+ ystart = y
+ drag = 1
+ first = 1
+ else
+ if (drag == 1) then
+ drag = 0
+ canvas:Rect(xstart,xend,ystart,yend)
+ end
+ end
+end
+
+
+function cnv:motion_cb(x,y,r)
+ canvas = self.canvas -- retrieve the CD canvas from the IUP attribute
+
+ if (drag == 1) then
+ y = canvas:UpdateYAxis(y)
+
+ if (first == 1) then
+ first = 0
+ else
+ canvas:Rect(xstart,xend,ystart,yend)
+ end
+
+ canvas:Rect(xstart,x,ystart,y)
+
+ xend = x
+ yend = y
+ end
+end
+
+first = 1
+drag = 0
+
+dlg:show()
+iup.MainLoop()