summaryrefslogtreecommitdiff
path: root/html/examples/iup_dbuffer.wlua
blob: 3f3374601d11b5262fa0efdf00b64f5334edf2f9 (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
59
60
61
62
63
64
65
66
67
68
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()
  local canvas = cd.CreateCanvas(cd.IUP, self)
  local dbuffer = cdCreateCanvas(cd.DBUFFER, canvas);
  self.canvas = canvas     -- store the CD canvas in a IUP attribute
  self.dbuffer = dbuffer
end

function cnv:unmap_cb()
  local canvas = self.canvas     -- retrieve the CD canvas from the IUP attribute
  local dbuffer = self.dbuffer
  dbuffer:Kill()
  canvas:Kill()
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 Render(dbuffer)
  dbuffer:Activate()
  dbuffer:Clear()
  dbuffer:Foreground (cd.RED)
  dbuffer:Box (10, 55, 10, 55)
  dbuffer:Foreground(cd.EncodeColor(255, 32, 140))
  dbuffer:Line(0, 0, 300, 100)
end

function cnv:action()
  local dbuffer = self.dbuffer     -- retrieve the CD canvas from the IUP attribute
  dbuffer:Flush()
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()
  local dbuffer = self.dbuffer     -- retrieve the CD canvas from the IUP attribute
  
  -- update size
  dbuffer:Activate()

  -- update render
  Render(dbuffer);
end

dlg:show()
iup.MainLoop()