FeynmanTech

CodeOS

Dec 30th, 2014
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 36.61 KB | None | 0 0
  1.  
  2. --# Rounded
  3. --[[
  4. local _f = fill
  5. local _fill = vec4(0,0,0,0)
  6. fill = function(r, g, b, a)
  7.     _fill = vec4(...)
  8.     _f(...)
  9. end
  10. --]]
  11.  
  12. rr = {}
  13. local v = vec2(10,10)
  14. rr.sh = nil
  15. rr.m = nil
  16. function rr._ms() return rr.sh end
  17. function rr._mm() return rr.m end
  18. function rr.ms() if rr.sh then return rr.sh else rr.sh = shader("Documents:Rrect") rr.ms = rr._ms return rr.sh end end
  19. function rr.mm() if rr.m  then return rr.m  else rr.m  = mesh() rr.mm = rr._mm return rr.m end end
  20. function rrect(x, y, w, h, r, g)
  21.     m = rr.mm()
  22.     ---[[
  23.     m.shader = rr.ms()
  24.     --m:addRect(x * 2, y * 2, w * 2, h * 2)
  25.    
  26.     if g and not g.w then
  27.         g = vec4(g.x, g.y, g.z, 0)
  28.     end
  29.    
  30.     -- Assign a shader
  31.     m.shader.r = (r > w / 2 and w / 2) or (r > h / 2 and h / 2) or r
  32.     m.shader.a = 1--ContentScaleFactor
  33.     m.shader.coords = vec2(x, y)
  34.     m.shader.size = vec2(w,h)
  35.     m.shader.g = g and g / 255 or vec4(0,0,0,0)
  36.     --]]
  37.    
  38.     -- Set vertices
  39.     --[[
  40.     m.vertices = triangulate{
  41.         vec2(x,y),
  42.         vec2(x+w,y),
  43.         vec2(x+w,y+h),
  44.         vec2(x,y+h)
  45.     }
  46.     --[=[
  47.     --]]
  48.     m.vertices = {
  49.         vec2(x, y),
  50.        vec2(x + w, y),
  51.         vec2(x, y + h),
  52.         vec2(x, y + h),
  53.         vec2(x + w, y + h),
  54.         vec2(x + w, y)
  55.     }
  56.     -- Assign texture coordinates
  57.     m.texCoords = m.vertices
  58.    
  59.     -- Assign a texture
  60.     --m.texture = readImage("Documents:BOXOFFICON")
  61.    
  62.     -- Set all vertex colors to white
  63.     m:setColors(fill())
  64.    
  65.     --m:setRect(re, x, y, w, h)
  66.    
  67.     -- Draw the mesh
  68.     m:draw()
  69. end
  70. --# RoundedSprite
  71. --[[
  72. local _f = fill
  73. local _fill = vec4(0,0,0,0)
  74. fill = function(r, g, b, a)
  75.     _fill = vec4(...)
  76.     _f(...)
  77. end
  78. --]]
  79.  
  80. rs = {}
  81. local v = vec2(10,10)
  82. rs.sh = nil
  83. rr.m = nil
  84. function rs._ms() return rs.sh end
  85. function rs._mm() return rs.m end
  86. function rs.ms() if rs.sh then return rs.sh else rs.sh = shader("Documents:rsprite") rs.ms = rs._ms return rs.sh end end
  87. function rs.mm() if rs.m  then return rs.m  else rs.m  = mesh() rs.mm = rs._mm return rs.m end end
  88. function rsprite(i, x, y, w, h, r, g)
  89.     local m2 = rs.mm()
  90.     ---[[
  91.     m2.shader = rs.ms()
  92.     --m:addRect(0,0,1,1)
  93.    
  94.     if g and not g.w then
  95.         g = vec4(g.x, g.y, g.z, 0)
  96.     end
  97.    
  98.     -- Assign a shader
  99.     m2.shader.r = r / math.max(w, h)
  100.     m2.shader.a = math.max(w, h) * ContentScaleFactor
  101.     m2.shader.coords = vec2(x, y)
  102.     m2.shader.size = vec2(w,h)
  103.     m2.shader.g = g and g / 255 or vec4(0,0,0,0)
  104.     --]]
  105.    
  106.     -- Set vertices
  107.     --[[
  108.     m.vertices = triangulate 2     vec2(x,y),
  109.         vec2(x+w,y),
  110.         vec2(x+w,y+h),
  111.         vec2(x,y+h)
  112.     }
  113.     --[=[
  114.     --]]
  115.     m2.vertices = {
  116.         vec2(x, y),
  117.         vec2(x + w, y),
  118.         vec2(x, y + h),
  119.         vec2(x, y + h),
  120.         vec2(x + w, y + h),
  121.         vec2(x + w, y)
  122.     }
  123.     -- Assign texture coordinates
  124.     m2.texCoords = {vec2(0,0), vec2(1,0), vec2(0,1), vec2(0,1), vec2(1,1), vec2(1,0)}
  125.    
  126.     -- Assign a texture
  127.     m2.texture = i--"Documents:BOXOFFICON"
  128.    
  129.     -- Set all vertex colors to white
  130.     m2:setColors(0,0,0,0)
  131.    
  132.     --m:setRect(re, x, y, w, h)
  133.    
  134.     -- Draw the mesh
  135.     m2:draw()
  136. end
  137. --rsprite = sprite
  138. --# Main
  139. --UPLOADED_TAB:Main
  140. -- CodeOS
  141.  
  142. -- Use this function to perform your initial setup
  143. function setup()
  144.     debugging = false
  145.     local i = readImage("Documents:display")
  146.     saveImage("Project:Icon", i)
  147.     displayMode(FULLSCREEN_NO_BUTTONS)
  148.     keyPressed = ""
  149.     background(255)
  150.     backingMode(RETAINED)
  151.     background(255, 255, 255, 255)
  152.     moved = 2
  153.    
  154.     btext = text --????
  155.    
  156.     CurrentFrame = 0
  157.    
  158. end
  159.  
  160. -- This function gets called once every frame
  161. local FrameCount = 0
  162. function draw()
  163.     background(255)
  164.     FrameCount = FrameCount + 1
  165.     if FrameCount == 10 then
  166.         draw = function()
  167.             --flashAlert = 10 - ElapsedTime
  168.             -- This sets a dark background color
  169.             --background(255, 255, 255, 255)
  170.            
  171.             -- This sets the line thickness
  172.             --strokeWidth(5)
  173.            
  174.             -- Do your drawing here
  175.             CurrentFrame = CurrentFrame + 1
  176.             drawWindows()
  177.             if keyPressed ~= "NP" then keyPressed = "NP" end
  178.             --keyPressed = "NP"
  179.            
  180.             --if msg then msg() end -- Debugging, doesn't do anything unless you have my print library
  181.                
  182.             --flashAlert = flashAlert - 1
  183.         end
  184.     end
  185. end
  186.  
  187. function keyboard(k)
  188.     keyPressed = k
  189.     --print(string.byte(k))
  190. end
  191.  
  192.  
  193.  
  194. --# Taskbar
  195. --UPLOADED_TAB:Taskbar
  196. local tapped = false
  197.  
  198. local s = 50
  199.  
  200. local home = readImage("Cargo Bot:Codea Icon")
  201.    
  202. function taskbar()
  203.     ---[[
  204.     fill(255)
  205.     noStroke()
  206.     rect(0, HEIGHT - 45, WIDTH, 45)
  207.     --]]
  208.     fill(0, 0, 0, 49)
  209.     noStroke()
  210.    
  211.     local t = 0
  212.    
  213.     rrect(s, HEIGHT - 43 + t, WIDTH - 3 - s + t*3, 40 + t*3, 10, vec4(50,50,50,-50))
  214.     ---[[
  215.     if
  216.         bounds(CurrentTouch.x, WIDTH - 39, WIDTH - 9 ) and
  217.         bounds(CurrentTouch.y, HEIGHT - 37, HEIGHT - 8.5)
  218.     then
  219.         fill(213, 57, 57, 255)
  220.         rrect(WIDTH - 39, HEIGHT - 37 + t, 30, 28.5, 5, vec4(40,100,100, 0))
  221.         if CurrentTouch.state == ENDED then
  222.             close()
  223.         end
  224.     else
  225.         fill(226, 114, 114, 255)
  226.         rrect(WIDTH - 39, HEIGHT - 37 + t, 30, 28.5, 5, vec4(40,100,100, 0))
  227.     end
  228.     --]]
  229.     smooth()
  230.     spriteMode(CORNER)
  231.     ---[[
  232.     if CurrentTouch.state == ENDED and not(tapped) and bounds(CurrentTouch.y, HEIGHT-43 + t, HEIGHT-3 + t) and bounds(CurrentTouch.x, s + 6, s + 6+(#winsOrig) * 35) then
  233.         local toRun = math.ceil((CurrentTouch.x - s - 6) / 35)
  234.         --wins[winIndexes[toRun]].active = true
  235.         ---[[
  236.         for n = 1, #wins do
  237.             if winsOrig[toRun] and wins[n].index == winsOrig[toRun].index then
  238.                 --wins[n].active = true
  239.                 --for i, v in pairs(wins[n]) do print(i) end
  240.                 wins[n]:show()
  241.                 moved = 1
  242.                 wins[n].done = false
  243.                 wins[n].closed = false
  244.             end
  245.         end
  246.         --]]
  247.         tapped = true
  248.     elseif CurrentTouch.state == BEGAN then
  249.         tapped = false
  250.     end
  251.     --]]
  252.     local sk = 0
  253.     for n = 1, #winsOrig do
  254.         if winsOrig[n] then
  255.             if winsOrig[n].active then
  256.                 fill(113, 113, 113, 255)
  257.                 rrect(s + 3 + (n - 1 - sk) * 35, HEIGHT - 39.5 + t, 33, 33, 9, vec4(30,30,30,0))
  258.                 fill(210)
  259.                 rrect(s + 5 + (n - 1 - sk) * 35, HEIGHT - 37.5 + t, 29, 29, 7, vec4(30,30,30,0))
  260.             end
  261.             rsprite(winsOrig[n].i, s + 6 + (n - 1 - sk) * 35, HEIGHT - 36.5 + t, 27, 27, 6, vec4(70,70,70,0))
  262.         else
  263.             s = s + 1
  264.         end
  265.     end
  266.     rsprite(home, s - 42, HEIGHT - 44, 40, 40, 5)
  267.     noSmooth()
  268. end
  269.  
  270.  
  271.  
  272. --# Optimizers
  273. function bounds(n, l, u)
  274.     if n >= l and n <= u then return true end
  275. end
  276.  
  277. function range(a, l, h)
  278.     ---[[
  279.     if a < l then
  280.         return l
  281.     elseif a > h then
  282.         return h
  283.     else
  284.         return a
  285.     end
  286.     --]]
  287.     --return math.max(l, math.min(a, h))
  288. end
  289.  
  290. _titlebar = {}
  291. _titlebar[1] = function(self)
  292.     fill(202, 202, 202, 255)
  293.     rrect(self.x, HEIGHT - self.y, self.w, 20, 5, vec3(50,50,50))
  294.     fill(202 - 40)
  295.     noStroke()
  296.     rrect(self.x, HEIGHT - self.y, self.w, 4, 0, vec3(10,10,10))
  297.     fill(150)
  298.     rrect(self.x + self.w - 50, HEIGHT - self.y + 3, 17, 14, 4, vec3(50,50,50))
  299.     rrect(self.x + self.w - 70, HEIGHT - self.y + 3, 17, 14, 4, vec3(50,50,50))
  300.     fill(230)
  301.     text(self.t, self.x + 19.5, HEIGHT - self.y + 0.5)
  302.     fill(0)
  303.     text(self.t, self.x + 20, HEIGHT - self.y + 1)
  304. end
  305. _titlebar[0] = function(self)
  306.     fill(150)
  307.     rrect(self.x, HEIGHT - self.y, self.w, 20, 5, vec3(50,50,50))
  308.     fill(150 - 40)
  309.     noStroke()
  310.     rrect(self.x, HEIGHT - self.y, self.w, 4, 0, vec3(10,10,10))
  311.     fill(175)
  312.     rrect(self.x + self.w - 50, HEIGHT - self.y + 3, 17, 14, 4, vec3(50,50,50))
  313.     rrect(self.x + self.w - 70, HEIGHT - self.y + 3, 17, 14, 4, vec3(50,50,50))
  314.     fill(30)
  315.     text(self.t, self.x + 19.5, HEIGHT - self.y + 0.5)
  316.     fill(230)
  317.     text(self.t, self.x + 20, HEIGHT - self.y + 1)
  318. end
  319.  
  320. _isOnTop = {function() return true end}
  321. _isOnTop[0] = function(self, x, y)
  322.     for n = 1, self.cindex - 1 do
  323.         if
  324.             bounds(x, wins[n].x, wins[n].x + wins[n].w) and
  325.             bounds(y, HEIGHT - wins[n].y - wins[n].h, HEIGHT - wins[n].y + 20) and
  326.             wins[n].active
  327.         then
  328.             return false
  329.         end
  330.     end
  331.     return true
  332. end
  333.  
  334. local t = {[0] = false, [1] = true}
  335.  
  336. function isN(n, b) return t[math.floor(b / n)] end
  337.  
  338. --# UI
  339. --UPLOADED_TAB:UI
  340. ui = {}
  341.  
  342. --Button
  343. ui.button = class()
  344.  
  345. function ui.button:init(win, x, y, w, h, t, c)
  346.     self.win = win
  347.     self.x, self.y, self.w, self.h, self.t, self.c = x, y, w, h, t, c or function() end
  348. end
  349.  
  350. function ui.button:draw()
  351.     fill(100)
  352.     rrect(self.x, self.y, self.w, self.h, 6, vec3(50,50,50))
  353.     if
  354.         (mousex and mousey) and
  355.         bounds(mousex, self.x, self.x + self.w) and bounds(mousey, self.y, self.y + self.h)
  356.     then
  357.         if CurrentTouch.state < ENDED then
  358.             fill(200)
  359.         elseif not self.ct then
  360.             self.c()
  361.             fill(240)
  362.             self.ct = true
  363.         else
  364.             fill(240)
  365.         end
  366.     else
  367.         fill(240)
  368.         self.ct = false
  369.     end
  370.     rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 5, vec3(50,50,50))
  371.     textMode(CENTER)
  372.     fill(50)
  373.     text(self.t, self.x + self.w / 2, self.y + self.h / 2)
  374. end
  375.  
  376. -- Link
  377. ui.link = class()
  378.  
  379. function ui.link:init(win, x, y, w, h, t, c, i)
  380.     self.win = win
  381.     self.x, self.y, self.w, self.h, self.t, self.c = x, y, w, h, t, c or function() end
  382.     self.selected = 0
  383.     self.i = i or image(0,0)
  384. end
  385.  
  386. function ui.link:draw()
  387.     if
  388.         (mousex and mousey) and
  389.         bounds(mousex, self.x, self.x + self.w) and bounds(mousey, self.y, self.y + self.h)
  390.     then
  391.         if CurrentTouch.state < ENDED then
  392.             fill(230 - self.selected * 100, 230 - self.selected * 100, 230 - self.selected * 100, 255)
  393.             rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 2, vec3(20,20,20))
  394.             self.lt = false
  395.         elseif not self.lt then
  396.             self.selected = self.selected == 1 and 0 or 1
  397.             self.c()
  398.             fill(150,150,150, self.selected * 255)
  399.             rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 2, vec3(20,20,20))
  400.             self.lt = true
  401.         else
  402.             fill(150,150,150, self.selected * 255)
  403.             rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 2, vec3(20,20,20))
  404.         end
  405.     else
  406.         fill(150,150,150, self.selected * 255)
  407.         rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 2, vec3(20,20,20))
  408.         self.lt = false
  409.     end
  410.     textMode(CORNER)
  411.     fill(50)
  412.     text(self.t, self.x + self.h, self.y + 2)
  413.     rsprite(self.i, self.x + 1, self.y + 1, self.h - 2, self.h - 2, 1)
  414. end
  415.  
  416. --Text Edit
  417. ui.textedit = class()
  418.  
  419. function ui.textedit:init(win, x, y, w, h, t, d)
  420.     self.win = win
  421.     self.x, self.y = x, y
  422.     self.w, self.h = w, h
  423.     self.t = t and {t} or {""}
  424.     self.d = d and d or "Enter text..."
  425.     --self.c = self.t.len()
  426.     self.f = false
  427.     self.e = 0
  428.     self.th = 13
  429.    
  430.     self.c = {0, 0}
  431.     font("Inconsolata")
  432.     fontSize(12)
  433.    
  434.     function self:text()
  435.         return table.concat(self.t, "\n")
  436.     end
  437. end
  438.  
  439. function ui.textedit:draw()
  440.     clip(self.win.x + self.x, (HEIGHT - self.win.y - self.win.h) + self.y, self.w + 2, self.h + 2)
  441.     fill(100)
  442.     rrect(self.x, self.y, self.w, self.h, 6, vec3(30,30,30))
  443.     if self.f then
  444.         fill(240)
  445.     else
  446.         fill(220)
  447.     end
  448.     rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 5, vec3(10,10,10))
  449.    
  450.     textMode(CORNER)
  451.     textWrapWidth(self.w - 12)
  452.     font("Inconsolata")
  453.     fontSize(12)
  454.     if #self.t == 1 and self.t[1] == "" then
  455.         fill(127)
  456.         text(self.d, self.x + 6, self.y + self.h - 2 - 12 * #self.t)
  457.     else
  458.         fill(0)
  459.         text(table.concat(self.t, "\n"), self.x + 6, self.y + self.h - 2 - 12 * #self.t)
  460.     end
  461.    
  462.     if
  463.         bounds(mousex, self.x, self.x + self.w) and
  464.         bounds(mousey, self.y, self.y + self.h)
  465.     then
  466.         if CurrentTouch.state < ENDED then
  467.             showKeyboard()
  468.             self.f = ElapsedTime
  469.             self.c[1] = math.floor((mousex - self.x) / 6) - 1
  470.             self.c[1] = self.c[1] >= 0 and self.c[1] or 0
  471.             self.c[2] = math.floor((self.y + self.h - (mousey) + 6) * (self.h - 6) / (12) / (self.h - 6))
  472.             self.c[2] = self.c[2] <= #self.t and self.c[2] or #self.t
  473.             self.c[2] = self.c[2] > 0 and self.c[2] or 1
  474.             self.c[1] = self.c[1] < #self.t[self.c[2]] and self.c[1] or #self.t[self.c[2]]
  475.         end
  476.     else
  477.         self.f = false
  478.     end
  479.    
  480.     if self.f and (ElapsedTime - self.f) % 1 < 0.5 then
  481.         line(
  482.             self.x + self.c[1] * 6 + 6, self.y + self.h - (self.c[2] - 1) * 12 - 5,
  483.             self.x + self.c[1] * 6 + 6, self.y + self.h - (self.c[2] - 1) * 12 - 19
  484.         )
  485.     end
  486.     if keyPressed ~= "NP" and self.f then
  487.         if keyPressed == "\n" then
  488.             self.c[2] = self.c[2] + 1
  489.             table.insert(self.t, self.c[2], "")
  490.             self.c[1] = 0
  491.         elseif keyPressed == BACKSPACE then
  492.             self.t[self.c[2]] =
  493.                 (self.t[self.c[2]]):sub(1, range(self.c[1] - 1, 0, 9^99)) ..
  494.                 (self.t[self.c[2]]):sub(self.c[1] + 1, -1)
  495.             self.c[1] = self.c[1] - 1
  496.             if self.c[1] < 0 then
  497.                 self.c[2] = (self.c[2] > 1 and self.c[2] - 1 or 1)
  498.                 self.c[1] = self.t[self.c[2]] and #self.t[self.c[2]] or 0
  499.             end
  500.         else
  501.             self.t[self.c[2]] =
  502.                 (self.t[self.c[2]]):sub(1, self.c[1]) .. keyPressed ..
  503.                 (self.t[self.c[2]]):sub(self.c[1] + 1, -1)
  504.             self.c[1] = self.c[1] + 1
  505.             if #self.t[self.c[2]] >= (self.w - 12) / 6 - 1 then
  506.                 self.c[1] = 0
  507.                 self.c[2] = self.c[2] + 1
  508.                 table.insert(self.t, self.c[2], "")
  509.             end
  510.         end
  511.     end
  512.     textWrapWidth(WIDTH)
  513. end
  514.  
  515. --Scrolling Text Edit
  516. ui.textscroll = class()
  517.  
  518. function ui.textscroll:init(win, x, y, w, h, t, d)
  519.     self.win = win
  520.     self.x, self.y = x, y
  521.     self.w, self.h = w, h
  522.     self.t = t and {t} or {""}
  523.     self.d = d and d or "Enter text..."
  524.     --self.c = self.t.len()
  525.     self.f = false
  526.     self.e = 0
  527.     self.scroll = 0
  528.     self.th = 13
  529.    
  530.     self.c = {0, 0}
  531.     font("Inconsolata")
  532.     fontSize(12)
  533.     --self.fm = fontMetrics()
  534.     self.sbegin = 0
  535.    
  536.     function self:text()
  537.         return table.concat(self.t, "\n")
  538.     end
  539. end
  540.  
  541. function ui.textscroll:draw()
  542.     clip(self.win.x + self.x, (HEIGHT - self.win.y - self.win.h) + self.y, self.w + 2, self.h + 2)
  543.     fill(100)
  544.     rrect(self.x, self.y, self.w, self.h, 6, vec3(30,30,30))
  545.     if self.f then
  546.         fill(240 - (self.scrolling > 0 and 0 or 10))
  547.     else
  548.         fill(220)
  549.     end
  550.     rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 5, vec3(10,10,10))
  551.    
  552.     textMode(CORNER)
  553.     textWrapWidth(self.w - 12)
  554.     font("Inconsolata")
  555.     fontSize(12)
  556.     if #self.t == 1 and self.t[1] == "" then
  557.         fill(127)
  558.         text(self.d, self.x + 6, self.y + self.h - 6 - 12 * #self.t)
  559.     else
  560.         fill(0)
  561.         text(table.concat(self.t, "\n"), self.x + 6, self.y + self.h - 6 - 12 * #self.t - self.scroll)
  562.     end
  563.    
  564.     if
  565.         bounds(mousex, self.x, self.x + self.w) and
  566.         bounds(mousey, self.y, self.y + self.h)
  567.     then
  568.         if CurrentTouch.state < ENDED then
  569.             if CurrentTouch.state == BEGAN then
  570.                 self.sbegin = ElapsedTime
  571.                 self.sx, self.sy = mousex, mousey
  572.                 self.scrolling = 1
  573.             else
  574.                 if ElapsedTime - self.sbegin > 0.5 and not(self.scrolling == 2) then
  575.                     showKeyboard()
  576.                     self.f = ElapsedTime
  577.                     self.c[1] = math.floor((mousex - self.x) / 6) - 1
  578.                     self.c[1] = self.c[1] >= 0 and self.c[1] or 0
  579.                     self.c[2] = math.floor((self.y + self.h - (mousey + self.scroll) + 6) * (self.h - 6) / (12) / (self.h - 6))
  580.                     self.c[2] = self.c[2] <= #self.t and self.c[2] or #self.t
  581.                     self.c[2] = self.c[2] > 0 and self.c[2] or 1
  582.                     self.c[1] = self.c[1] < #self.t[self.c[2]] and self.c[1] or #self.t[self.c[2]]
  583.                     self.scrolling = 0
  584.                 elseif self.scrolling >= 1 and CurrentTouch.state >= BEGAN then
  585.                     if
  586.                         bounds(CurrentTouch.deltaX, -1, 1) and bounds(CurrentTouch.deltaY, -1, 1) and
  587.                         ElapsedTime - self.sbegin < 0.5 and self.scrolling == 1
  588.                     then
  589.                         self.scrolling = 0
  590.                     elseif #self.t >= (self.h - 12) / 12 then
  591.                         self.scrolling = 2
  592.                         self.scroll = self.scroll + (self.sy - mousey)
  593.                         if self.scroll < self.h - 12 - #self.t * 12 then
  594.                             self.scroll = self.scroll - (self.sy - mousey)
  595.                         elseif self.scroll > (#self.t) - (self.h - 6) / 12 then
  596.                             --self.scroll = (#self.t) - (self.h - 6) / 12
  597.                             self.scroll = self.scroll - (self.sy - mousey)
  598.                         end
  599.                         self.sy = mousey
  600.                     end
  601.                 end
  602.             end
  603.         elseif self.scrolling == 1 then
  604.             showKeyboard()
  605.             self.f = ElapsedTime
  606.             self.c[1] = math.floor((mousex - self.x) / 6) - 1
  607.             self.c[1] = self.c[1] >= 0 and self.c[1] or 0
  608.             self.c[2] = math.floor((self.y + self.h - (mousey + self.scroll) + 6) * (self.h - 6) / (12 + 0) / (self.h - 6))
  609.             self.c[2] = self.c[2] <= #self.t and self.c[2] or #self.t
  610.             self.c[2] = self.c[2] > 0 and self.c[2] or 1
  611.             self.c[1] = self.c[1] < #self.t[self.c[2]] and self.c[1] or #self.t[self.c[2]]
  612.             self.scrolling = 0
  613.         end
  614.     elseif CurrentTouch.state == ENDED then
  615.         self.f = false
  616.     end
  617.    
  618.     if self.f and (ElapsedTime - self.f) % 1 < 0.5 then
  619.         stroke(40, 84, 185, 255)
  620.         strokeWidth(1)
  621.         line(
  622.             self.x + self.c[1] * 6 + 6, self.y + self.h - (self.c[2] - 1) * 12 - 5 - self.scroll,
  623.             self.x + self.c[1] * 6 + 6, self.y + self.h - (self.c[2] - 1) * 12 - 19 - self.scroll
  624.         )
  625.     end
  626.     if keyPressed ~= "NP" and self.f then
  627.         if keyPressed == "\n" then
  628.             self.c[2] = self.c[2] + 1
  629.             table.insert(self.t, self.c[2], "")
  630.             self.c[1] = 0
  631.         elseif keyPressed == BACKSPACE then
  632.             self.t[self.c[2]] =
  633.                 (self.t[self.c[2]]):sub(1, range(self.c[1] - 1, 0, 9^99)) ..
  634.                 (self.t[self.c[2]]):sub(self.c[1] + 1, -1)
  635.             self.c[1] = self.c[1] - 1
  636.             if self.c[1] < 0 then
  637.                 if #self.t[self.c[2]] == 0 then
  638.                     table.remove(self.t, self.c[2])
  639.                 end
  640.                 self.c[2] = (self.c[2] > 1 and self.c[2] - 1 or 1)
  641.                 self.c[1] = self.t[self.c[2]] and #self.t[self.c[2]] or 0
  642.             end
  643.         else
  644.             self.t[self.c[2]] =
  645.                 (self.t[self.c[2]]):sub(1, self.c[1]) .. keyPressed ..
  646.                 (self.t[self.c[2]]):sub(self.c[1] + 1, -1)
  647.             self.c[1] = self.c[1] + 1
  648.             if #self.t[self.c[2]] >= (self.w - 12) / 6 - 1 then
  649.                 self.c[1] = 0
  650.                 self.c[2] = self.c[2] + 1
  651.                 table.insert(self.t, self.c[2], "")
  652.             end
  653.         end
  654.     end
  655.     textWrapWidth(WIDTH)
  656. end
  657.  
  658.  
  659.  
  660. --# Flash
  661. local _print = print
  662.  
  663. flashAlert = 0
  664. flashText = ""
  665. flashStart = 0
  666.    
  667. function flash(t, duration)
  668.     flashText = t
  669.     flashAlert = duration
  670.     flashStart = ElapsedTime
  671. end
  672.  
  673. --# Win
  674.  
  675. --UPLOADED_TAB:Win
  676. local titlebar = _titlebar
  677. local isOnTop = _isOnTop
  678.  
  679. local isOne = isOne
  680.  
  681. wins = {}
  682. awins = {}
  683.  
  684. ftypes = {}
  685.  
  686. context = setContext
  687.  
  688. --local bounds, range = bounds, range
  689.  
  690. function adjustcindex()
  691.     for i, v in ipairs(wins) do
  692.         wins[i].cindex = i
  693.         --winIndexes[wins[i].index] = wins[i].cindex
  694.     end
  695. end
  696.  
  697. local function runAll()
  698.     for n = #wins, 1, -1 do
  699.         if wins[n].active then
  700.             wins[n]:run()
  701.         end
  702.     end
  703. end
  704. --[[
  705. local function runAll()
  706.     for i, v in pairs(awins) do
  707.         v:draw()
  708.     end
  709. end
  710. --]]
  711. local function drawAndRunAll()
  712.     for n = #wins, 1, -1 do
  713.         if wins[n].active then
  714.             wins[n]:run()
  715.             wins[n]:draw()
  716.         end
  717.     end
  718. end
  719.  
  720. local movedOpt = {
  721.     [2] = function()
  722.         moved = 1
  723.         background(255)
  724.         drawAndRunAll()
  725.     end,
  726.     [1] = function()
  727.         moved = 0
  728.         background(255)
  729.         drawAndRunAll()
  730.     end,
  731.     [0] = function() runAll() end
  732. }
  733.  
  734. function drawFlashAlert()
  735.     if ElapsedTime - flashStart < flashAlert + 1 then
  736.         fill(255)
  737.         rect(0,0,WIDTH,12)
  738.         fill(255, 0, 0, 255)
  739.         rrect(0,-5, WIDTH, 17 -
  740.             (((ElapsedTime - flashStart - flashAlert) * 25) > 0 and ((ElapsedTime - flashStart - flashAlert) * 25) or 0),
  741.         5)
  742.         textMode(CENTER)
  743.         fontSize(11)
  744.         fill(255)
  745.         text(tostring(flashText), WIDTH / 2, 6)
  746.         --_print(flashAlert)
  747.     end
  748. end
  749.  
  750. function drawWindows()
  751.     noStroke()
  752.     noSmooth()
  753.     rectMode(CORNER)
  754.     textMode(CORNER)
  755.     spriteMode(CORNER)
  756.     font("SourceSansPro-Regular")
  757.     --font("HelveticaNeue")
  758.     fontSize(13.5)
  759.     pushStyle()
  760.     movedOpt[moved]()
  761.     --background(255)
  762.     --drawAndRunAll()
  763.     taskbar()
  764.     ctended = isN(CurrentTouch.state, ENDED)
  765.    
  766.     drawFlashAlert()
  767. end
  768.  
  769. local cwinindex = 1
  770. window = class()
  771.  
  772. function window:init(x, y, w, h, t, i)
  773.     for i, v in pairs(ui) do self[i] = ui[i] end
  774.     -- you can accept and set parameters here
  775.     self.x = x
  776.     self.y = y
  777.     self.w = w
  778.     self.h = h
  779.     self.t = t
  780.     self.i = i
  781.     self.touches = {}
  782.     self.index = cwinindex -- A unique identifier
  783.     self.cindex = #wins + 1 --self.index
  784.     cwinindex = cwinindex + 1
  785.     self.__CONTENTS = image(self.w, self.h)
  786.     self.clip = function() clip(self.x + 1, HEIGHT - self.y - self.h + 2, self.w - 2, self.h - 2) end
  787.     self.translate = function() translate(self.x + 1, HEIGHT - self.y - self.h + 1) end
  788.     self.mousex, self.mousey, self.pmousex, self.pmousey = nil
  789.     table.insert(wins, self)
  790. end
  791.  
  792. function window:optimize()
  793.     self.main = self.main or function() end
  794.     self.background = self.background or function() end
  795.     self.onclose = self.onclose or function() end
  796.     ---[=[
  797.     if not self.i then
  798.         self.i = image(27, 27)
  799.         --[[
  800.         setContext(self.i)
  801.         font("HelveticaNeue-Light")
  802.         fontSize(28)
  803.         textMode(CENTER)
  804.         fill(0)
  805.         background(255)
  806.         text(self.t, 10, 13)
  807.         setContext()
  808.         --]]
  809.     end
  810.     --]=]
  811.     if not self.ismall then self.ismall = self.i end
  812. end
  813.  
  814. function window:draw()
  815.     popStyle()
  816.    
  817.     titlebar[math.floor(1/self.cindex)](self)
  818.     fill(self.closehover and color(175,50,50) or color(230, 30, 30))
  819.     rrect(self.x + self.w - 30, HEIGHT - self.y + 3, 27, 14, 4, vec3(50,70,70))
  820.     local r, g, b = fill()
  821.     fill(r-40,g-60,b-60)
  822.     rrect(self.x + self.w - 7, HEIGHT - self.y + 3, 4, 4, 0, vec3(5,10,10))
  823.     --smooth()
  824.    
  825.     pushStyle()
  826. end
  827.  
  828. function window:run()
  829.    
  830.     --if self.done then return end
  831.    
  832.     local x, y = CurrentTouch.x, CurrentTouch.y
  833.     local onTop = isOnTop[math.floor(1/self.cindex)](self, x, y)
  834.     --if self.cindex > 1 then
  835.     --[[
  836.         for n = 1, self.cindex - 1 do
  837.             if
  838.                 bounds(x, wins[n].x, wins[n].x + wins[n].w) and
  839.                 bounds(y, HEIGHT - wins[n].y - wins[n].h, HEIGHT - wins[n].y + 20) and
  840.                 wins[n].active
  841.             then
  842.                 onTop = false
  843.                 break
  844.             end
  845.         end
  846.     --end
  847.     --]]
  848.     if bounds(x, self.x, self.x + self.w) and bounds(y, HEIGHT - self.y - self.h, HEIGHT - self.y) and onTop then
  849.         self:show()
  850.         adjustcindex()
  851.     end
  852.     if
  853.         (bounds(x, self.x + self.w - 30, self.x + self.w - 3) and
  854.         bounds(y, HEIGHT - self.y + 3, HEIGHT - self.y + 17) and onTop)
  855.         or self.done
  856.     then
  857.         if self.closed then else
  858.             if (CurrentTouch.state == ENDED and ctended) then
  859.                 self.closed = true
  860.                 local persist = self:hide()
  861.                 if not persist then
  862.                     return
  863.                 else
  864.                     self.active = true
  865.                     self.done = false
  866.                     self.closed = true
  867.                 end
  868.             elseif self.done then
  869.                 local persist = self:hide()
  870.                 self.done = false
  871.                 return
  872.             else
  873.                 self.closehover = true
  874.             end
  875.         end
  876.     else
  877.         self.closed = false
  878.         self.closehover = false
  879.         if bounds(x, self.x, self.x + self.w) and bounds(y, HEIGHT - self.y, HEIGHT - self.y + 20) and
  880.             not(self.dragx and self.dragy) and CurrentTouch.state == BEGAN and onTop
  881.         then
  882.             moved = 1
  883.             self.dragx = x
  884.             self.dragy = y
  885.             self.sdx = self.x
  886.             self.sdy = self.y
  887.             table.remove(wins, self.cindex)
  888.             table.insert(wins, 1, self)
  889.             adjustcindex()
  890.             --[[
  891.             for i, v in ipairs(wins) do
  892.                 winIndexes[wins[i].index] = wins[i].cindex
  893.             end
  894.             --]]
  895.             if self.onFocus then
  896.                 self.onFocus()
  897.             end
  898.         elseif self.dragx and self.dragy then
  899.             moved = 1
  900.             if CurrentTouch.state == ENDED then
  901.                 self.dragx, self.dragy = nil
  902.                 self.clip = function() clip(self.x + 1, HEIGHT - self.y - self.h + 2, self.w - 2, self.h - 2) end
  903.                 self.translate = function() translate(self.x + 1, HEIGHT - self.y - self.h + 1) end
  904.             else
  905.                 self.x = math.floor(self.sdx + (x - self.dragx))
  906.                 self.y = math.floor(self.sdy - (y - self.dragy))
  907.                 self.clip = function() clip(self.x + 1, HEIGHT - self.y - self.h + 2, self.w - 2, self.h - 2) end
  908.                 self.translate = function() translate(self.x + 1, HEIGHT - self.y - self.h + 1) end
  909.             end
  910.         end
  911.     end
  912.     pushStyle()
  913.     fill(237, 237, 237, 255)
  914.     stroke(127)
  915.     strokeWidth(1/ContentScaleFactor)
  916.     rect(self.x, HEIGHT - self.y - self.h + 1, self.w, self.h)
  917.     stroke(150)
  918.     rect(self.x + 1/ContentScaleFactor, HEIGHT - self.y - self.h + 1 + 1/ContentScaleFactor, self.w-1, self.h-1)
  919.    
  920.     --Run window
  921.     --if self.main then
  922.         --clip()
  923.     self.pmousex, self.pmousey = self.mousex and self.mousex or CurrentTouch.x - self.x - 1, self.mousey and self.mousey or CurrentTouch.y - (HEIGHT - self.y - self.h + 1)
  924.     self.mousex, self.mousey = CurrentTouch.x - self.x - 1, CurrentTouch.y - (HEIGHT - self.y - self.h + 1)
  925.     --pmousex, pmousey = CurrentTouch.prevX - self.x - 1, CurrentTouch.prevY - (HEIGHT - self.y - self.h + 1)
  926.     if onTop then
  927.         mousex, mousey, pmousex, pmousey = self.mousex, self.mousey, self.pmousex, self.pmousey
  928.     else
  929.         mousex, mousey, pmousex, pmousey = 0,0,0,0
  930.     end
  931.     clip(self.x + 1, HEIGHT - self.y - self.h + 2, self.w - 2, self.h - 2)
  932.     pushMatrix()
  933.     popStyle()
  934.     translate(self.x + 1, HEIGHT - self.y - self.h + 1)
  935.     self.main()
  936.     clip()
  937.     popMatrix()
  938. --end
  939. --if self.background then
  940.     self.background()
  941.     --end
  942.     --self:draw()
  943. end
  944.  
  945. function window:show()
  946.     --adjustcindex()
  947.     table.remove(wins, self.cindex)
  948.     table.insert(wins, 1, self)
  949.     adjustcindex()
  950.     self.active = true
  951.     awins[self.index] = self
  952.     moved = 1
  953.     --self.done = false
  954. end
  955.  
  956. function window:hide()
  957.     moved = 1
  958.     if self.active then
  959.         self.active = false
  960.         if self.temp then
  961.             adjustcindex()
  962.             table.remove(wins, self.cindex)
  963.             adjustcindex()
  964.             return
  965.         end
  966.         return self.onclose()
  967.     end
  968. end
  969.  
  970. function window:mhide()
  971.     self.active = false
  972.     awins[self.index] = nil
  973.     moved = 1
  974.     self.done = true
  975. end
  976.  
  977. function window:destroy()
  978.     --adjustcindex()
  979.     for i = 1, #wins do
  980.         if wins[i] and wins[i].index == self.index then
  981.             table.remove(wins, i)
  982.         end
  983.     end
  984.     awins[self.index] = nil
  985.     self.active = false
  986.     self.done = true
  987.     self.draw = function() end
  988.     moved = 1
  989. end
  990.  
  991. function window:newInstance()
  992.     adjustcindex()
  993.     table.insert(wins, cwindex, {})
  994.     for i, v in pairs(wins[self.cindex]) do
  995.         wins[cwindex][i] = v
  996.     end
  997.     table.insert(winsOrig, wins[#wins])
  998.     wins[n + 1].temp = true
  999.     wins[n + 1].cindex = #wins
  1000.     wins[n + 1].index = cwinindex
  1001.     winsOrig[n + 1].temp = true
  1002.     winsOrig[n + 1].cindex = #winsOrig
  1003.     winsOrig[n + 1].index = cwinindex
  1004.     adjustcindex()
  1005. end
  1006.  
  1007. function new(i)
  1008.     return wins[i]:newInstance()
  1009. end
  1010.  
  1011. function window:extensions(...)
  1012.     for i, v in ipairs{...} do
  1013.         ftypes[v] = self
  1014.     end
  1015. end
  1016.  
  1017. --# Filesys
  1018. --UPLOADED_TAB:Filesys
  1019. file = file or {}
  1020.  
  1021. file.open = function(f, ...)
  1022.     if not readText("Documents:" .. f) then
  1023.         saveText("Documents:" .. f, "")
  1024.     end
  1025.     return {
  1026.         ["file"] = f,
  1027.         ["contents"] = readText("Documents:" .. f),
  1028.         ["write"] = function(self, text)
  1029.             self.contents = self.contents .. text
  1030.         end,
  1031.         ["commit"] = function(self)
  1032.             saveText("Documents:" .. self.file, self.contents)
  1033.         end
  1034.     }
  1035. end
  1036.  
  1037. file.list = function(type)
  1038.     return assetList("Documents", type or TEXT)
  1039. end
  1040.  
  1041. file.sep = ":"
  1042. --# Alert
  1043. --UPLOADED_TAB:Alert
  1044. ui.OKAY_CANCEL = 0
  1045.  
  1046. ui.alerttypes = {}
  1047.    
  1048. ui.alerttypes[ui.OKAY_CANCEL] = function(win, title, contents, f_okay, f_cancel)
  1049.     font("SourceSansPro-Regular")
  1050.     fontSize(13.5)
  1051.     local x, y = textSize(contents)
  1052.     win.calert = window(WIDTH / 2 - x / 2 + 20,  HEIGHT / 2 - (y + 20 + 24) / 2, x + 20, y + 20 + 24, title)
  1053.     win.calert.hidden = true
  1054.    
  1055.     --ui.calert.w_ = ui.calert.w
  1056.     --ui.calert.h_ = ui.calert.h
  1057.    
  1058.     win.calert.i = readImage("Documents:gear")
  1059.    
  1060.     win.calert.done = false
  1061.    
  1062.     local okay = win.calert:button(10, 10, 50, 16, "Okay", function()
  1063.         adjustcindex()
  1064.         table.remove(wins, win.calert.cindex)
  1065.         win.calert = nil
  1066.         adjustcindex()
  1067.         f_okay()
  1068.     end)
  1069.     local cancel = win.calert:button(70, 10, 50, 16, "Cancel", function()
  1070.         adjustcindex()
  1071.         table.remove(wins, win.calert.cindex)
  1072.         win.calert = nil
  1073.         adjustcindex()
  1074.         f_cancel()
  1075.     end)
  1076.    
  1077.     win.calert.main = function()
  1078.         fill(0)
  1079.         textMode(CORNER)
  1080.         font("SourceSansPro-Regular")
  1081.         fontSize(13.5)
  1082.        
  1083.         text(contents, 10, y)
  1084.         okay:draw()
  1085.         cancel:draw()
  1086.     end
  1087.    
  1088.     win.calert:optimize()
  1089.     win.calert:show()
  1090. end
  1091.  
  1092. function ui.alert(win, alert_type, ...)
  1093.     ui.alerttypes[alert_type](win, ...)
  1094. end
  1095.  
  1096. ---[[
  1097. --]]
  1098. --# FileBrowser
  1099. deficon = image(10,10)
  1100.    
  1101. ui.filebrowser = function(win, callback)
  1102.     local numFiles = #(file.list())
  1103.     win.browse = window(WIDTH / 2 - 150,  HEIGHT / 2 - (numFiles * 20 + 30) / 2, 300, (numFiles * 20 + 30), "Choose a file...")
  1104.     win.browse.hidden = true
  1105.    
  1106.     win.browse.i = win.i
  1107.    
  1108.     win.browse.done = false
  1109.    
  1110.     win.browse.files = file.list()
  1111.    
  1112.     local fv = win.browse:textedit(5, 5, win.browse.w - 40, 16, "", "Enter file name...")
  1113.     local fb = win.browse:button(win.browse.w - 30, 5, 20, 16, "Go",
  1114.         function()
  1115.             win.selectedfile = fv.t[1]
  1116.             if callback then callback(fv.t[1]) end
  1117.             adjustcindex()
  1118.             table.remove(wins, win.browse.cindex)
  1119.             win.browse = nil
  1120.             adjustcindex()
  1121.         end
  1122.     )
  1123.    
  1124.     for i, v in ipairs(win.browse.files) do
  1125.         local ov = v
  1126.         local tpos = v:find(file.sep) and v:find(file.sep) - 1 or 0
  1127.         local ft
  1128.         if tpos > 0 then
  1129.             ft = v:sub(1, tpos)
  1130.             v = v:sub(tpos + 2, -1)
  1131.         else
  1132.             ft = "null"
  1133.         end
  1134.         win.browse.files[i] = win.browse:link(5, 20 * i + 5, win.browse.w - 10, 20, ft .. ":\t" .. v,
  1135.             function()
  1136.                 for i_, v in ipairs(win.browse.files) do
  1137.                     if i_ ~= i then
  1138.                         v.selected = 0
  1139.                     end
  1140.                 end
  1141.                 fv.t = {ov}
  1142.             end,
  1143.             ftypes[ft] and ftypes[ft].i or deficon
  1144.         )
  1145.     end
  1146.    
  1147.     function win.browse.main()
  1148.         for i, v in ipairs(win.browse.files) do
  1149.             win.browse.files[i]:draw()
  1150.         end
  1151.         fb:draw()
  1152.         fv:draw()
  1153.     end
  1154.    
  1155.     win.browse:optimize()
  1156.     win.browse:show()
  1157. end
  1158.  
  1159. --# LoadWindows
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165. --UPLOADED_TAB:LoadWindows
  1166. local programs = readGlobalData("CodeOS_AppProj")
  1167.  
  1168. print(listProjectTabs(programs))
  1169.  
  1170. if not(programs) or (not(listProjectTabs(programs))) or not(#(listProjectTabs(programs)) > 0) then
  1171.     if not(programs) or programs == "" then
  1172.         cerror = "No program source file found"
  1173.         ferror = "Sorry, there doesn't seem to be a set source project.\nPlease enter a project name..."
  1174.     else
  1175.         cerror = "Project " .. programs .. " does not exist"
  1176.         ferror = "Sorry, the project " .. programs .. " doesn't exist."
  1177.     end
  1178.     flash("Error: " .. cerror, 3) --Probably won't work, but just in case...
  1179.     local i = readImage("Documents:ngear")
  1180.     sfw = window(0, 100, WIDTH - 100, HEIGHT - 100, "Source Project...", i)
  1181.    
  1182.     setSource = function()
  1183.         saveGlobalData("CodeOS_AppProj", ri.t[1])
  1184.         restart()
  1185.     end
  1186.     rb = sfw:button(WIDTH / 2 - 100, HEIGHT / 2 - 8, 200, 16, "Set source project", setSource)
  1187.    
  1188.     ri = sfw:textedit(WIDTH / 2 - 100, HEIGHT / 2 + 13, 200, 16, programs or "", "Enter source project...")
  1189.    
  1190.     function sfw:draw()
  1191.         self:show()
  1192.         background(255)
  1193.         fill(0)
  1194.         textMode(CORNER)
  1195.         text(ferror, WIDTH / 2 - 100, HEIGHT / 2 + 34)
  1196.         rb:draw()
  1197.         ri:draw()
  1198.         drawFlashAlert()
  1199.     end    
  1200.     sfw:show()
  1201. else
  1202.  
  1203.     _tabs = listProjectTabs(programs)
  1204.     --print(_tabs)
  1205.     ---[[
  1206.     print(pcall(function()
  1207.         --_tabs = {_tabs[3], _tabs[5], _tabs[6], _tabs[7]
  1208.         for i, v in pairs(_tabs) do
  1209.             if v ~= "Main" then
  1210.                 print(pcall(loadstring(readProjectTab(programs .. ":" .. v))))
  1211.                 --dofile(os.getenv("HOME") .. "/Documents/" .. programs .. ".codea/" .. v .. ".lua")
  1212.             end
  1213.         end
  1214.     end))
  1215.     --]]
  1216.    
  1217. end
  1218. --# ProgramRun
  1219. --UPLOADED_TAB:ProgramRun
  1220. --[[
  1221. run = window(450, 200, 170, 72, "Run")
  1222. run.i = readImage("Documents:ui")
  1223.  
  1224. local p = run:textedit(10, 10, 150, 24, "", "Program...")
  1225.  
  1226. local b = run:button(10, 44, 150, 16, "Run program",
  1227. function()
  1228.     local s, t = pcall(listProjectTabs, p:text())
  1229.     if t then
  1230.         for i, v in ipairs(t) do
  1231.             if v ~= "Main" then
  1232.                 s, err = pcall(loadstring(readProjectTab(p:text() .. ":" .. v)))
  1233.                 if not s then
  1234.                     print(err)
  1235.                 end
  1236.             end
  1237.         end
  1238.     end
  1239. end
  1240. )
  1241.  
  1242. run.main = function()
  1243.     b:draw()
  1244.     p:draw()
  1245. end
  1246. --]]
  1247.  
  1248. --# SetUpWindows
  1249. --UPLOADED_TAB:SetUpWindows
  1250. ---[[
  1251. winsOrig, winIndexes = {}, {}
  1252. for i, v in ipairs(wins) do
  1253.     wins[i]:optimize()
  1254.     if not wins[i].hidden then
  1255.         table.insert(winsOrig, v)
  1256.     end
  1257.     winIndexes[i] = i
  1258. end
  1259.  
  1260. --]]
  1261. --# Print
  1262. _print = print
  1263. print = function(...)
  1264.     local arg = {...}
  1265.     for i, v in ipairs(arg) do arg[i] = tostring(v) end
  1266.     local msg = table.concat(arg, "\t")
  1267.     local d = debug.getinfo(2, "Sl")
  1268.     if d then
  1269.         msg = ("\nSource: " .. (d.short_src):sub(1, (d.short_src:find("\n") or 0) - 1) .. ", line " .. d.currentline .. ":\n" .. msg)
  1270.     else
  1271.         msg = ("Data unavailable!\n" .. msg)
  1272.     end
  1273.     ui.alerttypes[0]({}, "Message", msg, function() end, function() end)
  1274. end
Advertisement
Add Comment
Please, Sign In to add comment