Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --WARNING: THIS PROGRAM IS MADE BY JENS KOLBINGER!!!
- -- SEND ALL YOU WANT TO TELL ME ABOUT THIS PROGRAM TO jens.software@gmail.com
- __mG={} --my globals! Dont overwrite them!
- __mG.version="0.4.2.1"
- __mG.on={}
- __mG.WW=318 --WindowWidth
- __mG.WH=212 --WindowHeight
- __mG.maxChars=36
- __mG.maxLines=12
- __mG.chrS={25,2,8,15} --1: posX of first character / 2: posY of first character / 3: width of each character / 4: height of each character
- __mG.nl=string.char(10)
- __mG.dialogue=false
- __mG.dialogueVar={}
- __mG.dialogueField=1
- __mG.skriptName=""
- --__mG.code={'chr=""',"function on.timer()"," chr=string.uchar(math.random(32,1000))"," platform.window:invalidate()","end","function on.paint(gc)"," gc:drawString('Funzt'..chr,50,50)","end","timer.start(0.1)"}
- __mG.code={""}
- __mG.scroll={1,1}
- __mG.coursor={1,1}
- __mG.selection={}
- __mG.mouseDown=false
- __mG.ERRline=nil
- __mG.ERR=nil
- __mG.font="serif"
- __mG.moveOK=true
- __mG.chrOffset={}
- __mG.colDsp=platform.isColorDisplay()
- __mG.calcLayout="touch"
- __mG.markSyntax=true
- __mG.message = class()
- __mG.state={} --state[__mG.stateNo].before/after = {lineStart,lineEnd,{"line at lineStart",...,"line at lineEnd},{cursor position}}
- __mG.stateNo=0 --current position in state history (min 0, max 10)
- function __mG.message:reset()
- function __mG.message:action() end
- __mG.message.show=false
- __mG.message.selButton=1
- __mG.text={}
- end
- __mG.message:reset()
- function __mG.copy_table(t)
- local t2 = {}
- for k,v in pairs(t) do
- if type(v)=="table" then v=__mG.copy_table(v) end
- t2[k] = v
- end
- return t2
- end
- __mG.fileList={} --Table that indicates if a file with name n already exists: __mG.fileList["test"]=true if the file "test" exists
- __mG.repChr={} --replace character(s)
- __mG.repChr["touch"]={}
- --basic universial functions
- __mG.repChr["touch"]["−"]=":" --key [(-)]
- __mG.repChr["touch"]["≥"]=">="
- __mG.repChr["touch"]["≤"]="<="
- __mG.repChr["touch"]["≠"]="~="
- __mG.repChr["touch"]["√"]="math.sqrt("
- for i, name in pairs({"sin(","cos(","tan("}) do __mG.repChr["touch"][name]="math."..name end
- __mG.repChr["touch"]["sin("]="math.asin("
- __mG.repChr["touch"]["cos("]="math.acos("
- __mG.repChr["touch"]["tan("]="math.atan("
- __mG.repChr["touch"]["π"]="math.pi"
- --special functions for clickpad
- __mG.repChr["click"]=__mG.copy_table(__mG.repChr["touch"])
- __mG.repChr["click"]["cos("]="["
- __mG.repChr["click"]["tan("]="]"
- __mG.repChr["click"]["cos("]="{"
- __mG.repChr["click"]["tan("]="}"
- __mG.repChr["click"]["exp("]="math.exp("
- __mG.repChr["click"]["ln("]="math.log10("
- __mG.repChr["click"]["log("]="math.log("
- __mG.repChr["click"][""]="~" --that i button below the > button
- --special functions for touchpad
- __mG.repChr["touch"]["exp("]="["
- __mG.repChr["touch"]["10^("]="]"
- __mG.repChr["touch"]["ln("]="{"
- __mG.repChr["touch"]["log("]="}"
- __mG.wordRGB={}
- __mG.wordRGB["--"]={128,128,128}
- for i, word in pairs({"'",'"',"[[","]]","nil","true","false"}) do
- if __mG.colDsp then
- __mG.wordRGB[word]={128,0,128}
- else
- __mG.wordRGB[word]={110,110,110}
- end
- end
- for i, word in pairs({"function","return","end","for","in","do","if","then","else","elseif","while","and","or","not","local"}) do
- if __mG.colDsp then
- __mG.wordRGB[word]={0,0,210}
- else
- __mG.wordRGB[word]={80,80,80}
- end
- end
- for i, word in pairs({"assert","collectgarbage","error","_G","getfenv","getmetatable","ipairs","load","loadstring","next","pairs","pcall","print","rawequal","rawget","rawset","select","setfenv","setmetatable","tonumber","tostring","type","unpack","_VERSION","xpcall","require"}) do
- if __mG.colDsp then
- __mG.wordRGB[word]={255,0,255}
- else
- __mG.wordRGB[word]={170,170,170}
- end
- end
- function __mG.createMenu()
- __mG.fileList={}
- local loadMenu={"Load"}
- local files=var.recall("JSEFiles") --List of all saved files as string
- if not files or files=="" then
- __mG.fileList={}
- else
- files=files:split("§") --list as string to table
- for i, fileName in pairs(files) do
- if fileName and fileName~="" then
- __mG.fileList[fileName]=true
- table.insert(loadMenu,{fileName,__mG_translateMenu})
- end
- end
- end
- __mG.menu = {
- {"Code",
- {"Run", __mG_translateMenu},
- {"Undo (ctrl+del)", __mG_translateMenu},
- {"Redo (ctrl+menu)", __mG_translateMenu},
- {"Copy all", __mG_translateMenu},
- {"Import from clipboard", __mG_translateMenu},
- {"Import from library...", __mG_translateMenu}
- },
- {"Insert",
- {"platform.window:invalidate()", __mG_translateMenu},
- {"function on.paint(gc)", __mG_translateMenu},
- {"gc:setColorRGB(", __mG_translateMenu},
- {"gc:drawString(", __mG_translateMenu},
- {"gc:drawLine(", __mG_translateMenu},
- {"gc:fillRect(", __mG_translateMenu},
- {"gc:drawRect(", __mG_translateMenu},
- {"function on.arrowKey(dir)", __mG_translateMenu},
- {"function on.charIn(chr)", __mG_translateMenu},
- {"function on.enterKey()", __mG_translateMenu},
- {"function on.escapeKey()", __mG_translateMenu},
- {"function on.mouseDown(x,y)", __mG_translateMenu},
- {"function on.mouseMove(x,y)", __mG_translateMenu},
- {"function on.timer()", __mG_translateMenu}
- },
- {"File",
- {"New", __mG_translateMenu},
- {"Save", __mG_translateMenu},
- {"Save as...", __mG_translateMenu},
- {"Delete", __mG_translateMenu}
- },
- __mG.copy_table(loadMenu),
- {"View",
- {"Go to top", __mG_translateMenu},
- {"Go to end", __mG_translateMenu},
- {"Go to line...", __mG_translateMenu},
- {"Toggle serifs", __mG_translateMenu},
- {"Toggle syntax marking", __mG_translateMenu},
- },
- {"Controls",
- {"nspire with touchpad", __mG_translateMenu},
- {"nspire with clickpad", __mG_translateMenu}
- },
- {"Help",
- {"Help", __mG_translateMenu},
- {"About", __mG_translateMenu}
- }
- }
- toolpalette.register(__mG.menu)
- end
- function __mG.resetEditor()
- __mG.message:reset()
- __mG.dialogue=false
- __mG.skriptName=""
- __mG.code={""}
- __mG.coursor={1,1}
- __mG.scroll={1,1}
- end
- function __mG_translateMenu(box,item)
- if box=="Load" then
- local code=var.recall("JSEF"..item)
- if code then
- __mG.message.show=true
- __mG.message.text={"Warning!","When you load a file, the current","code will be lost (if not saved).","","Do you want to continue anyways?","","","Continue with [enter] Cancel with [esc]"}
- function __mG.message:action()
- __mG.resetEditor()
- __mG.skriptName=item
- __mG.code=code:split(__mG.nl)
- end
- end
- elseif box=="Insert" then
- __mG.on.charIn(item)
- elseif item=="New" then
- __mG.message.show=true
- __mG.message.text={"Warning!","When you create a new file, the current","code will be lost (if not saved).","","Do you want to continue anyways?","","","Continue with [enter] Cancel with [esc]"}
- function __mG.message:action()
- __mG.resetEditor()
- end
- elseif item=="Save" then
- if not __mG.skriptName or __mG.skriptName=="" then
- __mG.dialogue="inputName"
- __mG.dialogueVar={__mG.skriptName}
- else
- __mG.saveAs(__mG.skriptName)
- end
- elseif item=="Save as..." then
- __mG.dialogue="inputName"
- __mG.dialogueVar={__mG.skriptName}
- elseif item=="nspire with touchpad" then
- __mG.calcLayout="touch"
- math.eval("DelVar JSElayout")
- var.store("JSElayout", __mG.calcLayout)
- document.markChanged()
- elseif item=="nspire with clickpad" then
- __mG.calcLayout="click"
- math.eval("DelVar JSElayout")
- var.store("JSElayout", __mG.calcLayout)
- document.markChanged()
- elseif item=="Delete" then
- __mG.message.show=true
- __mG.message.text={"Delete?","Do you really want to delete the current file:","'"..__mG.skriptName.."' ?","","","","","Continue with [enter] Cancel with [esc]"}
- function __mG.message:action()
- math.eval("DelVar JSEF"..__mG.skriptName)
- __mG.fileList[__mG.skriptName]=false
- __mG.saveFileList()
- __mG.createMenu()
- end
- elseif item=="Run" then
- if var.recall("JSEshowInfo")~="NO" then
- __mG.message.show=true
- __mG.message.text={"Info!","Stop the running code with the [EE] key on","the left!","Better save your code before running it!","","Press [tab] to continue and never show","this info again!","Continue with [enter] Cancel with [esc]"}
- function __mG.message:action()
- __mG.runCode()
- end
- platform.window:invalidate()
- else
- __mG.runCode()
- end
- elseif item=="Undo (ctrl+del)" then
- __mG.undo()
- elseif item=="Redo (ctrl+menu)" then
- __mG.redo()
- elseif item=="Go to top" then
- __mG.coursor={1,1}
- __mG.adjustScroll()
- elseif item=="Go to end" then
- __mG.coursor[2]=#__mG.code
- __mG.coursor[1]=__mG.code[__mG.coursor[2]]:len()
- __mG.adjustScroll()
- elseif item=="Go to line..." then
- __mG.dialogue="gotoLine"
- __mG.dialogueVar={""}
- elseif item=="Toggle serifs" then
- if __mG.font=="sansserif" then __mG.font="serif"
- else __mG.font="sansserif" end
- math.eval("DelVar JSEfont")
- var.store("JSEfont",__mG.font)
- document.markChanged()
- __mG.initialChrOff()
- elseif item=="Toggle syntax marking" then
- __mG.markSyntax=not __mG.markSyntax
- math.eval("DelVar JSEmarkSyntax")
- var.store("JSEmarkSyntax", tostring(__mG.markSyntax))
- document.markChanged()
- elseif item=="Copy all" then
- local codeStr=__mG.arrToStr(__mG.code)
- clipboard.addText(codeStr)
- elseif item=="Import from clipboard" then
- local newCode=clipboard.getText()
- if newCode and newCode~="" then
- __mG.message.show=true
- __mG.message.text={"Warning!","When you import code, your current code","code will be lost (if not saved)","","Do you want to import anyways?","","","Continue with [enter] Cancel with [esc]"}
- function __mG.message:action()
- local newCode=clipboard.getText()
- __mG.resetEditor()
- __mG.code=newCode:split(__mG.nl)
- end
- end
- elseif item=="Import from library..." then
- __mG.dialogue="importFromLibrary"
- __mG.dialogueVar={"",""}
- __mG.dialogueField=1
- elseif item=="Help" then
- __mG.message.show=true
- if __mG.calcLayout=="touch" then
- __mG.message.text={"Help","Run your program with 'Code'==>'Run'. Stop","running program with the [EE] key on the","left! Ctrl+click and move around to select","code. There are several rebound buttons:","e^x==>[ 10^x==>] ln==>{ log==>}","(-)==>: Switch calc-layout in 'Controls'!","Close with [esc]"}
- else
- __mG.message.text={"Help","Run your program with 'Code'==>'Run'. Stop","running program with the [EE] key on the","left! Ctrl+click and move around to select","code. There are several rebound buttons:","cos==>[ tan==>] cos==>{ tan==>}","==>~ Switch calculator layout in 'Controls'!","Close with [esc]"}
- end
- elseif item=="About" then
- __mG.message.show=true
- __mG.message.text={"About","This is Jens' Script Editor "..__mG.version.." by","Jens Kolbinger","Inspired by 'oclua' by Olivier Armand.","","Any feedback to jens.software@gmail.com","","Close with [esc]"}
- end
- platform.window:invalidate()
- end
- function __mG.on.create()
- __mG.createMenu()
- local font=var.recall("JSEfont")
- if font=="serif" then
- __mG.font="serif"
- elseif font=="sansserif" then
- __mG.font="sansserif"
- end
- __mG.initialChrOff()
- local layout=var.recall("JSElayout")
- if layout=="touch" then
- __mG.calcLayout="touch"
- elseif layout=="click" then
- __mG.calcLayout="click"
- end
- local markSyntax=var.recall("JSEmarkSyntax")
- if markSyntax=="true" then
- __mG.markSyntax=true
- elseif markSyntax=="false" then
- __mG.markSyntax=false
- end
- end
- function __mG.on.construction() __mG.on.create() end
- function __mG.initialChrOff()
- --rendering is much faster if you calculate every characters position before rendering them!
- __mG.chrOffset={}
- local function init(gc)
- gc:setFont(__mG.font,"r",10)
- for i=33,126 do --all displayable characters
- __mG.chrOffset[string.uchar(i)]=math.floor(4-gc:getStringWidth(string.uchar(i))/2+0.5)
- end
- end
- if platform.withGC then
- platform.withGC(init)
- else
- local gc
- gc=platform.gc()
- gc:begin()
- init(gc)
- gc:finish()
- end
- if __mG.font=="serif" then
- for i, chr in pairs({"i","j","l","m","W","E","T","Z","I","L","M","(",")","{","}","-","?","&","+","^"}) do
- __mG.chrOffset[chr]=__mG.chrOffset[chr]+1
- end
- else
- for i, chr in pairs({"T","W","^","<","=",">","}","+",",",";"}) do
- __mG.chrOffset[chr]=__mG.chrOffset[chr]+1
- end
- end
- end
- function __mG.saveFileList()
- local fileListStr=""
- for name, bool in pairs(__mG.fileList) do
- if bool then
- fileListStr=fileListStr..name.."§"
- end
- end
- math.eval("DelVar JSEFiles")
- var.store("JSEFiles", fileListStr)
- document.markChanged()
- end
- function __mG.saveAs(skriptName)
- __mG.fileList[skriptName]=true
- __mG.saveFileList()
- math.eval("DelVar "..skriptName)
- var.store("JSEF"..skriptName, __mG.arrToStr(__mG.code))
- __mG.createMenu()
- document.markChanged()
- end
- function __mG.on.help()
- __mG_translateMenu("Help","Help")
- end
- function __mG.arrToStr(arr)
- local str=""
- for i=1, #arr do
- if i<#arr then
- str=str..arr[i]..__mG.nl
- else
- str=str..arr[i]
- end
- end
- return str
- end
- function __mG.insert(str,i,insertion)
- return str:sub(0,i-1)..insertion..str:sub(i,str:len())
- end
- function __mG.onError()
- print(__mG.ERR)
- local errArr=__mG.ERR:split(":")
- __mG.ERRline=tonumber(errArr[#errArr-1])
- __mG.ERR=errArr[#errArr]
- __mG.reloadSEHandlers()
- end
- function __mG.runCode()
- timer.stop()
- __mG.ERR = nil
- __mG.ERRline=nil
- local codeStr=__mG.arrToStr(__mG.code)
- local chunk, errload = loadstring(codeStr)
- if not chunk then
- __mG.ERR = errload
- __mG.onError()
- else
- on = {}
- toolpalette.register({})
- cursor.set("default")
- local status, errcall = pcall(chunk)
- if not status then
- __mG.ERR = errcall
- __mG.onError()
- return
- end
- for name, funct in pairs(on) do --make every function save!
- if funct then
- on[name]=function(v1,v2,v3,v4,v5)
- local status, errcall = pcall(function() funct(v1,v2,v3,v4,v5) end)
- if not status then
- __mG.ERR = errcall
- __mG.onError()
- return
- end
- end
- end
- end
- if not __mG.ERR then
- function on.charIn(chr,v2,v3,v4,v5)
- if chr=="" then --that EE button thing
- __mG.reloadSEHandlers()
- else
- if userCharIn then
- userCharIn(chr,v2,v3,v4,v5)
- end
- end
- end
- if on.construction then on.construction() end
- if on.resize then on.resize(platform.window:width(),platform.window:height()) end
- if on.activate then on.activate() end
- if on.getFocus then on.getFocus() end
- if on.create then on.create() end
- if platform.isTabletModeRendering and platform.isTabletModeRendering() then toolpalette.register({{"Script Editor",{"Go back", __mG.reloadSEHandlers}}}) end
- -- toolpalette bug workaround
- platform.window:setFocus(false)
- platform.window:setFocus(true)
- end
- platform.window:invalidate()
- end
- end
- function __mG.validSel(oldSel)
- if not oldSel then return false end
- if not (oldSel[1] and oldSel[2]) then
- return false
- end
- local newSel=__mG.copy_table(oldSel)
- if oldSel[1][2]==oldSel[2][2] then
- if oldSel[1][1]==oldSel[2][1] then
- return false
- elseif oldSel[1][1]>oldSel[2][1] then
- newSel[1][1]=oldSel[2][1]
- newSel[2][1]=oldSel[1][1]
- end
- elseif oldSel[1][2]>oldSel[2][2] then
- newSel[1]=__mG.copy_table(oldSel[2])
- newSel[2]=__mG.copy_table(oldSel[1])
- end
- return newSel
- end
- function __mG.on.grabDown()
- if __mG.selection[1] then
- if __mG.selection[2] then
- __mG.selection={}
- else
- __mG.selection[2]=__mG.copy_table(__mG.coursor)
- end
- else
- __mG.selection[1]=__mG.copy_table(__mG.coursor)
- end
- platform.window:invalidate()
- end
- function __mG.getSelAsStr()
- local newSel=__mG.validSel(__mG.selection)
- if newSel then
- local text=""
- if newSel[1][2]==newSel[2][2] then
- text = __mG.code[newSel[1][2]]:sub(newSel[1][1],newSel[2][1]-1)
- else
- local firstLine = __mG.code[newSel[1][2]]
- text = firstLine:sub(newSel[1][1],firstLine:len())
- if newSel[2][2]-newSel[1][2]>1 then
- for l=newSel[1][2]+1, newSel[2][2]-1 do
- text=text..__mG.nl..__mG.code[l]
- end
- end
- local lastLine=__mG.code[newSel[2][2]]
- text=text..__mG.nl..lastLine:sub(1,newSel[2][1]-1)
- end
- return text
- end
- end
- function __mG.on.copy()
- local markLine=false
- if __mG.selection[1] then
- if __mG.selection[2] then
- if __mG.selection[2][2]==__mG.selection[1][2] and __mG.selection[2][1]==__mG.selection[1][1] then
- markLine=true
- end
- else
- markLine=true
- end
- else
- markLine=true
- end
- if markLine then
- local line=__mG.code[__mG.coursor[2]]
- __mG.selection={{1,__mG.coursor[2]},{line:len()+1,__mG.coursor[2]}}
- platform.window:invalidate()
- end
- clipboard.addText(__mG.getSelAsStr())
- end
- function __mG.on.cut()
- __mG.on.copy()
- __mG.on.backspaceKey()
- end
- function __mG.insertText(text)
- if text and text~=""then
- local state={}
- state.before=__mG.createState("coursor")
- text=text:split(__mG.nl)
- if #text==1 or (#text==2 and text[2]=="") then
- __mG.code[__mG.coursor[2]]=__mG.insert(__mG.code[__mG.coursor[2]],__mG.coursor[1],text[1])
- __mG.coursor[1]=__mG.coursor[1]+text[1]:len()
- state.after = __mG.createState("coursor")
- else
- state.after = {__mG.coursor[2],1,{}}
- local oldLine = __mG.code[__mG.coursor[2]]
- local leftOfC = oldLine:sub(1,__mG.coursor[1]-1)
- local rightOfC = oldLine:sub(__mG.coursor[1],oldLine:len())
- __mG.code[__mG.coursor[2]]=leftOfC..text[1]
- table.insert(state.after[3], __mG.code[__mG.coursor[2]])
- table.remove(text,1)
- for i, line in pairs(text) do
- __mG.coursor={1,__mG.coursor[2]+1}
- table.insert(__mG.code, __mG.coursor[2], line)
- table.insert(state.after[3], line)
- state.after[2]=state.after[2]+1
- end
- __mG.coursor[1]=__mG.code[__mG.coursor[2]]:len()+1
- __mG.code[__mG.coursor[2]]=__mG.code[__mG.coursor[2]]..rightOfC
- state.after[3][#state.after+1]=__mG.code[__mG.coursor[2]]
- state.after[4]=__mG.copy_table(__mG.coursor)
- __mG.adjustScroll()
- platform.window:invalidate()
- end
- __mG.registerState(state)
- end
- end
- function __mG.on.paste()
- local text=clipboard.getText()
- if __mG.selection[1] and __mG.selection[2] then
- __mG.on.backspaceKey()
- end
- __mG.insertText(text)
- end
- function __mG.on.escapeKey()
- if __mG.message.show then
- __mG.message:reset()
- elseif __mG.dialogue then
- __mG.dialogue=false
- __mG.dialogueVar={}
- elseif __mG.selection[1] then
- __mG.selection={}
- end
- platform.window:invalidate()
- end
- function __mG.on.enterKey()
- if __mG.message.show then
- __mG.message:action()
- __mG.message:reset()
- platform.window:invalidate()
- return
- elseif __mG.dialogue=="inputName" then
- if __mG.dialogueVar[1]:len()>0 then
- if __mG.fileList[__mG.dialogueVar[1]] then
- __mG.message.show=true
- __mG.message.text={"File already exists!","There is already a file with the name:","'"..__mG.dialogueVar[1].."'","","Do you want to overwrite it?","","","Continue with [enter] Cancel with [esc]"}
- function __mG.message:action()
- __mG.skriptName=__mG.dialogueVar[1]
- __mG.saveAs(__mG.skriptName)
- __mG.dialogue=false
- platform.window:invalidate()
- end
- else
- __mG.skriptName=__mG.dialogueVar[1]
- __mG.saveAs(__mG.skriptName)
- __mG.dialogue=false
- end
- platform.window:invalidate()
- end
- return
- elseif __mG.dialogue=="gotoLine" then
- if __mG.dialogueVar[1]:len()>0 then
- local line=math.max(math.min(tonumber(__mG.dialogueVar[1]),#__mG.code),1)
- __mG.coursor={1,line}
- __mG.adjustScroll()
- __mG.dialogue=false
- __mG.dialogueVar={}
- platform.window:invalidate()
- end
- return
- elseif __mG.dialogue=="importFromLibrary" then
- if __mG.dialogueVar[1]:len()>0 and __mG.dialogueVar[2]:len()>0 then
- local text, err = var.recall(__mG.dialogueVar[1].."\\"..__mG.dialogueVar[2])
- if err then
- print(text, err)
- __mG.message.show=true
- __mG.message.text={"Error importing from library!","There was an error while loading the","requested variable!",'Check if the file "'..__mG.dialogueVar[1]..'.tns"','is in the folder "MyLib" and contains the','variable "'..__mG.dialogueVar[2]..'"!',"","Close with [esc]"}
- elseif text and text~="" then
- __mG.insertText(text)
- __mG.dialogue=false
- __mG.dialogueVar={}
- end
- platform.window:invalidate()
- end
- return
- end
- if __mG.selection[1] then
- __mG.on.backspaceKey()
- end
- local state={}
- state.before = __mG.createState("coursor")
- local oldLine = __mG.code[__mG.coursor[2]]
- local leftOfC = oldLine:sub(1,__mG.coursor[1]-1)
- local rightOfC = oldLine:sub(__mG.coursor[1],oldLine:len())
- table.insert(__mG.code, __mG.coursor[2], "")
- __mG.code[__mG.coursor[2]]=leftOfC
- __mG.code[__mG.coursor[2]+1]=rightOfC
- __mG.coursor={1,__mG.coursor[2]+1}
- local c=1
- while c<=__mG.code[__mG.coursor[2]-1]:len() and __mG.code[__mG.coursor[2]-1]:sub(c,c)==" " do
- __mG.on.charIn(" ")
- c=c+1
- end
- state.after={__mG.coursor[2]-1,__mG.coursor[2],{__mG.code[__mG.coursor[2]-1],__mG.code[__mG.coursor[2]]},__mG.copy_table(__mG.coursor)}
- __mG.registerState(state)
- __mG.adjustScroll()
- platform.window:invalidate()
- end
- function __mG.on.returnKey()
- __mG.on.enterKey()
- end
- function __mG.on.tabKey()
- if __mG.message.show then
- if __mG.message.text[1]=="Info!" then
- var.store("JSEshowInfo","NO")
- __mG.message:reset()
- platform.window:invalidate()
- __mG.runCode()
- end
- return
- elseif __mG.dialogue then
- if __mG.dialogue=="importFromLibrary" then
- if __mG.dialogueField==1 then
- __mG.dialogueField=2
- else
- __mG.dialogueField=1
- end
- platform.window:invalidate()
- end
- return
- end
- local state={}
- local newSel=__mG.validSel(__mG.selection)
- if newSel then
- state.before={newSel[1][2],newSel[2][2],{},__mG.copy_table(newSel[2])}
- state.after={newSel[1][2],newSel[2][2],{}}
- for l=newSel[1][2], newSel[2][2] do
- table.insert(state.before[3],__mG.code[l])
- __mG.code[l]=" "..__mG.code[l]
- table.insert(state.after[3],__mG.code[l])
- end
- if newSel[1][1]==1 then
- __mG.selection[1][1]=1
- else
- __mG.selection[1][1]=newSel[1][1]+4
- end
- __mG.selection[2][1]=newSel[2][1]+4
- __mG.coursor=__mG.copy_table(__mG.selection[2])
- state.after[4]=__mG.copy_table(__mG.selection[2])
- __mG.adjustScroll()
- platform.window:invalidate()
- else
- state.before=__mG.createState("coursor")
- __mG.code[__mG.coursor[2]]=__mG.insert(__mG.code[__mG.coursor[2]],__mG.coursor[1]," ")
- __mG.coursor[1]=__mG.coursor[1]+4
- state.after=__mG.createState("coursor")
- end
- __mG.registerState(state)
- end
- function __mG.on.backtabKey()
- if __mG.dialogue or __mG.message.show then return end
- local function backTabInLine(lineNo)
- __mG.coursor[2]=lineNo
- local found=false
- local i=1
- local line=__mG.code[lineNo]
- while i<=line:len()+1 and not found do --search for first character
- if line:sub(i,i)~=" " then found=true end
- i=i+1
- end
- i=i-1
- if i>1 then --if first character is not at left border
- __mG.coursor[1]=i --go to the left of first character
- __mG.code[lineNo]=line:sub(math.min(i-1,4)+1,line:len()+1)
- __mG.coursor[1]=__mG.coursor[1]-math.min(i-1,4)
- end
- end
- local state={}
- local newSel=__mG.validSel(__mG.selection)
- if newSel then
- state.before={newSel[1][2],newSel[2][2],{},__mG.copy_table(newSel[2])}
- state.after={newSel[1][2],newSel[2][2],{}}
- for l=newSel[1][2], newSel[2][2] do
- table.insert(state.before[3],__mG.code[l])
- backTabInLine(l)
- table.insert(state.after[3],__mG.code[l])
- end
- __mG.selection[1]={1,newSel[1][2]}
- __mG.selection[2]=__mG.copy_table(__mG.coursor)
- state.after[4]=__mG.copy_table(__mG.coursor)
- else
- state.before=__mG.createState("coursor")
- backTabInLine(__mG.coursor[2])
- state.after=__mG.createState("coursor")
- end
- __mG.registerState(state)
- platform.window:invalidate()
- end
- function __mG.adjustScroll()
- if __mG.coursor[2]-__mG.scroll[2]<1 then
- __mG.scroll[2]=math.max(__mG.coursor[2]-1,1)
- end
- if __mG.coursor[2]-__mG.scroll[2]>__mG.maxLines-2 then
- __mG.scroll[2]=math.min(__mG.coursor[2]-__mG.maxLines+2,#__mG.code)
- end
- if __mG.scroll[2]+__mG.maxLines>#__mG.code then
- __mG.scroll[2]=math.max(#__mG.code-__mG.maxLines+1,1)
- end
- if __mG.coursor[1]-__mG.scroll[1]<1 then
- __mG.scroll[1]=math.max(__mG.coursor[1]-1,1)
- end
- if __mG.coursor[1]-__mG.scroll[1]>__mG.maxChars-1 then
- __mG.scroll[1]=math.max(__mG.coursor[1]-__mG.maxChars+1,1)
- end
- end
- function __mG.on.arrowKey(dir)
- cursor.hide()
- if __mG.message.show then return
- elseif __mG.dialogue then
- if __mG.dialogue=="importFromLibrary" then
- if __mG.dialogueField==1 then
- __mG.dialogueField=2
- else
- __mG.dialogueField=1
- end
- platform.window:invalidate()
- end
- return
- end
- if dir=="up" then
- if __mG.code[__mG.coursor[2]-1] then
- __mG.coursor[2]=__mG.coursor[2]-1
- end
- if __mG.scroll[2]>1 and __mG.coursor[2]-__mG.scroll[2]<1 then
- __mG.scroll[2]=__mG.scroll[2]-1
- end
- elseif dir=="down" then
- if __mG.code[__mG.coursor[2]+1] then
- __mG.coursor[2]=__mG.coursor[2]+1
- end
- elseif dir=="right" then
- __mG.coursor[1]=__mG.coursor[1]+1
- if __mG.coursor[1]>__mG.code[__mG.coursor[2]]:len()+1 then
- if __mG.code[__mG.coursor[2]+1] then
- __mG.coursor[2]=__mG.coursor[2]+1
- __mG.coursor[1]=1
- end
- end
- elseif dir=="left" then
- __mG.coursor[1]=__mG.coursor[1]-1
- if __mG.coursor[1]<1 then
- if __mG.code[__mG.coursor[2]-1] then
- __mG.coursor[2]=__mG.coursor[2]-1
- __mG.coursor[1]=__mG.code[__mG.coursor[2]]:len()+1
- end
- end
- end
- __mG.moveOK=false
- __mG.coursor[1]=math.max(math.min(__mG.coursor[1],__mG.code[__mG.coursor[2]]:len()+1),1)
- if __mG.selection[1] then
- __mG.selection[2]=__mG.copy_table(__mG.coursor)
- end
- __mG.adjustScroll()
- platform.window:invalidate()
- end
- function __mG.on.backspaceKey()
- if __mG.message.show then return end
- if __mG.dialogue then
- local i = 1
- if __mG.dialogue=="importFromLibrary" then
- i=__mG.dialogueField
- end
- if __mG.dialogueVar[i]:len()>0 then
- __mG.dialogueVar[i]=__mG.dialogueVar[i]:sub(1,__mG.dialogueVar[i]:len()-1)
- platform.window:invalidate()
- end
- return
- end
- local state={}
- local line=__mG.code[__mG.coursor[2]]
- if __mG.selection[1] then
- local newSel=__mG.validSel(__mG.selection)
- if newSel then
- state.before=__mG.createState("selection",newSel)
- if newSel[1][2]==newSel[2][2] then
- __mG.code[newSel[1][2]]=line:sub(1,newSel[1][1]-1)..line:sub(newSel[2][1],line:len())
- __mG.coursor[1]=newSel[1][1]
- else
- local firstLine=__mG.code[newSel[1][2]]
- local lastLine=__mG.code[newSel[2][2]]
- __mG.code[newSel[1][2]]=firstLine:sub(1,newSel[1][1]-1)..lastLine:sub(newSel[2][1],lastLine:len())
- for i=newSel[1][2]+1, newSel[2][2] do
- table.remove(__mG.code,newSel[1][2]+1)
- end
- __mG.coursor=__mG.copy_table(newSel[1])
- end
- __mG.selection={}
- end
- elseif __mG.coursor[1]==1 then --if coursor is at left border
- if __mG.coursor[2]>1 then --not at first line
- state.before={__mG.coursor[2]-1,__mG.coursor[2],{__mG.code[__mG.coursor[2]-1],__mG.code[__mG.coursor[2]]},__mG.copy_table(__mG.coursor)}
- local oldLen=__mG.code[__mG.coursor[2]-1]:len()+1
- __mG.code[__mG.coursor[2]-1]=__mG.code[__mG.coursor[2]-1]..__mG.code[__mG.coursor[2]] --add old line to line above
- table.remove(__mG.code,__mG.coursor[2])
- __mG.coursor={oldLen,__mG.coursor[2]-1}
- end
- else --remove character
- state.before=__mG.createState("coursor")
- __mG.code[__mG.coursor[2]]=line:sub(1,__mG.coursor[1]-2)..line:sub(__mG.coursor[1],line:len())
- __mG.coursor[1]=__mG.coursor[1]-1
- end
- state.after=__mG.createState("coursor")
- __mG.registerState(state)
- __mG.adjustScroll()
- platform.window:invalidate()
- end
- function __mG.on.mouseMove(mx,my)
- if __mG.mouseDown then
- __mG.selection[1]=__mG.copy_table(__mG.mouseDown)
- __mG.selection[2]=__mG.getChrPos(mx,my)
- __mG.coursor=__mG.copy_table(__mG.selection[2])
- __mG.adjustScroll()
- platform.window:invalidate()
- end
- if mx>=(__mG.WW-3) then
- cursor.set("hand pointer")
- else
- cursor.set("text")
- end
- end
- function __mG.on.mouseUp()
- __mG.mouseDown=nil
- if platform.isTabletModeRendering then -- 3.4 detection
- -- toolpalette bug workaround
- platform.window:setFocus(false)
- platform.window:setFocus(true)
- if touch then
- if not touch.isKeyboardVisible() then
- touch.showKeyboard()
- end
- end
- end
- end
- function __mG.getChrPos(x,y)
- y=y+5 --middle of the "text" cursor
- local newY = math.max(math.min(math.floor((y-__mG.chrS[2])/__mG.chrS[4])+__mG.scroll[2],#__mG.code),1)
- local newX = math.max(math.min(math.floor((x-__mG.chrS[1])/__mG.chrS[3])+__mG.scroll[1],__mG.code[newY]:len()+1),1)
- return {newX,newY}
- end
- function __mG.on.mouseDown(mx,my)
- if __mG.dialogue or __mG.message.show then return end
- if mx>=(__mG.WW-3) then
- __mG.scroll[2]=math.max(math.min(math.floor((my/(__mG.WH-20))*(#__mG.code-math.floor(__mG.maxLines/2-0.5)-1)),#__mG.code-(__mG.maxLines-1)),1)
- elseif mx==0 and my==0 then --cursor is hidden
- cursor.show()
- else
- __mG.coursor=__mG.getChrPos(mx,my)
- __mG.mouseDown=__mG.copy_table(__mG.coursor)
- if __mG.selection[1] then
- __mG.on.grabDown()
- end
- end
- platform.window:invalidate()
- end
- function __mG.on.charIn(chr)
- if __mG.message.show then return end
- if __mG.dialogue=="inputName" then
- if chr~=" " and not var.store("tEsT"..__mG.dialogueVar[1]..chr,"") then
- __mG.dialogueVar[1]=__mG.dialogueVar[1]..chr
- math.eval("DelVar ".."tEsT"..__mG.dialogueVar[1])
- end
- elseif __mG.dialogue=="gotoLine" then
- if tostring(tonumber(chr))==chr and __mG.dialogueVar[1]:len()<5 then --chr is a number
- __mG.dialogueVar[1]=__mG.dialogueVar[1]..chr
- end
- elseif __mG.dialogue=="importFromLibrary" then
- if __mG.dialogueVar[__mG.dialogueField]:len()<15 then
- __mG.dialogueVar[__mG.dialogueField]=__mG.dialogueVar[__mG.dialogueField]..chr
- end
- else
- if not __mG.code[__mG.coursor[2]] then __mG.code[__mG.coursor[2]]="" end
- local state={}
- state.before=__mG.createState("coursor")
- if __mG.selection[1] then
- if __mG.selection[2] then
- __mG.on.backspaceKey()
- else
- __mG.selection={}
- end
- end
- if __mG.repChr[__mG.calcLayout][chr] then
- chr=__mG.repChr[__mG.calcLayout][chr]
- end
- __mG.code[__mG.coursor[2]]=__mG.insert(__mG.code[__mG.coursor[2]],__mG.coursor[1],chr)
- __mG.coursor[1]=__mG.coursor[1]+chr:len()
- __mG.adjustScroll()
- state.after=__mG.createState("coursor")
- __mG.registerState(state)
- end
- platform.window:invalidate()
- end
- function __mG.on.clearKey()
- __mG.undo()
- end
- function __mG.on.contextMenu()
- __mG.redo()
- end
- function __mG.createState(param,sel)
- local state={}
- if param=="coursor" then
- state={__mG.coursor[2],__mG.coursor[2],{__mG.code[__mG.coursor[2]]},__mG.copy_table(__mG.coursor)}
- elseif param=="selection" then
- state={sel[1][2],sel[2][2],{},__mG.copy_table(sel[2])}
- for l=sel[1][2],sel[2][2] do
- table.insert(state[3], __mG.code[l])
- end
- end
- return state
- end
- function __mG.registerState(state)
- if __mG.stateNo>=10 then
- table.remove(__mG.state,1)
- else
- __mG.stateNo=__mG.stateNo+1
- for i=__mG.stateNo, 10 do
- __mG.state[i]=nil
- end
- end
- __mG.state[__mG.stateNo]=state
- end
- function __mG.undo()
- if __mG.stateNo>=1 then
- __mG.selection={}
- local state=__mG.state[__mG.stateNo]
- for l=state.after[1], state.after[2] do
- table.remove(__mG.code,state.after[1])
- end
- l2=1
- for l=state.before[1], state.before[2] do
- table.insert(__mG.code,l,state.before[3][l2])
- l2=l2+1
- end
- __mG.coursor=state.before[4]
- __mG.stateNo=__mG.stateNo-1
- platform.window:invalidate()
- end
- end
- function __mG.redo()
- if __mG.stateNo<10 and __mG.state[__mG.stateNo+1] then
- __mG.selection={}
- __mG.stateNo=__mG.stateNo+1
- local state=__mG.state[__mG.stateNo]
- for l=state.before[1], state.before[2] do
- table.remove(__mG.code,state.before[1])
- end
- l2=1
- for l=state.after[1], state.after[2] do
- table.insert(__mG.code,l,state.after[3][l2])
- l2=l2+1
- end
- __mG.coursor=state.after[4]
- platform.window:invalidate()
- end
- end
- function __mG.on.timer()
- timer.stop()
- __mG.on.create()
- platform.window:invalidate()
- end
- function __mG.on.resize(w,h)
- __mG.WW=w
- __mG.WH=h
- if platform.isDeviceModeRendering() then
- __mG.chrS[3]=8
- __mG.chrS[4]=15
- else
- __mG.chrS[3]=10
- __mG.chrS[4]=18
- end
- __mG.maxLines=math.floor((h-__mG.chrS[2]-30)/__mG.chrS[4])
- __mG.maxChars=math.floor((w-__mG.chrS[1]-5)/__mG.chrS[3])
- platform.window:invalidate()
- end
- -- 3.4 tablet things
- -- doesn't actually work yet, because I think we have to do things with the new 3.4's getScrollHeight....
- __mG.on.keyboardUp = function() __mG.on.resize(platform.window:width(), platform.window:height()) end
- __mG.on.keyboardDown = function() __mG.on.resize(platform.window:width(), platform.window:height()) end
- function __mG.on.paint(gc)
- local function getPosX(pos) --pixel koordinate of a character on position pos
- return __mG.chrS[1]+(pos-__mG.scroll[1])*__mG.chrS[3]
- end
- --draw Rim
- if __mG.colDsp then
- gc:setColorRGB(240,240,240)
- else
- gc:setColorRGB(220,220,220)
- end
- gc:fillRect(0,0,__mG.chrS[1],__mG.WH-20)
- --draw Line markers
- for l=0,__mG.maxLines-1 do
- local lineNo=__mG.scroll[2]+l
- local line=__mG.code[lineNo]
- local posY=__mG.chrS[2]+(l)*__mG.chrS[4]
- local newSel=__mG.validSel(__mG.selection)
- --mark active line
- if lineNo==__mG.coursor[2] then
- if __mG.colDsp then
- gc:setColorRGB(255,255,215)
- else
- gc:setColorRGB(240,240,240)
- end
- gc:fillRect(__mG.chrS[1],posY+2,__mG.WW-__mG.chrS[1],__mG.chrS[4])
- gc:setColorRGB(0,0,0)
- end
- --mark error line
- if lineNo==__mG.ERRline then
- if __mG.colDsp then
- gc:setColorRGB(230,150,150)
- else
- gc:setColorRGB(150,150,150)
- end
- gc:fillRect(0,posY+2,__mG.chrS[1],__mG.chrS[4])
- end
- if line then
- --draw line number
- if newSel and lineNo>=newSel[1][2] and lineNo<=newSel[2][2] then
- if __mG.colDsp then
- gc:setColorRGB(0,0,255)
- else
- gc:setColorRGB(255,255,255)
- end
- else
- if __mG.colDsp then
- gc:setColorRGB(128,0,0)
- else
- gc:setColorRGB(20,20,20)
- end
- end
- if lineNo>9999 then --who would write that much on a calulator?! I
- gc:setFont("serif","r",7)
- gc:drawString(tostring(lineNo),1,posY+3,"top")
- elseif lineNo>999 then
- if platform.isDeviceModeRendering() then
- gc:setFont("serif","r",9)
- gc:drawString(tostring(lineNo),1,posY+1,"top")
- else
- gc:setFont("serif","r",6)
- gc:drawString(tostring(lineNo),1,posY+3,"top")
- end
- else
- gc:setFont("serif","r",10)
- gc:drawString(tostring(lineNo),1,posY,"top")
- end
- end
- --mark selection
- if __mG.selection[1] then
- if __mG.colDsp then
- gc:setColorRGB(200,200,255)
- else
- gc:setColorRGB(200,200,200)
- end
- if newSel then
- if newSel[1][2]==newSel[2][2] and lineNo==newSel[1][2] then
- local startX=math.max(getPosX(newSel[1][1]),__mG.chrS[1])
- local endX=math.min(getPosX(newSel[2][1]),__mG.WW)
- if startX<__mG.WW and endX>__mG.chrS[1] then
- gc:fillRect(startX,posY+2,endX-startX,__mG.chrS[4])
- end
- else
- if lineNo==newSel[1][2] then
- local posX1=math.max(getPosX(newSel[1][1]),__mG.chrS[1])
- if posX1<__mG.WW then
- gc:fillRect(posX1,posY+2,__mG.WW-posX1,__mG.chrS[4])
- end
- end
- if lineNo>newSel[1][2] and lineNo<newSel[2][2] then
- gc:fillRect(__mG.chrS[1],posY+2,__mG.WW-__mG.chrS[1],__mG.chrS[4])
- end
- if lineNo==newSel[2][2] then
- local posX2=math.min(getPosX(newSel[2][1]),__mG.WW)
- if posX2>__mG.chrS[1] then
- gc:fillRect(__mG.chrS[1],posY+2,posX2-__mG.chrS[1],__mG.chrS[4])
- end
- end
- end
- end
- end
- --draw line
- if line and line~="" then
- gc:setFont(__mG.font,"r",10)
- local lineRGB={}
- local comment=false
- if __mG.markSyntax then
- --compute syntax marking
- local function markSyntax()
- local line=__mG.code[lineNo].." "
- local isString=false
- local word=""
- for c=1, line:len() do
- local chr = line:usub(c,c)
- local no=string.byte(chr)
- if not no then no=0 end
- if comment then
- lineRGB[c]=__mG.wordRGB["--"]
- elseif isString then
- lineRGB[c]=__mG.wordRGB['"']
- if chr==isString then
- isString=false
- elseif isString=="[[" and chr=="]" and line:sub(c-1,c-1)=="]" then
- isString=false
- end
- else
- if not((no>=65 and no<=90) or (no>=97 and no<=122) or no==95) then --other character than letter or _
- if __mG.wordRGB[word] then
- for lc=c-word:len(), c-1 do
- lineRGB[lc]=__mG.wordRGB[word]
- end
- end
- word=""
- if c>__mG.scroll[1]+__mG.maxChars then
- return
- end
- elseif string.byte(chr)>=33 then
- word=word..chr
- end
- if chr=='"' or chr=="'" then
- isString=chr
- lineRGB[c]=__mG.wordRGB['"']
- elseif chr=="-" then
- if line:sub(c+1,c+1)=="-" then
- comment=c
- lineRGB[c]=__mG.wordRGB["--"]
- end
- elseif chr=="[" then
- if line:sub(c+1,c+1)=="[" then
- isString="[["
- lineRGB[c]=__mG.wordRGB['"']
- end
- end
- end
- end
- end
- markSyntax()
- end
- --draw characters
- for c=0, __mG.maxChars-1 do --for all visible characters
- i=__mG.scroll[1]+c
- if i<=line:len() then
- char=line:usub(i,i)
- if not char then print("FAIL!") end
- local no=string.byte(char)
- if not no then
- no=0
- end
- local posX=__mG.chrS[1]+c*__mG.chrS[3]
- gc:setColorRGB(0,0,0)
- gc:setFont(__mG.font,"r",10)
- if __mG.markSyntax then
- if lineRGB[i] then
- gc:setColorRGB(unpack(lineRGB[i]))
- end
- if comment then
- if i>=comment then
- gc:setFont(__mG.font,"i",10)
- end
- end
- end
- if not __mG.chrOffset[char] then
- __mG.chrOffset[char]=5-gc:getStringWidth(char)/2
- end
- if no>=33 then
- gc:drawString(char,posX+__mG.chrOffset[char],posY,"top")
- end
- end
- end --for c=0, 35 do
- end --if not(line=="" or line==nil) then
- end --for l=0,11 do
- --draw cursor
- if __mG.selection[1] then
- gc:setColorRGB(0,0,255)
- else
- gc:setColorRGB(0,0,0)
- end
- local posX=getPosX(__mG.coursor[1]) local posY=__mG.chrS[2]+(__mG.coursor[2]-__mG.scroll[2])*__mG.chrS[4]+2
- gc:drawLine(posX,posY,posX,posY+__mG.chrS[4]-1)
- --draw error "console"
- gc:setColorRGB(0,0,0)
- gc:drawLine(0,__mG.WH-20,__mG.WW,__mG.WH-20)
- if __mG.ERR then
- if __mG.colDsp then
- gc:setColorRGB(100,0,50)
- else
- gc:setColorRGB(20,20,20)
- end
- gc:setFont("serif","r",7)
- gc:drawString(__mG.ERRline..": "..__mG.ERR,5,__mG.WH-15,"top")
- end
- --draw scroll bar
- gc:setColorRGB(130,130,130)
- local posY1=math.floor((__mG.scroll[2]-1)/#__mG.code*(__mG.WH-20))
- local posY2=math.min(math.floor(((__mG.scroll[2]+(__mG.maxLines-1))/#__mG.code)*(__mG.WH-20)),(__mG.WH-20))
- local height=posY2-posY1
- gc:fillRect(__mG.WW-3,posY1,3,height)
- __mG.moveOK=true
- if __mG.dialogue=="inputName" or __mG.dialogue=="gotoLine" then
- gc:setColorRGB(0,0,0)
- gc:drawRect(30,70,258,72)
- gc:setColorRGB(200,200,200)
- gc:fillRect(31,71,257,71)
- gc:setColorRGB(230,230,230)
- gc:fillRect(40,100,238,20)
- gc:setFont("sansserif","b",12)
- gc:setColorRGB(20,20,20)
- if __mG.dialogue=="inputName" then
- gc:drawString("Save as...",40,75,"top")
- gc:setFont("sansserif","r",10)
- gc:drawString("Press enter to save (esc to cancel)",41,140,"bottom")
- elseif __mG.dialogue=="gotoLine" then
- gc:drawString("Go to line...",40,75,"top")
- gc:setFont("sansserif","r",10)
- gc:drawString("Press enter to go (esc to cancel)",41,140,"bottom")
- end
- gc:drawString(__mG.dialogueVar[1],45,100,"top")
- elseif __mG.dialogue=="importFromLibrary" then
- gc:setColorRGB(0,0,0)
- gc:drawRect(30,50,258,112)
- gc:setColorRGB(200,200,200)
- gc:fillRect(31,51,257,111)
- gc:setColorRGB(230,230,230)
- gc:fillRect(40,80,238,20)
- gc:fillRect(40,120,238,20)
- gc:setColorRGB(20,20,20)
- gc:setPen("medium")
- gc:drawRect(40,80+(__mG.dialogueField-1)*40,238,20)
- gc:setPen("thin")
- gc:setFont("sansserif","b",12)
- gc:drawString("Import from file...",40,55,"top")
- gc:setFont("sansserif","b",10)
- gc:drawString("Variable name...",40,100,"top")
- gc:setFont("sansserif","r",10)
- gc:drawString("Press enter to save (esc to cancel)",41,160,"bottom")
- gc:drawString(__mG.dialogueVar[1],45,80,"top")
- gc:drawString(__mG.dialogueVar[2],45,120,"top")
- end
- if __mG.message.show then
- gc:setColorRGB(0,0,0)
- gc:drawRect(24,24,318-49,212-49)
- gc:setColorRGB(255,255,200)
- gc:fillRect(25,25,318-50,212-50)
- gc:setColorRGB(0,0,0)
- gc:drawLine(25,60,318-25,60)
- gc:setFont("sansserif","b",11)
- gc:drawString(__mG.message.text[1],40,32,"top")
- gc:setFont("sansserif","r",10)
- for l=0,6 do
- if not __mG.message.text[l+2] then __mG.message.text[l+2]="" end
- gc:drawString(__mG.message.text[l+2], 33, 63+l*17, "top")
- end
- end
- end
- function __mG.reloadSEHandlers()
- timer.stop()
- __mG.createMenu()
- cursor.set("text")
- toolpalette.enableCut(true) toolpalette.enableCopy(true) toolpalette.enablePaste(true)
- -- toolpalette bug workaround
- platform.window:setFocus(false)
- platform.window:setFocus(true) on={}
- on=__mG.copy_table(__mG.on)
- platform.window:invalidate()
- timer.start(0.1) --after a crash in the on.paint funcion it won't update directly
- end
- __mG.reloadSEHandlers()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement