summaryrefslogtreecommitdiff
path: root/cd/test/lua/iuplua_cdlua.wlua
blob: 552811775f48ee1df3b0eb4e98174e51ea792a0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require"cdlua"
require"iuplua"
require"iupluacd"

cnv = iup.canvas {size = "200x100"}

box = iup.vbox{
       iup.button { title="Version" },
       cnv,
       iup.button { title="Close" },
     }

dlg = iup.dialog{box; title="Example IUPLUA/CDLUA"}

function cnv:map_cb()
  canvas = cd.CreateCanvas(cd.IUP, self)
  self.canvas = canvas     -- store the CD canvas in a IUP attribute
end

function dlg:close_cb()
  cnv = self[1][2]
  canvas = cnv.canvas     -- retrieve the CD canvas from the IUP attribute
  canvas:Kill()
  self:destroy()
  return iup.IGNORE -- because we destroy the dialog
end

bt_version = dlg[1][1]
function bt_version:action()
  iup.Message("Version", "CD Version: " .. cd.Version() .. "\nIUP Version: " .. iup.Version() .. "\n" .. _VERSION)
end

bt_close = dlg[1][3]
function bt_close:action()
  return iup.CLOSE
end

function cnv:action()
  canvas = self.canvas     -- retrieve the CD canvas from the IUP attribute

  canvas:Activate()
  canvas:Clear()
  canvas:Foreground (cd.RED)
  canvas:Box (10, 55, 10, 55)
  canvas:Foreground(cd.EncodeColor(255, 32, 140))
  canvas:Line(0, 0, 300, 100)
end

function cnv:button_cb(b, e, x, y, r)
  print ("Button: " .. "Button="..tostring(b).." Pressed="..tostring(e).." X="..tostring(x).." Y="..tostring(y) )
end

function cnv:resize_cb(w, h)
  print("Resize: Width="..w.."   Height="..h)
end

dlg:show()
iup.MainLoop()