Advertisement
boxmein

Texter.lua with Tlines()

Nov 3rd, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.11 KB | None | 0 0
  1. texter={}
  2. texter.lastcolor = "whol"
  3. function texter.Tchar(text,x,y,ptype)
  4. local mtx={}
  5. local voffset=0
  6. local hoffset=0
  7.  
  8.         mtx[1]={0,0,0}
  9.  
  10. if text=="a" then
  11.     mtx[1]={0,1,0}
  12.     mtx[2]={1,0,1}
  13.     mtx[3]={1,1,1}
  14.     mtx[4]={1,0,1}
  15.     mtx[5]={1,0,1}
  16. elseif text=="b" then
  17.     mtx[1]={1,1,0}
  18.     mtx[2]={1,0,1}
  19.     mtx[3]={1,1,0}
  20.     mtx[4]={1,0,1}
  21.     mtx[5]={1,1,0}
  22. elseif text=="c" then
  23.     mtx[1]={0,1,1}
  24.     mtx[2]={1,0,0}
  25.     mtx[3]={1,0,0}
  26.     mtx[4]={1,0,0}
  27.     mtx[5]={0,1,1}
  28. elseif text=="d" then
  29.     mtx[1]={1,1,0}
  30.     mtx[2]={1,0,1}
  31.     mtx[3]={1,0,1}
  32.     mtx[4]={1,0,1}
  33.     mtx[5]={1,1,0}
  34. elseif text=="e" then
  35.     mtx[1]={1,1,1}
  36.     mtx[2]={1,0,0}
  37.     mtx[3]={1,1,0}
  38.     mtx[4]={1,0,0}
  39.     mtx[5]={1,1,1}
  40. elseif text=="f" then
  41.     mtx[1]={1,1,1}
  42.     mtx[2]={1,0,0}
  43.     mtx[3]={1,1,0}
  44.     mtx[4]={1,0,0}
  45.     mtx[5]={1,0,0}
  46. elseif text=="g" then
  47.     mtx[1]={0,1,1,1}
  48.     mtx[2]={1,0,0,0}
  49.     mtx[3]={1,0,1,1}
  50.     mtx[4]={1,0,0,1}
  51.     mtx[5]={0,1,1,0}
  52. elseif text=="h" then
  53.     mtx[1]={1,0,1}
  54.     mtx[2]={1,0,1}
  55.     mtx[3]={1,1,1}
  56.     mtx[4]={1,0,1}
  57.     mtx[5]={1,0,1}
  58. elseif text=="i" then
  59.     mtx[1]={1,1,1}
  60.     mtx[2]={0,1,0}
  61.     mtx[3]={0,1,0}
  62.     mtx[4]={0,1,0}
  63.     mtx[5]={1,1,1}
  64. elseif text=="j" then
  65.     mtx[1]={0,1}
  66.     mtx[2]={0,1}
  67.     mtx[3]={0,1}
  68.     mtx[4]={0,1}
  69.     mtx[5]={1,0}
  70. elseif text=="k" then
  71.     mtx[1]={1,0,1}
  72.     mtx[2]={1,0,1}
  73.     mtx[3]={1,1,0}
  74.     mtx[4]={1,0,1}
  75.     mtx[5]={1,0,1}
  76. elseif text=="l" then
  77.     mtx[1]={1,0,0}
  78.     mtx[2]={1,0,0}
  79.     mtx[3]={1,0,0}
  80.     mtx[4]={1,0,0}
  81.     mtx[5]={1,1,1}
  82. elseif text=="m" then
  83.     mtx[1]={1,0,0,0,1}
  84.     mtx[2]={1,1,0,1,1}
  85.     mtx[3]={1,0,1,0,1}
  86.     mtx[4]={1,0,0,0,1}
  87.     mtx[5]={1,0,0,0,1}
  88. elseif text=="n" then
  89.     mtx[1]={1,0,0,1}
  90.     mtx[2]={1,1,0,1}
  91.     mtx[3]={1,0,1,1}
  92.     mtx[4]={1,0,0,1}
  93.     mtx[5]={1,0,0,1}
  94. elseif text=="o" then
  95.     mtx[1]={0,1,1,0}
  96.     mtx[2]={1,0,0,1}
  97.     mtx[3]={1,0,0,1}
  98.     mtx[4]={1,0,0,1}
  99.     mtx[5]={0,1,1,0}
  100. elseif text=="p" then
  101.     mtx[1]={1,1,0}
  102.     mtx[2]={1,0,1}
  103.     mtx[3]={1,1,0}
  104.     mtx[4]={1,0,0}
  105.     mtx[5]={1,0,0}
  106. elseif text=="q" then
  107.     mtx[1]={0,1,1,1,0}
  108.     mtx[2]={1,0,0,0,1}
  109.     mtx[3]={1,0,1,0,1}
  110.     mtx[4]={1,0,0,1,0}
  111.     mtx[5]={0,1,1,0,1}
  112. elseif text=="r" then
  113.     mtx[1]={1,1,0}
  114.     mtx[2]={1,0,1}
  115.     mtx[3]={1,1,0}
  116.     mtx[4]={1,0,1}
  117.     mtx[5]={1,0,1}
  118. elseif text=="s" then
  119.     mtx[1]={0,1,1}
  120.     mtx[2]={1,0,0}
  121.     mtx[3]={0,1,0}
  122.     mtx[4]={0,0,1}
  123.     mtx[5]={1,1,0}
  124. elseif text=="t" then
  125.     mtx[1]={1,1,1}
  126.     mtx[2]={0,1,0}
  127.     mtx[3]={0,1,0}
  128.     mtx[4]={0,1,0}
  129.     mtx[5]={0,1,0}
  130. elseif text=="u" then
  131.     mtx[1]={1,0,0,1}
  132.     mtx[2]={1,0,0,1}
  133.     mtx[3]={1,0,0,1}
  134.     mtx[4]={1,0,0,1}
  135.     mtx[5]={0,1,1,0}
  136. elseif text=="v" then
  137.     mtx[1]={1,0,1}
  138.     mtx[2]={1,0,1}
  139.     mtx[3]={1,0,1}
  140.     mtx[4]={1,0,1}
  141.     mtx[5]={0,1,0}
  142. elseif text=="w" then
  143.     mtx[1]={1,0,1,0,1}
  144.     mtx[2]={1,0,1,0,1}
  145.     mtx[3]={1,0,1,0,1}
  146.     mtx[4]={1,0,1,0,1}
  147.     mtx[5]={0,1,0,1,0}
  148. elseif text=="x" then
  149.     mtx[1]={1,0,1}
  150.     mtx[2]={1,0,1}
  151.     mtx[3]={0,1,0}
  152.     mtx[4]={1,0,1}
  153.     mtx[5]={1,0,1}
  154. elseif text=="y" then
  155.     mtx[1]={1,0,1}
  156.     mtx[2]={1,0,1}
  157.     mtx[3]={0,1,0}
  158.     mtx[4]={0,1,0}
  159.     mtx[5]={0,1,0}
  160. elseif text=="z" then
  161.     mtx[1]={1,1,1}
  162.     mtx[2]={0,0,1}
  163.     mtx[3]={0,1,0}
  164.     mtx[4]={1,0,0}
  165.     mtx[5]={1,1,1}
  166. elseif text=="0" then
  167.     mtx[1]={0,1,0}
  168.     mtx[2]={1,0,1}
  169.     mtx[3]={1,0,1}
  170.     mtx[4]={1,0,1}
  171.     mtx[5]={0,1,0}
  172. elseif text=="1" then
  173.     mtx[1]={0,1,0}
  174.     mtx[2]={1,1,0}
  175.     mtx[3]={0,1,0}
  176.     mtx[4]={0,1,0}
  177.     mtx[5]={1,1,1}
  178. elseif text=="2" then
  179.     mtx[1]={1,1,0}
  180.     mtx[2]={0,0,1}
  181.     mtx[3]={0,1,0}
  182.     mtx[4]={1,0,0}
  183.     mtx[5]={1,1,1}
  184. elseif text=="3" then
  185.     mtx[1]={1,1,0}
  186.     mtx[2]={0,0,1}
  187.     mtx[3]={0,1,0}
  188.     mtx[4]={0,0,1}
  189.     mtx[5]={1,1,0}
  190. elseif text=="4" then
  191.     mtx[1]={1,0,1}
  192.     mtx[2]={1,0,1}
  193.     mtx[3]={1,1,1}
  194.     mtx[4]={0,0,1}
  195.     mtx[5]={0,0,1}
  196. elseif text=="5" then
  197.     mtx[1]={1,1,1}
  198.     mtx[2]={1,0,0}
  199.     mtx[3]={1,1,0}
  200.     mtx[4]={0,0,1}
  201.     mtx[5]={1,1,0}
  202. elseif text=="6" then
  203.     mtx[1]={0,1,1}
  204.     mtx[2]={1,0,0}
  205.     mtx[3]={1,1,0}
  206.     mtx[4]={1,0,1}
  207.     mtx[5]={0,1,0}
  208. elseif text=="7" then
  209.     mtx[1]={1,1,1}
  210.     mtx[2]={0,0,1}
  211.     mtx[3]={0,1,0}
  212.     mtx[4]={0,1,0}
  213.     mtx[5]={0,1,0}
  214. elseif text=="8" then
  215.     mtx[1]={0,1,0}
  216.     mtx[2]={1,0,1}
  217.     mtx[3]={0,1,0}
  218.     mtx[4]={1,0,1}
  219.     mtx[5]={0,1,0}
  220. elseif text=="9" then
  221.     mtx[1]={0,1,0}
  222.     mtx[2]={1,0,1}
  223.     mtx[3]={0,1,1}
  224.     mtx[4]={0,0,1}
  225.     mtx[5]={1,1,0}
  226. elseif text=="!" then
  227.     mtx[1]={0,1,0}
  228.     mtx[2]={0,1,0}
  229.     mtx[3]={0,1,0}
  230.     mtx[4]={0,0,0}
  231.     mtx[5]={0,1,0}
  232. elseif text=="(" then
  233.     mtx[1]={0,0,1}
  234.     mtx[2]={0,1,0}
  235.     mtx[3]={0,1,0}
  236.     mtx[4]={0,1,0}
  237.     mtx[5]={0,0,1}
  238. elseif text==")" then
  239.     mtx[1]={1,0,0}
  240.     mtx[2]={0,1,0}
  241.     mtx[3]={0,1,0}
  242.     mtx[4]={0,1,0}
  243.     mtx[5]={1,0,0}
  244. elseif text=="-" then
  245.     mtx[1]={1,1,1}
  246.  voffset=2
  247. elseif text=="_" then
  248.     mtx[1]={1,1,1}
  249.  voffset=4
  250. elseif text=="=" then
  251.     mtx[1]={1,1,1}
  252.     mtx[2]={0,0,0}
  253.     mtx[3]={1,1,1}
  254.  voffset=1
  255. elseif text=="+" then
  256.     mtx[1]={0,1,0}
  257.     mtx[2]={1,1,1}
  258.     mtx[3]={0,1,0}
  259.  voffset=1
  260.  elseif text=="[" then
  261.     mtx[1]={1,1,0}
  262.     mtx[2]={1,0,0}
  263.     mtx[3]={1,0,0}
  264.     mtx[4]={1,0,0}
  265.     mtx[5]={1,1,0}
  266. elseif text=="]" then
  267.     mtx[1]={0,1,1}
  268.     mtx[2]={0,0,1}
  269.     mtx[3]={0,0,1}
  270.     mtx[4]={0,0,1}
  271.     mtx[5]={0,1,1}
  272. elseif text=="{" then
  273.     mtx[1]={0,1,1}
  274.     mtx[2]={0,1,0}
  275.     mtx[3]={1,0,0}
  276.     mtx[4]={0,1,0}
  277.     mtx[5]={0,1,1}
  278. elseif text=="}" then
  279.     mtx[1]={1,1,0}
  280.     mtx[2]={0,1,0}
  281.     mtx[3]={0,0,1}
  282.     mtx[4]={0,1,0}
  283.     mtx[5]={1,1,0}
  284. elseif text=="|" then
  285.     mtx[1]={0,1,0}
  286.     mtx[2]={0,1,0}
  287.     mtx[3]={0,1,0}
  288.     mtx[4]={0,1,0}
  289.     mtx[5]={0,1,0}
  290. elseif text==":" then
  291.     mtx[1]={0,0,0}
  292.     mtx[2]={0,1,0}
  293.     mtx[3]={0,0,0}
  294.     mtx[4]={0,1,0}
  295. elseif text==";" then
  296.     mtx[1]={0,1,0}
  297.     mtx[2]={0,0,0}
  298.     mtx[3]={0,1,0}
  299.     mtx[4]={1,0,0}
  300.  voffset=1
  301. elseif text=="\'" or text=="`" then
  302.     mtx[1]={0,1,0}
  303.     mtx[2]={0,1,0}
  304.  voffset=-1
  305. elseif text=="\"" then
  306.     mtx[1]={0,1,0,1}
  307.     mtx[2]={0,1,0,1}
  308.  voffset=-1
  309. elseif text=="," then
  310.     mtx[1]={0,1,0}
  311.     mtx[2]={1,0,0}
  312.  voffset=4
  313. elseif text=="." then
  314.     mtx[5]={1}
  315.  voffset=4
  316. elseif text=="<" then
  317.     mtx[1]={0,0,0,1}
  318.     mtx[2]={0,0,1,0}
  319.     mtx[3]={0,1,0,0}
  320.     mtx[4]={0,0,1,0}
  321.     mtx[5]={0,0,0,1}
  322. elseif text==">" then
  323.     mtx[1]={0,1,0,0}
  324.     mtx[2]={0,0,1,0}
  325.     mtx[3]={0,0,0,1}
  326.     mtx[4]={0,0,1,0}
  327.     mtx[5]={0,1,0,0}
  328. elseif text=="/" then
  329.     mtx[1]={0,0,0,0,1}
  330.     mtx[2]={0,0,0,1,0}
  331.     mtx[3]={0,0,1,0,0}
  332.     mtx[4]={0,1,0,0,0}
  333.     mtx[5]={1,0,0,0,0}
  334. elseif text=="\\" then
  335.     mtx[1]={1,0,0,0,0}
  336.     mtx[2]={0,1,0,0,0}
  337.     mtx[3]={0,0,1,0,0}
  338.     mtx[4]={0,0,0,1,0}
  339.     mtx[5]={0,0,0,0,1}
  340. elseif text=="?" then
  341.     mtx[1]={1,1,1}
  342.     mtx[2]={0,0,1}
  343.     mtx[3]={0,1,0}
  344.     mtx[4]={0,0,0}
  345.     mtx[5]={0,1,0}
  346. elseif text=="^" then
  347.     mtx[1]={0,1,0}
  348.     mtx[2]={1,0,1}
  349. elseif text=="#" then
  350.     mtx[1]={0,1,0,1,0}
  351.     mtx[2]={1,1,1,1,1}
  352.     mtx[3]={0,1,0,1,0}
  353.     mtx[4]={1,1,1,1,1}
  354.     mtx[5]={0,1,0,1,0}
  355. elseif text=="$" then
  356.     mtx[1]={0,0,1,0,0}
  357.     mtx[2]={0,1,1,1,1}
  358.     mtx[3]={1,0,1,0,0}
  359.     mtx[4]={0,1,1,1,0}
  360.     mtx[5]={0,0,1,0,1}
  361.     mtx[6]={1,1,1,1,0}
  362.     mtx[7]={0,0,1,0,0}
  363.  voffset=-1
  364. elseif text=="%" then
  365.     mtx[1]={1,1,0,0,1}
  366.     mtx[2]={1,1,0,1,0}
  367.     mtx[3]={0,0,1,0,0}
  368.     mtx[4]={0,1,0,1,1}
  369.     mtx[5]={1,0,0,1,1}
  370. elseif text=="&" then
  371.     mtx[1]={0,0,1,1,1}
  372.     mtx[2]={0,0,1,0,0}
  373.     mtx[3]={0,1,1,1,1}
  374.     mtx[4]={1,0,0,1,0}
  375.     mtx[5]={0,1,1,0,1}
  376. elseif text=="@" then
  377.     mtx[1]={0,1,1,1,1,1,0}
  378.     mtx[2]={1,0,0,1,1,0,1}
  379.     mtx[3]={1,0,1,0,1,0,1}
  380.     mtx[4]={1,0,1,1,1,1,1}
  381.     mtx[5]={1,0,0,0,0,0,0}
  382.     mtx[6]={0,1,1,1,1,1,0}
  383.  voffset=-1
  384. elseif text=="*" then
  385.     mtx[1]={0,1,0,0,1,0}
  386.     mtx[2]={0,0,1,1,0,0}
  387.     mtx[3]={1,1,1,1,1,1}
  388.     mtx[4]={0,0,1,1,0,0}
  389.     mtx[5]={0,1,0,0,1,0}
  390. elseif text=="~" then
  391.     mtx[1]={0,0,0,0,0,0}
  392.     mtx[2]={0,0,0,0,0,0}
  393.     mtx[3]={0,1,1,0,0,1}
  394.     mtx[4]={1,0,0,1,1,0}
  395. elseif text==" " then
  396.     mtx[1]={0,0,0}
  397. else --unknow character
  398.     mtx[1]={1,1,1,1,1}
  399.     mtx[2]={1,0,0,0,1}
  400.     mtx[3]={1,0,0,0,1}
  401.     mtx[4]={1,0,0,0,1}
  402.     mtx[5]={1,1,1,1,1}
  403. end
  404.  
  405. local height = #    mtx
  406. local width = 3
  407. for i=1,height do
  408.  if     mtx[i]==nil then else
  409.   width = # mtx[i]
  410.   for j=1,width do
  411.    if   mtx[i][j]==1 then
  412.     tpt.create(x+j-1+hoffset,y+i-1+voffset,ptype)
  413.    end
  414.   end
  415.  end
  416. end
  417. return width
  418. end
  419.  
  420. function texter.Tstr(text,x,y,ptype)
  421.     local ox=0
  422.     for i=1,string.len(text) do
  423.         ox = 1 + ox + texter.Tchar(string.sub(string.lower(text),i,i),x+ox,y,ptype)
  424.     end
  425.     return string.len(text)
  426. end
  427.  
  428. function T(text,ptype) -- Print one line to mouse position
  429.     if ptype == nil then
  430.         ptype = texter.lastcolor -- Use last used if not specified
  431.     else
  432.         texter.lastcolor = ptype -- Set last used if specified
  433.     end
  434.     texter.Tstr(text,tpt.mousex,tpt.mousey,ptype)
  435.     return string.len(text)
  436. end
  437. function Txy(text,x,y,ptype) -- Print one line to x, y (Same as texter.Tstr, but uses last colour)
  438.   if ptype == nil then
  439.     ptype = texter.lastcolor
  440.   else
  441.     texter.lastcolor = ptype
  442.   end
  443.   texter.Tstr(text,x,y,ptype)
  444. end
  445. function Tlines(startx, starty, ...) -- Print multiple lines split by comma
  446.  
  447.     if starty + arg.n * 6 > 383 then -- Start Y + amount of lines * line width
  448.         tpt.log("Too many lines to fit on screen!")
  449.         return
  450.     end
  451.     local curr_string = "" -- Current line
  452.     local curr_liney = 0 -- Current Y position.
  453.     for i=1, arg.n, 1 do
  454.         curr_liney = starty + i * 6 -- One line is 6px wide.
  455.         curr_string = arg[i]
  456.         Txy(curr_string, startx, curr_liney)
  457.     end
  458. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement