PrgmId = nil isEditor = false isError = false msg = "" function on.create() if not PrgmId then editor = D2Editor.newRichText() else exec(create) end end function on.enterKey() local s if not PrgmId then if isError then isError = false isEditor = false editor:setText("") msg = "" platform.window:invalidate() else PrgmId = editor:getText() editor:setText("") editor:move(0,0) editor:resize(1,1) isEditor = false s = var.recall(PrgmId .. "_reload") if type(s) ~= "number" then isError = true isEditor=false msg = "number var : " .. PrgmId .. "_reload not found" PrgmId = nil else var.monitor(PrgmId .. "_reload") if s==1 then reload() end end end platform.window:invalidate() else exec(enterKey) end end function on.paint(gc) local x,y if isError then gc:setColorRGB(255,0,0) gc:drawString("Error", platform.window:width()/2-gc:getStringWidth("Error")/2, 0, "top") gc:setColorRGB(0,0,0) if not isEditor then editor:move(10,20) editor:resize(platform.window:width()-20, platform.window:height()-30) editor:setText(msg) editor:setReadOnly(true) isEditor=true end elseif not PrgmId then x=platform.window:width()/2 y=platform.window:height()/5 gc:setColorRGB(0,0,0) gc:drawString("Prgm ID", x-gc:getStringWidth("Prgm ID")/2, platform.window:height()/5, "bottom") gc:drawRect(x-gc:getStringWidth("#####Prgm ID#####")/2-2, platform.window:height()/5 + 3, gc:getStringWidth("#####Prgm ID#####")+4, 32) if not isEditor then editor:move(x-gc:getStringWidth("#####Prgm ID#####")/2, platform.window:height()/5 + 5) editor:resize(gc:getStringWidth("#####Prgm ID#####"), 30) editor:setReadOnly(false) isEditor=true end else exec(paint,gc) end end function on.varChange(varlist) local s,r if not PrgmId then return end s = var.recall(PrgmId .. "_reload") if type(s) ~= "number" then isError = true isEditor=false msg = "number var : " .. PrgmId .. "_reload not found" PrgmId = nil return 0 elseif s==1 then reload() return 0 else if isError or not varChange then return end s,r = pcall(varChange, varlist) if not s then isError = true isEditor=false msg = "(E) in " .. name .. ", " .. r return 0 else return r end end end function loadprgm(name) local str, cmp, err str = var.recall(name) if str then cmp,err = loadstring("return " .. str, name) if cmp then return cmp() else isError = true isEditor=false msg = "(C) " ..err return nil end else return nil end end function reload() isError = false msg = "" editor:setText("") editor:move(0,0) editor:resize(1,1) isEditor = false var.store(PrgmId .. "_reload", 0) init = loadprgm("LUA_init") activate = loadprgm("LUA_activate") arrowDown = loadprgm("LUA_arrowDown") arrowKey = loadprgm("LUA_arrowKey") arrowRight = loadprgm("LUA_arrowRight") arrowUp = loadprgm("LUA_arrowUp") charIn = loadprgm("LUA_charIn") backspaceKey = loadprgm("LUA_backspaceKey") backtabKey = loadprgm("LUA_backtabKey") clearKey = loadprgm("LUA_clearKey") contextMenu = loadprgm("LUA_contextMenu") copy = loadprgm("LUA_copy") create = loadprgm("LUA_create") cut = loadprgm("LUA_cut") deactivate = loadprgm("LUA_deactivate") deleteKey = loadprgm("LUA_deleteKey") destroy = loadprgm("LUA_destroy") enterKey = loadprgm("LUA_enterKey") escapeKey = loadprgm("LUA_escapeKey") help = loadprgm("LUA_help") mouseDown = loadprgm("LUA_mouseDown") mouseMove = loadprgm("LUA_mouseMove") mouseUp = loadprgm("LUA_mouseUp") paint = loadprgm("LUA_paint") paste = loadprgm("LUA_paste") resize = loadprgm("LUA_resize") restore = loadprgm("LUA_restore") returnKey = loadprgm("LUA_returnKey") rightMouseDown = loadprgm("LUA_rightMouseDown") rightMouseUp = loadprgm("LUA_rightMouseUp") save = loadprgm("LUA_save") tabKey = loadprgm("LUA_tabKey") timer = loadprgm("LUA_timer") varChange = loadprgm("LUA_varChange") exec(init) end function exec(f,args) local s,err if isError or not PrgmId or not f then return end s,err = pcall(f, args) if not s then isError = true isEditor=false msg = "(E) "..err end end function on.activate() exec(activate) end function on.arrowDown() exec(arrowDown) end function on.arrowKey(key) -- not called because of other key functions exec(arrowKey,key) end function on.arrowLeft() exec(arrowLeft) end function on.arrowRight() exec(arrowRight) end function on.arrowUp() exec(arrowUp) end function on.charIn(char) exec(charIn,char) end function on.backspaceKey() exec(backspaceKey) end function on.backtabKey() exec(backtabKey) end function on.clearKey() exec(clearKey) end function on.contextMenu() exec(contextMenu) end function on.copy() exec(copy) end function on.cut() exec(cut) end function on.deactivate() exec(deactivate) end function on.deleteKey() exec(deleteKey) end function on.destroy() exec(destroy) end function on.escapeKey() exec(escapeKey) end function on.help() exec(help) end function on.mouseDown(x, y) exec(mouseDown,x,y) end function on.mouseMove(x, y) exec(mouseMove,x,y) end function on.mouseUp(x, y) exec(mouseUp,x,y) end function on.paste() exec(paste) end function on.resize(width, height) exec(resize,width, height) end function on.restore(state) exec(restore,state) end function on.returnKey() exec(returnKey) end function on.rightMouseDown(x, y) exec(rightMouseDown,x,y) end function on.rightMouseUp(x, y) exec(rightMouseUp,x,y) end function on.save() local s,r if isError or not PrgmId or not save then return end s,r = pcall(save) if not s then isError = true isEditor=false msg = "(E) " .. r else return r end end function on.tabKey() exec(tabKey) end function on.timer() exec(timer) end