Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fontdata={}
- local meta={}
- function meta:SetFont(newfont)
- if(fontdata[newfont]) then
- self.Font=newfont
- local font=fontdata[newfont]
- self.FontW=font.w
- self.FontH=font.h
- return
- end
- local maxw,maxh=0,0
- surface.SetFont(newfont)
- for i=16,127 do--Todo: UNICODE
- local w,h=surface.GetTextSize(string.char(i))
- if(w>maxw) then
- maxw=w
- end
- if(h>maxh) then
- maxh=h
- end
- end
- local font={w=maxw,h=maxh}
- fontdata[newfont]=font
- self.Font=newfont
- self.FontW=maxw
- self.FontH=maxh
- end
- function meta:Draw(xpos,ypos)
- local width,height=self.W,self.H
- local cursor=self.Cursor
- if(cursor and math.floor(CurTime()*4)%2==1) then
- surface.SetDrawColor(200,200,200)
- surface.DrawRect(cursor.x*self.FontW+xpos,cursor.y*self.FontH+ypos+(cursor.size*self.FontH),self.FontW,self.FontH*cursor.size)
- end
- surface.SetFont(self.Font)
- local curcol=color_white
- surface.SetTextColor(255,255,255)--TODO: Customizable character colors
- for y=0,height-1 do
- for x=0,width-1 do
- local charcol=self.CharCols[x][y]
- surface.SetTextColor(charcol)
- surface.SetTextPos(xpos+x*self.FontW,y*self.FontH+ypos)
- local char=self.Chars[x][y]
- if(char~="") then
- surface.DrawText(char)
- surface.SetTextColor(curcol)
- end
- end
- end
- end
- function meta:SetChar(x,y,char, col)
- if(self.Chars[x] and self.Chars[x][y]) then
- self.Chars[x][y]=char
- if(col) then
- self.CharCols[x][y]=col
- end
- end
- end
- function meta:SetCursorScale(scale)
- if(self.Cursor) then
- self.Cursor.size=scale
- end
- end
- function meta:SetCursor(x,y)
- self.Cursor={x=x,y=y,size=0.5}
- end
- --v1: SetSize clears screen!
- function meta:Clear()
- local w,h=self.W,self.H
- local chars={}
- local charcols={}
- for x=0,w-1 do
- for y=0,h-1 do
- chars[x]=chars[x] or {}
- chars[x][y]=""
- charcols[x]=charcols[x] or {}
- charcols[x][y]=color_white
- end
- end
- self.Chars=chars
- self.CharCols=charcols
- end
- function meta:SetSize(w,h)
- self.W=w
- self.H=h
- local chars={}
- local charcols={}
- for x=0,w-1 do
- for y=0,h-1 do
- chars[x]=chars[x] or {}
- chars[x][y]=""
- charcols[x]=charcols[x] or {}
- charcols[x][y]=color_white
- end
- end
- self.Chars=chars
- self.CharCols=charcols
- end
- meta.__index=meta
- display={}
- function display.Create(initialWidth,initialHeight)
- local display=setmetatable({},meta)
- display:SetSize(initialWidth or 67, initialHeight or 13)
- display:SetFont("ConsoleText")
- return display
- end
- local PANEL={}
- function PANEL:Init()
- local display=display.Create()
- self:SetSize(display.W*display.FontW,display.H*display.FontH)
- end
- local frame=vgui.Create("DFrame")
- local display=display.Create()
- frame:SetSize(display.W*display.FontW,display.H*display.FontH+22)
- local str="Loading..."
- for i=1,#str do
- display:SetChar(i-1,0,str[i])
- end
- local filmText
- local loaded=false
- local last=CurTime()
- local lines={}
- local lineidx=0
- local finished=false
- http.Get("http://dl.dropbox.com/u/4992578/starwars.txt","",function(content)
- filmText=content:gsub("\\n","\n")
- for line in string.gmatch( filmText, "([^\n]*)\n") do
- table.insert(lines,line)
- end
- loaded=true
- end)
- function frame:PaintOver()
- if(last>CurTime() or finished or not loaded) then
- display:Draw(0,22)
- return
- end
- -- Get this every frame incase the monitor resizes
- local w,h = display.W,display.H
- local startX = math.floor( (w - 68) / 2 )
- local startY = math.floor( (h - 14) / 2 )
- -- Print the frame
- display:Clear()
- local holdLine=lines[lineidx+1]
- lineidx=lineidx+1
- for n=1,13 do
- local line = lines[lineidx+n]
- if line then
- for i=1,#line-1 do
- display:SetChar(startX+i, startY + n, line[i])
- end
- else
- finished = true
- return
- end
- end
- lineidx=lineidx+13
- -- Hold the frame
- local hold = tonumber(holdLine) or 1
- local delay = (hold * 0.05)-0.01
- last=CurTime()+delay
- display:Draw(0,22)
- end
- --[=[
- local str="Hello world"
- local chars={" ", "x", "X", " "}
- concommand.Add("chars",function(_,_,args) chars=args end)
- local lines={"+---------------------------------------+","|Please log in |","|User:__________________________________|","|Pass:__________________________________|","+---------------------------------------+"}
- local lineNum=0 ---------------------------------------
- local lineIdx=1
- local asciiart=
- string.Explode("\n",[[ .88888888:.
- 88888888.88888.
- .8888888888888888.
- 888888888888888888
- 88' _`88'_ `88888
- 88 88 88 88 88888
- 88_88_::_88_:88888
- 88:::,::,:::::8888
- 88`:::::::::'`8888
- .88 `::::' 8:88.
- 8888 `8:888.
- .8888' `888888.
- .8888:.. .::. ...:'8888888:.
- .8888.' :' `'::`88:88888
- .8888 ' `.888:8888.
- 888:8 . 888:88888
- .888:88 .: 888:88888:
- 8888888. :: 88:888888
- `.::.888. :: .88888888
- .::::::.888. :: :::`8888'.:.
- ::::::::::.888 ' .::::::::::::
- ::::::::::::.8 ' .:8::::::::::::.
- .::::::::::::::. .:888:::::::::::::
- :::::::::::::::88:.__..:88888:::::::::::'
- `'.:::::::::::88888888888.88:::::::::'
- `':::_:' -- '' -'-' `':_::::'` ]])
- local map={["8"]=Color(50,50,50),[":"]=Color(255,255,0),[","]=Color(150,150,0),["."]=Color(100,100,100)}
- for k,line in pairs(asciiart) do
- for i=1,#line do
- display:SetChar(56+i,k,line[i],map[line[i]])
- end
- end
- local lastTick=CurTime()
- function frame:PaintOver()
- for i=0,45 do
- for amt=16,256,8 do
- local x,y=math.Rad2Deg(math.sin(i*(amt/45)+(CurTime())%45)),math.Rad2Deg(math.cos(i*(amt/45)+(CurTime())%45))
- display:SetChar(math.floor(x/360*amt)+16,math.floor(y/360*amt)+16,chars[(i%#chars+1)],Color(i*4,i*2,255))
- --local x,y=math.Rad2Deg(math.sin(i*(amt/45)+(CurTime())%45)),math.Rad2Deg(math.cos(i*(amt/45)+(CurTime())%45))
- end
- --display:SetChar(math.floor(x/360*32)+16,math.floor(y/360*32)+16,i%2==1 and "B" or "N")
- end
- if(CurTime()>lastTick and lineNum<=#lines) then
- local line=lines[lineNum]
- if not line or #line<lineIdx then
- lineIdx=1
- lineNum=lineNum+1
- line=lines[lineNum]
- end
- if not line then
- lineNum=lineNum+1
- display:SetCursor(48+7,3+39)
- return
- end
- display:SetChar(48+lineIdx,lineNum+39,line[lineIdx])
- display:SetCursor(48+lineIdx,lineNum+39)
- lineIdx=lineIdx+1
- lastTick=CurTime()+0
- end
- display:Draw(0,22)
- end]=]
Advertisement
Add Comment
Please, Sign In to add comment