-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdk_canvas.lua
113 lines (92 loc) · 2.52 KB
/
dk_canvas.lua
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package.cpath = ";?51.dll;"..package.cpath
local iuplua_open = package.loadlib("iuplua51.dll", "iuplua_open");
local iuplua_close = package.loadlib("iuplua51.dll", "iuplua_close");
require "cdlua"
require "iuplua"
require "iupluacd"
pos_x=0
pos_y=0
function get_mem()
--X and Y postion in Donkey Kong(JU) for gameboy
pos_x = memory.readbyte(0x1)
pos_y = memory.readbyte(0x0)
gui.text(10,10,string.format("Xpos: %d",pos_x))
gui.text(10,20,string.format("Ypos: %d",pos_y))
end
--event.onframeend(get_mem)
-- Initialize some IUP component for the UI
label_counter = iup.label{title="1", size="20x20"}
label_x = iup.label{title="0", size="20x20"}
label_y = iup.label{title="0", size="20x20"}
btn_exit = iup.button{ title = "Exit" }
btn_print = iup.button{ title = "Print" }
function close_cb()
print("halting the timer")
timer1.run = "NO"
self:destroy()
return iup.IGNORE -- because we destroy the dialog
end
timer1 = iup.timer{time=10}
isInit = false
function timer1:action_cb()
if(isInit==false) then
isInit=true
return iup.CLOSE
end
--print("")
--print("timer1 called")
isInit=false;
if (iup.MainLoopLevel()==0) then
iup.MainLoop()
end
return iup.DEFAULT
end
-- can only be set after the time is created
timer1.run = "YES"
-- callback called when the exit button is activated
function btn_exit:action()
dlg:hide()
print("halting the timer")
timer1.run = "NO"
self:destroy()
return iup.IGNORE -- because we destroy the dialog
end
function btn_print:action()
print("Button press.")
return iup.DEFAULT
end
canvas = iup.canvas{rastersize="300x300",border="no"}
function canvas:map_cb()
self.canvas = cd.CreateCanvas(cd.IUP, self)
end
myCanvas = null;
function canvas:action()
myCanvas=self;
self.canvas:Activate()
self.canvas:Clear()
if self.Draw then
self:Draw(self.canvas)
end
end
function canvas:Draw()
canvas = self.canvas
canvas:Rect(25,275,25,275)
canvas:Rect(35+pos_x,40+pos_x,35+pos_y,40+pos_y)
end
dlg = iup.dialog{ iup.vbox{ iup.hbox{canvas, iup.vbox{ label_counter, label_x, label_y}, iup.vbox{btn_print, btn_exit}}}; title = "My Canvas"}
--dlg:showxy(iup.CENTER, iup.CENTER)
dlg:show()
function idle_cb()
get_mem();
label_counter.title = tonumber(label_counter.title) + 1;
label_x.title = "x: "..pos_x;
label_y.title = "y: "..pos_y;
myCanvas.canvas:Clear()
myCanvas:Draw(myCanvas.canvas)
return iup.DEFAULT
end
-- Registers idle callback
iup.SetIdle(idle_cb)
if (iup.MainLoopLevel()==0) then
iup.MainLoop()
end