summaryrefslogtreecommitdiff
path: root/html/examples
diff options
context:
space:
mode:
Diffstat (limited to 'html/examples')
-rw-r--r--html/examples/show_image_tuio.wlua220
-rw-r--r--html/examples/view.wlua30
-rw-r--r--html/examples/viewGL.wlua2
3 files changed, 236 insertions, 16 deletions
diff --git a/html/examples/show_image_tuio.wlua b/html/examples/show_image_tuio.wlua
new file mode 100644
index 0000000..97642b4
--- /dev/null
+++ b/html/examples/show_image_tuio.wlua
@@ -0,0 +1,220 @@
+require"imlua"
+require"cdlua"
+require"cdluaim"
+require"iuplua"
+require"iupluacd"
+require"iupluatuio"
+
+cnv = iup.canvas{rastersize = "1024x768", border = "NO"}
+img_x = 0
+img_y = 0
+
+tuio = iup.tuioclient{}
+
+function load_image(filename)
+ local new_image = im.FileImageLoadBitmap(filename)
+ if (not new_image) then
+ iup.Message("Error", "LoadBitmap failed.")
+ else
+ if (image) then image:Destroy() end
+ loaded = true
+ image = new_image
+ iup.Update(cnv)
+ end
+end
+
+function cnv:map_cb() -- the CD canvas can only be created when the IUP canvas is mapped
+ canvas = cd.CreateCanvas(cd.IUP, self)
+end
+
+function cnv:action() -- called everytime the IUP canvas needs to be repainted
+ canvas:Activate()
+ canvas:Clear()
+ if (image) then
+ if (loaded) then
+ local cnv_w, cnv_h = canvas:GetSize()
+
+ -- inicial zoom and position
+ img_w = image:Width()
+ img_h = image:Height()
+ img_x = (cnv_w-img_w)/2
+ img_y = (cnv_h-img_h)/2
+ loaded = false
+ end
+ image:cdCanvasPutImageRect(canvas, img_x, img_y, img_w, img_h, 0, 0, 0, 0) -- use default values
+ end
+end
+
+function cnv:multitouch_cb(count, pid, px, py, pstatus)
+ if (count == 1) then
+ if (pstatus[1] == 68) then -- 'D' DOWN
+ old_x = px[1]
+ old_y = canvas:UpdateYAxis(py[1])
+ translate = 1
+ elseif (pstatus[1] == 85) then -- 'U' UP
+ if (translate == 1) then
+ translate = 0
+ end
+ elseif (pstatus[1] == 77) then -- 'M' MOVE
+ if (translate == 1) then
+ -- translate only
+ local y = canvas:UpdateYAxis(py[1])
+ local x = px[1]
+ img_x = img_x + (x - old_x)
+ img_y = img_y + (y - old_y)
+ old_x = x
+ old_y = y
+ iup.Update(cnv)
+ end
+ end
+ elseif (count == 2) then
+ if (pstatus[1] == 68 or pstatus[2] == 68) then -- 'D' DOWN
+ diff_x = math.abs(px[2]-px[1])
+ diff_y = math.abs(py[2]-py[1])
+ ref_x = (px[2]+px[1])/2
+ ref_y = (py[2]+py[1])/2
+ zoom = 1
+ elseif (pstatus[1] == 85 or pstatus[2] == 85) then -- 'U' UP
+ if (zoom == 1) then
+ zoom = 0
+ end
+ elseif (pstatus[1] == 77 or pstatus[2] == 77) then -- 'M' MOVE
+ if (zoom == 1) then
+ -- zoom
+ local new_diff_x = math.abs(px[2]-px[1])
+ local new_diff_y = math.abs(py[2]-py[1])
+
+ local abs_diff_x = new_diff_x-diff_x
+ local abs_diff_y = new_diff_y-diff_y
+ local diff = 0
+ if (math.abs(abs_diff_y) > math.abs(abs_diff_x)) then
+ diff = abs_diff_y
+ else
+ diff = abs_diff_x
+ end
+ local prev_w = img_w
+ local prev_h = img_h
+ img_w = img_w + diff
+ img_h = img_h + diff
+
+ -- translate to maintain fixed the reference point
+ local orig_x = ref_x - img_x
+ local orig_y = ref_y - img_y
+ orig_x = (img_w/prev_w)*orig_x
+ orig_y = (img_h/prev_h)*orig_y
+ img_x = ref_x - orig_x
+ img_y = ref_y - orig_y
+
+ diff_x = new_diff_x
+ diff_y = new_diff_y
+ iup.Update(cnv)
+ end
+ end
+ end
+end
+
+function cnv:button_cb(button,pressed,x,y,status)
+ -- start drag if button1 is pressed
+ if button ==iup.BUTTON1 and pressed == 1 then
+ y = canvas:UpdateYAxis(y)
+
+ old_x = x
+ old_y = y
+ start_x = x
+ start_y = y
+ drag = 1
+ else
+ if (drag == 1) then
+ drag = 0
+ end
+ end
+end
+
+function cnv:motion_cb(x,y,status)
+ if (drag == 1) then
+ y = canvas:UpdateYAxis(y)
+
+ if (iup.iscontrol(status)) then
+ -- zoom
+ local diff_x = (x - old_x)
+ local diff_y = (y - old_y)
+ local diff = 0
+ if (math.abs(diff_y) > math.abs(diff_x)) then
+ diff = diff_y
+ else
+ diff = diff_x
+ end
+ local prev_w = img_w
+ local prev_h = img_h
+ img_w = img_w + diff
+ img_h = img_h + diff
+
+ -- translate to maintain fixed the reference point
+ local orig_x = start_x - img_x
+ local orig_y = start_y - img_y
+ orig_x = (img_w/prev_w)*orig_x
+ orig_y = (img_h/prev_h)*orig_y
+ img_x = start_x - orig_x
+ img_y = start_y - orig_y
+ else
+ -- translate only
+ img_x = img_x + (x - old_x)
+ img_y = img_y + (y - old_y)
+ end
+ old_x = x
+ old_y = y
+ iup.Update(cnv)
+ end
+end
+
+function cnv:k_any(c)
+ if c == iup.K_q or c == iup.K_ESC then
+ return iup.CLOSE
+ end
+ if c == iup.K_F1 then
+ if fullscreen then
+ fullscreen = false
+ dlg.fullscreen = "No"
+ else
+ fullscreen = true
+ dlg.fullscreen = "Yes"
+ end
+ end
+ if c == iup.K_F2 then
+ filename = iup.GetFile("*.*")
+ if (filename) then
+ load_image(filename)
+ end
+ end
+
+end
+
+dlg = iup.dialog{cnv}
+
+function dlg:close_cb()
+ if (image) then
+ image:Destroy()
+ end
+ canvas:Kill()
+ self:destroy()
+ return iup.IGNORE -- because we destroy the dialog
+end
+
+tuio.connect = "YES"
+tuio.targetcanvas = cnv
+
+dlg:show()
+cnv.rastersize = nil -- remove minimum size
+
+if arg and arg[1] ~= nil then
+ filename = arg[1]
+else
+ filename = iup.GetFile("*.*")
+end
+if (filename) then
+ load_image(filename)
+end
+
+if (iup.MainLoopLevel()==0) then
+ iup.MainLoop()
+end
diff --git a/html/examples/view.wlua b/html/examples/view.wlua
index 60be33e..65eaac7 100644
--- a/html/examples/view.wlua
+++ b/html/examples/view.wlua
@@ -4,7 +4,7 @@ require"cdluaim"
require"iuplua"
require"iupluacd"
-function PrintError(func, error)
+function PrintError(func, err)
local msg = {}
msg[im.ERR_OPEN] = "Error Opening File."
msg[im.ERR_MEM] = "Insuficient memory."
@@ -13,8 +13,8 @@ function PrintError(func, error)
msg[im.ERR_FORMAT] = "Invalid Format."
msg[im.ERR_COMPRESS] = "Invalid or unsupported compression."
- if msg[error] then
- print(func..": "..msg[error])
+ if msg[err] then
+ print(func..": "..msg[err])
else
print("Unknown Error.")
end
@@ -22,17 +22,17 @@ end
function LoadImage(file_name)
local image
- local ifile, error = im.FileOpen(file_name)
+ local ifile, err = im.FileOpen(file_name)
if not ifile then
- PrintError("open", error)
+ PrintError("open", err)
return
end
-- load the first image in the file.
-- force the image to be converted to a bitmap
- image, error = ifile:LoadBitmap()
+ image, err = ifile:LoadBitmap()
if not image then
- PrintError("load", error)
+ PrintError("load", err)
return
end
@@ -86,10 +86,10 @@ function ShowImage(file_name)
function cnv:button_cb()
local file_name = "*.*"
- local error
+ local err
- file_name, error = iup.GetFile(file_name)
- if error ~= 0 then
+ file_name, err = iup.GetFile(file_name)
+ if err ~= 0 then
return iup.DEFAULT
end
@@ -146,12 +146,12 @@ end
function main(arg)
local file_name = "*.*"
- local error
+ local err
-- Try to get a file name from the command line.
if (arg == nil or table.getn(arg) < 2) then
- file_name, error = iup.GetFile(file_name)
- if error ~= 0 then
+ file_name, err = iup.GetFile(file_name)
+ if err ~= 0 then
return true
end
else
@@ -165,8 +165,8 @@ function main(arg)
while Try do
file_name = "*.*"
- file_name, error = iup.GetFile(file_name)
- if error ~= 0 then
+ file_name, err = iup.GetFile(file_name)
+ if err ~= 0 then
return true
end
diff --git a/html/examples/viewGL.wlua b/html/examples/viewGL.wlua
index f5ce58a..a5b2ebb 100644
--- a/html/examples/viewGL.wlua
+++ b/html/examples/viewGL.wlua
@@ -71,6 +71,6 @@ dlg = iup.dialog{cnv; title="LuaGL/IUP/IM Loader"}
dlg:show()
cnv.rastersize = nil -- reset minimum limitation
-if (not iup.MainLoopLevel or iup.MainLoopLevel()==0) then
+if (iup.MainLoopLevel()==0) then
iup.MainLoop()
end