|
| 1 | +package.cpath = ";?51.dll;..package.cpath" |
| 2 | + |
| 3 | +require "cdlua" |
| 4 | +require "iuplua" |
| 5 | +require "iupluacd" |
| 6 | + |
| 7 | +pos_x=0 |
| 8 | +pos_y=0 |
| 9 | +function get_mem() |
| 10 | + --X and Y postion in Donkey Kong(JU) for gameboy |
| 11 | + pos_x = memory.readbyte(0x1) |
| 12 | + pos_y = memory.readbyte(0x0) |
| 13 | + gui.text(10,10,string.format("Xpos: %d",pos_x)) |
| 14 | + gui.text(10,20,string.format("Ypos: %d",pos_y)) |
| 15 | +end |
| 16 | +event.onframeend(get_mem) |
| 17 | + |
| 18 | +-- Initialize some IUP component for the UI |
| 19 | +label_counter = iup.label{title="1", size="20x20"} |
| 20 | +label_x = iup.label{title="0", size="20x20"} |
| 21 | +label_y = iup.label{title="0", size="20x20"} |
| 22 | +btn_exit = iup.button{ title = "Exit" } |
| 23 | +btn_print = iup.button{ title = "Print" } |
| 24 | + |
| 25 | +function close_cb() |
| 26 | + print("halting the timer") |
| 27 | + timer1.run = "NO" |
| 28 | + self:destroy() |
| 29 | + return iup.IGNORE -- because we destroy the dialog |
| 30 | +end |
| 31 | + |
| 32 | +timer1 = iup.timer{time=40} |
| 33 | +isInit = false |
| 34 | +function timer1:action_cb() |
| 35 | + if(isInit==false) then |
| 36 | + isInit=true |
| 37 | + --print("init timer") |
| 38 | + return iup.CLOSE |
| 39 | + end |
| 40 | + print("") |
| 41 | + --print("timer1 called") |
| 42 | + |
| 43 | + isInit=false; |
| 44 | + if (iup.MainLoopLevel()==0) then |
| 45 | + iup.MainLoop() |
| 46 | + end |
| 47 | + return iup.DEFAULT |
| 48 | +end |
| 49 | +-- can only be set after the time is created |
| 50 | +timer1.run = "YES" |
| 51 | + |
| 52 | +-- callback called when the exit button is activated |
| 53 | +function btn_exit:action() |
| 54 | + dlg:hide() |
| 55 | + print("halting the timer") |
| 56 | + timer1.run = "NO" |
| 57 | + self:destroy() |
| 58 | + return iup.IGNORE -- because we destroy the dialog |
| 59 | +end |
| 60 | + |
| 61 | +function btn_print:action() |
| 62 | + print("Button press.") |
| 63 | + return iup.DEFAULT |
| 64 | +end |
| 65 | + |
| 66 | +canvas = iup.canvas{rastersize="300x300",border="no"} |
| 67 | +function canvas:map_cb() |
| 68 | + self.canvas = cd.CreateCanvas(cd.IUP, self) |
| 69 | +end |
| 70 | + |
| 71 | +myCanvas = null; |
| 72 | +function canvas:action() |
| 73 | + myCanvas=self; |
| 74 | + self.canvas:Activate() |
| 75 | + self.canvas:Clear() |
| 76 | + if self.Draw then |
| 77 | + self:Draw(self.canvas) |
| 78 | + end |
| 79 | +end |
| 80 | + |
| 81 | +function canvas:Draw() |
| 82 | + canvas = self.canvas |
| 83 | + canvas:Rect(25,275,25,275) |
| 84 | + canvas:Rect(35+pos_x,40+pos_x,35+pos_y,40+pos_y) |
| 85 | +end |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | +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"} |
| 90 | +--dlg:showxy(iup.CENTER, iup.CENTER) |
| 91 | +dlg:show() |
| 92 | + |
| 93 | + |
| 94 | +function idle_cb() |
| 95 | + label_counter.title = tonumber(label_counter.title) + 1; |
| 96 | + label_x.title = "x: "..pos_x; |
| 97 | + label_y.title = "y: "..pos_y; |
| 98 | + |
| 99 | + myCanvas.canvas:Clear() |
| 100 | + myCanvas:Draw(myCanvas.canvas) |
| 101 | + |
| 102 | + return iup.DEFAULT |
| 103 | +end |
| 104 | + |
| 105 | +-- Registers idle callback |
| 106 | +iup.SetIdle(idle_cb) |
| 107 | + |
| 108 | +if (iup.MainLoopLevel()==0) then |
| 109 | + iup.MainLoop() |
| 110 | +end |
0 commit comments