From f72baa6fb3f929fa01508b7ae167ebad817079f6 Mon Sep 17 00:00:00 2001 From: Samkist Date: Wed, 18 May 2022 19:58:49 -0400 Subject: [PATCH] reformatted code, removed minified file --- basalt.lua | 1 - source/basalt.lua | 2421 ++++++++++++++++++++++++--------------------- 2 files changed, 1306 insertions(+), 1116 deletions(-) delete mode 100644 basalt.lua diff --git a/basalt.lua b/basalt.lua deleted file mode 100644 index aa21070..0000000 --- a/basalt.lua +++ /dev/null @@ -1 +0,0 @@ -local a={basaltBG=colors.lightGray,basaltFG=colors.black,FrameBG=colors.gray,FrameFG=colors.black,ButtonBG=colors.gray,ButtonFG=colors.black,CheckboxBG=colors.gray,CheckboxFG=colors.black,InputBG=colors.gray,InputFG=colors.black,textfieldBG=colors.gray,textfieldFG=colors.black,listBG=colors.gray,listFG=colors.black,dropdownBG=colors.gray,dropdownFG=colors.black,radioBG=colors.gray,radioFG=colors.black,selectionBG=colors.black,selectionFG=colors.lightGray}local b={debugger=true,version=1}local c;local d={}local e={}local f=term.current()local g=string.sub;local function h(i,j,k)local i=string.sub(i,1,j)local l=j-string.len(i)if k=="right"then i=string.rep(" ",l)..i elseif k=="center"then i=string.rep(" ",math.floor(l/2))..i..string.rep(" ",math.floor(l/2))i=i..(string.len(i)=1 and M<=n then if L+i:len()>0 and L<=j then local N=v[M]local O;local P=L+#i-1;if L<1 then local Q=1-L+1;local R=j-L+1;i=g(i,Q,R)elseif P>j then local R=j-L+1;i=g(i,1,R)end;if L>1 then local R=L-1;O=g(N,1,R)..i else O=i end;if P=1 and M<=n then if L+T:len()>0 and L<=j then local N=w[M]local O;local P=L+#T-1;if L<1 then T=g(T,1-L+1,j-L+1)elseif P>j then T=g(T,1,j-L+1)end;if L>1 then O=g(N,1,L-1)..T else O=T end;if P=1 and M<=n then if L+T:len()>0 and L<=j then local N=x[M]local O;local P=L+#T-1;if L<1 then local Q=1-L+1;local R=j-L+1;T=g(T,Q,R)elseif P>j then local R=j-L+1;T=g(T,1,R)end;if L>1 then local R=L-1;O=g(N,1,R)..T else O=T end;if PL and aM<=M and aM+self.h>M and ar then if self.parent~=nil then self.parent:setFocusedObject(self)end;at:sendEvent(a5,self,a5,aK,L,M)return true end;return false end,keyHandler=function(self,a5,aN)if self:isFocused()then at:sendEvent(a5,self,a5,aN)return true end;return false end,backgroundKeyHandler=function(self,a5,aN)at:sendEvent("background_"..a5,self,a5,aN)end,valueChangedHandler=function(self)at:sendEvent("value_changed",self)end,eventHandler=function(self,a5,aO,aP,aQ,aR)at:sendEvent("custom_event_handler",self,a5,aO,aP,aQ,aR)end,getFocusHandler=function(self)at:sendEvent("get_focus",self)end,loseFocusHandler=function(self)at:sendEvent("lose_focus",self)end}au.__index=au;return au end;local function aS(ak)local aT=aj(ak)local al="Button"aT:setValue("Button")aT:setZIndex(5)aT.w=8;aT.bgcolor=a.ButtonBG;aT.fgcolor=a.ButtonFG;local aU="center"local aV="center"local au={getType=function(self)return al end,setHorizontalAlign=function(self,aW)aU=aW end,setVerticalAlign=function(self,aW)aV=aW end,setText=function(self,i)aT:setValue(i)return self end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()local aZ=m(self.h,aV)self.parent:drawBackgroundBox(aX,aY,self.w,self.h,self.bgcolor)self.parent:drawForegroundBox(aX,aY,self.w,self.h,self.fgcolor)self.parent:drawTextBox(aX,aY,self.w,self.h," ")for l=1,self.h do if l==aZ then self.parent:setText(aX,aY+l-1,h(self:getValue(),self.w,aU))end end end end end}return setmetatable(au,aT)end;local function a_(ak)local aT=aj(ak)local al="Program"aT:setZIndex(5)local au;local function b0(L,M,j,n)local b1,b2=1,1;local b3,b4=colors.black,colors.white;local b5=false;local b6=false;local v={}local w={}local x={}local b7={}local B;local C={}for r=0,15 do local b8=2^r;b7[b8]={f.getPaletteColour(b8)}end;local function D()B=(" "):rep(j)for l=0,15 do local E=2^l;local F=s[E]C[E]=F:rep(j)end end;local function G()D()local H=B;local I=C[colors.white]local J=C[colors.black]for l=1,n do v[l]=g(v[l]==nil and H or v[l]..H:sub(1,j-v[l]:len()),1,j)x[l]=g(x[l]==nil and I or x[l]..I:sub(1,j-x[l]:len()),1,j)w[l]=g(w[l]==nil and J or w[l]..J:sub(1,j-w[l]:len()),1,j)end end;G()local function b9()if b1>=1 and b2>=1 and b1<=j and b2<=n then else end end;local function ba(bb,bc,bd)local be=b1;local P=be+#bb-1;if b2>=1 and b2<=n then if be<=j and P>=1 then if be==1 and P==j then v[b2]=bb;x[b2]=bc;w[b2]=bd else local bf,bg,bh;if be<1 then local bi=1-be+1;local bj=j-be+1;bf=g(bb,bi,bj)bg=g(bc,bi,bj)bh=g(bd,bi,bj)elseif P>j then local bj=j-be+1;bf=g(bb,1,bj)bg=g(bc,1,bj)bh=g(bd,1,bj)else bf=bb;bg=bc;bh=bd end;local bk=v[b2]local bl=x[b2]local bm=w[b2]local bn,bo,bp;if be>1 then local bq=be-1;bn=g(bk,1,bq)..bf;bo=g(bl,1,bq)..bg;bp=g(bm,1,bq)..bh else bn=bf;bo=bg;bp=bh end;if P=1 and M<=n then v[bO]=v[M]w[bO]=w[M]x[bO]=x[M]else v[bO]=bL;x[bO]=bM;w[bO]=bN end end end;if b6 then b9()end end,isColor=function()return f.isColor()end,isColour=function()return f.isColor()end,write=function(i)i=tostring(i)if b6 then ba(i,s[b4]:rep(i:len()),s[b3]:rep(i:len()))end end,clearLine=function()if b6 then K(1,b2,(" "):rep(j))S(1,b2,s[b3]:rep(j))U(1,b2,s[b4]:rep(j))end;if b6 then b9()end end,clear=function()for l=1,n do K(1,l,(" "):rep(j))S(1,l,s[b3]:rep(j))U(1,l,s[b4]:rep(j))end;if b6 then b9()end end,blit=function(i,bP,bQ)if type(i)~="string"then error("bad argument #1 (expected string, got "..type(i)..")",2)end;if type(bP)~="string"then error("bad argument #2 (expected string, got "..type(bP)..")",2)end;if type(bQ)~="string"then error("bad argument #3 (expected string, got "..type(bQ)..")",2)end;if#bP~=#i or#bQ~=#i then error("Arguments must be the same length",2)end;if b6 then ba(i,bP,bQ)end end}return bG end;aT.w=30;aT.h=12;local bR=b0(1,1,aT.w,aT.h)local bS;local bT=false;local bU={}au={getType=function(self)return al end,show=function(self)aT.show(self)bR.setBackgroundColor(self.bgcolor)bR.setTextColor(self.fgcolor)bR.basalt_setVisible(true)return self end,hide=function(self)aT.hide(self)bR.basalt_setVisible(false)return self end,setPosition=function(self,L,M,aA)aT.setPosition(self,L,M,aA)bR.basalt_reposition(self:getAnchorPosition())return self end,getBasaltWindow=function()return bR end,getBasaltProcess=function()return bS end,setSize=function(self,j,n)aT.setSize(self,j,n)bR.basalt_resize(self.w,self.h)return self end,getStatus=function(self)if bS~=nil then return bS:getStatus()end;return"inactive"end,execute=function(self,ad,...)bS=ab:new(ad,bR,...)bR.setBackgroundColor(colors.black)bR.setTextColor(colors.white)bR.clear()bR.setCursorPos(1,1)bS:resume()bT=false;return self end,stop=function(self)if bS~=nil then if not bS:isDead()then bS:resume("terminate")if bS:isDead()then if self.parent~=nil then self.parent:setCursor(false)end end end end;return self end,pause=function(self,bV)bT=bV or not bT;if bS~=nil then if not bS:isDead()then if not bT then self:injectEvents(bU)bU={}end end end;return self end,isPaused=function(self)return bT end,injectEvent=function(self,a5,aO,aP,aQ,aR,bW)if bS~=nil then if not bS:isDead()then if bT==false or bW then bS:resume(a5,aO,aP,aQ,aR)else table.insert(bU,{event=a5,args={aO,aP,aQ,aR}})end end end;return self end,getQueuedEvents=function(self)return bU end,updateQueuedEvents=function(self,a3)bU=a3 or bU;return self end,injectEvents=function(self,a3)if bS~=nil then if not bS:isDead()then for aJ,a9 in pairs(a3)do bS:resume(a9.event,table.unpack(a9.args))end end end;return self end,mouseClickHandler=function(self,a5,aK,L,M)if aT.mouseClickHandler(self,a5,aK,L,M)then if bS==nil then return false end;if not bS:isDead()then if not bT then local bX,bY=self:getAbsolutePosition(self:getAnchorPosition(nil,nil,true))bS:resume(a5,aK,L-bX+1,M-bY+1)end end;return true end end,keyHandler=function(self,a5,aN)aT.keyHandler(self,a5,aN)if self:isFocused()then if bS==nil then return false end;if not bS:isDead()then if not bT then if self.draw then bS:resume(a5,aN)end end end end end,getFocusHandler=function(self)aT.getFocusHandler(self)if bS~=nil then if not bS:isDead()then if not bT then if self.parent~=nil then local bZ,b_=bR.getCursorPos()local aX,aY=self:getAnchorPosition()if self.parent~=nil then if aX+bZ-1>=1 and aX+bZ-1<=aX+self.w-1 and b_+aY-1>=1 and b_+aY-1<=aY+self.h-1 then self.parent:setCursor(bR.getCursorBlink(),aX+bZ-1,b_+aY-1,bR.getTextColor())end end end end end end end,loseFocusHandler=function(self)aT.loseFocusHandler(self)if bS~=nil then if not bS:isDead()then if self.parent~=nil then self.parent:setCursor(false)end end end end,eventHandler=function(self,a5,aO,aP,aQ,aR)if bS==nil then return end;if not bS:isDead()then if not bT then if a5~="mouse_click"and a5~="mouse_up"and a5~="mouse_scroll"and a5~="mouse_drag"and a5~="key_up"and a5~="key"and a5~="char"and a5~="terminate"then bS:resume(a5,aO,aP,aQ,aR)end;if self:isFocused()then local aX,aY=self:getAnchorPosition()local bZ,b_=bR.getCursorPos()if self.parent~=nil then if aX+bZ-1>=1 and aX+bZ-1<=aX+self.w-1 and b_+aY-1>=1 and b_+aY-1<=aY+self.h-1 then self.parent:setCursor(bR.getCursorBlink(),aX+bZ-1,b_+aY-1,bR.getTextColor())end end;if a5=="terminate"and self:isFocused()then self:stop()end end else if a5~="mouse_click"and a5~="mouse_up"and a5~="mouse_scroll"and a5~="mouse_drag"and a5~="key_up"and a5~="key"and a5~="char"and a5~="terminate"then table.insert(bU,{event=a5,args={aO,aP,aQ,aR}})end end end end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()bR.basalt_reposition(aX,aY)self.parent:drawBackgroundBox(aX,aY,self.w,self.h,self.bgcolor)bR.basalt_update()end end end}return setmetatable(au,aT)end;local function c0(ak)local aT=aj(ak)local al="Label"aT:setZIndex(3)local c1=true;aT:setValue("")local au={getType=function(self)return al end,setText=function(self,i)i=tostring(i)aT:setValue(i)if c1 then self.w=i:len()end;return self end,setSize=function(self,j,n)self.w,self.h=j,n;c1=false;return self end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()self.parent:writeText(aX,aY,self:getValue(),self.bgcolor,self.fgcolor)end end end}return setmetatable(au,aT)end;local function c2(ak)local aT=aj(ak)local al="Pane"local au={getType=function(self)return al end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()self.parent:drawBackgroundBox(aX,aY,self.w,self.h,self.bgcolor)self.parent:drawForegroundBox(aX,aY,self.w,self.h,self.bgcolor)end end end}return setmetatable(au,aT)end;local function c3(ak)local aT=aj(ak)local al="Image"aT:setZIndex(2)local c4;local c5;local c6=false;local function c7()local c8={[0]={8,4,3,6,5},{4,14,8,7},{6,10,8,7},{9,11,8,0},{1,14,8,0},{13,12,8,0},{2,10,8,0},{15,8,10,11,12,14},{0,7,1,9,2,13},{3,11,8,7},{2,6,7,15},{9,3,7,15},{13,5,7,15},{5,12,8,7},{1,4,7,15},{7,10,11,12,14}}local c9,ca,cb={},{},{}for r=0,15 do ca[2^r]=r end;do local cc="0123456789abcdef"for r=1,16 do c9[cc:sub(r,r)]=r-1;c9[r-1]=cc:sub(r,r)cb[cc:sub(r,r)]=2^(r-1)cb[2^(r-1)]=cc:sub(r,r)local cd=c8[r-1]for r=1,#cd do cd[r]=2^cd[r]end end end;local function ce(cf)local cg=c8[ca[cf[#cf][1]]]for ch=1,#cg do local ci=cg[ch]for r=1,#cf-1 do if cf[r][1]==ci then return r end end end;return 1 end;local function cj(ck,cl)if not cl then local cm={}cl={}for r=1,6 do local cn=ck[r]local co=cl[cn]cl[cn],cm[r]=co and co+1 or 1,cn end;ck=cm end;local cf={}for aN,am in pairs(cl)do cf[#cf+1]={aN,am}end;if#cf>1 then while#cf>2 do table.sort(cf,function(cp,bD)return cp[2]>bD[2]end)local cq,cr=ce(cf),#cf;local cs,ct=cf[cr][1],cf[cq][1]for r=1,6 do if ck[r]==cs then ck[r]=ct;cf[cq][2]=cf[cq][2]+1 end end;cf[cr]=nil end;local cu=128;for r=1,#ck-1 do if ck[r]~=ck[6]then cu=cu+2^(r-1)end end;return string.char(cu),cb[cf[1][1]==ck[6]and cf[2][1]or cf[1][1]],cb[ck[6]]else return"\128",cb[ck[1]],cb[ck[1]]end end;local cv,cw,cx,W={{},{},{}},0,#c4+#c4%3,aT.bgcolor or colors.black;for r=1,#c4 do if#c4[r]>cw then cw=#c4[r]end end;for M=0,cx-1,3 do local cy,cz,cA,cB={},{},{},1;for L=0,cw-1,2 do local ck,cl={},{}for cC=1,3 do for cD=1,2 do ck[#ck+1]=c4[M+cC]and c4[M+cC][L+cD]and(c4[M+cC][L+cD]==0 and W or c4[M+cC][L+cD])or W;cl[ck[#ck]]=cl[ck[#ck]]and cl[ck[#ck]]+1 or 1 end end;cy[cB],cz[cB],cA[cB]=cj(ck,cl)cB=cB+1 end;cv[1][#cv[1]+1],cv[2][#cv[2]+1],cv[3][#cv[3]+1]=table.concat(cy),table.concat(cz),table.concat(cA)end;cv.width,cv.height=#cv[1][1],#cv[1]c5=cv end;local au={getType=function(self)return al end,loadImage=function(self,ad)c4=paintutils.loadImage(ad)c6=false;return self end,loadBlittleImage=function(self,ad)c6=true;return self end,shrinkImage=function(self)c7()c6=true;return self end,draw=function(self)if aT.draw(self)then if self.parent~=nil then if c4~=nil then local aX,aY=self:getAnchorPosition()if c6 then local q,cE,cF=c5[1],c5[2],c5[3]for r=1,c5.height do local cG=q[r]if type(cG)=="string"then self.parent:setText(aX,aY+r-1,cG)self.parent:setFG(aX,aY+r-1,cE[r])self.parent:setBG(aX,aY+r-1,cF[r])elseif type(cG)=="table"then self.parent:setText(aX,aY+r-1,cG[2])self.parent:setFG(aX,aY+r-1,cE[r])self.parent:setBG(aX,aY+r-1,cF[r])end end else for az=1,math.min(#c4,self.h)do local cH=c4[az]for ay=1,math.min(#cH,self.w)do if cH[ay]>0 then self.parent:drawBackgroundBox(aX+ay-1,aY+az-1,1,1,cH[ay])end end end end end end end end}return setmetatable(au,aT)end;local function cI(ak)local aT=aj(ak)local al="Checkbox"aT:setZIndex(5)aT:setValue(false)aT.w=1;aT.h=1;aT.bgcolor=a.CheckboxBG;aT.fgcolor=a.CheckboxFG;local au={symbol="\42",getType=function(self)return al end,mouseClickHandler=function(self,a5,aK,L,M)if aT.mouseClickHandler(self,a5,aK,L,M)then if a5=="mouse_click"and aK==1 then if self:getValue()~=true and self:getValue()~=false then self:setValue(false)else self:setValue(not self:getValue())end end;return true end;return false end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()local aZ=m(self.h,"center")self.parent:drawBackgroundBox(aX,aY,self.w,self.h,self.bgcolor)for l=1,self.h do if l==aZ then if self:getValue()==true then self.parent:writeText(aX,aY+l-1,h(self.symbol,self.w,"center"),self.bgcolor,self.fgcolor)else self.parent:writeText(aX,aY+l-1,h(" ",self.w,"center"),self.bgcolor,self.fgcolor)end end end end end end}return setmetatable(au,aT)end;local function cJ(ak)local aT=aj(ak)local al="Progressbar"local cK=0;aT:setZIndex(5)aT:setValue(false)aT.w=25;aT.h=1;aT.bgcolor=a.CheckboxBG;aT.fgcolor=a.CheckboxFG;local cL=colors.black;local cM=""local cN=colors.white;local cO=""local cP=0;local au={getType=function(self)return al end,setDirection=function(self,cQ)cP=cQ;return self end,setProgressBar=function(self,aC,Y,cR)cL=aC or cL;cM=Y or cM;cN=cR or cN;return self end,setBackgroundSymbol=function(self,Y)cO=Y:sub(1,1)return self end,setProgress=function(self,am)if am>=0 and am<=100 and cK~=am then cK=am;self:setValue(cK)if cK==100 then self:progressDoneHandler()end end;return self end,getProgress=function(self)return cK end,onProgressDone=function(self,cS)self:registerEvent("progress_done",cS)return self end,progressDoneHandler=function(self)self:sendEvent("progress_done")end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()self.parent:drawBackgroundBox(aX,aY,self.w,self.h,self.bgcolor)self.parent:drawForegroundBox(aX,aY,self.w,self.h,self.fgcolor)self.parent:drawTextBox(aX,aY,self.w,self.h,cO)if cP==1 then self.parent:drawBackgroundBox(aX,aY,self.w,self.h/100*cK,cL)self.parent:drawForegroundBox(aX,aY,self.w,self.h/100*cK,cN)self.parent:drawTextBox(aX,aY,self.w,self.h/100*cK,cM)elseif cP==2 then self.parent:drawBackgroundBox(aX,aY+math.ceil(self.h-self.h/100*cK),self.w,self.h/100*cK,cL)self.parent:drawForegroundBox(aX,aY+math.ceil(self.h-self.h/100*cK),self.w,self.h/100*cK,cN)self.parent:drawTextBox(aX,aY+math.ceil(self.h-self.h/100*cK),self.w,self.h/100*cK,cM)elseif cP==3 then self.parent:drawBackgroundBox(aX+math.ceil(self.w-self.w/100*cK),aY,self.w/100*cK,self.h,cL)self.parent:drawForegroundBox(aX+math.ceil(self.w-self.w/100*cK),aY,self.w/100*cK,self.h,cN)self.parent:drawTextBox(aX+math.ceil(self.w-self.w/100*cK),aY,self.w/100*cK,self.h,cM)else self.parent:drawBackgroundBox(aX,aY,self.w/100*cK,self.h,cL)self.parent:drawForegroundBox(aX,aY,self.w/100*cK,self.h,cN)self.parent:drawTextBox(aX,aY,self.w/100*cK,self.h,cM)end end end end}return setmetatable(au,aT)end;local function cT(ak)local aT=aj(ak)local al="Input"local cU="text"local cV=0;aT:setZIndex(5)aT:setValue("")aT.w=10;aT.h=1;aT.bgcolor=a.InputBG;aT.fgcolor=a.InputFG;local cW=1;local cX=1;local cY=""local cZ;local c_;local d0=cY;local d1=false;local au={getType=function(self)return al end,setInputType=function(self,d2)if d2=="password"or d2=="number"or d2=="text"then cU=d2 end;return self end,setDefaultText=function(self,i,d3,d4)cY=i;cZ=d4 or cZ;c_=d3 or c_;if self:isFocused()then d0=""else d0=cY end;return self end,getInputType=function(self)return cU end,setValue=function(self,d5)aT.setValue(self,tostring(d5))if not d1 then cW=tostring(d5):len()+1 end;return self end,getValue=function(self)local d5=aT.getValue(self)return cU=="number"and tonumber(d5)or d5 end,setInputLimit=function(self,d6)cV=tonumber(d6)or cV;return self end,getInputLimit=function(self)return cV end,getFocusHandler=function(self)aT.getFocusHandler(self)if self.parent~=nil then local aX,aY=self:getAnchorPosition()d0=""if self.parent~=nil then self.parent:setCursor(true,aX+cW-cX,aY,self.fgcolor)end end end,loseFocusHandler=function(self)aT.loseFocusHandler(self)if self.parent~=nil then self.parent:setCursor(false)d0=cY end end,keyHandler=function(self,a5,aN)if aT.keyHandler(self,a5,aN)then d1=true;if a5=="key"then if aN==keys.backspace then local i=tostring(aT.getValue())if cW>1 then self:setValue(i:sub(1,cW-2)..i:sub(cW,i:len()))if cW>1 then cW=cW-1 end;if cX>1 then if cWd7 then cW=d7+1 end;if cW<1 then cW=1 end;if cW=self.w+cX then cX=cW-self.w+1 end;if cX<1 then cX=1 end end;if aN==keys.left then cW=cW-1;if cW>=1 then if cW=self.w+cX then cX=cW end end;if cW<1 then cW=1 end;if cX<1 then cX=1 end end end;if a5=="char"then local i=aT.getValue()if i:len()=self.w+cX then cX=cX+1 end end end;local aX,aY=self:getAnchorPosition()local d5=tostring(aT.getValue())local d9=(cW<=d5:len()and cW-1 or d5:len())-(cX-1)if d9>self.x+self.w-1 then d9=self.x+self.w-1 end;if self.parent~=nil then self.parent:setCursor(true,aX+d9,aY,self.fgcolor)end;d1=false end end,mouseClickHandler=function(self,a5,aK,L,M)if aT.mouseClickHandler(self,a5,aK,L,M)then if a5=="mouse_click"and aK==1 then end;return true end;return false end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()local aZ=m(self.h,"center")self.parent:drawBackgroundBox(aX,aY,self.w,self.h,self.bgcolor)for l=1,self.h do if l==aZ then local d5=tostring(aT.getValue())local d4=self.bgcolor;local d3=self.fgcolor;local i;if d5:len()<=0 then i=d0;d4=cZ or d4;d3=c_ or d3 end;i=d0;if d5~=""then i=d5 end;i=i:sub(cX,self.w+cX-1)local da=self.w-i:len()if da<0 then da=0 end;if cU=="password"and d5~=""then i=string.rep("*",i:len())end;i=i..string.rep(" ",da)self.parent:writeText(aX,aY+l-1,i,d4,d3)end end end end end}return setmetatable(au,aT)end;local function db(ak)local aT=aj(ak)local al="Textfield"local dc,cX,cW,dd=1,1,1,1;local de={""}local df={[colors.purple]={"break"}}aT.w=20;aT.h=8;aT.bgcolor=a.textfieldBG;aT.fgcolor=a.textfieldFG;aT:setZIndex(5)local au={getType=function(self)return al end,getLines=function(self)return de end,getLine=function(self,a4)return de[a4]or""end,editLine=function(self,a4,i)de[a4]=i or de[a4]return self end,addLine=function(self,i,a4)if a4~=nil then table.insert(de,a4,i)else table.insert(de,i)end;return self end,addKeyword=function(self,dg,aC)end,removeLine=function(self,a4)table.remove(de,a4 or#de)if#de<=0 then table.insert(de,"")end;return self end,getTextCursor=function(self)return cW,dd end,getFocusHandler=function(self)aT.getFocusHandler(self)if self.parent~=nil then local aX,aY=self:getAnchorPosition()if self.parent~=nil then self.parent:setCursor(true,aX+cW-cX,aY+dd-dc,self.fgcolor)end end end,loseFocusHandler=function(self)aT.loseFocusHandler(self)if self.parent~=nil then self.parent:setCursor(false)end end,keyHandler=function(self,a5,aN)if aT.keyHandler(self,a5,aN)then local aX,aY=self:getAnchorPosition()if a5=="key"then if aN==keys.backspace then if de[dd]==""then if dd>1 then table.remove(de,dd)cW=de[dd-1]:len()+1;cX=cW-self.w+1;if cX<1 then cX=1 end;dd=dd-1 end elseif cW<=1 then if dd>1 then cW=de[dd-1]:len()+1;cX=cW-self.w+1;if cX<1 then cX=1 end;de[dd-1]=de[dd-1]..de[dd]table.remove(de,dd)dd=dd-1 end else de[dd]=de[dd]:sub(1,cW-2)..de[dd]:sub(cW,de[dd]:len())if cW>1 then cW=cW-1 end;if cX>1 then if cWde[dd]:len()then if de[dd+1]~=nil then de[dd]=de[dd]..de[dd+1]table.remove(de,dd+1)end else de[dd]=de[dd]:sub(1,cW-1)..de[dd]:sub(cW+1,de[dd]:len())end end;if aN==keys.enter then table.insert(de,dd+1,de[dd]:sub(cW,de[dd]:len()))de[dd]=de[dd]:sub(1,cW-1)dd=dd+1;cW=1;cX=1;if dd-dc>=self.h then dc=dc+1 end;self:setValue("")end;if aN==keys.up then if dd>1 then dd=dd-1;if cW>de[dd]:len()+1 then cW=de[dd]:len()+1 end;if cX>1 then if cW1 then if ddde[dd]:len()+1 then cW=de[dd]:len()+1 end;if dd>=dc+self.h then dc=dc+1 end end end;if aN==keys.right then cW=cW+1;if dd<#de then if cW>de[dd]:len()+1 then cW=1;dd=dd+1 end elseif cW>de[dd]:len()then cW=de[dd]:len()+1 end;if cW<1 then cW=1 end;if cW=self.w+cX then cX=cW-self.w+1 end;if cX<1 then cX=1 end end;if aN==keys.left then cW=cW-1;if cW>=1 then if cW=self.w+cX then cX=cW end end;if dd>1 then if cW<1 then dd=dd-1;cW=de[dd]:len()+1;cX=cW-self.w+1 end end;if cW<1 then cW=1 end;if cX<1 then cX=1 end end end;if a5=="char"then de[dd]=de[dd]:sub(1,cW-1)..aN..de[dd]:sub(cW,de[dd]:len())cW=cW+1;if cW>=self.w+cX then cX=cX+1 end;self:setValue("")end;local d9=(cW<=de[dd]:len()and cW-1 or de[dd]:len())-(cX-1)if d9>self.x+self.w-1 then d9=self.x+self.w-1 end;local dh=dd-dcde[dd]:len()then cW=de[dd]:len()+1 end;if cWde[dd]:len()then cW=de[dd]:len()+1 end;if cW#de-(self.h-1)then dc=#de-(self.h-1)end;if dc<1 then dc=1 end;if self.parent~=nil then if aX+cW-cX>=aX and aX+cW-cX<=aX+self.w and(aY+dd-dc>=aY and aY+dd-dc<=aY+self.h)then self.parent:setCursor(true,di+cW-cX,dj+dd-dc)else self.parent:setCursor(false)end end end;self:setVisualChanged()return true end end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()self.parent:drawBackgroundBox(aX,aY,self.w,self.h,self.bgcolor)self.parent:drawForegroundBox(aX,aY,self.w,self.h,self.fgcolor)for l=1,self.h do local i=""if de[l+dc-1]~=nil then i=de[l+dc-1]end;i=i:sub(cX,self.w+cX-1)local da=self.w-i:len()if da<0 then da=0 end;i=i..string.rep(" ",da)self.parent:setText(aX,aY+l-1,i)end end end end}return setmetatable(au,aT)end;local function dk(ak)local aT=aj(ak)local al="List"aT.w=16;aT.h=6;aT.bgcolor=a.listBG;aT.fgcolor=a.listFG;aT:setZIndex(5)local dl={}local dm=a.selectionBG;local dn=a.selectionFG;local dp=true;local dq="left"local dr=0;local ds=true;local au={getType=function(self)return al end,addItem=function(self,i,W,X,...)table.insert(dl,{text=i,bgCol=W or self.bgcolor,fgCol=X or self.fgcolor,args={...}})if#dl==1 then self:setValue(dl[1])end;return self end,setIndexOffset=function(self,dt)dr=dt;return self end,getIndexOffset=function(self)return dr end,removeItem=function(self,a4)table.remove(dl,a4)return self end,getItem=function(self,a4)return dl[a4]end,getItemIndex=function(self)local du=self:getValue()for a8,a9 in pairs(dl)do if a9==du then return a8 end end end,clear=function(self)dl={}self:setValue({})return self end,getItemCount=function(self)return#dl end,editItem=function(self,a4,i,W,X,...)table.remove(dl,a4)table.insert(dl,a4,{text=i,bgCol=W or self.bgcolor,fgCol=X or self.fgcolor,args={...}})return self end,selectItem=function(self,a4)self:setValue(dl[a4]or{})return self end,setSelectedItem=function(self,W,X,dv)dm=W or self.bgcolor;dn=X or self.fgcolor;dp=dv;return self end,setScrollable=function(self,dw)ds=dw;return self end,mouseClickHandler=function(self,a5,aK,L,M)local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())if aX<=L and aX+self.w>L and aY<=M and aY+self.h>M and self:isVisible()then if a5=="mouse_click"or a5=="mouse_drag"then if aK==1 then if#dl>0 then for l=1,self.h do if dl[l+dr]~=nil then if aX<=L and aX+self.w>L and aY+l-1==M then self:setValue(dl[l+dr])self:getEventSystem():sendEvent("mouse_click",self,"mouse_click",0,L,M,dl[l+dr])end end end end end end;if a5=="mouse_scroll"and ds then dr=dr+aK;if dr<0 then dr=0 end;if aK>=1 then if#dl>self.h then if dr>#dl-self.h then dr=#dl-self.h end;if dr>=#dl then dr=#dl-1 end else dr=dr-1 end end end;self:setVisualChanged()return true end end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()self.parent:drawBackgroundBox(aX,aY,self.w,self.h,self.bgcolor)for l=1,self.h do if dl[l+dr]~=nil then if dl[l+dr]==self:getValue()then if dp then self.parent:writeText(aX,aY+l-1,h(dl[l+dr].text,self.w,dq),dm,dn)else self.parent:writeText(aX,aY+l-1,h(dl[l+dr].text,self.w,dq),dl[l+dr].bgCol,dl[l+dr].fgCol)end else self.parent:writeText(aX,aY+l-1,h(dl[l+dr].text,self.w,dq),dl[l+dr].bgCol,dl[l+dr].fgCol)end end end end end end}return setmetatable(au,aT)end;local function dx(ak)local aT=aj(ak)local al="Menubar"local au={}aT.w=30;aT.h=1;aT.bgcolor=colors.gray;aT.fgcolor=colors.lightGray;aT:setZIndex(5)local dl={}local dm=a.selectionBG;local dn=a.selectionFG;local dp=true;local dq="left"local dy=0;local da=2;local ds=false;local function dz()local dA=0;local ay=1;for l=1,#dl do if ay+dl[l].text:len()+da*2>au.w then dA=dA+dl[l].text:len()+da*2 end;ay=ay+dl[l].text:len()+da*2 end;return dA end;au={getType=function(self)return al end,addItem=function(self,i,W,X,...)table.insert(dl,{text=i,bgCol=W or self.bgcolor,fgCol=X or self.fgcolor,args={...}})if#dl==1 then self:setValue(dl[1])end;return self end,getItemIndex=function(self)local du=self:getValue()for a8,a9 in pairs(dl)do if a9==du then return a8 end end end,clear=function(self)dl={}self:setValue({})return self end,setSpace=function(self,dB)da=dB or da;return self end,setButtonOffset=function(self,o)dy=o or 0;if dy<0 then dy=0 end;local dA=dz()if dy>dA then dy=dA end;return self end,setScrollable=function(self,dw)ds=dw;return self end,removeItem=function(self,a4)table.remove(dl,a4)return self end,getItem=function(self,a4)return dl[a4]end,getItemCount=function(self)return#dl end,editItem=function(self,a4,i,W,X,...)table.remove(dl,a4)table.insert(dl,a4,{text=i,bgCol=W or self.bgcolor,fgCol=X or self.fgcolor,args={...}})return self end,selectItem=function(self,a4)self:setValue(dl[a4]or{})return self end,setSelectedItem=function(self,W,X,dv)dm=W or self.bgcolor;dn=X or self.fgcolor;dp=dv;return self end,mouseClickHandler=function(self,a5,aK,L,M)local aL,aM=self:getAbsolutePosition(self:getAnchorPosition())if aL<=L and aL+self.w>L and aM<=M and aM+self.h>M and self:isVisible()then if self.parent~=nil then self.parent:setFocusedObject(self)end;if a5=="mouse_click"then local ay=1;for l=1+dy,#dl do if dl[l]~=nil then if ay+dl[l].text:len()+da*2<=self.w then if aL+ay-1<=L and aL+ay-1+dl[l].text:len()+da*2>L and aM==M then self:setValue(dl[l])self:getEventSystem():sendEvent("mouse_click",self,"mouse_click",0,L,M,dl[l])end;ay=ay+dl[l].text:len()+da*2 else break end end end end;if a5=="mouse_scroll"and ds then dy=dy+aK;if dy<0 then dy=0 end;local dA=dz()if dy>dA then dy=dA end end;return true end;return false end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()self.parent:drawBackgroundBox(aX,aY,self.w,self.h,self.bgcolor)local ay=0;for a8,a9 in pairs(dl)do if ay+a9.text:len()+da*2<=self.w then if a9==self:getValue()then self.parent:writeText(aX+ay-1+-dy,aY,h((" "):rep(da)..a9.text..(" "):rep(da),a9.text:len()+da*2,dq),dm or a9.bgCol,dn or a9.fgCol)else self.parent:writeText(aX+ay-1+-dy,aY,h((" "):rep(da)..a9.text..(" "):rep(da),a9.text:len()+da*2,dq),a9.bgCol,a9.fgCol)end;ay=ay+a9.text:len()+da*2 else if ay0 then for l=1,dE do if dl[l+dr]~=nil then if aX<=L and aX+dD>L and aY+l==M then self:setValue(dl[l+dr])return true end end end end end end;if a5=="mouse_scroll"then dr=dr+aK;if dr<0 then dr=0 end;if aK==1 then if#dl>dE then if dr>#dl-dE then dr=#dl-dE end else dr=dl-1 end end;return true end;self:setVisualChanged()end;if aT.mouseClickHandler(self,a5,aK,L,M)then dH=2 else dH=1 end end,draw=function(self)if aT.draw(self)then local aX,aY=self:getAnchorPosition()if self.parent~=nil then self.parent:drawBackgroundBox(aX,aY,self.w,self.h,self.bgcolor)if#dl>=1 then if self:getValue()~=nil then if self:getValue().text~=nil then if dH==1 then self.parent:writeText(aX,aY,h(self:getValue().text,self.w,dq):sub(1,self.w-1)..dF,self.bgcolor,self.fgcolor)else self.parent:writeText(aX,aY,h(self:getValue().text,self.w,dq):sub(1,self.w-1)..dG,self.bgcolor,self.fgcolor)end end end;if dH==2 then for l=1,dE do if dl[l+dr]~=nil then if dl[l+dr]==self:getValue()then if dp then self.parent:writeText(aX,aY+l,h(dl[l+dr].text,dD,dq),dm,dn)else self.parent:writeText(aX,aY+l,h(dl[l+dr].text,dD,dq),dl[l+dr].bgCol,dl[l+dr].fgCol)end else self.parent:writeText(aX,aY+l,h(dl[l+dr].text,dD,dq),dl[l+dr].bgCol,dl[l+dr].fgCol)end end end end end end end end}return setmetatable(au,aT)end;local function dI(ak)local aT=aj(ak)local al="Radio"aT.w=8;aT.bgcolor=a.listBG;aT.fgcolor=a.listFG;aT:setZIndex(5)local dl={}local dm=a.selectionBG;local dn=a.selectionFG;local dJ=aT.bgcolor;local dK=aT.fgcolor;local dp=true;local Y="\7"local dq="left"local au={getType=function(self)return al end,addItem=function(self,i,L,M,W,X,...)table.insert(dl,{x=L or 1,y=M or 1,text=i,bgCol=W or self.bgcolor,fgCol=X or self.fgcolor,args={...}})if#dl==1 then self:setValue(dl[1])end;return self end,removeItem=function(self,a4)table.remove(dl,a4)return self end,getItem=function(self,a4)return dl[a4]end,getItemIndex=function(self)local du=self:getValue()for a8,a9 in pairs(dl)do if a9==du then return a8 end end end,clear=function(self)dl={}self:setValue({})return self end,getItemCount=function(self)return#dl end,editItem=function(self,a4,i,L,M,W,X,...)table.remove(dl,a4)table.insert(dl,a4,{x=L or 1,y=M or 1,text=i,bgCol=W or self.bgcolor,fgCol=X or self.fgcolor,args={...}})return self end,selectItem=function(self,a4)self:setValue(dl[a4]or{})return self end,setSelectedItem=function(self,W,X,dL,dM,dv)dm=W or dm;dn=X or dn;dJ=dL or dJ;dK=dM or dK;dp=dv;return self end,mouseClickHandler=function(self,a5,aK,L,M)local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())if a5=="mouse_click"then if aK==1 then if#dl>0 then for aJ,a9 in pairs(dl)do if aX+a9.x-1<=L and aX+a9.x-1+a9.text:len()+2>=L and aY+a9.y-1==M then self:setValue(a9)if self.parent~=nil then self.parent:setFocusedObject(self)end;self:setVisualChanged()return true end end end end end;return false end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()for aJ,a9 in pairs(dl)do if a9==self:getValue()then if dq=="left"then self.parent:writeText(a9.x+aX-1,a9.y+aY-1,Y,dJ,dK)self.parent:writeText(a9.x+2+aX-1,a9.y+aY-1,a9.text,dm,dn)end else self.parent:drawBackgroundBox(a9.x+aX-1,a9.y+aY-1,1,1,self.bgcolor)self.parent:writeText(a9.x+2+aX-1,a9.y+aY-1,a9.text,a9.bgCol,a9.fgCol)end end end end end}return setmetatable(au,aT)end;local function dN(ak)local al="Timer"local dO=0;local dP=0;local dQ=0;local dR;local at=a2()local au={name=ak,getType=function(self)return al end,getZIndex=function(self)return 1 end,getName=function(self)return self.name end,setTime=function(self,dS,dT)dO=dS or 0;dP=dT or 1;return self end,start=function(self)dQ=dP;dR=os.startTimer(dO)return self end,cancel=function(self)if dR~=nil then os.cancelTimer(dR)end;return self end,onCall=function(self,a7)at:registerEvent("timed_event",a7)return self end,eventHandler=function(self,a5,dU)if a5=="timer"and dU==dR then at:sendEvent("timed_event",self)if dQ>=1 then dQ=dQ-1;if dQ>=1 then dR=os.startTimer(dO)end elseif dQ==-1 then dR=os.startTimer(dO)end end end}au.__index=au;return au end;local function dV(ak)local au;local al="Thread"local a7;local dW;local dX=false;au={name=ak,getType=function(self)return al end,getZIndex=function(self)return 1 end,getName=function(self)return self.name end,start=function(self,cS)if cS==nil then error("function is nil")end;a7=cS;dW=coroutine.create(a7)dX=true;local ah,ai=coroutine.resume(dW)if not ah then if ai~="Terminated"then error("Threaderror - "..ai)end end;return self end,getStatus=function(self,cS)if dW~=nil then return coroutine.status(dW)end;return nil end,stop=function(self,cS)dX=false;return self end,eventHandler=function(self,a5,aO,aP,aQ)if dX then if coroutine.status(dW)~="dead"then local ah,ai=coroutine.resume(dW,a5,aO,aP,aQ)if not ah then if ai~="Terminated"then error("Threaderror - "..ai)end end else dX=false end end end}au.__index=au;return au end;local function dY(ak)local au={}local al="Animation"local dR;local dZ={}local a4=1;local d_=0;local e0;local function e1()if dZ[a4]~=nil then dZ[a4].f(au,a4)end;a4=a4+1;if dZ[a4]~=nil then if dZ[a4].t>0 then dR=os.startTimer(dZ[a4].t)else e1()end end end;au={name=ak,getType=function(self)return al end,getZIndex=function(self)return 1 end,getName=function(self)return self.name end,add=function(self,a7,e2)e0=a7;table.insert(dZ,{f=a7,t=e2 or d_})return self end,wait=function(self,e2)d_=e2;return self end,rep=function(self,e3)for L=1,e3 do table.insert(dZ,{f=e0,t=d_})end;return self end,clear=function(self)dZ={}e0=nil;d_=0;a4=1;return self end,play=function(self)a4=1;if dZ[a4]~=nil then if dZ[a4].t>0 then dR=os.startTimer(dZ[a4].t)else e1()end end;return self end,cancel=function(self)os.cancelTimer(dR)return self end,eventHandler=function(self,a5,dU)if a5=="timer"and dU==dR then if dZ[a4]~=nil then e1()end end end}au.__index=au;return au end;local function e4(ak)local aT=aj(ak)local al="Slider"aT.w=8;aT.bgcolor=colors.lightGray;aT.fgcolor=colors.gray;aT:setValue(1)local e5="horizontal"local Y=" "local e6=colors.black;local e7="\140"local e8=aT.w;local a4=1;local au={getType=function(self)return al end,setSymbol=function(self,e9)Y=e9:sub(1,1)self:setVisualChanged()return self end,setBackgroundSymbol=function(self,ea)e7=string.sub(ea,1,1)self:setVisualChanged()return self end,setSymbolColor=function(self,eb)e6=eb;self:setVisualChanged()return self end,setBarType=function(self,ec)e5=ec:lower()return self end,mouseClickHandler=function(self,a5,aK,L,M)if aT.mouseClickHandler(self,a5,aK,L,M)then local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())if e5=="horizontal"then for ed=0,self.w-1 do if aX+ed==L and aY<=M and aY+self.h>M then a4=ed+1;self:setValue(e8/self.w*a4)self:setVisualChanged()end end end;if e5=="vertical"then for ed=0,self.h-1 do if aY+ed==M and aX<=L and aX+self.w>L then a4=ed+1;self:setValue(e8/self.h*a4)self:setVisualChanged()end end end end end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()if e5=="horizontal"then self.parent:writeText(aX,aY,e7:rep(a4-1),self.bgcolor,self.fgcolor)self.parent:writeText(aX+a4-1,aY,Y,e6,e6)self.parent:writeText(aX+a4,aY,e7:rep(self.w-a4),self.bgcolor,self.fgcolor)end;if e5=="vertical"then for l=0,self.h-1 do if l+1==a4 then self.parent:writeText(aX,aY+l,Y,e6,e6)else self.parent:writeText(aX,aY+l,e7,self.bgcolor,self.fgcolor)end end end end end end}return setmetatable(au,aT)end;local function ee(ak)local aT=aj(ak)local al="Scrollbar"aT.w=1;aT.h=8;aT.bgcolor=colors.lightGray;aT.fgcolor=colors.gray;aT:setValue(1)aT:setZIndex(2)local e5="vertical"local Y=" "local e6=colors.black;local e7="\127"local e8=aT.h;local a4=1;local ef=1;local au={getType=function(self)return al end,setSymbol=function(self,e9)Y=e9:sub(1,1)self:setVisualChanged()return self end,setSymbolSize=function(self,eg)ef=tonumber(eg)or 1;if e5=="vertical"then self:setValue(a4-1*e8/(self.h-(ef-1))-e8/(self.h-(ef-1)))elseif e5=="horizontal"then self:setValue(a4-1*e8/(self.w-(ef-1))-e8/(self.w-(ef-1)))end;self:setVisualChanged()return self end,setMaxValue=function(self,d5)e8=d5;return self end,setBackgroundSymbol=function(self,ea)e7=string.sub(ea,1,1)self:setVisualChanged()return self end,setSymbolColor=function(self,eb)e6=eb;self:setVisualChanged()return self end,setBarType=function(self,ec)e5=ec:lower()return self end,mouseClickHandler=function(self,a5,aK,L,M)if aT.mouseClickHandler(self,a5,aK,L,M)then local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())if(a5=="mouse_click"or a5=="mouse_drag")and aK==1 then if e5=="horizontal"then for ed=0,self.w do if aX+ed==L and aY<=M and aY+self.h>M then a4=math.min(ed+1,self.w-(ef-1))self:setValue(e8/self.w*a4)self:setVisualChanged()end end end;if e5=="vertical"then for ed=0,self.h do if aY+ed==M and aX<=L and aX+self.w>L then a4=math.min(ed+1,self.h-(ef-1))self:setValue(e8/self.h*a4)self:setVisualChanged()end end end end;if a5=="mouse_scroll"then a4=a4+aK;if a4<1 then a4=1 end;a4=math.min(a4,(e5=="vertical"and self.h or self.w)-(ef-1))self:setValue(e8/(e5=="vertical"and self.h or self.w)*a4)end;return true end end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()if e5=="horizontal"then self.parent:writeText(aX,aY,e7:rep(a4-1),self.bgcolor,self.fgcolor)self.parent:writeText(aX+a4-1,aY,Y:rep(ef),e6,e6)self.parent:writeText(aX+a4+ef-1,aY,e7:rep(self.w-(a4+ef-1)),self.bgcolor,self.fgcolor)end;if e5=="vertical"then for l=0,self.h-1 do if a4==l+1 then for eh=0,math.min(ef-1,self.h)do self.parent:writeText(aX,aY+l+eh,Y,e6,e6)end else if l+1a4-1+ef then self.parent:writeText(aX,aY+l,e7,self.bgcolor,self.fgcolor)end end end end end end end}return setmetatable(au,aT)end;local function ei(ak)local aT=aj(ak)local al="Switch"aT.w=3;aT.h=1;aT.bgcolor=colors.lightGray;aT.fgcolor=colors.gray;aT:setValue(false)aT:setZIndex(5)local au={getType=function(self)return al end,mouseClickHandler=function(self,a5,aK,L,M)if aT.mouseClickHandler(self,a5,aK,L,M)then local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())if(a5=="mouse_click"or a5=="mouse_drag")and aK==1 then end;return true end end,draw=function(self)if aT.draw(self)then if self.parent~=nil then local aX,aY=self:getAnchorPosition()end end end}return setmetatable(au,aT)end;local function ej(ak,ek)local aT=aj(ak)local al="Frame"local el={}local em={}local au={}local en;aT:setZIndex(10)local b5=false;local b1=1;local b2=1;local eo=colors.white;local ep,dr=0,0;if ek~=nil then aT.parent=ek;aT.w,aT.h=ek.w,ek.h;aT.bgcolor=a.FrameBG;aT.fgcolor=a.FrameFG else local eq,er=f.getSize()aT.w,aT.h=eq,er;aT.bgcolor=a.basaltBG;aT.fgcolor=a.basaltFG end;local function es(ak)for a8,a9 in pairs(el)do for cp,bD in pairs(a9)do if bD.name==ak then return a9 end end end end;local function et(eu)local an=eu:getZIndex()if es(eu.name)~=nil then return nil end;if el[an]==nil then for L=1,#em+1 do if em[L]~=nil then if an==em[L]then break end;if an>em[L]then table.insert(em,L,an)break end else table.insert(em,an)end end;if#em<=0 then table.insert(em,an)end;el[an]={}end;eu.parent=au;table.insert(el[an],eu)return eu end;local function ev(eu)for cp,bD in pairs(el)do for a8,a9 in pairs(bD)do if a9==eu then table.remove(el[cp],a8)return true end end end;return false end;au={barActive=false,barBackground=colors.gray,barTextcolor=colors.black,barText="New Frame",barTextAlign="left",isMoveable=false,getType=function(self)return al end,setFocusedObject=function(self,eu)for aJ,a4 in pairs(em)do for aJ,a9 in pairs(el[a4])do if a9==eu then if en~=nil then en:loseFocusHandler()end;en=eu;en:getFocusHandler()end end end;return self end,setOffset=function(self,aG,aH)ep=aG~=nil and math.floor(aG<0 and math.abs(aG)or-aG)or ep;dr=aH~=nil and math.floor(aH<0 and math.abs(aH)or-aH)or dr;return self end,getFrameOffset=function(self)return ep,dr end,removeFocusedObject=function(self)if en~=nil then en:loseFocusHandler()end;en=nil;return self end,getFocusedObject=function(self)return en end,show=function(self)aT:show()if self.parent==nil then c=self end;return self end,setCursor=function(self,ew,ex,ey,aC)local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())b5=ew or false;if ex~=nil then b1=aX+ex-1 end;if ey~=nil then b2=aY+ey-1 end;eo=aC or eo;self:setVisualChanged()return self end,setMoveable=function(self,ez)self.isMoveable=ez or not self.isMoveable;self:setVisualChanged()return self end,showBar=function(self,eA)self.barActive=eA or not self.barActive;self:setVisualChanged()return self end,setBar=function(self,i,W,X)self.barText=i or""self.barBackground=W or self.barBackground;self.barTextcolor=X or self.barTextcolor;self:setVisualChanged()return self end,setBarTextAlign=function(self,dq)self.barTextAlign=dq or"left"self:setVisualChanged()return self end,getVisualChanged=function(self)local eB=aT.getVisualChanged(self)for aJ,a4 in pairs(em)do if el[a4]~=nil then for aJ,a9 in pairs(el[a4])do if a9.getVisualChanged~=nil and a9:getVisualChanged()then eB=true end end end end;return eB end,loseFocusHandler=function(self)aT.loseFocusHandler(self)end,getFocusHandler=function(self)aT.getFocusHandler(self)if self.parent~=nil then self.parent:removeObject(self)self.parent:addObject(self)end end,keyHandler=function(self,a5,aN)if en~=nil then if en.keyHandler~=nil then if en:keyHandler(a5,aN)then return true end end end;return false end,backgroundKeyHandler=function(self,a5,aN)aT.backgroundKeyHandler(self,a5,aN)for aJ,a4 in pairs(em)do if el[a4]~=nil then for aJ,a9 in pairs(el[a4])do if a9.backgroundKeyHandler~=nil then a9:backgroundKeyHandler(a5,aN)end end end end end,eventHandler=function(self,a5,aO,aP,aQ,aR)aT.eventHandler(self,a5,aO,aP,aQ,aR)for aJ,a4 in pairs(em)do if el[a4]~=nil then for aJ,a9 in pairs(el[a4])do if a9.eventHandler~=nil then a9:eventHandler(a5,aO,aP,aQ,aR)end end end end;if a5=="terminate"then f.clear()f.setCursorPos(1,1)b.stop()end end,mouseClickHandler=function(self,a5,aK,L,M)local aG,aH=self:getOffset()aG=aG<0 and math.abs(aG)or-aG;aH=aH<0 and math.abs(aH)or-aH;if self.drag then if a5=="mouse_drag"then local eC=1;local eD=1;if self.parent~=nil then eC,eD=self.parent:getAbsolutePosition(self.parent:getAnchorPosition())end;self:setPosition(L+self.xToRem-(eC-1)+aG,M-(eD-1)+aH)end;if a5=="mouse_up"then self.drag=false end;return true end;if aT.mouseClickHandler(self,a5,aK,L,M)then local aD,aE=self:getAbsolutePosition(self:getAnchorPosition())for aJ,a4 in pairs(em)do if el[a4]~=nil then for aJ,a9 in p(el[a4])do if a9.mouseClickHandler~=nil then if a9:mouseClickHandler(a5,aK,L+aG,M+aH)then return true end end end end end;if self.isMoveable then if L>=aD and L<=aD+self.w-1 and M==aE and a5=="mouse_click"then self.drag=true;self.xToRem=aD-L end end;if en~=nil then en:loseFocusHandler()en=nil end;return true end;return false end,setText=function(self,L,M,i)local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())if M>=1 and M<=self.h then if self.parent~=nil then self.parent:setText(math.max(L+aX-1,aX)-(self.parent.x-1),aY+M-1-(self.parent.y-1),g(i,math.max(1-L+1,1),self.w-L+1))else V.setText(math.max(L+aX-1,aX),aY+M-1,g(i,math.max(1-L+1,1),self.w-L+1))end end end,setBG=function(self,L,M,W)local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())if M>=1 and M<=self.h then if self.parent~=nil then self.parent:setBG(math.max(L+aX-1,aX)-(self.parent.x-1),aY+M-1-(self.parent.y-1),g(W,math.max(1-L+1,1),self.w-L+1))else V.setBG(math.max(L+aX-1,aX),aY+M-1,g(W,math.max(1-L+1,1),self.w-L+1))end end end,setFG=function(self,L,M,X)local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())if M>=1 and M<=self.h then if self.parent~=nil then self.parent:setFG(math.max(L+aX-1,aX)-(self.parent.x-1),aY+M-1-(self.parent.y-1),g(X,math.max(1-L+1,1),self.w-L+1))else V.setFG(math.max(L+aX-1,aX),aY+M-1,g(X,math.max(1-L+1,1),self.w-L+1))end end end,writeText=function(self,L,M,i,W,X)local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())if M>=1 and M<=self.h then if self.parent~=nil then self.parent:writeText(math.max(L+aX-1,aX)-(self.parent.x-1),aY+M-1-(self.parent.y-1),g(i,math.max(1-L+1,1),self.w-L+1),W,X)else V.writeText(math.max(L+aX-1,aX),aY+M-1,g(i,math.max(1-L+1,1),self.w-L+1),W,X)end end end,drawBackgroundBox=function(self,L,M,j,n,W)local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())n=M<1 and(n+M>self.h and self.h or n+M-1)or(n+M>self.h and self.h-M+1 or n)j=L<1 and(j+L>self.w and self.w or j+L-1)or(j+L>self.w and self.w-L+1 or j)if self.parent~=nil then self.parent:drawBackgroundBox(math.max(L+aX-1,aX)-(self.parent.x-1),math.max(M+aY-1,aY)-(self.parent.y-1),j,n,W)else V.drawBackgroundBox(math.max(L+aX-1,aX),math.max(M+aY-1,aY),j,n,W)end end,drawTextBox=function(self,L,M,j,n,Y)local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())n=M<1 and(n+M>self.h and self.h or n+M-1)or(n+M>self.h and self.h-M+1 or n)j=L<1 and(j+L>self.w and self.w or j+L-1)or(j+L>self.w and self.w-L+1 or j)if self.parent~=nil then self.parent:drawTextBox(math.max(L+aX-1,aX)-(self.parent.x-1),math.max(M+aY-1,aY)-(self.parent.y-1),j,n,Y:sub(1,1))else V.drawTextBox(math.max(L+aX-1,aX),math.max(M+aY-1,aY),j,n,Y:sub(1,1))end end,drawForegroundBox=function(self,L,M,j,n,X)local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())n=M<1 and(n+M>self.h and self.h or n+M-1)or(n+M>self.h and self.h-M+1 or n)j=L<1 and(j+L>self.w and self.w or j+L-1)or(j+L>self.w and self.w-L+1 or j)if self.parent~=nil then self.parent:drawForegroundBox(math.max(L+aX-1,aX)-(self.parent.x-1),math.max(M+aY-1,aY)-(self.parent.y-1),j,n,X)else V.drawForegroundBox(math.max(L+aX-1,aX),math.max(M+aY-1,aY),j,n,X)end end,draw=function(self)if self:getVisualChanged()then if aT.draw(self)then local aX,aY=self:getAbsolutePosition(self:getAnchorPosition())local di,dj=self:getAnchorPosition()if self.parent~=nil then self.parent:drawBackgroundBox(di,dj,self.w,self.h,self.bgcolor)self.parent:drawForegroundBox(di,dj,self.w,self.h,self.fgcolor)self.parent:drawTextBox(di,dj,self.w,self.h," ")else V.drawBackgroundBox(aX,aY,self.w,self.h,self.bgcolor)V.drawForegroundBox(aX,aY,self.w,self.h,self.fgcolor)V.drawTextBox(aX,aY,self.w,self.h," ")end;f.setCursorBlink(false)if self.barActive then if self.parent~=nil then self.parent:writeText(di,dj,h(self.barText,self.w,self.barTextAlign),self.barBackground,self.barTextcolor)else V.writeText(aX,aY,h(self.barText,self.w,self.barTextAlign),self.barBackground,self.barTextcolor)end end;for aJ,a4 in p(em)do if el[a4]~=nil then for aJ,a9 in pairs(el[a4])do if a9.draw~=nil then a9:draw()end end end end;if b5 then f.setTextColor(eo)f.setCursorPos(b1,b2)if self.parent~=nil then f.setCursorBlink(self:isFocused())else f.setCursorBlink(b5)end end;self:setVisualChanged(false)end end end,addObject=function(self,eu)return et(eu)end,removeObject=function(self,eu)return ev(eu)end,getObject=function(self,eu)return es(eu)end,addButton=function(self,ak)local eu=aS(ak)eu.name=ak;return et(eu)end,addLabel=function(self,ak)local eu=c0(ak)eu.name=ak;eu.bgcolor=self.bgcolor;eu.fgcolor=self.fgcolor;return et(eu)end,addCheckbox=function(self,ak)local eu=cI(ak)eu.name=ak;return et(eu)end,addInput=function(self,ak)local eu=cT(ak)eu.name=ak;return et(eu)end,addProgram=function(self,ak)local eu=a_(ak)eu.name=ak;return et(eu)end,addTextfield=function(self,ak)local eu=db(ak)eu.name=ak;return et(eu)end,addList=function(self,ak)local eu=dk(ak)eu.name=ak;return et(eu)end,addDropdown=function(self,ak)local eu=dC(ak)eu.name=ak;return et(eu)end,addRadio=function(self,ak)local eu=dI(ak)eu.name=ak;return et(eu)end,addTimer=function(self,ak)local eu=dN(ak)eu.name=ak;return et(eu)end,addAnimation=function(self,ak)local eu=dY(ak)eu.name=ak;return et(eu)end,addSlider=function(self,ak)local eu=e4(ak)eu.name=ak;return et(eu)end,addScrollbar=function(self,ak)local eu=ee(ak)eu.name=ak;return et(eu)end,addMenubar=function(self,ak)local eu=dx(ak)eu.name=ak;return et(eu)end,addThread=function(self,ak)local eu=dV(ak)eu.name=ak;return et(eu)end,addPane=function(self,ak)local eu=c2(ak)eu.name=ak;return et(eu)end,addImage=function(self,ak)local eu=c3(ak)eu.name=ak;return et(eu)end,addProgressbar=function(self,ak)local eu=cJ(ak)eu.name=ak;return et(eu)end,addFrame=function(self,ak)local eu=ej(ak,self)eu.name=ak;return et(eu)end}setmetatable(au,aT)if ek==nil then table.insert(d,au)end;return au end;local eE=false;local function eF(a5,aO,aP,aQ,aR)if a5=="mouse_click"then c:mouseClickHandler(a5,aO,aP,aQ,aR)end;if a5=="mouse_drag"then c:mouseClickHandler(a5,aO,aP,aQ,aR)end;if a5=="mouse_up"then c:mouseClickHandler(a5,aO,aP,aQ,aR)end;if a5=="mouse_scroll"then c:mouseClickHandler(a5,aO,aP,aQ,aR)end;if a5=="key"or a5=="char"then c:keyHandler(a5,aO)c:backgroundKeyHandler(a5,aO)end;for aJ,a9 in pairs(d)do a9:eventHandler(a5,aO,aP,aQ,aR)end;if eE then c:draw()V.update()end end;function b.autoUpdate(dX)f.clear()eE=dX or true;c:draw()V.update()while eE do local a5,aO,aP,aQ,aR=os.pullEventRaw()eF(a5,aO,aP,aQ,aR)end end;function b.update(a5,aO,aP,aQ,aR)if a5~="nil"then eF(a5,aO,aP,aQ,aR)else c:draw()V.update()end end;function b.stop()eE=false end;function b.getFrame(ak)for a8,a9 in pairs(d)do if a9.name==ak then return a9 end end end;function b.getActiveFrame()return c end;function b.setActiveFrame(av)if av:getType()=="Frame"then c=av;return true end;return false end;function b.createFrame(ak)local av=ej(ak)return av end;function b.removeFrame(ak)for a8,a9 in pairs(d)do if a9.name==ak then d[a8]=nil;return true end end;return false end;if b.debugger then b.debugFrame=b.createFrame("basaltDebuggingFrame"):showBar():setBackground(colors.lightGray):setBar("Debug",colors.black,colors.gray)b.debugList=b.debugFrame:addList("debugList"):setSize(b.debugFrame.w-2,b.debugFrame.h-3):setPosition(2,3):setScrollable(true):show()b.debugFrame:addButton("back"):setAnchor("right"):setSize(1,1):setText("\22"):onClick(function()b.oldFrame:show()end):setBackground(colors.red):show()b.debugLabel=b.debugFrame:addLabel("debugLabel"):onClick(function()b.oldFrame=c;b.debugFrame:show()end):setBackground(colors.black):setForeground(colors.white):setAnchor("bottom"):setZIndex(20):show()end;if b.debugger then function b.debug(...)local af={...}if c.name~="basaltDebuggingFrame"then if c~=b.debugLabel.frame then b.debugLabel:setParent(c)end end;local eG=""for a8,a9 in pairs(af)do eG=eG..tostring(a9)..(#af~=a8 and", "or"")end;b.debugLabel:setText("[Debug] "..eG)b.debugList:addItem(eG)if b.debugList:getItemCount()>50 then b.debugList:removeItem(1)end;b.debugList:setValue(b.debugList:getItem(b.debugList:getItemCount()))b.debugLabel:show()end end;return b \ No newline at end of file diff --git a/source/basalt.lua b/source/basalt.lua index 8f32c3c..03a71a3 100644 --- a/source/basalt.lua +++ b/source/basalt.lua @@ -1,9 +1,8 @@ -- current version 1 - local theme = { - basaltBG = colors.lightGray, - basaltFG = colors.black, - FrameBG = colors.gray, + basaltBG = colors.lightGray, + basaltFG = colors.black, + FrameBG = colors.gray, FrameFG = colors.black, ButtonBG = colors.gray, ButtonFG = colors.black, @@ -23,7 +22,7 @@ local theme = { selectionFG = colors.lightGray, } -local basalt = {debugger=true, version=1} +local basalt = { debugger = true, version = 1 } local activeFrame local frames = {} @@ -33,62 +32,64 @@ local parentTerminal = term.current() local sub = string.sub local function getTextHorizontalAlign(text, w, textAlign) - local text = string.sub(text, 1, w) - local n = w-string.len(text) - if(textAlign=="right")then - text = string.rep(" ", n)..text - elseif(textAlign=="center")then - text = string.rep(" ", math.floor(n/2))..text..string.rep(" ", math.floor(n/2)) - text = text..(string.len(text) < w and " " or "") + text = string.sub(text, 1, w) + local n = w - string.len(text) + if (textAlign == "right") then + text = string.rep(" ", n) .. text + elseif (textAlign == "center") then + text = string.rep(" ", math.floor(n / 2)) .. text .. string.rep(" ", math.floor(n / 2)) + text = text .. (string.len(text) < w and " " or "") else - text = text..string.rep(" ", n) + text = text .. string.rep(" ", n) end return text end -local function getTextVerticalAlign(h,textAlign) -local offset = 0 - if(textAlign=="center")then +local function getTextVerticalAlign(h, textAlign) + local offset = 0 + if (textAlign == "center") then offset = math.ceil(h / 2) - if(offset<1)then offset = 1 end + if (offset < 1) then + offset = 1 + end end - if(textAlign=="bottom")then + if (textAlign == "bottom") then offset = h end return offset end local function rpairs(t) - return function(t, i) - i = i - 1 - if i ~= 0 then - return i, t[i] - end - end, t, #t + 1 + return function(t, i) + i = i - 1 + if i ~= 0 then + return i, t[i] + end + end, t, #t + 1 end local tHex = { -- copy paste is a very important feature - [ colors.white ] = "0", - [ colors.orange ] = "1", - [ colors.magenta ] = "2", - [ colors.lightBlue ] = "3", - [ colors.yellow ] = "4", - [ colors.lime ] = "5", - [ colors.pink ] = "6", - [ colors.gray ] = "7", - [ colors.lightGray ] = "8", - [ colors.cyan ] = "9", - [ colors.purple ] = "a", - [ colors.blue ] = "b", - [ colors.brown ] = "c", - [ colors.green ] = "d", - [ colors.red ] = "e", - [ colors.black ] = "f", + [colors.white] = "0", + [colors.orange] = "1", + [colors.magenta] = "2", + [colors.lightBlue] = "3", + [colors.yellow] = "4", + [colors.lime] = "5", + [colors.pink] = "6", + [colors.gray] = "7", + [colors.lightGray] = "8", + [colors.cyan] = "9", + [colors.purple] = "a", + [colors.blue] = "b", + [colors.brown] = "c", + [colors.green] = "d", + [colors.red] = "e", + [colors.black] = "f", } local function basaltDrawHelper() local terminal = parentTerminal - local w,h = terminal.getSize() + local width, height = terminal.getSize() local cacheT = {} local cacheBG = {} local cacheFG = {} @@ -101,108 +102,108 @@ local function basaltDrawHelper() local emptyColorLines = {} local function createEmptyLines() - emptySpaceLine = (" "):rep(w) - for n=0,15 do - local nColor = 2^n + emptySpaceLine = (" "):rep(width) + for n = 0, 15 do + local nColor = 2 ^ n local sHex = tHex[nColor] - emptyColorLines[nColor] = sHex:rep(w) + emptyColorLines[nColor] = sHex:rep(width) end end - ---- + ---- createEmptyLines() - local function recreateWindowArray() + local function recreateWindowArray() local emptyText = emptySpaceLine local emptyFG = emptyColorLines[colors.white] local emptyBG = emptyColorLines[colors.black] - for n=1,h do - cacheT[n] = sub(cacheT[n] == nil and emptyText or cacheT[n]..emptyText:sub(1,w-cacheT[n]:len()),1,w) - cacheFG[n] = sub(cacheFG[n] == nil and emptyFG or cacheFG[n]..emptyFG:sub(1,w-cacheFG[n]:len()),1,w) - cacheBG[n] = sub(cacheBG[n] == nil and emptyBG or cacheBG[n]..emptyBG:sub(1,w-cacheBG[n]:len()),1,w) + for n = 1, height do + cacheT[n] = sub(cacheT[n] == nil and emptyText or cacheT[n] .. emptyText:sub(1, width - cacheT[n]:len()), 1, width) + cacheFG[n] = sub(cacheFG[n] == nil and emptyFG or cacheFG[n] .. emptyFG:sub(1, width - cacheFG[n]:len()), 1, width) + cacheBG[n] = sub(cacheBG[n] == nil and emptyBG or cacheBG[n] .. emptyBG:sub(1, width - cacheBG[n]:len()), 1, width) end end recreateWindowArray() - local function setText(x,y,text) - if(y>=1)and(y<=h)then - if(x+text:len()>0)and(x<=w)then + local function setText(x, y, text) + if (y >= 1) and (y <= height) then + if (x + text:len() > 0) and (x <= width) then local oldCache = cacheT[y] local newCache local nEnd = x + #text - 1 - - if(x < 1)then + + if (x < 1) then local startN = 1 - x + 1 - local endN = w - x + 1 + local endN = width - x + 1 text = sub(text, startN, endN) - elseif(nEnd > w)then - local endN = w - x + 1 + elseif (nEnd > width) then + local endN = width - x + 1 text = sub(text, 1, endN) end - if(x > 1)then + if (x > 1) then local endN = x - 1 - newCache = sub( oldCache, 1, endN )..text + newCache = sub(oldCache, 1, endN) .. text else newCache = text end - if nEnd < w then - newCache = newCache .. sub(oldCache, nEnd + 1, w) + if nEnd < width then + newCache = newCache .. sub(oldCache, nEnd + 1, width) end cacheT[y] = newCache end end end - local function setBG(x,y,colorStr) - if(y>=1)and(y<=h)then - if(x+colorStr:len()>0)and(x<=w)then + local function setBG(x, y, colorStr) + if (y >= 1) and (y <= height) then + if (x + colorStr:len() > 0) and (x <= width) then local oldCache = cacheBG[y] local newCache local nEnd = x + #colorStr - 1 - - if(x < 1)then - colorStr = sub(colorStr, 1 - x + 1, w - x + 1) - elseif(nEnd > w)then - colorStr = sub(colorStr, 1, w - x + 1) + + if (x < 1) then + colorStr = sub(colorStr, 1 - x + 1, width - x + 1) + elseif (nEnd > width) then + colorStr = sub(colorStr, 1, width - x + 1) end - if(x > 1)then - newCache = sub( oldCache, 1, x - 1)..colorStr + if (x > 1) then + newCache = sub(oldCache, 1, x - 1) .. colorStr else newCache = colorStr end - if nEnd < w then - newCache = newCache .. sub(oldCache, nEnd + 1, w) + if nEnd < width then + newCache = newCache .. sub(oldCache, nEnd + 1, width) end cacheBG[y] = newCache end end end - local function setFG(x,y,colorStr) - if(y>=1)and(y<=h)then - if(x+colorStr:len()>0)and(x<=w)then + local function setFG(x, y, colorStr) + if (y >= 1) and (y <= height) then + if (x + colorStr:len() > 0) and (x <= width) then local oldCache = cacheFG[y] local newCache local nEnd = x + #colorStr - 1 - - if(x < 1)then + + if (x < 1) then local startN = 1 - x + 1 - local endN = w - x + 1 + local endN = width - x + 1 colorStr = sub(colorStr, startN, endN) - elseif(nEnd > w)then - local endN = w - x + 1 + elseif (nEnd > width) then + local endN = width - x + 1 colorStr = sub(colorStr, 1, endN) end - if(x > 1)then + if (x > 1) then local endN = x - 1 - newCache = sub( oldCache, 1, endN )..colorStr + newCache = sub(oldCache, 1, endN) .. colorStr else newCache = colorStr end - if nEnd < w then - newCache = newCache .. sub( oldCache, nEnd + 1, w ) + if nEnd < width then + newCache = newCache .. sub(oldCache, nEnd + 1, width) end cacheFG[y] = newCache end @@ -210,34 +211,34 @@ local function basaltDrawHelper() end local drawHelper = { - setBG = function(x,y,colorStr) - setBG(x,y,colorStr) - end; - - setText = function(x,y,text) - setText(x,y,text) + setBG = function(x, y, colorStr) + setBG(x, y, colorStr) end; - setFG = function(x,y,colorStr) - setFG(x,y,colorStr) + setText = function(x, y, text) + setText(x, y, text) end; - drawBackgroundBox = function (x, y, w, h, bgCol) + setFG = function(x, y, colorStr) + setFG(x, y, colorStr) + end; + + drawBackgroundBox = function(x, y, w, h, bgCol) for n = 1, h do - setBG(x, y + (n-1), tHex[bgCol]:rep(w)) + setBG(x, y + (n - 1), tHex[bgCol]:rep(w)) end end; - drawForegroundBox = function (x, y, w, h, fgCol) + drawForegroundBox = function(x, y, w, h, fgCol) for n = 1, h do - setFG(x, y + (n-1), tHex[fgCol]:rep(w)) + setFG(x, y + (n - 1), tHex[fgCol]:rep(w)) end end; - drawTextBox = function (x, y, w, h, symbol) + drawTextBox = function(x, y, w, h, symbol) for n = 1, h do - setText(x, y + (n-1), symbol:rep(w)) + setText(x, y + (n - 1), symbol:rep(w)) end end; - writeText = function (x, y, text, bgCol, fgCol) + writeText = function(x, y, text, bgCol, fgCol) bgCol = bgCol or terminal.getBackgroundColor() fgCol = fgCol or terminal.getTextColor() setText(x, y, text) @@ -245,12 +246,14 @@ local function basaltDrawHelper() setFG(x, y, tHex[fgCol]:rep(text:len())) end; - update = function () + update = function() local xC, yC = terminal.getCursorPos() local isBlinking = false - if(terminal.getCursorBlink~=nil)then isBlinking = terminal.getCursorBlink() end + if (terminal.getCursorBlink ~= nil) then + isBlinking = terminal.getCursorBlink() + end terminal.setCursorBlink(false) - for n=1, h do + for n = 1, height do terminal.setCursorPos(1, n) terminal.blit(cacheT[n], cacheFG[n], cacheBG[n]) end @@ -258,7 +261,7 @@ local function basaltDrawHelper() terminal.setCursorPos(xC, yC) end; - setTerm = function (newTerm) + setTerm = function(newTerm) terminal = newTerm; end; } @@ -272,20 +275,23 @@ local function BasaltEvents() local index = {} local event = { - registerEvent = function(self,_event,func) - if( events[_event] == nil)then events[_event] = {} index[_event] = 1 end + registerEvent = function(self, _event, func) + if (events[_event] == nil) then + events[_event] = {} + index[_event] = 1 + end events[_event][index[_event]] = func index[_event] = index[_event] + 1 return index[_event] - 1 end; - removeEvent = function(self,_event,index) + removeEvent = function(self, _event, index) events[_event][index[_event]] = nil end; - sendEvent = function(self,_event,...) - if(events[_event]~=nil)then - for k,v in pairs(events[_event])do + sendEvent = function(self, _event, ...) + if (events[_event] ~= nil) then + for k, v in pairs(events[_event]) do v(...) end end @@ -299,13 +305,13 @@ local processes = {} local process = {} local processId = 0 -function process:new(path,window,...) - local args = table.pack( ... ) - local newP = setmetatable({path=path},{__index = self}) +function process:new(path, window, ...) + local args = table.pack(...) + local newP = setmetatable({ path = path }, { __index = self }) newP.window = window newP.processId = processId newP.coroutine = coroutine.create(function() - os.run({basalt=basalt}, path, table.unpack(args)) + os.run({ basalt = basalt }, path, table.unpack(args)) end) processes[processId] = newP processId = processId + 1 @@ -314,18 +320,18 @@ end function process:resume(event, ...) term.redirect(self.window) - local ok, result = coroutine.resume( self.coroutine, event, ... ) + local ok, result = coroutine.resume(self.coroutine, event, ...) self.window = term.current() if ok then self.filter = result else - basalt.debug( result ) + basalt.debug(result) end end function process:isDead() - if(self.coroutine~=nil)then - if(coroutine.status(self.coroutine)=="dead")then + if (self.coroutine ~= nil) then + if (coroutine.status(self.coroutine) == "dead") then table.remove(processes, self.processId) return true end @@ -336,7 +342,7 @@ function process:isDead() end function process:getStatus() - if(self.coroutine~=nil)then + if (self.coroutine ~= nil) then return coroutine.status(self.coroutine) end return nil @@ -346,7 +352,8 @@ function process:start() coroutine.resume(self.coroutine) end -local function Object(name) -- Base object +local function Object(name) + -- Base object local typ = "Object" -- not changeable --[[ local horizontalAnchor = "left" @@ -395,7 +402,7 @@ local function Object(name) -- Base object end; setFocus = function(self) - if(self.parent~=nil)then + if (self.parent ~= nil) then self.parent:setFocusedObject(self) end return self @@ -403,7 +410,7 @@ local function Object(name) -- Base object setZIndex = function(self, index) zIndex = index - if(self.parent~=nil)then + if (self.parent ~= nil) then self.parent:removeObject(self) self.parent:addObject(self) end @@ -419,67 +426,67 @@ local function Object(name) -- Base object end; remove = function(self) - if(self.parent~=nil)then + if (self.parent ~= nil) then self.parent:removeObject(self) end return self end; setParent = function(self, frame) - if(frame.getType~=nil and frame:getType()=="Frame")then + if (frame.getType ~= nil and frame:getType() == "Frame") then self:remove() frame:addObject(self) - if(self.draw)then - self:show() + if (self.draw) then + self:show() end end return self end; setValue = function(self, _value) - if(value~=_value)then + if (value ~= _value) then value = _value visualsChanged = true self:valueChangedHandler() end return self - end; + end; getValue = function(self) return value - end; + end; getVisualChanged = function(self) return visualsChanged - end; + end; setVisualChanged = function(self, change) visualsChanged = change or true return self - end; + end; getEventSystem = function(self) return eventSystem - end; + end; + - getParent = function(self) return self.parent - end; + end; setPosition = function(self, xPos, yPos, rel) - if(rel)then + if (rel) then self.x, self.y = self.x + xPos, self.y + yPos else self.x, self.y = xPos, yPos end visualsChanged = true return self - end; - + end; + getPosition = function(self) - return self.x,self.y + return self.x, self.y end; getVisibility = function(self) @@ -527,43 +534,52 @@ local function Object(name) -- Base object end; draw = function(self) - if(isVisible)then + if (isVisible) then return true end return false end; - getAbsolutePosition = function(self, x,y) -- relative position to absolute position - if(x==nil)then x = self.x end - if(y==nil)then y = self.y end - - if(self.parent~=nil)then - local fx,fy = self.parent:getAbsolutePosition(self.parent:getAnchorPosition()) - x=fx+x-1 - y=fy+y-1 + getAbsolutePosition = function(self, x, y) + -- relative position to absolute position + if (x == nil) then + x = self.x + end + if (y == nil) then + y = self.y + end + + if (self.parent ~= nil) then + local fx, fy = self.parent:getAbsolutePosition(self.parent:getAnchorPosition()) + x = fx + x - 1 + y = fy + y - 1 end return x, y end; - getAnchorPosition = function(self,x, y, ignOff) - if(x==nil)then x = self.x end - if(y==nil)then y = self.y end - if(hanchor=="right")then - x = self.parent.w-x-self.w+2 + getAnchorPosition = function(self, x, y, ignOff) + if (x == nil) then + x = self.x end - if(vanchor=="bottom")then - y = self.parent.h-y-self.h+2 + if (y == nil) then + y = self.y + end + if (hanchor == "right") then + x = self.parent.w - x - self.w + 2 + end + if (vanchor == "bottom") then + y = self.parent.h - y - self.h + 2 end local xO, yO = self:getOffset() - if(ignOffset or ignOff)then + if (ignOffset or ignOff) then return x, y end - return x+xO, y+yO + return x + xO, y + yO end; getOffset = function(self) - if(self.parent~=nil)and(ignOffset==false)then + if (self.parent ~= nil) and (ignOffset == false) then return self.parent:getFrameOffset() end return 0, 0 @@ -574,12 +590,12 @@ local function Object(name) -- Base object return self end; - setAnchor = function(self,...) - for _,v in pairs(table.pack(...))do - if(v=="right")or(v=="left")then + setAnchor = function(self, ...) + for _, v in pairs(table.pack(...)) do + if (v == "right") or (v == "left") then hanchor = v end - if(v=="top")or(v=="bottom")then + if (v == "top") or (v == "bottom") then vanchor = v end end @@ -589,7 +605,7 @@ local function Object(name) -- Base object getAnchor = function(self) return hanchor, vanchor - end; + end; onChange = function(self, func) self:registerEvent("value_changed", func) @@ -634,8 +650,8 @@ local function Object(name) -- Base object end; isFocused = function(self) - if(self.parent~=nil)then - return self.parent:getFocusedObject()==self + if (self.parent ~= nil) then + return self.parent:getFocusedObject() == self end return false end; @@ -663,9 +679,11 @@ local function Object(name) -- Base object end; mouseClickHandler = function(self, event, button, x, y) - local objX,objY = self:getAbsolutePosition(self:getAnchorPosition()) - if(objX<=x)and(objX+self.w>x)and(objY<=y)and(objY+self.h>y)and(isVisible)then - if(self.parent~=nil)then self.parent:setFocusedObject(self) end + local objX, objY = self:getAbsolutePosition(self:getAnchorPosition()) + if (objX <= x) and (objX + self.w > x) and (objY <= y) and (objY + self.h > y) and (isVisible) then + if (self.parent ~= nil) then + self.parent:setFocusedObject(self) + end eventSystem:sendEvent(event, self, event, button, x, y) return true end @@ -673,7 +691,7 @@ local function Object(name) -- Base object end; keyHandler = function(self, event, key) - if(self:isFocused())then + if (self:isFocused()) then eventSystem:sendEvent(event, self, event, key) return true end @@ -681,7 +699,7 @@ local function Object(name) -- Base object end; backgroundKeyHandler = function(self, event, key) - eventSystem:sendEvent("background_"..event, self, event, key) + eventSystem:sendEvent("background_" .. event, self, event, key) end; valueChangedHandler = function(self) @@ -699,15 +717,16 @@ local function Object(name) -- Base object loseFocusHandler = function(self) eventSystem:sendEvent("lose_focus", self) end; - - + + } object.__index = object return object end -local function Button(name) -- Button +local function Button(name) + -- Button local base = Object(name) local typ = "Button" @@ -719,36 +738,36 @@ local function Button(name) -- Button local textHorizontalAlign = "center" local textVerticalAlign = "center" - + local object = { getType = function(self) return typ end; - setHorizontalAlign = function (self, pos) + setHorizontalAlign = function(self, pos) textHorizontalAlign = pos end; - setVerticalAlign = function (self, pos) + setVerticalAlign = function(self, pos) textVerticalAlign = pos end; - - setText = function(self,text) + + setText = function(self, text) base:setValue(text) return self end; draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() local verticalAlign = getTextVerticalAlign(self.h, textVerticalAlign) self.parent:drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor) self.parent:drawForegroundBox(obx, oby, self.w, self.h, self.fgcolor) self.parent:drawTextBox(obx, oby, self.w, self.h, " ") - for n=1,self.h do - if(n==verticalAlign)then - self.parent:setText(obx, oby+(n-1), getTextHorizontalAlign(self:getValue(), self.w, textHorizontalAlign)) + for n = 1, self.h do + if (n == verticalAlign) then + self.parent:setText(obx, oby + (n - 1), getTextHorizontalAlign(self:getValue(), self.w, textHorizontalAlign)) end end end @@ -770,43 +789,43 @@ local function Program(name) local bgcolor, fgcolor = colors.black, colors.white local cursorBlink = false local visible = false - + local cacheT = {} local cacheBG = {} local cacheFG = {} - + local tPalette = {} - + local emptySpaceLine local emptyColorLines = {} - - for i=0,15 do + + for i = 0, 15 do local c = 2 ^ i - tPalette[c] = { parentTerminal.getPaletteColour( c ) } + tPalette[c] = { parentTerminal.getPaletteColour(c) } end - + local function createEmptyLines() emptySpaceLine = (" "):rep(w) - for n=0,15 do - local nColor = 2^n + for n = 0, 15 do + local nColor = 2 ^ n local sHex = tHex[nColor] emptyColorLines[nColor] = sHex:rep(w) end end - - local function recreateWindowArray() + + local function recreateWindowArray() createEmptyLines() local emptyText = emptySpaceLine local emptyFG = emptyColorLines[colors.white] local emptyBG = emptyColorLines[colors.black] - for n=1,h do - cacheT[n] = sub(cacheT[n] == nil and emptyText or cacheT[n]..emptyText:sub(1,w-cacheT[n]:len()),1,w) - cacheFG[n] = sub(cacheFG[n] == nil and emptyFG or cacheFG[n]..emptyFG:sub(1,w-cacheFG[n]:len()),1,w) - cacheBG[n] = sub(cacheBG[n] == nil and emptyBG or cacheBG[n]..emptyBG:sub(1,w-cacheBG[n]:len()),1,w) + for n = 1, h do + cacheT[n] = sub(cacheT[n] == nil and emptyText or cacheT[n] .. emptyText:sub(1, w - cacheT[n]:len()), 1, w) + cacheFG[n] = sub(cacheFG[n] == nil and emptyFG or cacheFG[n] .. emptyFG:sub(1, w - cacheFG[n]:len()), 1, w) + cacheBG[n] = sub(cacheBG[n] == nil and emptyBG or cacheBG[n] .. emptyBG:sub(1, w - cacheBG[n]:len()), 1, w) end end recreateWindowArray() - + local function updateCursor() if xCursor >= 1 and yCursor >= 1 and xCursor <= w and yCursor <= h then --parentTerminal.setCursorPos(xCursor + x - 1, yCursor + y - 1) @@ -815,8 +834,9 @@ local function Program(name) end --parentTerminal.setTextColor(fgcolor) end - - local function internalBlit( sText, sTextColor, sBackgroundColor ) -- copy pasti strikes again (cc: window.lua) + + local function internalBlit(sText, sTextColor, sBackgroundColor) + -- copy pasti strikes again (cc: window.lua) local nStart = xCursor local nEnd = nStart + #sText - 1 if yCursor >= 1 and yCursor <= h then @@ -831,29 +851,29 @@ local function Program(name) if nStart < 1 then local nClipStart = 1 - nStart + 1 local nClipEnd = w - nStart + 1 - sClippedText = sub( sText, nClipStart, nClipEnd ) - sClippedTextColor = sub( sTextColor, nClipStart, nClipEnd ) - sClippedBackgroundColor = sub( sBackgroundColor, nClipStart, nClipEnd ) + sClippedText = sub(sText, nClipStart, nClipEnd) + sClippedTextColor = sub(sTextColor, nClipStart, nClipEnd) + sClippedBackgroundColor = sub(sBackgroundColor, nClipStart, nClipEnd) elseif nEnd > w then local nClipEnd = w - nStart + 1 - sClippedText = sub( sText, 1, nClipEnd ) - sClippedTextColor = sub( sTextColor, 1, nClipEnd ) - sClippedBackgroundColor = sub( sBackgroundColor, 1, nClipEnd ) + sClippedText = sub(sText, 1, nClipEnd) + sClippedTextColor = sub(sTextColor, 1, nClipEnd) + sClippedBackgroundColor = sub(sBackgroundColor, 1, nClipEnd) else sClippedText = sText sClippedTextColor = sTextColor sClippedBackgroundColor = sBackgroundColor end - + local sOldText = cacheT[yCursor] local sOldTextColor = cacheFG[yCursor] local sOldBackgroundColor = cacheBG[yCursor] local sNewText, sNewTextColor, sNewBackgroundColor if nStart > 1 then local nOldEnd = nStart - 1 - sNewText = sub( sOldText, 1, nOldEnd ) .. sClippedText - sNewTextColor = sub( sOldTextColor, 1, nOldEnd ) .. sClippedTextColor - sNewBackgroundColor = sub( sOldBackgroundColor, 1, nOldEnd ) .. sClippedBackgroundColor + sNewText = sub(sOldText, 1, nOldEnd) .. sClippedText + sNewTextColor = sub(sOldTextColor, 1, nOldEnd) .. sClippedTextColor + sNewBackgroundColor = sub(sOldBackgroundColor, 1, nOldEnd) .. sClippedBackgroundColor else sNewText = sClippedText sNewTextColor = sClippedTextColor @@ -861,209 +881,228 @@ local function Program(name) end if nEnd < w then local nOldStart = nEnd + 1 - sNewText = sNewText .. sub( sOldText, nOldStart, w ) - sNewTextColor = sNewTextColor .. sub( sOldTextColor, nOldStart, w ) - sNewBackgroundColor = sNewBackgroundColor .. sub( sOldBackgroundColor, nOldStart, w ) + sNewText = sNewText .. sub(sOldText, nOldStart, w) + sNewTextColor = sNewTextColor .. sub(sOldTextColor, nOldStart, w) + sNewBackgroundColor = sNewBackgroundColor .. sub(sOldBackgroundColor, nOldStart, w) end - + cacheT[yCursor] = sNewText cacheFG[yCursor] = sNewTextColor cacheBG[yCursor] = sNewBackgroundColor end end xCursor = nEnd + 1 - if(visible)then + if (visible) then updateCursor() end end end - - local function setText(_x,_y,text) - if(text~=nil)then - local gText = cacheT[_y] - if(gText~=nil)then - cacheT[_y] = sub(gText:sub(1,_x-1)..text..gText:sub(_x+(text:len()),w),1,w) + + local function setText(_x, _y, text) + if (text ~= nil) then + local gText = cacheT[_y] + if (gText ~= nil) then + cacheT[_y] = sub(gText:sub(1, _x - 1) .. text .. gText:sub(_x + (text:len()), w), 1, w) end end end - - local function setBG(_x,_y,colorStr) - if(colorStr~=nil)then - local gBG = cacheBG[_y] - if(gBG~=nil)then - cacheBG[_y] = sub(gBG:sub(1,_x-1)..colorStr..gBG:sub(_x+(colorStr:len()),w),1,w) + + local function setBG(_x, _y, colorStr) + if (colorStr ~= nil) then + local gBG = cacheBG[_y] + if (gBG ~= nil) then + cacheBG[_y] = sub(gBG:sub(1, _x - 1) .. colorStr .. gBG:sub(_x + (colorStr:len()), w), 1, w) end end end - - local function setFG(_x,_y,colorStr) - if(colorStr~=nil)then - local gFG = cacheFG[_y] - if(gFG~=nil)then - cacheFG[_y] = sub(gFG:sub(1,_x-1)..colorStr..gFG:sub(_x+(colorStr:len()),w),1,w) + + local function setFG(_x, _y, colorStr) + if (colorStr ~= nil) then + local gFG = cacheFG[_y] + if (gFG ~= nil) then + cacheFG[_y] = sub(gFG:sub(1, _x - 1) .. colorStr .. gFG:sub(_x + (colorStr:len()), w), 1, w) end end end - + local setTextColor = function(color) - if type( color ) ~= "number" then - error( "bad argument #1 (expected number, got " .. type( color ) .. ")", 2 ) + if type(color) ~= "number" then + error("bad argument #1 (expected number, got " .. type(color) .. ")", 2) elseif tHex[color] == nil then - error( "Invalid color (got " .. color .. ")" , 2 ) + error("Invalid color (got " .. color .. ")", 2) end fgcolor = color end - + local setBackgroundColor = function(color) - if type( color ) ~= "number" then - error( "bad argument #1 (expected number, got " .. type( color ) .. ")", 2 ) + if type(color) ~= "number" then + error("bad argument #1 (expected number, got " .. type(color) .. ")", 2) elseif tHex[color] == nil then - error( "Invalid color (got " .. color .. ")" , 2 ) + error("Invalid color (got " .. color .. ")", 2) end bgcolor = color end - - local setPaletteColor = function( colour, r, g, b ) -- have to work on - if type( colour ) ~= "number" then error( "bad argument #1 (expected number, got " .. type( colour ) .. ")", 2 ) end - - if tHex[colour] == nil then - error( "Invalid color (got " .. colour .. ")" , 2 ) + + local setPaletteColor = function(colour, r, g, b) + -- have to work on + if type(colour) ~= "number" then + error("bad argument #1 (expected number, got " .. type(colour) .. ")", 2) end - + + if tHex[colour] == nil then + error("Invalid color (got " .. colour .. ")", 2) + end + local tCol if type(r) == "number" and g == nil and b == nil then - tCol = { colours.rgb8( r ) } - tPalette[ colour ] = tCol + tCol = { colours.rgb8(r) } + tPalette[colour] = tCol else - if type( r ) ~= "number" then error( "bad argument #2 (expected number, got " .. type( r ) .. ")", 2 ) end - if type( g ) ~= "number" then error( "bad argument #3 (expected number, got " .. type( g ) .. ")", 2 ) end - if type( b ) ~= "number" then error( "bad argument #4 (expected number, got " .. type( b ) .. ")", 2 ) end - - tCol = tPalette[ colour ] + if type(r) ~= "number" then + error("bad argument #2 (expected number, got " .. type(r) .. ")", 2) + end + if type(g) ~= "number" then + error("bad argument #3 (expected number, got " .. type(g) .. ")", 2) + end + if type(b) ~= "number" then + error("bad argument #4 (expected number, got " .. type(b) .. ")", 2) + end + + tCol = tPalette[colour] tCol[1] = r tCol[2] = g tCol[3] = b end end - - local getPaletteColor = function( colour ) - if type( colour ) ~= "number" then error( "bad argument #1 (expected number, got " .. type( colour ) .. ")", 2 ) end - if tHex[colour] == nil then - error( "Invalid color (got " .. colour .. ")" , 2 ) + + local getPaletteColor = function(colour) + if type(colour) ~= "number" then + error("bad argument #1 (expected number, got " .. type(colour) .. ")", 2) end - local tCol = tPalette[ colour ] + if tHex[colour] == nil then + error("Invalid color (got " .. colour .. ")", 2) + end + local tCol = tPalette[colour] return tCol[1], tCol[2], tCol[3] end - + local basaltwindow = { setCursorPos = function(_x, _y) - if type( _x ) ~= "number" then error( "bad argument #1 (expected number, got " .. type( _x ) .. ")", 2 ) end - if type( _y ) ~= "number" then error( "bad argument #2 (expected number, got " .. type( _y ) .. ")", 2 ) end + if type(_x) ~= "number" then + error("bad argument #1 (expected number, got " .. type(_x) .. ")", 2) + end + if type(_y) ~= "number" then + error("bad argument #2 (expected number, got " .. type(_y) .. ")", 2) + end xCursor = math.floor(_x) yCursor = math.floor(_y) - if(visible)then + if (visible) then updateCursor() end end; - + getCursorPos = function() return xCursor, yCursor end; - + setCursorBlink = function(blink) - if type( blink ) ~= "boolean" then error( "bad argument #1 (expected boolean, got " .. type( blink ) .. ")", 2 ) end + if type(blink) ~= "boolean" then + error("bad argument #1 (expected boolean, got " .. type(blink) .. ")", 2) + end cursorBlink = blink end; - + getCursorBlink = function() return cursorBlink end; - - + + getPaletteColor = getPaletteColor, getPaletteColour = getPaletteColor, - + setBackgroundColor = setBackgroundColor, setBackgroundColour = setBackgroundColor, - + setTextColor = setTextColor, setTextColour = setTextColor, - + setPaletteColor = setPaletteColor, setPaletteColour = setPaletteColor, - + getBackgroundColor = function() return bgcolor end; getBackgroundColour = function() return bgcolor end; - + getSize = function() return w, h end; - + getTextColor = function() return fgcolor end; getTextColour = function() return fgcolor end; - + basalt_resize = function(_w, _h) w, h = _w, _h recreateWindowArray() end; - + basalt_reposition = function(_x, _y) x, y = _x, _y end; - + basalt_setVisible = function(vis) visible = vis end; - - drawBackgroundBox = function (_x, _y, _w, _h, bgCol) + + drawBackgroundBox = function(_x, _y, _w, _h, bgCol) for n = 1, _h do - setBG(_x, _y + (n-1), tHex[bgCol]:rep(_w)) + setBG(_x, _y + (n - 1), tHex[bgCol]:rep(_w)) end end; - drawForegroundBox = function (_x, _y, _w, _h, fgCol) + drawForegroundBox = function(_x, _y, _w, _h, fgCol) for n = 1, _h do - setFG(_x, _y + (n-1), tHex[fgCol]:rep(_w)) + setFG(_x, _y + (n - 1), tHex[fgCol]:rep(_w)) end end; - drawTextBox = function (_x, _y, _w, _h, symbol) + drawTextBox = function(_x, _y, _w, _h, symbol) for n = 1, _h do - setText(_x, _y + (n-1), symbol:rep(_w)) + setText(_x, _y + (n - 1), symbol:rep(_w)) end end; - writeText = function (_x, _y, text, bgCol, fgCol) + writeText = function(_x, _y, text, bgCol, fgCol) bgCol = bgCol or bgcolor fgCol = fgCol or fgcolor setText(x, _y, text) setBG(_x, _y, tHex[bgCol]:rep(text:len())) setFG(_x, _y, tHex[fgCol]:rep(text:len())) end; - + basalt_update = function() - if(object.parent~=nil)then - for n=1, h do - object.parent:setText(x, y + (n-1), cacheT[n]) - object.parent:setBG(x, y + (n-1), cacheBG[n]) - object.parent:setFG(x, y + (n-1), cacheFG[n]) + if (object.parent ~= nil) then + for n = 1, h do + object.parent:setText(x, y + (n - 1), cacheT[n]) + object.parent:setBG(x, y + (n - 1), cacheBG[n]) + object.parent:setFG(x, y + (n - 1), cacheFG[n]) end end end; - - scroll = function (offset) - if type( offset ) ~= "number" then error( "bad argument #1 (expected number, got " .. type( offset ) .. ")", 2 ) end + + scroll = function(offset) + if type(offset) ~= "number" then + error("bad argument #1 (expected number, got " .. type(offset) .. ")", 2) + end if offset ~= 0 then local sEmptyText = emptySpaceLine - local sEmptyTextColor = emptyColorLines[ fgcolor ] - local sEmptyBackgroundColor = emptyColorLines[ bgcolor ] - for newY=1,h do + local sEmptyTextColor = emptyColorLines[fgcolor] + local sEmptyBackgroundColor = emptyColorLines[bgcolor] + for newY = 1, h do local y = newY + offset if y >= 1 and y <= h then cacheT[newY] = cacheT[y] @@ -1076,57 +1115,63 @@ local function Program(name) end end end - if(visible)then + if (visible) then updateCursor() end end; - - + + isColor = function() return parentTerminal.isColor() end; - + isColour = function() return parentTerminal.isColor() end; - + write = function(text) text = tostring(text) - if(visible)then - internalBlit( text, tHex[fgcolor]:rep(text:len()), tHex[bgcolor]:rep(text:len())) + if (visible) then + internalBlit(text, tHex[fgcolor]:rep(text:len()), tHex[bgcolor]:rep(text:len())) end end; - + clearLine = function() - if(visible)then + if (visible) then setText(1, yCursor, (" "):rep(w)) setBG(1, yCursor, tHex[bgcolor]:rep(w)) setFG(1, yCursor, tHex[fgcolor]:rep(w)) end - if(visible)then + if (visible) then updateCursor() end end; - + clear = function() - for n=1,h do + for n = 1, h do setText(1, n, (" "):rep(w)) setBG(1, n, tHex[bgcolor]:rep(w)) setFG(1, n, tHex[fgcolor]:rep(w)) end - if(visible)then + if (visible) then updateCursor() end end; - + blit = function(text, fgcol, bgcol) - if type( text ) ~= "string" then error( "bad argument #1 (expected string, got " .. type( text ) .. ")", 2 ) end - if type( fgcol ) ~= "string" then error( "bad argument #2 (expected string, got " .. type( fgcol ) .. ")", 2 ) end - if type( bgcol ) ~= "string" then error( "bad argument #3 (expected string, got " .. type( bgcol ) .. ")", 2 ) end - if #fgcol ~= #text or #bgcol ~= #text then - error( "Arguments must be the same length", 2 ) + if type(text) ~= "string" then + error("bad argument #1 (expected string, got " .. type(text) .. ")", 2) end - if(visible)then + if type(fgcol) ~= "string" then + error("bad argument #2 (expected string, got " .. type(fgcol) .. ")", 2) + end + if type(bgcol) ~= "string" then + error("bad argument #3 (expected string, got " .. type(bgcol) .. ")", 2) + end + if #fgcol ~= #text or #bgcol ~= #text then + error("Arguments must be the same length", 2) + end + if (visible) then --setText(xCursor, yCursor, text) --setBG(xCursor, yCursor, bgcol) --setFG(xCursor, yCursor, fgcol) @@ -1134,10 +1179,10 @@ local function Program(name) internalBlit(text, fgcol, bgcol) end end - - + + } - + return basaltwindow end @@ -1168,7 +1213,7 @@ local function Program(name) end; setPosition = function(self, x, y, rel) - base.setPosition(self,x,y, rel) + base.setPosition(self, x, y, rel) pWindow.basalt_reposition(self:getAnchorPosition()) return self end; @@ -1182,13 +1227,13 @@ local function Program(name) end; setSize = function(self, w, h) - base.setSize(self,w,h) + base.setSize(self, w, h) pWindow.basalt_resize(self.w, self.h) return self end; getStatus = function(self) - if(curProcess~=nil)then + if (curProcess ~= nil) then return curProcess:getStatus() end return "inactive" @@ -1206,11 +1251,11 @@ local function Program(name) end; stop = function(self) - if(curProcess~=nil)then - if not(curProcess:isDead())then + if (curProcess ~= nil) then + if not (curProcess:isDead()) then curProcess:resume("terminate") - if(curProcess:isDead())then - if(self.parent~=nil)then + if (curProcess:isDead()) then + if (self.parent ~= nil) then self.parent:setCursor(false) end end @@ -1221,9 +1266,9 @@ local function Program(name) pause = function(self, p) paused = p or (not paused) - if(curProcess~=nil)then - if not(curProcess:isDead())then - if not(paused)then + if (curProcess ~= nil) then + if not (curProcess:isDead()) then + if not (paused) then self:injectEvents(queuedEvent) queuedEvent = {} end @@ -1237,12 +1282,12 @@ local function Program(name) end; injectEvent = function(self, event, p1, p2, p3, p4, ign) - if(curProcess~=nil)then - if not(curProcess:isDead())then - if (paused==false)or(ign)then - curProcess:resume(event,p1,p2,p3,p4) + if (curProcess ~= nil) then + if not (curProcess:isDead()) then + if (paused == false) or (ign) then + curProcess:resume(event, p1, p2, p3, p4) else - table.insert(queuedEvent, {event=event, args = {p1,p2,p3,p4}}) + table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } }) end end end @@ -1259,9 +1304,9 @@ local function Program(name) end; injectEvents = function(self, events) - if(curProcess~=nil)then - if not(curProcess:isDead())then - for _,v in pairs(events)do + if (curProcess ~= nil) then + if not (curProcess:isDead()) then + for _, v in pairs(events) do curProcess:resume(v.event, table.unpack(v.args)) end end @@ -1270,12 +1315,14 @@ local function Program(name) end; mouseClickHandler = function(self, event, button, x, y) - if(base.mouseClickHandler(self,event,button,x,y))then - if(curProcess==nil)then return false end - if not(curProcess:isDead())then - if not(paused)then - local absX,absY = self:getAbsolutePosition(self:getAnchorPosition(nil,nil,true)) - curProcess:resume(event, button, x-absX+1, y-absY+1) + if (base.mouseClickHandler(self, event, button, x, y)) then + if (curProcess == nil) then + return false + end + if not (curProcess:isDead()) then + if not (paused) then + local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true)) + curProcess:resume(event, button, x - absX + 1, y - absY + 1) end end return true @@ -1284,11 +1331,13 @@ local function Program(name) keyHandler = function(self, event, key) base.keyHandler(self, event, key) - if(self:isFocused())then - if(curProcess==nil)then return false end - if not(curProcess:isDead())then - if not(paused)then - if(self.draw)then + if (self:isFocused()) then + if (curProcess == nil) then + return false + end + if not (curProcess:isDead()) then + if not (paused) then + if (self.draw) then curProcess:resume(event, key) end end @@ -1298,14 +1347,14 @@ local function Program(name) getFocusHandler = function(self) base.getFocusHandler(self) - if(curProcess~=nil)then - if not(curProcess:isDead())then - if not(paused)then - if(self.parent~=nil)then + if (curProcess ~= nil) then + if not (curProcess:isDead()) then + if not (paused) then + if (self.parent ~= nil) then local xCur, yCur = pWindow.getCursorPos() local obx, oby = self:getAnchorPosition() - if(self.parent~=nil)then - if(obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + self.w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + self.h - 1)then + if (self.parent ~= nil) then + if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + self.w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + self.h - 1) then self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor()) end end @@ -1317,9 +1366,9 @@ local function Program(name) loseFocusHandler = function(self) base.loseFocusHandler(self) - if(curProcess~=nil)then - if not(curProcess:isDead())then - if(self.parent~=nil)then + if (curProcess ~= nil) then + if not (curProcess:isDead()) then + if (self.parent ~= nil) then self.parent:setCursor(false) end end @@ -1327,50 +1376,53 @@ local function Program(name) end; eventHandler = function(self, event, p1, p2, p3, p4) - if(curProcess==nil)then return end - if not(curProcess:isDead())then - if not(paused)then - if(event~="mouse_click")and(event~="mouse_up")and(event~="mouse_scroll")and(event~="mouse_drag")and(event~="key_up")and(event~="key")and(event~="char")and(event~="terminate")then - curProcess:resume(event,p1,p2,p3,p4) + if (curProcess == nil) then + return + end + if not (curProcess:isDead()) then + if not (paused) then + if (event ~= "mouse_click") and (event ~= "mouse_up") and (event ~= "mouse_scroll") and (event ~= "mouse_drag") and (event ~= "key_up") and (event ~= "key") and (event ~= "char") and (event ~= "terminate") then + curProcess:resume(event, p1, p2, p3, p4) end - if(self:isFocused())then + if (self:isFocused()) then local obx, oby = self:getAnchorPosition() local xCur, yCur = pWindow.getCursorPos() - if(self.parent~=nil)then - if(obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + self.w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + self.h - 1)then + if (self.parent ~= nil) then + if (obx + xCur - 1 >= 1 and obx + xCur - 1 <= obx + self.w - 1 and yCur + oby - 1 >= 1 and yCur + oby - 1 <= oby + self.h - 1) then self.parent:setCursor(pWindow.getCursorBlink(), obx + xCur - 1, yCur + oby - 1, pWindow.getTextColor()) end end - if(event=="terminate")and(self:isFocused())then + if (event == "terminate") and (self:isFocused()) then self:stop() end end else - if(event~="mouse_click")and(event~="mouse_up")and(event~="mouse_scroll")and(event~="mouse_drag")and(event~="key_up")and(event~="key")and(event~="char")and(event~="terminate")then - table.insert(queuedEvent, {event=event, args = {p1,p2,p3,p4}}) + if (event ~= "mouse_click") and (event ~= "mouse_up") and (event ~= "mouse_scroll") and (event ~= "mouse_drag") and (event ~= "key_up") and (event ~= "key") and (event ~= "char") and (event ~= "terminate") then + table.insert(queuedEvent, { event = event, args = { p1, p2, p3, p4 } }) end end end end; draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() - pWindow.basalt_reposition(obx,oby) + pWindow.basalt_reposition(obx, oby) self.parent:drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor) pWindow.basalt_update() end end end; - + } return setmetatable(object, base) end -local function Label(name) -- Label +local function Label(name) + -- Label local base = Object(name) local typ = "Label" @@ -1383,24 +1435,24 @@ local function Label(name) -- Label getType = function(self) return typ end; - setText = function(self,text) + setText = function(self, text) text = tostring(text) base:setValue(text) - if(autoWidth)then + if (autoWidth) then self.w = text:len() end return self end; - setSize = function(self,w,h) + setSize = function(self, w, h) self.w, self.h = w, h autoWidth = false return self end; draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() self.parent:writeText(obx, oby, self:getValue(), self.bgcolor, self.fgcolor) end @@ -1412,19 +1464,19 @@ local function Label(name) -- Label return setmetatable(object, base) end -local function Pane(name) -- Pane +local function Pane(name) + -- Pane local base = Object(name) local typ = "Pane" - local object = { getType = function(self) return typ end; draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() self.parent:drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor) self.parent:drawForegroundBox(obx, oby, self.w, self.h, self.bgcolor) @@ -1437,7 +1489,8 @@ local function Pane(name) -- Pane return setmetatable(object, base) end -local function Image(name) -- Pane +local function Image(name) + -- Pane local base = Object(name) local typ = "Image" base:setZIndex(2) @@ -1448,98 +1501,122 @@ local function Image(name) -- Pane local function shrink() -- shrinkSystem is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/ - local relations = {[0] = {8, 4, 3, 6, 5}, {4, 14, 8, 7}, {6, 10, 8, 7}, {9, 11, 8, 0}, {1, 14, 8, 0}, {13, 12, 8, 0}, {2, 10, 8, 0}, {15, 8, 10, 11, 12, 14}, - {0, 7, 1, 9, 2, 13}, {3, 11, 8, 7}, {2, 6, 7, 15}, {9, 3, 7, 15}, {13, 5, 7, 15}, {5, 12, 8, 7}, {1, 4, 7, 15}, {7, 10, 11, 12, 14}} + local relations = { [0] = { 8, 4, 3, 6, 5 }, { 4, 14, 8, 7 }, { 6, 10, 8, 7 }, { 9, 11, 8, 0 }, { 1, 14, 8, 0 }, { 13, 12, 8, 0 }, { 2, 10, 8, 0 }, { 15, 8, 10, 11, 12, 14 }, + { 0, 7, 1, 9, 2, 13 }, { 3, 11, 8, 7 }, { 2, 6, 7, 15 }, { 9, 3, 7, 15 }, { 13, 5, 7, 15 }, { 5, 12, 8, 7 }, { 1, 4, 7, 15 }, { 7, 10, 11, 12, 14 } } -local colourNum, exponents, colourChar = {}, {}, {} -for i = 0, 15 do exponents[2^i] = i end -do - local hex = "0123456789abcdef" - for i = 1, 16 do - colourNum[hex:sub(i, i)] = i - 1 - colourNum[i - 1] = hex:sub(i, i) - colourChar[hex:sub(i, i)] = 2 ^ (i - 1) - colourChar[2 ^ (i - 1)] = hex:sub(i, i) - - local thisRel = relations[i - 1] - for i = 1, #thisRel do thisRel[i] = 2 ^ thisRel[i] end - end -end - -local function getBestColourMatch(usage) - local lastCol = relations[exponents[usage[#usage][1]]] - - for j = 1, #lastCol do - local thisRelation = lastCol[j] - for i = 1, #usage - 1 do if usage[i][1] == thisRelation then return i end end - end - - return 1 -end - -local function colsToChar(pattern, totals) - if not totals then - local newPattern = {} - totals = {} - for i = 1, 6 do - local thisVal = pattern[i] - local thisTot = totals[thisVal] - totals[thisVal], newPattern[i] = thisTot and (thisTot + 1) or 1, thisVal + local colourNum, exponents, colourChar = {}, {}, {} + for i = 0, 15 do + exponents[2 ^ i] = i + end + do + local hex = "0123456789abcdef" + for i = 1, 16 do + colourNum[hex:sub(i, i)] = i - 1 + colourNum[i - 1] = hex:sub(i, i) + colourChar[hex:sub(i, i)] = 2 ^ (i - 1) + colourChar[2 ^ (i - 1)] = hex:sub(i, i) + + local thisRel = relations[i - 1] + for i = 1, #thisRel do + thisRel[i] = 2 ^ thisRel[i] + end + end + end + + local function getBestColourMatch(usage) + local lastCol = relations[exponents[usage[#usage][1]]] + + for j = 1, #lastCol do + local thisRelation = lastCol[j] + for i = 1, #usage - 1 do + if usage[i][1] == thisRelation then + return i + end + end + end + + return 1 + end + + local function colsToChar(pattern, totals) + if not totals then + local newPattern = {} + totals = {} + for i = 1, 6 do + local thisVal = pattern[i] + local thisTot = totals[thisVal] + totals[thisVal], newPattern[i] = thisTot and (thisTot + 1) or 1, thisVal + end + pattern = newPattern + end + + local usage = {} + for key, value in pairs(totals) do + usage[#usage + 1] = { key, value } + end + + if #usage > 1 then + -- Reduce the chunk to two colours: + while #usage > 2 do + table.sort(usage, function(a, b) + return a[2] > b[2] + end) + local matchToInd, usageLen = getBestColourMatch(usage), #usage + local matchFrom, matchTo = usage[usageLen][1], usage[matchToInd][1] + for i = 1, 6 do + if pattern[i] == matchFrom then + pattern[i] = matchTo + usage[matchToInd][2] = usage[matchToInd][2] + 1 + end + end + usage[usageLen] = nil + end + + -- Convert to character. Adapted from oli414's function: + -- http://www.computercraft.info/forums2/index.php?/topic/25340-cc-176-easy-drawing-characters/ + local data = 128 + for i = 1, #pattern - 1 do + if pattern[i] ~= pattern[6] then + data = data + 2 ^ (i - 1) + end + end + return string.char(data), colourChar[usage[1][1] == pattern[6] and usage[2][1] or usage[1][1]], colourChar[pattern[6]] + else + -- Solid colour character: + return "\128", colourChar[pattern[1]], colourChar[pattern[1]] + end + end + + local results, width, height, bgCol = { {}, {}, {} }, 0, #image + #image % 3, base.bgcolor or colors.black + for i = 1, #image do + if #image[i] > width then + width = #image[i] + end end - pattern = newPattern - end - - local usage = {} - for key, value in pairs(totals) do usage[#usage + 1] = {key, value} end - - if #usage > 1 then - -- Reduce the chunk to two colours: - while #usage > 2 do - table.sort(usage, function (a, b) return a[2] > b[2] end) - local matchToInd, usageLen = getBestColourMatch(usage), #usage - local matchFrom, matchTo = usage[usageLen][1], usage[matchToInd][1] - for i = 1, 6 do if pattern[i] == matchFrom then - pattern[i] = matchTo - usage[matchToInd][2] = usage[matchToInd][2] + 1 - end end - usage[usageLen] = nil - end - - -- Convert to character. Adapted from oli414's function: - -- http://www.computercraft.info/forums2/index.php?/topic/25340-cc-176-easy-drawing-characters/ - local data = 128 - for i = 1, #pattern - 1 do if pattern[i] ~= pattern[6] then data = data + 2^(i-1) end end - return string.char(data), colourChar[usage[1][1] == pattern[6] and usage[2][1] or usage[1][1]], colourChar[pattern[6]] - else - -- Solid colour character: - return "\128", colourChar[pattern[1]], colourChar[pattern[1]] - end -end - local results, width, height, bgCol = {{}, {}, {}}, 0, #image + #image % 3, base.bgcolor or colors.black - for i = 1, #image do if #image[i] > width then width = #image[i] end end - for y = 0, height - 1, 3 do local cRow, tRow, bRow, counter = {}, {}, {}, 1 - + for x = 0, width - 1, 2 do -- Grab a 2x3 chunk: local pattern, totals = {}, {} - - for yy = 1, 3 do for xx = 1, 2 do - pattern[#pattern + 1] = (image[y + yy] and image[y + yy][x + xx]) and (image[y + yy][x + xx] == 0 and bgCol or image[y + yy][x + xx]) or bgCol - totals[pattern[#pattern]] = totals[pattern[#pattern]] and (totals[pattern[#pattern]] + 1) or 1 - end end - + + for yy = 1, 3 do + for xx = 1, 2 do + pattern[#pattern + 1] = (image[y + yy] and image[y + yy][x + xx]) and (image[y + yy][x + xx] == 0 and bgCol or image[y + yy][x + xx]) or bgCol + totals[pattern[#pattern]] = totals[pattern[#pattern]] and (totals[pattern[#pattern]] + 1) or 1 + end + end + cRow[counter], tRow[counter], bRow[counter] = colsToChar(pattern, totals) counter = counter + 1 end - + results[1][#results[1] + 1], results[2][#results[2] + 1], results[3][#results[3] + 1] = table.concat(cRow), table.concat(tRow), table.concat(bRow) end - + results.width, results.height = #results[1][1], #results[1] - + shrinkedImage = results end @@ -1567,11 +1644,12 @@ end end; draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then - if(image~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then + if (image ~= nil) then local obx, oby = self:getAnchorPosition() - if(imageGotShrinked)then -- this is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/ + if (imageGotShrinked) then + -- this is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/ local t, tC, bC = shrinkedImage[1], shrinkedImage[2], shrinkedImage[3] for i = 1, shrinkedImage.height do local tI = t[i] @@ -1586,9 +1664,9 @@ end end end else - for yPos=1,math.min(#image, self.h) do + for yPos = 1, math.min(#image, self.h) do local line = image[yPos] - for xPos=1,math.min(#line, self.w) do + for xPos = 1, math.min(#line, self.w) do if line[xPos] > 0 then self.parent:drawBackgroundBox(obx + xPos - 1, oby + yPos - 1, 1, 1, line[xPos]) end @@ -1604,7 +1682,8 @@ end return setmetatable(object, base) end -local function Checkbox(name) -- Checkbox +local function Checkbox(name) + -- Checkbox local base = Object(name) local typ = "Checkbox" @@ -1623,9 +1702,9 @@ local function Checkbox(name) -- Checkbox end; mouseClickHandler = function(self, event, button, x, y) - if(base.mouseClickHandler(self, event, button, x, y))then - if(event == "mouse_click")and(button == 1)then - if(self:getValue()~=true)and(self:getValue()~=false)then + if (base.mouseClickHandler(self, event, button, x, y)) then + if (event == "mouse_click") and (button == 1) then + if (self:getValue() ~= true) and (self:getValue() ~= false) then self:setValue(false) else self:setValue(not self:getValue()) @@ -1637,18 +1716,18 @@ local function Checkbox(name) -- Checkbox end; draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() local verticalAlign = getTextVerticalAlign(self.h, "center") self.parent:drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor) - for n=1,self.h do - if(n==verticalAlign)then - if(self:getValue()==true)then - self.parent:writeText(obx, oby+(n-1), getTextHorizontalAlign(self.symbol, self.w, "center"), self.bgcolor, self.fgcolor) + for n = 1, self.h do + if (n == verticalAlign) then + if (self:getValue() == true) then + self.parent:writeText(obx, oby + (n - 1), getTextHorizontalAlign(self.symbol, self.w, "center"), self.bgcolor, self.fgcolor) else - self.parent:writeText(obx, oby+(n-1), getTextHorizontalAlign(" ", self.w, "center"), self.bgcolor, self.fgcolor) + self.parent:writeText(obx, oby + (n - 1), getTextHorizontalAlign(" ", self.w, "center"), self.bgcolor, self.fgcolor) end end end @@ -1661,7 +1740,8 @@ local function Checkbox(name) -- Checkbox return setmetatable(object, base) end -local function Progressbar(name) -- Checkbox +local function Progressbar(name) + -- Checkbox local base = Object(name) local typ = "Progressbar" @@ -1699,15 +1779,15 @@ local function Progressbar(name) -- Checkbox end; setBackgroundSymbol = function(self, symbol) - bgBarSymbol = symbol:sub(1,1) + bgBarSymbol = symbol:sub(1, 1) return self end; setProgress = function(self, value) - if(value>=0)and(value<=100)and(progress~=value)then + if (value >= 0) and (value <= 100) and (progress ~= value) then progress = value self:setValue(progress) - if(progress==100)then + if (progress == 100) then self:progressDoneHandler() end end @@ -1728,28 +1808,28 @@ local function Progressbar(name) -- Checkbox end; draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() self.parent:drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor) self.parent:drawForegroundBox(obx, oby, self.w, self.h, self.fgcolor) self.parent:drawTextBox(obx, oby, self.w, self.h, bgBarSymbol) - if(direction==1)then - self.parent:drawBackgroundBox(obx, oby, self.w, self.h/100*progress, activeBarColor) - self.parent:drawForegroundBox(obx, oby, self.w, self.h/100*progress, activeBarSymbolCol) - self.parent:drawTextBox(obx, oby, self.w, self.h/100*progress, activeBarSymbol) - elseif(direction==2)then - self.parent:drawBackgroundBox(obx, oby+math.ceil(self.h-self.h/100*progress), self.w, self.h/100*progress, activeBarColor) - self.parent:drawForegroundBox(obx, oby+math.ceil(self.h-self.h/100*progress), self.w, self.h/100*progress, activeBarSymbolCol) - self.parent:drawTextBox(obx, oby+math.ceil(self.h-self.h/100*progress), self.w, self.h/100*progress, activeBarSymbol) - elseif(direction==3)then - self.parent:drawBackgroundBox(obx+math.ceil(self.w-self.w/100*progress), oby, self.w/100*progress, self.h, activeBarColor) - self.parent:drawForegroundBox(obx+math.ceil(self.w-self.w/100*progress), oby, self.w/100*progress, self.h, activeBarSymbolCol) - self.parent:drawTextBox(obx+math.ceil(self.w-self.w/100*progress), oby, self.w/100*progress, self.h, activeBarSymbol) + if (direction == 1) then + self.parent:drawBackgroundBox(obx, oby, self.w, self.h / 100 * progress, activeBarColor) + self.parent:drawForegroundBox(obx, oby, self.w, self.h / 100 * progress, activeBarSymbolCol) + self.parent:drawTextBox(obx, oby, self.w, self.h / 100 * progress, activeBarSymbol) + elseif (direction == 2) then + self.parent:drawBackgroundBox(obx, oby + math.ceil(self.h - self.h / 100 * progress), self.w, self.h / 100 * progress, activeBarColor) + self.parent:drawForegroundBox(obx, oby + math.ceil(self.h - self.h / 100 * progress), self.w, self.h / 100 * progress, activeBarSymbolCol) + self.parent:drawTextBox(obx, oby + math.ceil(self.h - self.h / 100 * progress), self.w, self.h / 100 * progress, activeBarSymbol) + elseif (direction == 3) then + self.parent:drawBackgroundBox(obx + math.ceil(self.w - self.w / 100 * progress), oby, self.w / 100 * progress, self.h, activeBarColor) + self.parent:drawForegroundBox(obx + math.ceil(self.w - self.w / 100 * progress), oby, self.w / 100 * progress, self.h, activeBarSymbolCol) + self.parent:drawTextBox(obx + math.ceil(self.w - self.w / 100 * progress), oby, self.w / 100 * progress, self.h, activeBarSymbol) else - self.parent:drawBackgroundBox(obx, oby, self.w/100*progress, self.h, activeBarColor) - self.parent:drawForegroundBox(obx, oby, self.w/100*progress, self.h, activeBarSymbolCol) - self.parent:drawTextBox(obx, oby, self.w/100*progress, self.h, activeBarSymbol) + self.parent:drawBackgroundBox(obx, oby, self.w / 100 * progress, self.h, activeBarColor) + self.parent:drawForegroundBox(obx, oby, self.w / 100 * progress, self.h, activeBarSymbolCol) + self.parent:drawTextBox(obx, oby, self.w / 100 * progress, self.h, activeBarSymbol) end end end @@ -1760,7 +1840,8 @@ local function Progressbar(name) -- Checkbox return setmetatable(object, base) end -local function Input(name) -- Input +local function Input(name) + -- Input local base = Object(name) local typ = "Input" @@ -1789,7 +1870,7 @@ local function Input(name) -- Input end; setInputType = function(self, iType) - if(iType=="password")or(iType=="number")or(iType=="text")then + if (iType == "password") or (iType == "number") or (iType == "text") then inputType = iType end return self @@ -1799,7 +1880,7 @@ local function Input(name) -- Input defaultText = text defaultBGCol = bCol or defaultBGCol defaultFGCol = fCol or defaultFGCol - if(self:isFocused())then + if (self:isFocused()) then showingText = "" else showingText = defaultText @@ -1813,15 +1894,15 @@ local function Input(name) -- Input setValue = function(self, val) base.setValue(self, tostring(val)) - if not(internalValueChange)then - textX = tostring(val):len()+1 + if not (internalValueChange) then + textX = tostring(val):len() + 1 end return self end; getValue = function(self) local val = base.getValue(self) - return inputType == "number" and tonumber(val)or val + return inputType == "number" and tonumber(val) or val end; setInputLimit = function(self, limit) @@ -1835,105 +1916,123 @@ local function Input(name) -- Input getFocusHandler = function(self) base.getFocusHandler(self) - if(self.parent~=nil)then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() showingText = "" - if(self.parent~=nil)then - self.parent:setCursor(true, obx+textX-wIndex, oby, self.fgcolor) + if (self.parent ~= nil) then + self.parent:setCursor(true, obx + textX - wIndex, oby, self.fgcolor) end end end; loseFocusHandler = function(self) base.loseFocusHandler(self) - if(self.parent~=nil)then + if (self.parent ~= nil) then self.parent:setCursor(false) showingText = defaultText end end; keyHandler = function(self, event, key) - if(base.keyHandler(self, event, key))then + if (base.keyHandler(self, event, key)) then internalValueChange = true - if(event=="key")then - if(key==keys.backspace)then -- on backspace + if (event == "key") then + if (key == keys.backspace) then + -- on backspace local text = tostring(base.getValue()) - if(textX>1)then - self:setValue(text:sub(1,textX-2)..text:sub(textX,text:len())) - if(textX>1)then textX = textX-1 end - if(wIndex>1)then - if(textX 1) then + self:setValue(text:sub(1, textX - 2) .. text:sub(textX, text:len())) + if (textX > 1) then + textX = textX - 1 + end + if (wIndex > 1) then + if (textX < wIndex) then + wIndex = wIndex - 1 end end end end - if(key==keys.enter)then -- on enter - if(self.parent~=nil)then + if (key == keys.enter) then + -- on enter + if (self.parent ~= nil) then --self.parent:removeFocusedObject(self) end end - if(key==keys.right)then -- right arrow + if (key == keys.right) then + -- right arrow local tLength = tostring(base.getValue()):len() - textX = textX+1 + textX = textX + 1 - if(textX > tLength)then - textX = tLength+1 + if (textX > tLength) then + textX = tLength + 1 + end + if (textX < 1) then + textX = 1 + end + if (textX < wIndex) or (textX >= self.w + wIndex) then + wIndex = textX - self.w + 1 + end + if (wIndex < 1) then + wIndex = 1 end - if(textX<1)then textX = 1 end - if(textX=self.w+wIndex)then - wIndex = textX-self.w+1 - end - if(wIndex<1)then wIndex = 1 end end - if(key==keys.left)then -- left arrow - textX = textX-1 - if(textX>=1)then - if(textX=self.w+wIndex)then + if (key == keys.left) then + -- left arrow + textX = textX - 1 + if (textX >= 1) then + if (textX < wIndex) or (textX >= self.w + wIndex) then wIndex = textX end end - if(textX<1)then textX = 1 end - if(wIndex<1)then wIndex = 1 end + if (textX < 1) then + textX = 1 + end + if (wIndex < 1) then + wIndex = 1 + end end end - if(event=="char")then + if (event == "char") then local text = base.getValue() - if(text:len() < inputLimit or inputLimit <= 0)then - if(inputType=="number")then + if (text:len() < inputLimit or inputLimit <= 0) then + if (inputType == "number") then local cache = text - if (key==".")or(tonumber(key)~=nil)then - self:setValue(text:sub(1,textX-1)..key..text:sub(textX,text:len())) + if (key == ".") or (tonumber(key) ~= nil) then + self:setValue(text:sub(1, textX - 1) .. key .. text:sub(textX, text:len())) textX = textX + 1 end - if(tonumber(base.getValue())==nil)then + if (tonumber(base.getValue()) == nil) then self:setValue(cache) end else - self:setValue(text:sub(1,textX-1)..key..text:sub(textX,text:len())) + self:setValue(text:sub(1, textX - 1) .. key .. text:sub(textX, text:len())) textX = textX + 1 end - if(textX>=self.w+wIndex)then wIndex = wIndex+1 end + if (textX >= self.w + wIndex) then + wIndex = wIndex + 1 + end end end - local obx,oby = self:getAnchorPosition() + local obx, oby = self:getAnchorPosition() local val = tostring(base.getValue()) - local cursorX = (textX <= val:len() and textX-1 or val:len())-(wIndex-1) + local cursorX = (textX <= val:len() and textX - 1 or val:len()) - (wIndex - 1) - if(cursorX>self.x+self.w-1)then cursorX = self.x+self.w-1 end - if(self.parent~=nil)then - self.parent:setCursor(true, obx+cursorX, oby, self.fgcolor) + if (cursorX > self.x + self.w - 1) then + cursorX = self.x + self.w - 1 + end + if (self.parent ~= nil) then + self.parent:setCursor(true, obx + cursorX, oby, self.fgcolor) end internalValueChange = false end end; mouseClickHandler = function(self, event, button, x, y) - if(base.mouseClickHandler(self, event, button, x, y))then - if(event == "mouse_click")and(button == 1)then - + if (base.mouseClickHandler(self, event, button, x, y)) then + if (event == "mouse_click") and (button == 1) then + end return true end @@ -1941,32 +2040,38 @@ local function Input(name) -- Input end; draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() local verticalAlign = getTextVerticalAlign(self.h, "center") self.parent:drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor) - for n=1,self.h do - if(n==verticalAlign)then + for n = 1, self.h do + if (n == verticalAlign) then local val = tostring(base.getValue()) local bCol = self.bgcolor local fCol = self.fgcolor local text - if(val:len()<=0)then text = showingText bCol = defaultBGCol or bCol fCol = defaultFGCol or fCol end + if (val:len() <= 0) then + text = showingText + bCol = defaultBGCol or bCol + fCol = defaultFGCol or fCol + end text = showingText - if(val~="")then + if (val ~= "") then text = val end - text = text:sub(wIndex, self.w+wIndex-1) - local space = self.w-text:len() - if(space<0)then space = 0 end - if(inputType=="password")and(val~="")then + text = text:sub(wIndex, self.w + wIndex - 1) + local space = self.w - text:len() + if (space < 0) then + space = 0 + end + if (inputType == "password") and (val ~= "") then text = string.rep("*", text:len()) end - text = text..string.rep(" ", space) - self.parent:writeText(obx, oby+(n-1), text, bCol, fCol) + text = text .. string.rep(" ", space) + self.parent:writeText(obx, oby + (n - 1), text, bCol, fCol) end end end @@ -1981,9 +2086,9 @@ local function Textfield(name) local base = Object(name) local typ = "Textfield" local hIndex, wIndex, textX, textY = 1, 1, 1, 1 - - local lines = {""} - local keyWords = {[colors.purple] = {"break"}} + + local lines = { "" } + local keyWords = { [colors.purple] = { "break" } } base.w = 20 base.h = 8 @@ -1996,21 +2101,21 @@ local function Textfield(name) return typ end; - getLines = function (self) + getLines = function(self) return lines end; - getLine = function (self, index) + getLine = function(self, index) return lines[index] or "" end; - editLine = function (self, index, text) + editLine = function(self, index, text) lines[index] = text or lines[index] return self end; - addLine = function (self, text, index) - if(index~=nil)then + addLine = function(self, text, index) + if (index ~= nil) then table.insert(lines, index, text) else table.insert(lines, text) @@ -2024,218 +2129,259 @@ local function Textfield(name) removeLine = function(self, index) table.remove(lines, index or #lines) - if(#lines <= 0)then + if (#lines <= 0) then table.insert(lines, "") end return self end; - getTextCursor = function (self) + getTextCursor = function(self) return textX, textY end; getFocusHandler = function(self) base.getFocusHandler(self) - if(self.parent~=nil)then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() - if(self.parent~=nil)then - self.parent:setCursor(true, obx+textX-wIndex, oby+textY-hIndex, self.fgcolor) + if (self.parent ~= nil) then + self.parent:setCursor(true, obx + textX - wIndex, oby + textY - hIndex, self.fgcolor) end end end; loseFocusHandler = function(self) base.loseFocusHandler(self) - if(self.parent~=nil)then + if (self.parent ~= nil) then self.parent:setCursor(false) end end; keyHandler = function(self, event, key) - if(base.keyHandler(self, event, key))then - local obx,oby = self:getAnchorPosition() - if(event=="key")then - if(key==keys.backspace)then -- on backspace - if(lines[textY]=="")then - if(textY>1)then - table.remove(lines,textY) - textX = lines[textY-1]:len()+1 - wIndex = textX-self.w+1 - if(wIndex<1)then wIndex = 1 end - textY = textY-1 + if (base.keyHandler(self, event, key)) then + local obx, oby = self:getAnchorPosition() + if (event == "key") then + if (key == keys.backspace) then + -- on backspace + if (lines[textY] == "") then + if (textY > 1) then + table.remove(lines, textY) + textX = lines[textY - 1]:len() + 1 + wIndex = textX - self.w + 1 + if (wIndex < 1) then + wIndex = 1 + end + textY = textY - 1 end - elseif(textX<=1)then - if(textY>1)then - textX = lines[textY-1]:len()+1 - wIndex = textX-self.w+1 - if(wIndex<1)then wIndex = 1 end - lines[textY-1] = lines[textY-1]..lines[textY] - table.remove(lines,textY) - textY = textY-1 + elseif (textX <= 1) then + if (textY > 1) then + textX = lines[textY - 1]:len() + 1 + wIndex = textX - self.w + 1 + if (wIndex < 1) then + wIndex = 1 + end + lines[textY - 1] = lines[textY - 1] .. lines[textY] + table.remove(lines, textY) + textY = textY - 1 end else - lines[textY] = lines[textY]:sub(1,textX-2)..lines[textY]:sub(textX,lines[textY]:len()) - if(textX>1)then textX = textX-1 end - if(wIndex>1)then - if(textX 1) then + textX = textX - 1 + end + if (wIndex > 1) then + if (textX < wIndex) then + wIndex = wIndex - 1 end end end - if(textYlines[textY]:len())then - if(lines[textY+1]~=nil)then - lines[textY] = lines[textY]..lines[textY+1] - table.remove(lines, textY+1) + if (key == keys.delete) then + -- on delete + if (textX > lines[textY]:len()) then + if (lines[textY + 1] ~= nil) then + lines[textY] = lines[textY] .. lines[textY + 1] + table.remove(lines, textY + 1) end else - lines[textY] = lines[textY]:sub(1,textX-1)..lines[textY]:sub(textX+1,lines[textY]:len()) + lines[textY] = lines[textY]:sub(1, textX - 1) .. lines[textY]:sub(textX + 1, lines[textY]:len()) end end - if(key==keys.enter)then -- on enter - table.insert(lines,textY+1,lines[textY]:sub(textX,lines[textY]:len())) - lines[textY] = lines[textY]:sub(1,textX-1) - textY = textY+1 + if (key == keys.enter) then + -- on enter + table.insert(lines, textY + 1, lines[textY]:sub(textX, lines[textY]:len())) + lines[textY] = lines[textY]:sub(1, textX - 1) + textY = textY + 1 textX = 1 wIndex = 1 - if(textY-hIndex>=self.h)then - hIndex = hIndex+1 + if (textY - hIndex >= self.h) then + hIndex = hIndex + 1 end self:setValue("") end - if(key==keys.up)then -- arrow up - if(textY>1)then - textY = textY-1 - if(textX>lines[textY]:len()+1)then textX = lines[textY]:len()+1 end - if(wIndex>1)then - if(textX 1) then + textY = textY - 1 + if (textX > lines[textY]:len() + 1) then + textX = lines[textY]:len() + 1 + end + if (wIndex > 1) then + if (textX < wIndex) then + wIndex = textX - self.w + 1 + if (wIndex < 1) then + wIndex = 1 + end end end - if(hIndex>1)then - if(textY 1) then + if (textY < hIndex) then + hIndex = hIndex - 1 end end end end - if(key==keys.down)then -- arrow down - if(textY<#lines)then - textY = textY+1 - if(textX>lines[textY]:len()+1)then textX = lines[textY]:len()+1 end - - if(textY>=hIndex+self.h)then - hIndex = hIndex+1 + if (key == keys.down) then + -- arrow down + if (textY < #lines) then + textY = textY + 1 + if (textX > lines[textY]:len() + 1) then + textX = lines[textY]:len() + 1 + end + + if (textY >= hIndex + self.h) then + hIndex = hIndex + 1 end end end - if(key==keys.right)then -- arrow right - textX = textX+1 - if(textY<#lines)then - if(textX>lines[textY]:len()+1)then + if (key == keys.right) then + -- arrow right + textX = textX + 1 + if (textY < #lines) then + if (textX > lines[textY]:len() + 1) then textX = 1 - textY = textY+1 + textY = textY + 1 end - elseif(textX > lines[textY]:len())then - textX = lines[textY]:len()+1 + elseif (textX > lines[textY]:len()) then + textX = lines[textY]:len() + 1 end - if(textX<1)then textX = 1 end - if(textX=self.w+wIndex)then - wIndex = textX-self.w+1 - end - if(wIndex<1)then wIndex = 1 end - + if (textX < 1) then + textX = 1 + end + if (textX < wIndex) or (textX >= self.w + wIndex) then + wIndex = textX - self.w + 1 + end + if (wIndex < 1) then + wIndex = 1 + end + end - if(key==keys.left)then -- arrow left - textX = textX-1 - if(textX>=1)then - if(textX=self.w+wIndex)then + if (key == keys.left) then + -- arrow left + textX = textX - 1 + if (textX >= 1) then + if (textX < wIndex) or (textX >= self.w + wIndex) then wIndex = textX - end - end - if(textY>1)then - if(textX<1)then - textY = textY-1 - textX = lines[textY]:len()+1 - wIndex = textX-self.w+1 end end - if(textX<1)then textX = 1 end - if(wIndex<1)then wIndex = 1 end + if (textY > 1) then + if (textX < 1) then + textY = textY - 1 + textX = lines[textY]:len() + 1 + wIndex = textX - self.w + 1 + end + end + if (textX < 1) then + textX = 1 + end + if (wIndex < 1) then + wIndex = 1 + end end end - if(event=="char")then - lines[textY] = lines[textY]:sub(1,textX-1)..key..lines[textY]:sub(textX,lines[textY]:len()) - textX = textX+1 - if(textX>=self.w+wIndex)then wIndex = wIndex+1 end + if (event == "char") then + lines[textY] = lines[textY]:sub(1, textX - 1) .. key .. lines[textY]:sub(textX, lines[textY]:len()) + textX = textX + 1 + if (textX >= self.w + wIndex) then + wIndex = wIndex + 1 + end self:setValue("") end - local cursorX = (textX <= lines[textY]:len() and textX-1 or lines[textY]:len())-(wIndex-1) - if(cursorX>self.x+self.w-1)then cursorX = self.x+self.w-1 end - local cursorY = (textY-hIndex < self.h and textY-hIndex or textY-hIndex-1) - if(cursorX<1)then cursorX = 0 end - self.parent:setCursor(true, obx+cursorX, oby+cursorY, self.fgcolor) + local cursorX = (textX <= lines[textY]:len() and textX - 1 or lines[textY]:len()) - (wIndex - 1) + if (cursorX > self.x + self.w - 1) then + cursorX = self.x + self.w - 1 + end + local cursorY = (textY - hIndex < self.h and textY - hIndex or textY - hIndex - 1) + if (cursorX < 1) then + cursorX = 0 + end + self.parent:setCursor(true, obx + cursorX, oby + cursorY, self.fgcolor) return true end end; mouseClickHandler = function(self, event, button, x, y) - if(base.mouseClickHandler(self, event, button, x, y))then - local obx,oby = self:getAbsolutePosition(self:getAnchorPosition()) - local anchx,anchy = self:getAnchorPosition() - if(event=="mouse_click")then - if(lines[y-oby+hIndex]~=nil)then - textX = x-obx+wIndex - textY = y-oby+hIndex - if(textX>lines[textY]:len())then - textX = lines[textY]:len()+1 + if (base.mouseClickHandler(self, event, button, x, y)) then + local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) + local anchx, anchy = self:getAnchorPosition() + if (event == "mouse_click") then + if (lines[y - oby + hIndex] ~= nil) then + textX = x - obx + wIndex + textY = y - oby + hIndex + if (textX > lines[textY]:len()) then + textX = lines[textY]:len() + 1 end - if(textXlines[textY]:len())then - textX = lines[textY]:len()+1 + if (event == "mouse_drag") then + if (lines[y - oby + hIndex] ~= nil) then + textX = x - obx + wIndex + textY = y - oby + hIndex + if (textX > lines[textY]:len()) then + textX = lines[textY]:len() + 1 end - if(textX#lines-(self.h-1))then hIndex = #lines-(self.h-1) end - - if(hIndex<1)then hIndex = 1 end + if (event == "mouse_scroll") then + hIndex = hIndex + button + if (hIndex > #lines - (self.h - 1)) then + hIndex = #lines - (self.h - 1) + end - if(self.parent~=nil)then - if(obx+textX-wIndex>=obx and obx+textX-wIndex <= obx+self.w)and(oby+textY-hIndex >= oby and oby+textY-hIndex <= oby+self.h)then - self.parent:setCursor(true, anchx+textX-wIndex, anchy+textY-hIndex) + if (hIndex < 1) then + hIndex = 1 + end + + if (self.parent ~= nil) then + if (obx + textX - wIndex >= obx and obx + textX - wIndex <= obx + self.w) and (oby + textY - hIndex >= oby and oby + textY - hIndex <= oby + self.h) then + self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex) else self.parent:setCursor(false) end @@ -2247,21 +2393,23 @@ local function Textfield(name) end; draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() self.parent:drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor) self.parent:drawForegroundBox(obx, oby, self.w, self.h, self.fgcolor) - for n=1, self.h do + for n = 1, self.h do local text = "" - if(lines[n+hIndex-1]~=nil)then - text = lines[n+hIndex-1] + if (lines[n + hIndex - 1] ~= nil) then + text = lines[n + hIndex - 1] end - text = text:sub(wIndex, self.w+wIndex-1) - local space = self.w-text:len() - if(space<0)then space = 0 end - text = text..string.rep(" ", space) - self.parent:setText(obx, oby+n-1, text) + text = text:sub(wIndex, self.w + wIndex - 1) + local space = self.w - text:len() + if (space < 0) then + space = 0 + end + text = text .. string.rep(" ", space) + self.parent:setText(obx, oby + n - 1, text) end end end @@ -2294,8 +2442,8 @@ local function List(name) end; addItem = function(self, text, bgCol, fgCol, ...) - table.insert(list, {text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args={...}}) - if(#list==1)then + table.insert(list, { text = text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args = { ... } }) + if (#list == 1) then self:setValue(list[1]) end return self @@ -2321,8 +2469,8 @@ local function List(name) getItemIndex = function(self) local selected = self:getValue() - for k,v in pairs(list)do - if(v==selected)then + for k, v in pairs(list) do + if (v == selected) then return k end end @@ -2340,7 +2488,7 @@ local function List(name) editItem = function(self, index, text, bgCol, fgCol, ...) table.remove(list, index) - table.insert(list, index, {text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args={...}}) + table.insert(list, index, { text = text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args = { ... } }) return self end; @@ -2362,16 +2510,17 @@ local function List(name) end; mouseClickHandler = function(self, event, button, x, y) - local obx,oby = self:getAbsolutePosition(self:getAnchorPosition()) - if(obx<=x)and(obx+self.w>x)and(oby<=y)and(oby+self.h>y)and(self:isVisible())then - if(event=="mouse_click")or(event=="mouse_drag")then -- remove mouse_drag if i want to make objects moveable uwuwuwuw - if(button==1)then - if(#list>0)then - for n=1,self.h do - if(list[n+yOffset]~=nil)then - if(obx<=x)and(obx+self.w>x)and(oby+n-1==y)then - self:setValue(list[n+yOffset]) - self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", 0, x, y, list[n+yOffset]) + local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) + if (obx <= x) and (obx + self.w > x) and (oby <= y) and (oby + self.h > y) and (self:isVisible()) then + if (event == "mouse_click") or (event == "mouse_drag") then + -- remove mouse_drag if i want to make objects moveable uwuwuwuw + if (button == 1) then + if (#list > 0) then + for n = 1, self.h do + if (list[n + yOffset] ~= nil) then + if (obx <= x) and (obx + self.w > x) and (oby + n - 1 == y) then + self:setValue(list[n + yOffset]) + self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", 0, x, y, list[n + yOffset]) end end end @@ -2379,18 +2528,22 @@ local function List(name) end end - if(event=="mouse_scroll")and(scrollable)then - yOffset = yOffset+button - if(yOffset<0)then yOffset = 0 end - if(button>=1)then - if(#list>self.h)then - if(yOffset>#list-self.h)then - yOffset = #list-self.h + if (event == "mouse_scroll") and (scrollable) then + yOffset = yOffset + button + if (yOffset < 0) then + yOffset = 0 + end + if (button >= 1) then + if (#list > self.h) then + if (yOffset > #list - self.h) then + yOffset = #list - self.h + end + if (yOffset >= #list) then + yOffset = #list - 1 end - if(yOffset>=#list)then yOffset = #list-1 end else - yOffset = yOffset-1 - end + yOffset = yOffset - 1 + end end end self:setVisualChanged() @@ -2399,20 +2552,20 @@ local function List(name) end; draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() self.parent:drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor) - for n=1, self.h do - if(list[n+yOffset]~=nil)then - if(list[n+yOffset]==self:getValue())then - if(selectionColorActive)then - self.parent:writeText(obx, oby+n-1, getTextHorizontalAlign(list[n+yOffset].text, self.w, align), itemSelectedBG, itemSelectedFG) + for n = 1, self.h do + if (list[n + yOffset] ~= nil) then + if (list[n + yOffset] == self:getValue()) then + if (selectionColorActive) then + self.parent:writeText(obx, oby + n - 1, getTextHorizontalAlign(list[n + yOffset].text, self.w, align), itemSelectedBG, itemSelectedFG) else - self.parent:writeText(obx, oby+n-1, getTextHorizontalAlign(list[n+yOffset].text, self.w, align), list[n+yOffset].bgCol, list[n+yOffset].fgCol) + self.parent:writeText(obx, oby + n - 1, getTextHorizontalAlign(list[n + yOffset].text, self.w, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol) end else - self.parent:writeText(obx, oby+n-1, getTextHorizontalAlign(list[n+yOffset].text, self.w, align), list[n+yOffset].bgCol,list[n+yOffset].fgCol) + self.parent:writeText(obx, oby + n - 1, getTextHorizontalAlign(list[n + yOffset].text, self.w, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol) end end end @@ -2447,11 +2600,11 @@ local function Menubar(name) local function maxScroll() local mScroll = 0 local xPos = 1 - for n=1,#list do - if(xPos + list[n].text:len() + space*2 > object.w)then - mScroll = mScroll + list[n].text:len() + space*2 + for n = 1, #list do + if (xPos + list[n].text:len() + space * 2 > object.w) then + mScroll = mScroll + list[n].text:len() + space * 2 end - xPos = xPos+list[n].text:len()+space*2 + xPos = xPos + list[n].text:len() + space * 2 end return mScroll @@ -2461,10 +2614,10 @@ local function Menubar(name) getType = function(self) return typ end; - + addItem = function(self, text, bgCol, fgCol, ...) - table.insert(list, {text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args={...}}) - if(#list==1)then + table.insert(list, { text = text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args = { ... } }) + if (#list == 1) then self:setValue(list[1]) end return self @@ -2472,8 +2625,8 @@ local function Menubar(name) getItemIndex = function(self) local selected = self:getValue() - for k,v in pairs(list)do - if(v==selected)then + for k, v in pairs(list) do + if (v == selected) then return k end end @@ -2492,12 +2645,12 @@ local function Menubar(name) setButtonOffset = function(self, offset) itemOffset = offset or 0 - if(itemOffset<0)then + if (itemOffset < 0) then itemOffset = 0 end local mScroll = maxScroll() - if(itemOffset>mScroll)then + if (itemOffset > mScroll) then itemOffset = mScroll end return self @@ -2523,7 +2676,7 @@ local function Menubar(name) editItem = function(self, index, text, bgCol, fgCol, ...) table.remove(list, index) - table.insert(list, index, {text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args={...}}) + table.insert(list, index, { text = text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args = { ... } }) return self end; @@ -2540,35 +2693,37 @@ local function Menubar(name) end; mouseClickHandler = function(self, event, button, x, y) - local objX,objY = self:getAbsolutePosition(self:getAnchorPosition()) - if(objX<=x)and(objX+self.w>x)and(objY<=y)and(objY+self.h>y)and(self:isVisible())then - if(self.parent~=nil)then self.parent:setFocusedObject(self) end - if(event=="mouse_click")then + local objX, objY = self:getAbsolutePosition(self:getAnchorPosition()) + if (objX <= x) and (objX + self.w > x) and (objY <= y) and (objY + self.h > y) and (self:isVisible()) then + if (self.parent ~= nil) then + self.parent:setFocusedObject(self) + end + if (event == "mouse_click") then local xPos = 1 - for n=1+itemOffset,#list do - if(list[n]~=nil)then - if(xPos + list[n].text:len() + space*2 <= self.w)then - if(objX + (xPos-1)<= x)and(objX + (xPos-1) + list[n].text:len() + space*2 > x)and(objY == y)then + for n = 1 + itemOffset, #list do + if (list[n] ~= nil) then + if (xPos + list[n].text:len() + space * 2 <= self.w) then + if (objX + (xPos - 1) <= x) and (objX + (xPos - 1) + list[n].text:len() + space * 2 > x) and (objY == y) then self:setValue(list[n]) self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", 0, x, y, list[n]) end - xPos = xPos+list[n].text:len()+space*2 + xPos = xPos + list[n].text:len() + space * 2 else break end end end - + end - if(event=="mouse_scroll")and(scrollable)then - itemOffset = itemOffset+button - if(itemOffset<0)then + if (event == "mouse_scroll") and (scrollable) then + itemOffset = itemOffset + button + if (itemOffset < 0) then itemOffset = 0 end local mScroll = maxScroll() - if(itemOffset>mScroll)then + if (itemOffset > mScroll) then itemOffset = mScroll end end @@ -2576,29 +2731,29 @@ local function Menubar(name) end return false end; - + draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() self.parent:drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor) local xPos = 0 - for k,v in pairs(list)do - if(xPos + v.text:len() + space*2 <= self.w)then - if(v==self:getValue())then - self.parent:writeText(obx + (xPos-1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space)..v.text..(" "):rep(space), v.text:len()+space*2, align), itemSelectedBG or v.bgCol, itemSelectedFG or v.fgCol) + for k, v in pairs(list) do + if (xPos + v.text:len() + space * 2 <= self.w) then + if (v == self:getValue()) then + self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. v.text .. (" "):rep(space), v.text:len() + space * 2, align), itemSelectedBG or v.bgCol, itemSelectedFG or v.fgCol) else - self.parent:writeText(obx + (xPos-1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space)..v.text..(" "):rep(space), v.text:len()+space*2, align), v.bgCol, v.fgCol) + self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. v.text .. (" "):rep(space), v.text:len() + space * 2, align), v.bgCol, v.fgCol) end - xPos = xPos+v.text:len()+space*2 + xPos = xPos + v.text:len() + space * 2 else - if(xPos0)then - for n=1,dropdownH do - if(list[n+yOffset]~=nil)then - if(obx<=x)and(obx+dropdownW>x)and(oby+n==y)then - self:setValue(list[n+yOffset]) + if (state == 2) then + local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) + if (event == "mouse_click") then + -- remove mouse_drag if i want to make objects moveable uwuwuwuw + if (button == 1) then + if (#list > 0) then + for n = 1, dropdownH do + if (list[n + yOffset] ~= nil) then + if (obx <= x) and (obx + dropdownW > x) and (oby + n == y) then + self:setValue(list[n + yOffset]) return true end end @@ -2720,23 +2876,25 @@ local function Dropdown(name) end end - if(event=="mouse_scroll")then - yOffset = yOffset+button - if(yOffset<0)then yOffset = 0 end - if(button==1)then - if(#list>dropdownH)then - if(yOffset>#list-dropdownH)then - yOffset = #list-dropdownH - end - else - yOffset = list-1 - end + if (event == "mouse_scroll") then + yOffset = yOffset + button + if (yOffset < 0) then + yOffset = 0 + end + if (button == 1) then + if (#list > dropdownH) then + if (yOffset > #list - dropdownH) then + yOffset = #list - dropdownH + end + else + yOffset = list - 1 + end end return true end self:setVisualChanged() end - if(base.mouseClickHandler(self, event, button, x, y))then + if (base.mouseClickHandler(self, event, button, x, y)) then state = 2 else state = 1 @@ -2744,31 +2902,31 @@ local function Dropdown(name) end; draw = function(self) - if(base.draw(self))then + if (base.draw(self)) then local obx, oby = self:getAnchorPosition() - if(self.parent~=nil)then + if (self.parent ~= nil) then self.parent:drawBackgroundBox(obx, oby, self.w, self.h, self.bgcolor) - if(#list>=1)then - if(self:getValue()~=nil)then - if(self:getValue().text~=nil)then - if(state==1)then - self.parent:writeText(obx, oby, getTextHorizontalAlign(self:getValue().text, self.w, align):sub(1,self.w-1)..closedSymbol, self.bgcolor, self.fgcolor) + if (#list >= 1) then + if (self:getValue() ~= nil) then + if (self:getValue().text ~= nil) then + if (state == 1) then + self.parent:writeText(obx, oby, getTextHorizontalAlign(self:getValue().text, self.w, align):sub(1, self.w - 1) .. closedSymbol, self.bgcolor, self.fgcolor) else - self.parent:writeText(obx, oby, getTextHorizontalAlign(self:getValue().text, self.w, align):sub(1,self.w-1)..openedSymbol, self.bgcolor, self.fgcolor) + self.parent:writeText(obx, oby, getTextHorizontalAlign(self:getValue().text, self.w, align):sub(1, self.w - 1) .. openedSymbol, self.bgcolor, self.fgcolor) end end end - if(state==2)then - for n=1, dropdownH do - if(list[n+yOffset]~=nil)then - if(list[n+yOffset]==self:getValue())then - if(selectionColorActive)then - self.parent:writeText(obx, oby+n, getTextHorizontalAlign(list[n+yOffset].text, dropdownW, align), itemSelectedBG, itemSelectedFG) + if (state == 2) then + for n = 1, dropdownH do + if (list[n + yOffset] ~= nil) then + if (list[n + yOffset] == self:getValue()) then + if (selectionColorActive) then + self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), itemSelectedBG, itemSelectedFG) else - self.parent:writeText(obx, oby+n, getTextHorizontalAlign(list[n+yOffset].text, dropdownW, align), list[n+yOffset].bgCol, list[n+yOffset].fgCol) + self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol) end else - self.parent:writeText(obx, oby+n, getTextHorizontalAlign(list[n+yOffset].text, dropdownW, align), list[n+yOffset].bgCol,list[n+yOffset].fgCol) + self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol) end end end @@ -2804,9 +2962,9 @@ local function Radio(name) return typ end; - addItem = function(self,text, x, y, bgCol, fgCol, ...) - table.insert(list, {x=x or 1, y=y or 1, text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args={...}}) - if(#list==1)then + addItem = function(self, text, x, y, bgCol, fgCol, ...) + table.insert(list, { x = x or 1, y = y or 1, text = text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args = { ... } }) + if (#list == 1) then self:setValue(list[1]) end return self @@ -2823,8 +2981,8 @@ local function Radio(name) getItemIndex = function(self) local selected = self:getValue() - for k,v in pairs(list)do - if(v==selected)then + for k, v in pairs(list) do + if (v == selected) then return k end end @@ -2842,7 +3000,7 @@ local function Radio(name) editItem = function(self, index, text, x, y, bgCol, fgCol, ...) table.remove(list, index) - table.insert(list, index, {x=x or 1, y=y or 1, text=text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args={...}}) + table.insert(list, index, { x = x or 1, y = y or 1, text = text, bgCol = bgCol or self.bgcolor, fgCol = fgCol or self.fgcolor, args = { ... } }) return self end; @@ -2861,14 +3019,17 @@ local function Radio(name) end; mouseClickHandler = function(self, event, button, x, y) - local obx,oby = self:getAbsolutePosition(self:getAnchorPosition()) - if(event=="mouse_click")then -- remove mouse_drag if i want to make objects moveable uwuwuwuw - if(button==1)then - if(#list>0)then - for _,v in pairs(list)do - if(obx+v.x-1<=x)and(obx+v.x-1+v.text:len()+2>=x)and(oby+v.y-1==y)then + local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) + if (event == "mouse_click") then + -- remove mouse_drag if i want to make objects moveable uwuwuwuw + if (button == 1) then + if (#list > 0) then + for _, v in pairs(list) do + if (obx + v.x - 1 <= x) and (obx + v.x - 1 + v.text:len() + 2 >= x) and (oby + v.y - 1 == y) then self:setValue(v) - if(self.parent~=nil)then self.parent:setFocusedObject(self) end + if (self.parent ~= nil) then + self.parent:setFocusedObject(self) + end --eventSystem:sendEvent(event, self, event, button, x, y) self:setVisualChanged() return true @@ -2881,21 +3042,21 @@ local function Radio(name) end; draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() - for _,v in pairs(list)do - if(v==self:getValue())then - if(align=="left")then - self.parent:writeText(v.x+obx-1,v.y+oby-1,symbol,boxSelectedBG,boxSelectedFG) - self.parent:writeText(v.x+2+obx-1,v.y+oby-1,v.text,itemSelectedBG,itemSelectedFG) + for _, v in pairs(list) do + if (v == self:getValue()) then + if (align == "left") then + self.parent:writeText(v.x + obx - 1, v.y + oby - 1, symbol, boxSelectedBG, boxSelectedFG) + self.parent:writeText(v.x + 2 + obx - 1, v.y + oby - 1, v.text, itemSelectedBG, itemSelectedFG) end else - self.parent:drawBackgroundBox(v.x+obx-1, v.y+oby-1,1,1,self.bgcolor) - self.parent:writeText(v.x+2+obx-1,v.y+oby-1,v.text,v.bgCol,v.fgCol) + self.parent:drawBackgroundBox(v.x + obx - 1, v.y + oby - 1, 1, 1, self.bgcolor) + self.parent:writeText(v.x + 2 + obx - 1, v.y + oby - 1, v.text, v.bgCol, v.fgCol) end - end - end + end + end end end; } @@ -2911,7 +3072,7 @@ local function Timer(name) local repeats = 0 local timerObj local eventSystem = BasaltEvents() - + local object = { name = name, getType = function(self) @@ -2939,7 +3100,7 @@ local function Timer(name) end; cancel = function(self) - if(timerObj~=nil)then + if (timerObj ~= nil) then os.cancelTimer(timerObj) end return self @@ -2951,14 +3112,14 @@ local function Timer(name) end; eventHandler = function(self, event, tObj) - if(event=="timer")and(tObj==timerObj)then - eventSystem:sendEvent("timed_event",self) - if(repeats>=1)then + if (event == "timer") and (tObj == timerObj) then + eventSystem:sendEvent("timed_event", self) + if (repeats >= 1) then repeats = repeats - 1 - if(repeats >= 1)then + if (repeats >= 1) then timerObj = os.startTimer(timer) end - elseif(repeats == -1)then + elseif (repeats == -1) then timerObj = os.startTimer(timer) end end @@ -2990,21 +3151,23 @@ local function Thread(name) end; start = function(self, f) - if(f==nil)then error("function is nil") end + if (f == nil) then + error("function is nil") + end func = f cRoutine = coroutine.create(func) isActive = true local ok, result = coroutine.resume(cRoutine) - if not(ok)then - if(result~="Terminated")then - error("Threaderror - "..result) + if not (ok) then + if (result ~= "Terminated") then + error("Threaderror - " .. result) end end return self end; getStatus = function(self, f) - if(cRoutine~=nil)then + if (cRoutine ~= nil) then return coroutine.status(cRoutine) end return nil @@ -3015,13 +3178,13 @@ local function Thread(name) return self end; - eventHandler = function(self, event, p1,p2,p3) - if(isActive)then - if(coroutine.status(cRoutine)~="dead")then - local ok, result = coroutine.resume(cRoutine, event,p1,p2,p3) - if not(ok)then - if(result~="Terminated")then - error("Threaderror - "..result) + eventHandler = function(self, event, p1, p2, p3) + if (isActive) then + if (coroutine.status(cRoutine) ~= "dead") then + local ok, result = coroutine.resume(cRoutine, event, p1, p2, p3) + if not (ok) then + if (result ~= "Terminated") then + error("Threaderror - " .. result) end end else @@ -3050,19 +3213,19 @@ local function Animation(name) local lastFunc local function onPlay() - if(animations[index]~=nil)then + if (animations[index] ~= nil) then animations[index].f(object, index) end - index = index+1 - if(animations[index]~=nil)then - if(animations[index].t>0)then + index = index + 1 + if (animations[index] ~= nil) then + if (animations[index].t > 0) then timerObj = os.startTimer(animations[index].t) else onPlay() end end end - + object = { name = name, getType = function(self) @@ -3079,7 +3242,7 @@ local function Animation(name) add = function(self, func, wait) lastFunc = func - table.insert(animations, {f=func,t = wait or nextWaitTimer}) + table.insert(animations, { f = func, t = wait or nextWaitTimer }) return self end; @@ -3089,8 +3252,8 @@ local function Animation(name) end; rep = function(self, reps) - for x=1,reps do - table.insert(animations, {f=lastFunc,t = nextWaitTimer}) + for x = 1, reps do + table.insert(animations, { f = lastFunc, t = nextWaitTimer }) end return self end; @@ -3105,8 +3268,8 @@ local function Animation(name) play = function(self) index = 1 - if(animations[index]~=nil)then - if(animations[index].t>0)then + if (animations[index] ~= nil) then + if (animations[index].t > 0) then timerObj = os.startTimer(animations[index].t) else onPlay() @@ -3121,8 +3284,8 @@ local function Animation(name) end; eventHandler = function(self, event, tObj) - if(event=="timer")and(tObj==timerObj)then - if(animations[index]~=nil)then + if (event == "timer") and (tObj == timerObj) then + if (animations[index] ~= nil) then onPlay() end end @@ -3144,30 +3307,28 @@ local function Slider(name) local barType = "horizontal" local symbol = " " - local symbolColor=colors.black + local symbolColor = colors.black local bgSymbol = "\140" local maxValue = base.w local index = 1 - - local object = { getType = function(self) return typ end; setSymbol = function(self, _symbol) - symbol = _symbol:sub(1,1) + symbol = _symbol:sub(1, 1) self:setVisualChanged() return self end; setBackgroundSymbol = function(self, _bgSymbol) - bgSymbol = string.sub(_bgSymbol,1,1) + bgSymbol = string.sub(_bgSymbol, 1, 1) self:setVisualChanged() return self end; - + setSymbolColor = function(self, col) symbolColor = col self:setVisualChanged() @@ -3180,22 +3341,22 @@ local function Slider(name) end; mouseClickHandler = function(self, event, button, x, y) - if(base.mouseClickHandler(self,event,button,x,y))then + if (base.mouseClickHandler(self, event, button, x, y)) then local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - if(barType=="horizontal")then - for _index=0,self.w-1 do - if(obx+_index==x)and(oby<=y)and(oby+self.h>y)then - index = _index+1 - self:setValue(maxValue/self.w*(index)) + if (barType == "horizontal") then + for _index = 0, self.w - 1 do + if (obx + _index == x) and (oby <= y) and (oby + self.h > y) then + index = _index + 1 + self:setValue(maxValue / self.w * (index)) self:setVisualChanged() end end end - if(barType=="vertical")then - for _index=0,self.h-1 do - if(oby+_index==y)and(obx<=x)and(obx+self.w>x)then - index = _index+1 - self:setValue(maxValue/self.h*(index)) + if (barType == "vertical") then + for _index = 0, self.h - 1 do + if (oby + _index == y) and (obx <= x) and (obx + self.w > x) then + index = _index + 1 + self:setValue(maxValue / self.h * (index)) self:setVisualChanged() end end @@ -3211,18 +3372,18 @@ local function Slider(name) end; draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() - if(barType=="horizontal")then - self.parent:writeText(obx, oby, bgSymbol:rep(index-1), self.bgcolor, self.fgcolor) + if (barType == "horizontal") then + self.parent:writeText(obx, oby, bgSymbol:rep(index - 1), self.bgcolor, self.fgcolor) self.parent:writeText(obx + index - 1, oby, symbol, symbolColor, symbolColor) self.parent:writeText(obx + index, oby, bgSymbol:rep(self.w - (index)), self.bgcolor, self.fgcolor) end - if(barType=="vertical")then - for n = 0, self.h-1 do - if(n+1 == index)then + if (barType == "vertical") then + for n = 0, self.h - 1 do + if (n + 1 == index) then self.parent:writeText(obx, oby + n, symbol, symbolColor, symbolColor) else self.parent:writeText(obx, oby + n, bgSymbol, self.bgcolor, self.fgcolor) @@ -3232,7 +3393,7 @@ local function Slider(name) end end end; - + } return setmetatable(object, base) @@ -3251,30 +3412,29 @@ local function Scrollbar(name) local barType = "vertical" local symbol = " " - local symbolColor=colors.black + local symbolColor = colors.black local bgSymbol = "\127" local maxValue = base.h local index = 1 local symbolSize = 1 - - + local object = { getType = function(self) return typ end; setSymbol = function(self, _symbol) - symbol = _symbol:sub(1,1) + symbol = _symbol:sub(1, 1) self:setVisualChanged() return self end; setSymbolSize = function(self, size) symbolSize = tonumber(size) or 1 - if(barType=="vertical")then - self:setValue(index-1 * (maxValue/(self.h-(symbolSize-1)))-(maxValue/(self.h-(symbolSize-1)))) - elseif(barType=="horizontal")then - self:setValue(index-1 * (maxValue/(self.w-(symbolSize-1)))-(maxValue/(self.w-(symbolSize-1)))) + if (barType == "vertical") then + self:setValue(index - 1 * (maxValue / (self.h - (symbolSize - 1))) - (maxValue / (self.h - (symbolSize - 1)))) + elseif (barType == "horizontal") then + self:setValue(index - 1 * (maxValue / (self.w - (symbolSize - 1))) - (maxValue / (self.w - (symbolSize - 1)))) end self:setVisualChanged() return self @@ -3286,11 +3446,11 @@ local function Scrollbar(name) end; setBackgroundSymbol = function(self, _bgSymbol) - bgSymbol = string.sub(_bgSymbol,1,1) + bgSymbol = string.sub(_bgSymbol, 1, 1) self:setVisualChanged() return self end; - + setSymbolColor = function(self, col) symbolColor = col self:setVisualChanged() @@ -3303,65 +3463,67 @@ local function Scrollbar(name) end; mouseClickHandler = function(self, event, button, x, y) - if(base.mouseClickHandler(self,event,button,x,y))then + if (base.mouseClickHandler(self, event, button, x, y)) then local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - if((event=="mouse_click")or(event=="mouse_drag"))and(button==1)then - if(barType=="horizontal")then - for _index=0,self.w do - if(obx+_index==x)and(oby<=y)and(oby+self.h>y)then - index = math.min(_index+1, self.w-(symbolSize-1)) - self:setValue(maxValue/self.w*(index)) + if ((event == "mouse_click") or (event == "mouse_drag")) and (button == 1) then + if (barType == "horizontal") then + for _index = 0, self.w do + if (obx + _index == x) and (oby <= y) and (oby + self.h > y) then + index = math.min(_index + 1, self.w - (symbolSize - 1)) + self:setValue(maxValue / self.w * (index)) self:setVisualChanged() end end end - if(barType=="vertical")then - for _index=0,self.h do - if(oby+_index==y)and(obx<=x)and(obx+self.w>x)then - index = math.min(_index+1, self.h-(symbolSize-1)) - self:setValue(maxValue/self.h*(index)) + if (barType == "vertical") then + for _index = 0, self.h do + if (oby + _index == y) and (obx <= x) and (obx + self.w > x) then + index = math.min(_index + 1, self.h - (symbolSize - 1)) + self:setValue(maxValue / self.h * (index)) self:setVisualChanged() end end end end - if(event=="mouse_scroll")then - index = index+button - if(index<1)then index = 1 end - index = math.min(index, (barType=="vertical" and self.h or self.w)-(symbolSize-1)) - self:setValue(maxValue/(barType=="vertical" and self.h or self.w)*index) + if (event == "mouse_scroll") then + index = index + button + if (index < 1) then + index = 1 + end + index = math.min(index, (barType == "vertical" and self.h or self.w) - (symbolSize - 1)) + self:setValue(maxValue / (barType == "vertical" and self.h or self.w) * index) end return true end end; - + draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() - if(barType=="horizontal")then - self.parent:writeText(obx, oby, bgSymbol:rep(index-1), self.bgcolor, self.fgcolor) + if (barType == "horizontal") then + self.parent:writeText(obx, oby, bgSymbol:rep(index - 1), self.bgcolor, self.fgcolor) self.parent:writeText(obx + index - 1, oby, symbol:rep(symbolSize), symbolColor, symbolColor) - self.parent:writeText(obx + index+symbolSize-1, oby, bgSymbol:rep(self.w - (index+symbolSize-1)), self.bgcolor, self.fgcolor) + self.parent:writeText(obx + index + symbolSize - 1, oby, bgSymbol:rep(self.w - (index + symbolSize - 1)), self.bgcolor, self.fgcolor) end - if(barType=="vertical")then - for n = 0, self.h-1 do + if (barType == "vertical") then + for n = 0, self.h - 1 do - if(index==n+1)then - for curIndexOffset=0,math.min(symbolSize-1,self.h) do - self.parent:writeText(obx, oby+n+curIndexOffset, symbol, symbolColor, symbolColor) + if (index == n + 1) then + for curIndexOffset = 0, math.min(symbolSize - 1, self.h) do + self.parent:writeText(obx, oby + n + curIndexOffset, symbol, symbolColor, symbolColor) end else - if(n+1index-1+symbolSize)then - self.parent:writeText(obx, oby+n, bgSymbol, self.bgcolor, self.fgcolor) + if (n + 1 < index) or (n + 1 > index - 1 + symbolSize) then + self.parent:writeText(obx, oby + n, bgSymbol, self.bgcolor, self.fgcolor) end end end end end end - end; + end; } return setmetatable(object, base) @@ -3378,41 +3540,38 @@ local function Switch(name) base:setValue(false) base:setZIndex(5) - - local object = { getType = function(self) return typ end; - mouseClickHandler = function(self, event, button, x, y) - if(base.mouseClickHandler(self,event,button,x,y))then + if (base.mouseClickHandler(self, event, button, x, y)) then local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - if((event=="mouse_click")or(event=="mouse_drag"))and(button==1)then - + if ((event == "mouse_click") or (event == "mouse_drag")) and (button == 1) then + end return true end end; - + draw = function(self) - if(base.draw(self))then - if(self.parent~=nil)then + if (base.draw(self)) then + if (self.parent ~= nil) then local obx, oby = self:getAnchorPosition() - + end end - end; + end; } return setmetatable(object, base) end - -local function Frame(name,parent) -- Frame +local function Frame(name, parent) + -- Frame local base = Object(name) local typ = "Frame" local objects = {} @@ -3428,7 +3587,7 @@ local function Frame(name,parent) -- Frame local xOffset, yOffset = 0, 0 - if(parent~=nil)then + if (parent ~= nil) then base.parent = parent base.w, base.h = parent.w, parent.h base.bgcolor = theme.FrameBG @@ -3441,9 +3600,9 @@ local function Frame(name,parent) -- Frame end local function getObject(name) - for k,v in pairs(objects)do - for a,b in pairs(v)do - if(b.name == name)then + for k, v in pairs(objects) do + for a, b in pairs(v) do + if (b.name == name) then return v end end @@ -3452,34 +3611,38 @@ local function Frame(name,parent) -- Frame local function addObject(obj) local zIndex = obj:getZIndex() - if(getObject(obj.name)~=nil)then return nil end - if(objects[zIndex]==nil)then - for x=1,#objZIndex+1 do - if(objZIndex[x]~=nil)then - if(zIndex == objZIndex[x])then break end - if(zIndex > objZIndex[x])then - table.insert(objZIndex,x,zIndex) + if (getObject(obj.name) ~= nil) then + return nil + end + if (objects[zIndex] == nil) then + for x = 1, #objZIndex + 1 do + if (objZIndex[x] ~= nil) then + if (zIndex == objZIndex[x]) then + break + end + if (zIndex > objZIndex[x]) then + table.insert(objZIndex, x, zIndex) break end else - table.insert(objZIndex,zIndex) + table.insert(objZIndex, zIndex) end end - if(#objZIndex<=0)then - table.insert(objZIndex,zIndex) + if (#objZIndex <= 0) then + table.insert(objZIndex, zIndex) end objects[zIndex] = {} end obj.parent = object - table.insert(objects[zIndex],obj) + table.insert(objects[zIndex], obj) return obj end local function removeObject(obj) - for a,b in pairs(objects)do - for k,v in pairs(b)do - if(v==obj)then - table.remove(objects[a],k) + for a, b in pairs(objects) do + for k, v in pairs(b) do + if (v == obj) then + table.remove(objects[a], k) return true; end end @@ -3500,10 +3663,12 @@ local function Frame(name,parent) -- Frame end; setFocusedObject = function(self, obj) - for _,index in pairs(objZIndex)do - for _,v in pairs(objects[index])do - if(v == obj)then - if(focusedObject~=nil)then focusedObject:loseFocusHandler() end + for _, index in pairs(objZIndex) do + for _, v in pairs(objects[index]) do + if (v == obj) then + if (focusedObject ~= nil) then + focusedObject:loseFocusHandler() + end focusedObject = obj focusedObject:getFocusHandler() end @@ -3523,7 +3688,9 @@ local function Frame(name,parent) -- Frame end; removeFocusedObject = function(self) - if(focusedObject~=nil)then focusedObject:loseFocusHandler() end + if (focusedObject ~= nil) then + focusedObject:loseFocusHandler() + end focusedObject = nil return self end; @@ -3534,8 +3701,8 @@ local function Frame(name,parent) -- Frame show = function(self) base:show() - if(self.parent==nil)then - activeFrame = self + if (self.parent == nil) then + activeFrame = self end return self end; @@ -3543,8 +3710,12 @@ local function Frame(name,parent) -- Frame setCursor = function(self, _blink, _xCursor, _yCursor, color) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) cursorBlink = _blink or false - if(_xCursor~=nil)then xCursor = obx+_xCursor-1 end - if(_yCursor~=nil)then yCursor = oby+_yCursor-1 end + if (_xCursor ~= nil) then + xCursor = obx + _xCursor - 1 + end + if (_yCursor ~= nil) then + yCursor = oby + _yCursor - 1 + end cursorColor = color or cursorColor self:setVisualChanged() return self @@ -3579,10 +3750,10 @@ local function Frame(name,parent) -- Frame getVisualChanged = function(self) local changed = base.getVisualChanged(self) - for _,index in pairs(objZIndex)do - if(objects[index]~=nil)then - for _,v in pairs(objects[index])do - if(v.getVisualChanged~=nil and v:getVisualChanged())then + for _, index in pairs(objZIndex) do + if (objects[index] ~= nil) then + for _, v in pairs(objects[index]) do + if (v.getVisualChanged ~= nil and v:getVisualChanged()) then changed = true end end @@ -3597,16 +3768,16 @@ local function Frame(name,parent) -- Frame getFocusHandler = function(self) base.getFocusHandler(self) - if(self.parent~=nil)then + if (self.parent ~= nil) then self.parent:removeObject(self) self.parent:addObject(self) end end; keyHandler = function(self, event, key) - if(focusedObject~=nil)then - if(focusedObject.keyHandler~=nil)then - if(focusedObject:keyHandler(event,key))then + if (focusedObject ~= nil) then + if (focusedObject.keyHandler ~= nil) then + if (focusedObject:keyHandler(event, key)) then return true end end @@ -3616,11 +3787,11 @@ local function Frame(name,parent) -- Frame backgroundKeyHandler = function(self, event, key) base.backgroundKeyHandler(self, event, key) - for _,index in pairs(objZIndex)do - if(objects[index]~=nil)then - for _,v in pairs(objects[index])do - if(v.backgroundKeyHandler~=nil)then - v:backgroundKeyHandler(event,key) + for _, index in pairs(objZIndex) do + if (objects[index] ~= nil) then + for _, v in pairs(objects[index]) do + if (v.backgroundKeyHandler ~= nil) then + v:backgroundKeyHandler(event, key) end end end @@ -3629,61 +3800,65 @@ local function Frame(name,parent) -- Frame eventHandler = function(self, event, p1, p2, p3, p4) base.eventHandler(self, event, p1, p2, p3, p4) - for _,index in pairs(objZIndex)do - if(objects[index]~=nil)then - for _,v in pairs(objects[index])do - if(v.eventHandler~=nil)then - v:eventHandler(event,p1, p2, p3, p4) + for _, index in pairs(objZIndex) do + if (objects[index] ~= nil) then + for _, v in pairs(objects[index]) do + if (v.eventHandler ~= nil) then + v:eventHandler(event, p1, p2, p3, p4) end end end end - if(event=="terminate")then + if (event == "terminate") then parentTerminal.clear() - parentTerminal.setCursorPos(1,1) - basalt.stop() + parentTerminal.setCursorPos(1, 1) + basalt.stop() end end; mouseClickHandler = function(self, event, button, x, y) local xO, yO = self:getOffset() - xO = xO < 0 and math.abs(xO) or -xO - yO = yO < 0 and math.abs(yO) or -yO - if(self.drag)then - if(event=="mouse_drag")then - local parentX=1;local parentY=1 - if(self.parent~=nil)then - parentX,parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition()) + xO = xO < 0 and math.abs(xO) or -xO + yO = yO < 0 and math.abs(yO) or -yO + if (self.drag) then + if (event == "mouse_drag") then + local parentX = 1; + local parentY = 1 + if (self.parent ~= nil) then + parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition()) end - self:setPosition(x+self.xToRem-(parentX-1) + xO,y-(parentY-1) + yO) + self:setPosition(x + self.xToRem - (parentX - 1) + xO, y - (parentY - 1) + yO) end - if(event=="mouse_up")then + if (event == "mouse_up") then self.drag = false end return true end - if(base.mouseClickHandler(self,event,button,x,y))then - local fx,fy = self:getAbsolutePosition(self:getAnchorPosition()) - for _,index in pairs(objZIndex)do - if(objects[index]~=nil)then - for _,v in rpairs(objects[index])do - if(v.mouseClickHandler~=nil)then - if(v:mouseClickHandler(event,button,x+xO,y+yO))then - return true - end + if (base.mouseClickHandler(self, event, button, x, y)) then + local fx, fy = self:getAbsolutePosition(self:getAnchorPosition()) + for _, index in pairs(objZIndex) do + if (objects[index] ~= nil) then + for _, v in rpairs(objects[index]) do + if (v.mouseClickHandler ~= nil) then + if (v:mouseClickHandler(event, button, x + xO, y + yO)) then + return true + end end end end end - if(self.isMoveable)then - if(x>=fx)and(x<=fx+self.w-1)and(y==fy)and(event=="mouse_click")then + if (self.isMoveable) then + if (x >= fx) and (x <= fx + self.w - 1) and (y == fy) and (event == "mouse_click") then self.drag = true - self.xToRem = fx-x + self.xToRem = fx - x end end - if(focusedObject~=nil)then focusedObject:loseFocusHandler() focusedObject = nil end + if (focusedObject ~= nil) then + focusedObject:loseFocusHandler() + focusedObject = nil + end return true end return false @@ -3691,87 +3866,87 @@ local function Frame(name,parent) -- Frame setText = function(self, x, y, text) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - if(y>=1)and(y<=self.h)then - if(self.parent~=nil)then - self.parent:setText(math.max(x+(obx-1),obx)-(self.parent.x-1), oby+y-1-(self.parent.y-1), sub( text, math.max(1 - x + 1, 1), self.w - x + 1 )) + if (y >= 1) and (y <= self.h) then + if (self.parent ~= nil) then + self.parent:setText(math.max(x + (obx - 1), obx) - (self.parent.x - 1), oby + y - 1 - (self.parent.y - 1), sub(text, math.max(1 - x + 1, 1), self.w - x + 1)) else - drawHelper.setText(math.max(x+(obx-1),obx), oby+y-1, sub( text, math.max(1 - x + 1, 1), self.w - x + 1 )) + drawHelper.setText(math.max(x + (obx - 1), obx), oby + y - 1, sub(text, math.max(1 - x + 1, 1), self.w - x + 1)) end end end; setBG = function(self, x, y, bgCol) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - if(y>=1)and(y<=self.h)then - if(self.parent~=nil)then - self.parent:setBG(math.max(x+(obx-1),obx)-(self.parent.x-1), oby+y-1-(self.parent.y-1), sub( bgCol, math.max(1 - x + 1, 1), self.w - x + 1 )) + if (y >= 1) and (y <= self.h) then + if (self.parent ~= nil) then + self.parent:setBG(math.max(x + (obx - 1), obx) - (self.parent.x - 1), oby + y - 1 - (self.parent.y - 1), sub(bgCol, math.max(1 - x + 1, 1), self.w - x + 1)) else - drawHelper.setBG(math.max(x+(obx-1),obx), oby+y-1, sub( bgCol, math.max(1 - x + 1, 1), self.w - x + 1 )) + drawHelper.setBG(math.max(x + (obx - 1), obx), oby + y - 1, sub(bgCol, math.max(1 - x + 1, 1), self.w - x + 1)) end end end; setFG = function(self, x, y, fgCol) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - if(y>=1)and(y<=self.h)then - if(self.parent~=nil)then - self.parent:setFG(math.max(x+(obx-1),obx)-(self.parent.x-1), oby+y-1-(self.parent.y-1), sub( fgCol, math.max(1 - x + 1, 1), self.w - x + 1 )) + if (y >= 1) and (y <= self.h) then + if (self.parent ~= nil) then + self.parent:setFG(math.max(x + (obx - 1), obx) - (self.parent.x - 1), oby + y - 1 - (self.parent.y - 1), sub(fgCol, math.max(1 - x + 1, 1), self.w - x + 1)) else - drawHelper.setFG(math.max(x+(obx-1),obx), oby+y-1, sub( fgCol, math.max(1 - x + 1, 1), self.w - x + 1 )) + drawHelper.setFG(math.max(x + (obx - 1), obx), oby + y - 1, sub(fgCol, math.max(1 - x + 1, 1), self.w - x + 1)) end end end; writeText = function(self, x, y, text, bgCol, fgCol) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - if(y>=1)and(y<=self.h)then - if(self.parent~=nil)then - self.parent:writeText(math.max(x+(obx-1),obx)-(self.parent.x-1), oby+y-1-(self.parent.y-1), sub( text, math.max(1 - x + 1, 1), self.w - x + 1 ), bgCol, fgCol) + if (y >= 1) and (y <= self.h) then + if (self.parent ~= nil) then + self.parent:writeText(math.max(x + (obx - 1), obx) - (self.parent.x - 1), oby + y - 1 - (self.parent.y - 1), sub(text, math.max(1 - x + 1, 1), self.w - x + 1), bgCol, fgCol) else - drawHelper.writeText(math.max(x+(obx-1),obx), oby+y-1, sub( text, math.max(1 - x + 1, 1), self.w - x + 1 ), bgCol, fgCol) + drawHelper.writeText(math.max(x + (obx - 1), obx), oby + y - 1, sub(text, math.max(1 - x + 1, 1), self.w - x + 1), bgCol, fgCol) end end end; drawBackgroundBox = function(self, x, y, w, h, bgCol) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - h = (y < 1 and (h+y > self.h and self.h or h+y-1) or (h+y > self.h and self.h-y+1 or h)) - w = (x < 1 and (w+x > self.w and self.w or w+x-1) or (w+x > self.w and self.w-x+1 or w)) - if(self.parent~=nil)then - self.parent:drawBackgroundBox(math.max(x+(obx-1),obx)-(self.parent.x-1), math.max(y+(oby-1),oby)-(self.parent.y-1), w, h, bgCol) + h = (y < 1 and (h + y > self.h and self.h or h + y - 1) or (h + y > self.h and self.h - y + 1 or h)) + w = (x < 1 and (w + x > self.w and self.w or w + x - 1) or (w + x > self.w and self.w - x + 1 or w)) + if (self.parent ~= nil) then + self.parent:drawBackgroundBox(math.max(x + (obx - 1), obx) - (self.parent.x - 1), math.max(y + (oby - 1), oby) - (self.parent.y - 1), w, h, bgCol) else - drawHelper.drawBackgroundBox(math.max(x+(obx-1),obx), math.max(y+(oby-1),oby), w, h, bgCol) + drawHelper.drawBackgroundBox(math.max(x + (obx - 1), obx), math.max(y + (oby - 1), oby), w, h, bgCol) end end; drawTextBox = function(self, x, y, w, h, symbol) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - h = (y < 1 and (h+y > self.h and self.h or h+y-1) or (h+y > self.h and self.h-y+1 or h)) - w = (x < 1 and (w+x > self.w and self.w or w+x-1) or (w+x > self.w and self.w-x+1 or w)) - if(self.parent~=nil)then - self.parent:drawTextBox(math.max(x+(obx-1),obx)-(self.parent.x-1), math.max(y+(oby-1),oby)-(self.parent.y-1), w, h, symbol:sub(1,1)) + h = (y < 1 and (h + y > self.h and self.h or h + y - 1) or (h + y > self.h and self.h - y + 1 or h)) + w = (x < 1 and (w + x > self.w and self.w or w + x - 1) or (w + x > self.w and self.w - x + 1 or w)) + if (self.parent ~= nil) then + self.parent:drawTextBox(math.max(x + (obx - 1), obx) - (self.parent.x - 1), math.max(y + (oby - 1), oby) - (self.parent.y - 1), w, h, symbol:sub(1, 1)) else - drawHelper.drawTextBox(math.max(x+(obx-1),obx), math.max(y+(oby-1),oby), w, h, symbol:sub(1,1)) + drawHelper.drawTextBox(math.max(x + (obx - 1), obx), math.max(y + (oby - 1), oby), w, h, symbol:sub(1, 1)) end end; drawForegroundBox = function(self, x, y, w, h, fgCol) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) - h = (y < 1 and (h+y > self.h and self.h or h+y-1) or (h+y > self.h and self.h-y+1 or h)) - w = (x < 1 and (w+x > self.w and self.w or w+x-1) or (w+x > self.w and self.w-x+1 or w)) - if(self.parent~=nil)then - self.parent:drawForegroundBox(math.max(x+(obx-1),obx)-(self.parent.x-1), math.max(y+(oby-1),oby)-(self.parent.y-1), w, h, fgCol) + h = (y < 1 and (h + y > self.h and self.h or h + y - 1) or (h + y > self.h and self.h - y + 1 or h)) + w = (x < 1 and (w + x > self.w and self.w or w + x - 1) or (w + x > self.w and self.w - x + 1 or w)) + if (self.parent ~= nil) then + self.parent:drawForegroundBox(math.max(x + (obx - 1), obx) - (self.parent.x - 1), math.max(y + (oby - 1), oby) - (self.parent.y - 1), w, h, fgCol) else - drawHelper.drawForegroundBox(math.max(x+(obx-1),obx), math.max(y+(oby-1),oby), w, h, fgCol) + drawHelper.drawForegroundBox(math.max(x + (obx - 1), obx), math.max(y + (oby - 1), oby), w, h, fgCol) end end; - + draw = function(self) - if(self:getVisualChanged())then - if(base.draw(self))then + if (self:getVisualChanged()) then + if (base.draw(self)) then local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local anchx, anchy = self:getAnchorPosition() - if(self.parent~=nil)then + if (self.parent ~= nil) then self.parent:drawBackgroundBox(anchx, anchy, self.w, self.h, self.bgcolor) self.parent:drawForegroundBox(anchx, anchy, self.w, self.h, self.fgcolor) self.parent:drawTextBox(anchx, anchy, self.w, self.h, " ") @@ -3781,28 +3956,28 @@ local function Frame(name,parent) -- Frame drawHelper.drawTextBox(obx, oby, self.w, self.h, " ") end parentTerminal.setCursorBlink(false) - if(self.barActive)then - if(self.parent~=nil)then + if (self.barActive) then + if (self.parent ~= nil) then self.parent:writeText(anchx, anchy, getTextHorizontalAlign(self.barText, self.w, self.barTextAlign), self.barBackground, self.barTextcolor) else drawHelper.writeText(obx, oby, getTextHorizontalAlign(self.barText, self.w, self.barTextAlign), self.barBackground, self.barTextcolor) end end - for _,index in rpairs(objZIndex)do - if(objects[index]~=nil)then - for _,v in pairs(objects[index])do - if(v.draw~=nil)then + for _, index in rpairs(objZIndex) do + if (objects[index] ~= nil) then + for _, v in pairs(objects[index]) do + if (v.draw ~= nil) then v:draw() end end end end - if(cursorBlink)then + if (cursorBlink) then parentTerminal.setTextColor(cursorColor) parentTerminal.setCursorPos(xCursor, yCursor) - if(self.parent~=nil)then + if (self.parent ~= nil) then parentTerminal.setCursorBlink(self:isFocused()) else parentTerminal.setCursorBlink(cursorBlink) @@ -3830,7 +4005,7 @@ local function Frame(name,parent) -- Frame obj.name = name return addObject(obj) end; - + addLabel = function(self, name) local obj = Label(name) obj.name = name @@ -3934,7 +4109,7 @@ local function Frame(name,parent) -- Frame obj.name = name return addObject(obj) end; - + addFrame = function(self, name) local obj = Frame(name, self) obj.name = name @@ -3942,24 +4117,34 @@ local function Frame(name,parent) -- Frame end; } setmetatable(object, base) - if(parent==nil)then + if (parent == nil) then table.insert(frames, object) end return object end - local updaterActive = false -local function basaltUpdateEvent(event, p1,p2,p3,p4) - if(event=="mouse_click")then activeFrame:mouseClickHandler(event,p1,p2,p3,p4) end - if(event=="mouse_drag")then activeFrame:mouseClickHandler(event,p1,p2,p3,p4) end - if(event=="mouse_up")then activeFrame:mouseClickHandler(event,p1,p2,p3,p4) end - if(event=="mouse_scroll")then activeFrame:mouseClickHandler(event,p1,p2,p3,p4) end - if(event=="key")or(event=="char")then activeFrame:keyHandler(event,p1) activeFrame:backgroundKeyHandler(event,p1) end - for _,v in pairs(frames)do +local function basaltUpdateEvent(event, p1, p2, p3, p4) + if (event == "mouse_click") then + activeFrame:mouseClickHandler(event, p1, p2, p3, p4) + end + if (event == "mouse_drag") then + activeFrame:mouseClickHandler(event, p1, p2, p3, p4) + end + if (event == "mouse_up") then + activeFrame:mouseClickHandler(event, p1, p2, p3, p4) + end + if (event == "mouse_scroll") then + activeFrame:mouseClickHandler(event, p1, p2, p3, p4) + end + if (event == "key") or (event == "char") then + activeFrame:keyHandler(event, p1) + activeFrame:backgroundKeyHandler(event, p1) + end + for _, v in pairs(frames) do v:eventHandler(event, p1, p2, p3, p4) end - if(updaterActive)then + if (updaterActive) then activeFrame:draw() drawHelper.update() end @@ -3971,14 +4156,14 @@ function basalt.autoUpdate(isActive) activeFrame:draw() drawHelper.update() while updaterActive do - local event, p1,p2,p3,p4 = os.pullEventRaw() -- change to raw later - basaltUpdateEvent(event, p1,p2,p3,p4) + local event, p1, p2, p3, p4 = os.pullEventRaw() -- change to raw later + basaltUpdateEvent(event, p1, p2, p3, p4) end end function basalt.update(event, p1, p2, p3, p4) - if(event~="nil")then - basaltUpdateEvent(event, p1,p2,p3,p4) + if (event ~= "nil") then + basaltUpdateEvent(event, p1, p2, p3, p4) else activeFrame:draw() drawHelper.update() @@ -3990,8 +4175,8 @@ function basalt.stop() end function basalt.getFrame(name) - for k,v in pairs(frames)do - if(v.name==name)then + for k, v in pairs(frames) do + if (v.name == name) then return v end end @@ -4002,7 +4187,7 @@ function basalt.getActiveFrame() end function basalt.setActiveFrame(frame) - if(frame:getType()=="Frame")then + if (frame:getType() == "Frame") then activeFrame = frame return true end @@ -4015,8 +4200,8 @@ function basalt.createFrame(name) end function basalt.removeFrame(name) - for k,v in pairs(frames)do - if(v.name==name)then + for k, v in pairs(frames) do + if (v.name == name) then frames[k] = nil return true end @@ -4024,29 +4209,35 @@ function basalt.removeFrame(name) return false end -if(basalt.debugger)then - basalt.debugFrame = basalt.createFrame("basaltDebuggingFrame"):showBar():setBackground(colors.lightGray):setBar("Debug",colors.black,colors.gray) - basalt.debugList = basalt.debugFrame:addList("debugList"):setSize(basalt.debugFrame.w - 2, basalt.debugFrame.h - 3):setPosition(2,3):setScrollable(true):show() - basalt.debugFrame:addButton("back"):setAnchor("right"):setSize(1,1):setText("\22"):onClick(function() basalt.oldFrame:show() end):setBackground(colors.red):show() - basalt.debugLabel = basalt.debugFrame:addLabel("debugLabel"):onClick(function() basalt.oldFrame = activeFrame basalt.debugFrame:show() end):setBackground(colors.black):setForeground(colors.white):setAnchor("bottom"):setZIndex(20):show() +if (basalt.debugger) then + basalt.debugFrame = basalt.createFrame("basaltDebuggingFrame"):showBar():setBackground(colors.lightGray):setBar("Debug", colors.black, colors.gray) + basalt.debugList = basalt.debugFrame:addList("debugList"):setSize(basalt.debugFrame.w - 2, basalt.debugFrame.h - 3):setPosition(2, 3):setScrollable(true):show() + basalt.debugFrame:addButton("back"):setAnchor("right"):setSize(1, 1):setText("\22"):onClick(function() + basalt.oldFrame:show() + end) :setBackground(colors.red):show() + basalt.debugLabel = basalt.debugFrame:addLabel("debugLabel"):onClick(function() + basalt.oldFrame = activeFrame + basalt.debugFrame:show() + end) :setBackground(colors.black):setForeground(colors.white):setAnchor("bottom"):setZIndex(20):show() end - -if(basalt.debugger)then +if (basalt.debugger) then function basalt.debug(...) - local args = {...} - if(activeFrame.name~="basaltDebuggingFrame")then - if(activeFrame~=basalt.debugLabel.frame)then + local args = { ... } + if (activeFrame.name ~= "basaltDebuggingFrame") then + if (activeFrame ~= basalt.debugLabel.frame) then basalt.debugLabel:setParent(activeFrame) end end local str = "" - for k,v in pairs(args)do - str = str..tostring(v)..(#args~=k and ", " or "") + for k, v in pairs(args) do + str = str .. tostring(v) .. (#args ~= k and ", " or "") end - basalt.debugLabel:setText("[Debug] "..str) + basalt.debugLabel:setText("[Debug] " .. str) basalt.debugList:addItem(str) - if(basalt.debugList:getItemCount()>50)then basalt.debugList:removeItem(1) end + if (basalt.debugList:getItemCount() > 50) then + basalt.debugList:removeItem(1) + end basalt.debugList:setValue(basalt.debugList:getItem(basalt.debugList:getItemCount())) basalt.debugLabel:show() end