Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# Rounded
- --[[
- local _f = fill
- local _fill = vec4(0,0,0,0)
- fill = function(r, g, b, a)
- _fill = vec4(...)
- _f(...)
- end
- --]]
- rr = {}
- local v = vec2(10,10)
- rr.sh = nil
- rr.m = nil
- function rr._ms() return rr.sh end
- function rr._mm() return rr.m end
- 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
- function rr.mm() if rr.m then return rr.m else rr.m = mesh() rr.mm = rr._mm return rr.m end end
- function rrect(x, y, w, h, r, g)
- m = rr.mm()
- ---[[
- m.shader = rr.ms()
- --m:addRect(x * 2, y * 2, w * 2, h * 2)
- if g and not g.w then
- g = vec4(g.x, g.y, g.z, 0)
- end
- -- Assign a shader
- m.shader.r = (r > w / 2 and w / 2) or (r > h / 2 and h / 2) or r
- m.shader.a = 1--ContentScaleFactor
- m.shader.coords = vec2(x, y)
- m.shader.size = vec2(w,h)
- m.shader.g = g and g / 255 or vec4(0,0,0,0)
- --]]
- -- Set vertices
- --[[
- m.vertices = triangulate{
- vec2(x,y),
- vec2(x+w,y),
- vec2(x+w,y+h),
- vec2(x,y+h)
- }
- --[=[
- --]]
- m.vertices = {
- vec2(x, y),
- vec2(x + w, y),
- vec2(x, y + h),
- vec2(x, y + h),
- vec2(x + w, y + h),
- vec2(x + w, y)
- }
- -- Assign texture coordinates
- m.texCoords = m.vertices
- -- Assign a texture
- --m.texture = readImage("Documents:BOXOFFICON")
- -- Set all vertex colors to white
- m:setColors(fill())
- --m:setRect(re, x, y, w, h)
- -- Draw the mesh
- m:draw()
- end
- --# RoundedSprite
- --[[
- local _f = fill
- local _fill = vec4(0,0,0,0)
- fill = function(r, g, b, a)
- _fill = vec4(...)
- _f(...)
- end
- --]]
- rs = {}
- local v = vec2(10,10)
- rs.sh = nil
- rr.m = nil
- function rs._ms() return rs.sh end
- function rs._mm() return rs.m end
- 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
- function rs.mm() if rs.m then return rs.m else rs.m = mesh() rs.mm = rs._mm return rs.m end end
- function rsprite(i, x, y, w, h, r, g)
- local m2 = rs.mm()
- ---[[
- m2.shader = rs.ms()
- --m:addRect(0,0,1,1)
- if g and not g.w then
- g = vec4(g.x, g.y, g.z, 0)
- end
- -- Assign a shader
- m2.shader.r = r / math.max(w, h)
- m2.shader.a = math.max(w, h) * ContentScaleFactor
- m2.shader.coords = vec2(x, y)
- m2.shader.size = vec2(w,h)
- m2.shader.g = g and g / 255 or vec4(0,0,0,0)
- --]]
- -- Set vertices
- --[[
- m.vertices = triangulate 2 vec2(x,y),
- vec2(x+w,y),
- vec2(x+w,y+h),
- vec2(x,y+h)
- }
- --[=[
- --]]
- m2.vertices = {
- vec2(x, y),
- vec2(x + w, y),
- vec2(x, y + h),
- vec2(x, y + h),
- vec2(x + w, y + h),
- vec2(x + w, y)
- }
- -- Assign texture coordinates
- m2.texCoords = {vec2(0,0), vec2(1,0), vec2(0,1), vec2(0,1), vec2(1,1), vec2(1,0)}
- -- Assign a texture
- m2.texture = i--"Documents:BOXOFFICON"
- -- Set all vertex colors to white
- m2:setColors(0,0,0,0)
- --m:setRect(re, x, y, w, h)
- -- Draw the mesh
- m2:draw()
- end
- --rsprite = sprite
- --# Main
- --UPLOADED_TAB:Main
- -- CodeOS
- -- Use this function to perform your initial setup
- function setup()
- debugging = false
- local i = readImage("Documents:display")
- saveImage("Project:Icon", i)
- displayMode(FULLSCREEN_NO_BUTTONS)
- keyPressed = ""
- background(255)
- backingMode(RETAINED)
- background(255, 255, 255, 255)
- moved = 2
- btext = text --????
- CurrentFrame = 0
- end
- -- This function gets called once every frame
- local FrameCount = 0
- function draw()
- background(255)
- FrameCount = FrameCount + 1
- if FrameCount == 10 then
- draw = function()
- --flashAlert = 10 - ElapsedTime
- -- This sets a dark background color
- --background(255, 255, 255, 255)
- -- This sets the line thickness
- --strokeWidth(5)
- -- Do your drawing here
- CurrentFrame = CurrentFrame + 1
- drawWindows()
- if keyPressed ~= "NP" then keyPressed = "NP" end
- --keyPressed = "NP"
- --if msg then msg() end -- Debugging, doesn't do anything unless you have my print library
- --flashAlert = flashAlert - 1
- end
- end
- end
- function keyboard(k)
- keyPressed = k
- --print(string.byte(k))
- end
- --# Taskbar
- --UPLOADED_TAB:Taskbar
- local tapped = false
- local s = 50
- local home = readImage("Cargo Bot:Codea Icon")
- function taskbar()
- ---[[
- fill(255)
- noStroke()
- rect(0, HEIGHT - 45, WIDTH, 45)
- --]]
- fill(0, 0, 0, 49)
- noStroke()
- local t = 0
- rrect(s, HEIGHT - 43 + t, WIDTH - 3 - s + t*3, 40 + t*3, 10, vec4(50,50,50,-50))
- ---[[
- if
- bounds(CurrentTouch.x, WIDTH - 39, WIDTH - 9 ) and
- bounds(CurrentTouch.y, HEIGHT - 37, HEIGHT - 8.5)
- then
- fill(213, 57, 57, 255)
- rrect(WIDTH - 39, HEIGHT - 37 + t, 30, 28.5, 5, vec4(40,100,100, 0))
- if CurrentTouch.state == ENDED then
- close()
- end
- else
- fill(226, 114, 114, 255)
- rrect(WIDTH - 39, HEIGHT - 37 + t, 30, 28.5, 5, vec4(40,100,100, 0))
- end
- --]]
- smooth()
- spriteMode(CORNER)
- ---[[
- 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
- local toRun = math.ceil((CurrentTouch.x - s - 6) / 35)
- --wins[winIndexes[toRun]].active = true
- ---[[
- for n = 1, #wins do
- if winsOrig[toRun] and wins[n].index == winsOrig[toRun].index then
- --wins[n].active = true
- --for i, v in pairs(wins[n]) do print(i) end
- wins[n]:show()
- moved = 1
- wins[n].done = false
- wins[n].closed = false
- end
- end
- --]]
- tapped = true
- elseif CurrentTouch.state == BEGAN then
- tapped = false
- end
- --]]
- local sk = 0
- for n = 1, #winsOrig do
- if winsOrig[n] then
- if winsOrig[n].active then
- fill(113, 113, 113, 255)
- rrect(s + 3 + (n - 1 - sk) * 35, HEIGHT - 39.5 + t, 33, 33, 9, vec4(30,30,30,0))
- fill(210)
- rrect(s + 5 + (n - 1 - sk) * 35, HEIGHT - 37.5 + t, 29, 29, 7, vec4(30,30,30,0))
- end
- rsprite(winsOrig[n].i, s + 6 + (n - 1 - sk) * 35, HEIGHT - 36.5 + t, 27, 27, 6, vec4(70,70,70,0))
- else
- s = s + 1
- end
- end
- rsprite(home, s - 42, HEIGHT - 44, 40, 40, 5)
- noSmooth()
- end
- --# Optimizers
- function bounds(n, l, u)
- if n >= l and n <= u then return true end
- end
- function range(a, l, h)
- ---[[
- if a < l then
- return l
- elseif a > h then
- return h
- else
- return a
- end
- --]]
- --return math.max(l, math.min(a, h))
- end
- _titlebar = {}
- _titlebar[1] = function(self)
- fill(202, 202, 202, 255)
- rrect(self.x, HEIGHT - self.y, self.w, 20, 5, vec3(50,50,50))
- fill(202 - 40)
- noStroke()
- rrect(self.x, HEIGHT - self.y, self.w, 4, 0, vec3(10,10,10))
- fill(150)
- rrect(self.x + self.w - 50, HEIGHT - self.y + 3, 17, 14, 4, vec3(50,50,50))
- rrect(self.x + self.w - 70, HEIGHT - self.y + 3, 17, 14, 4, vec3(50,50,50))
- fill(230)
- text(self.t, self.x + 19.5, HEIGHT - self.y + 0.5)
- fill(0)
- text(self.t, self.x + 20, HEIGHT - self.y + 1)
- end
- _titlebar[0] = function(self)
- fill(150)
- rrect(self.x, HEIGHT - self.y, self.w, 20, 5, vec3(50,50,50))
- fill(150 - 40)
- noStroke()
- rrect(self.x, HEIGHT - self.y, self.w, 4, 0, vec3(10,10,10))
- fill(175)
- rrect(self.x + self.w - 50, HEIGHT - self.y + 3, 17, 14, 4, vec3(50,50,50))
- rrect(self.x + self.w - 70, HEIGHT - self.y + 3, 17, 14, 4, vec3(50,50,50))
- fill(30)
- text(self.t, self.x + 19.5, HEIGHT - self.y + 0.5)
- fill(230)
- text(self.t, self.x + 20, HEIGHT - self.y + 1)
- end
- _isOnTop = {function() return true end}
- _isOnTop[0] = function(self, x, y)
- for n = 1, self.cindex - 1 do
- if
- bounds(x, wins[n].x, wins[n].x + wins[n].w) and
- bounds(y, HEIGHT - wins[n].y - wins[n].h, HEIGHT - wins[n].y + 20) and
- wins[n].active
- then
- return false
- end
- end
- return true
- end
- local t = {[0] = false, [1] = true}
- function isN(n, b) return t[math.floor(b / n)] end
- --# UI
- --UPLOADED_TAB:UI
- ui = {}
- --Button
- ui.button = class()
- function ui.button:init(win, x, y, w, h, t, c)
- self.win = win
- self.x, self.y, self.w, self.h, self.t, self.c = x, y, w, h, t, c or function() end
- end
- function ui.button:draw()
- fill(100)
- rrect(self.x, self.y, self.w, self.h, 6, vec3(50,50,50))
- if
- (mousex and mousey) and
- bounds(mousex, self.x, self.x + self.w) and bounds(mousey, self.y, self.y + self.h)
- then
- if CurrentTouch.state < ENDED then
- fill(200)
- elseif not self.ct then
- self.c()
- fill(240)
- self.ct = true
- else
- fill(240)
- end
- else
- fill(240)
- self.ct = false
- end
- rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 5, vec3(50,50,50))
- textMode(CENTER)
- fill(50)
- text(self.t, self.x + self.w / 2, self.y + self.h / 2)
- end
- -- Link
- ui.link = class()
- function ui.link:init(win, x, y, w, h, t, c, i)
- self.win = win
- self.x, self.y, self.w, self.h, self.t, self.c = x, y, w, h, t, c or function() end
- self.selected = 0
- self.i = i or image(0,0)
- end
- function ui.link:draw()
- if
- (mousex and mousey) and
- bounds(mousex, self.x, self.x + self.w) and bounds(mousey, self.y, self.y + self.h)
- then
- if CurrentTouch.state < ENDED then
- fill(230 - self.selected * 100, 230 - self.selected * 100, 230 - self.selected * 100, 255)
- rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 2, vec3(20,20,20))
- self.lt = false
- elseif not self.lt then
- self.selected = self.selected == 1 and 0 or 1
- self.c()
- fill(150,150,150, self.selected * 255)
- rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 2, vec3(20,20,20))
- self.lt = true
- else
- fill(150,150,150, self.selected * 255)
- rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 2, vec3(20,20,20))
- end
- else
- fill(150,150,150, self.selected * 255)
- rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 2, vec3(20,20,20))
- self.lt = false
- end
- textMode(CORNER)
- fill(50)
- text(self.t, self.x + self.h, self.y + 2)
- rsprite(self.i, self.x + 1, self.y + 1, self.h - 2, self.h - 2, 1)
- end
- --Text Edit
- ui.textedit = class()
- function ui.textedit:init(win, x, y, w, h, t, d)
- self.win = win
- self.x, self.y = x, y
- self.w, self.h = w, h
- self.t = t and {t} or {""}
- self.d = d and d or "Enter text..."
- --self.c = self.t.len()
- self.f = false
- self.e = 0
- self.th = 13
- self.c = {0, 0}
- font("Inconsolata")
- fontSize(12)
- function self:text()
- return table.concat(self.t, "\n")
- end
- end
- function ui.textedit:draw()
- clip(self.win.x + self.x, (HEIGHT - self.win.y - self.win.h) + self.y, self.w + 2, self.h + 2)
- fill(100)
- rrect(self.x, self.y, self.w, self.h, 6, vec3(30,30,30))
- if self.f then
- fill(240)
- else
- fill(220)
- end
- rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 5, vec3(10,10,10))
- textMode(CORNER)
- textWrapWidth(self.w - 12)
- font("Inconsolata")
- fontSize(12)
- if #self.t == 1 and self.t[1] == "" then
- fill(127)
- text(self.d, self.x + 6, self.y + self.h - 2 - 12 * #self.t)
- else
- fill(0)
- text(table.concat(self.t, "\n"), self.x + 6, self.y + self.h - 2 - 12 * #self.t)
- end
- if
- bounds(mousex, self.x, self.x + self.w) and
- bounds(mousey, self.y, self.y + self.h)
- then
- if CurrentTouch.state < ENDED then
- showKeyboard()
- self.f = ElapsedTime
- self.c[1] = math.floor((mousex - self.x) / 6) - 1
- self.c[1] = self.c[1] >= 0 and self.c[1] or 0
- self.c[2] = math.floor((self.y + self.h - (mousey) + 6) * (self.h - 6) / (12) / (self.h - 6))
- self.c[2] = self.c[2] <= #self.t and self.c[2] or #self.t
- self.c[2] = self.c[2] > 0 and self.c[2] or 1
- self.c[1] = self.c[1] < #self.t[self.c[2]] and self.c[1] or #self.t[self.c[2]]
- end
- else
- self.f = false
- end
- if self.f and (ElapsedTime - self.f) % 1 < 0.5 then
- line(
- self.x + self.c[1] * 6 + 6, self.y + self.h - (self.c[2] - 1) * 12 - 5,
- self.x + self.c[1] * 6 + 6, self.y + self.h - (self.c[2] - 1) * 12 - 19
- )
- end
- if keyPressed ~= "NP" and self.f then
- if keyPressed == "\n" then
- self.c[2] = self.c[2] + 1
- table.insert(self.t, self.c[2], "")
- self.c[1] = 0
- elseif keyPressed == BACKSPACE then
- self.t[self.c[2]] =
- (self.t[self.c[2]]):sub(1, range(self.c[1] - 1, 0, 9^99)) ..
- (self.t[self.c[2]]):sub(self.c[1] + 1, -1)
- self.c[1] = self.c[1] - 1
- if self.c[1] < 0 then
- self.c[2] = (self.c[2] > 1 and self.c[2] - 1 or 1)
- self.c[1] = self.t[self.c[2]] and #self.t[self.c[2]] or 0
- end
- else
- self.t[self.c[2]] =
- (self.t[self.c[2]]):sub(1, self.c[1]) .. keyPressed ..
- (self.t[self.c[2]]):sub(self.c[1] + 1, -1)
- self.c[1] = self.c[1] + 1
- if #self.t[self.c[2]] >= (self.w - 12) / 6 - 1 then
- self.c[1] = 0
- self.c[2] = self.c[2] + 1
- table.insert(self.t, self.c[2], "")
- end
- end
- end
- textWrapWidth(WIDTH)
- end
- --Scrolling Text Edit
- ui.textscroll = class()
- function ui.textscroll:init(win, x, y, w, h, t, d)
- self.win = win
- self.x, self.y = x, y
- self.w, self.h = w, h
- self.t = t and {t} or {""}
- self.d = d and d or "Enter text..."
- --self.c = self.t.len()
- self.f = false
- self.e = 0
- self.scroll = 0
- self.th = 13
- self.c = {0, 0}
- font("Inconsolata")
- fontSize(12)
- --self.fm = fontMetrics()
- self.sbegin = 0
- function self:text()
- return table.concat(self.t, "\n")
- end
- end
- function ui.textscroll:draw()
- clip(self.win.x + self.x, (HEIGHT - self.win.y - self.win.h) + self.y, self.w + 2, self.h + 2)
- fill(100)
- rrect(self.x, self.y, self.w, self.h, 6, vec3(30,30,30))
- if self.f then
- fill(240 - (self.scrolling > 0 and 0 or 10))
- else
- fill(220)
- end
- rrect(self.x + 1, self.y + 1, self.w - 2, self.h - 2, 5, vec3(10,10,10))
- textMode(CORNER)
- textWrapWidth(self.w - 12)
- font("Inconsolata")
- fontSize(12)
- if #self.t == 1 and self.t[1] == "" then
- fill(127)
- text(self.d, self.x + 6, self.y + self.h - 6 - 12 * #self.t)
- else
- fill(0)
- text(table.concat(self.t, "\n"), self.x + 6, self.y + self.h - 6 - 12 * #self.t - self.scroll)
- end
- if
- bounds(mousex, self.x, self.x + self.w) and
- bounds(mousey, self.y, self.y + self.h)
- then
- if CurrentTouch.state < ENDED then
- if CurrentTouch.state == BEGAN then
- self.sbegin = ElapsedTime
- self.sx, self.sy = mousex, mousey
- self.scrolling = 1
- else
- if ElapsedTime - self.sbegin > 0.5 and not(self.scrolling == 2) then
- showKeyboard()
- self.f = ElapsedTime
- self.c[1] = math.floor((mousex - self.x) / 6) - 1
- self.c[1] = self.c[1] >= 0 and self.c[1] or 0
- self.c[2] = math.floor((self.y + self.h - (mousey + self.scroll) + 6) * (self.h - 6) / (12) / (self.h - 6))
- self.c[2] = self.c[2] <= #self.t and self.c[2] or #self.t
- self.c[2] = self.c[2] > 0 and self.c[2] or 1
- self.c[1] = self.c[1] < #self.t[self.c[2]] and self.c[1] or #self.t[self.c[2]]
- self.scrolling = 0
- elseif self.scrolling >= 1 and CurrentTouch.state >= BEGAN then
- if
- bounds(CurrentTouch.deltaX, -1, 1) and bounds(CurrentTouch.deltaY, -1, 1) and
- ElapsedTime - self.sbegin < 0.5 and self.scrolling == 1
- then
- self.scrolling = 0
- elseif #self.t >= (self.h - 12) / 12 then
- self.scrolling = 2
- self.scroll = self.scroll + (self.sy - mousey)
- if self.scroll < self.h - 12 - #self.t * 12 then
- self.scroll = self.scroll - (self.sy - mousey)
- elseif self.scroll > (#self.t) - (self.h - 6) / 12 then
- --self.scroll = (#self.t) - (self.h - 6) / 12
- self.scroll = self.scroll - (self.sy - mousey)
- end
- self.sy = mousey
- end
- end
- end
- elseif self.scrolling == 1 then
- showKeyboard()
- self.f = ElapsedTime
- self.c[1] = math.floor((mousex - self.x) / 6) - 1
- self.c[1] = self.c[1] >= 0 and self.c[1] or 0
- self.c[2] = math.floor((self.y + self.h - (mousey + self.scroll) + 6) * (self.h - 6) / (12 + 0) / (self.h - 6))
- self.c[2] = self.c[2] <= #self.t and self.c[2] or #self.t
- self.c[2] = self.c[2] > 0 and self.c[2] or 1
- self.c[1] = self.c[1] < #self.t[self.c[2]] and self.c[1] or #self.t[self.c[2]]
- self.scrolling = 0
- end
- elseif CurrentTouch.state == ENDED then
- self.f = false
- end
- if self.f and (ElapsedTime - self.f) % 1 < 0.5 then
- stroke(40, 84, 185, 255)
- strokeWidth(1)
- line(
- self.x + self.c[1] * 6 + 6, self.y + self.h - (self.c[2] - 1) * 12 - 5 - self.scroll,
- self.x + self.c[1] * 6 + 6, self.y + self.h - (self.c[2] - 1) * 12 - 19 - self.scroll
- )
- end
- if keyPressed ~= "NP" and self.f then
- if keyPressed == "\n" then
- self.c[2] = self.c[2] + 1
- table.insert(self.t, self.c[2], "")
- self.c[1] = 0
- elseif keyPressed == BACKSPACE then
- self.t[self.c[2]] =
- (self.t[self.c[2]]):sub(1, range(self.c[1] - 1, 0, 9^99)) ..
- (self.t[self.c[2]]):sub(self.c[1] + 1, -1)
- self.c[1] = self.c[1] - 1
- if self.c[1] < 0 then
- if #self.t[self.c[2]] == 0 then
- table.remove(self.t, self.c[2])
- end
- self.c[2] = (self.c[2] > 1 and self.c[2] - 1 or 1)
- self.c[1] = self.t[self.c[2]] and #self.t[self.c[2]] or 0
- end
- else
- self.t[self.c[2]] =
- (self.t[self.c[2]]):sub(1, self.c[1]) .. keyPressed ..
- (self.t[self.c[2]]):sub(self.c[1] + 1, -1)
- self.c[1] = self.c[1] + 1
- if #self.t[self.c[2]] >= (self.w - 12) / 6 - 1 then
- self.c[1] = 0
- self.c[2] = self.c[2] + 1
- table.insert(self.t, self.c[2], "")
- end
- end
- end
- textWrapWidth(WIDTH)
- end
- --# Flash
- local _print = print
- flashAlert = 0
- flashText = ""
- flashStart = 0
- function flash(t, duration)
- flashText = t
- flashAlert = duration
- flashStart = ElapsedTime
- end
- --# Win
- --UPLOADED_TAB:Win
- local titlebar = _titlebar
- local isOnTop = _isOnTop
- local isOne = isOne
- wins = {}
- awins = {}
- ftypes = {}
- context = setContext
- --local bounds, range = bounds, range
- function adjustcindex()
- for i, v in ipairs(wins) do
- wins[i].cindex = i
- --winIndexes[wins[i].index] = wins[i].cindex
- end
- end
- local function runAll()
- for n = #wins, 1, -1 do
- if wins[n].active then
- wins[n]:run()
- end
- end
- end
- --[[
- local function runAll()
- for i, v in pairs(awins) do
- v:draw()
- end
- end
- --]]
- local function drawAndRunAll()
- for n = #wins, 1, -1 do
- if wins[n].active then
- wins[n]:run()
- wins[n]:draw()
- end
- end
- end
- local movedOpt = {
- [2] = function()
- moved = 1
- background(255)
- drawAndRunAll()
- end,
- [1] = function()
- moved = 0
- background(255)
- drawAndRunAll()
- end,
- [0] = function() runAll() end
- }
- function drawFlashAlert()
- if ElapsedTime - flashStart < flashAlert + 1 then
- fill(255)
- rect(0,0,WIDTH,12)
- fill(255, 0, 0, 255)
- rrect(0,-5, WIDTH, 17 -
- (((ElapsedTime - flashStart - flashAlert) * 25) > 0 and ((ElapsedTime - flashStart - flashAlert) * 25) or 0),
- 5)
- textMode(CENTER)
- fontSize(11)
- fill(255)
- text(tostring(flashText), WIDTH / 2, 6)
- --_print(flashAlert)
- end
- end
- function drawWindows()
- noStroke()
- noSmooth()
- rectMode(CORNER)
- textMode(CORNER)
- spriteMode(CORNER)
- font("SourceSansPro-Regular")
- --font("HelveticaNeue")
- fontSize(13.5)
- pushStyle()
- movedOpt[moved]()
- --background(255)
- --drawAndRunAll()
- taskbar()
- ctended = isN(CurrentTouch.state, ENDED)
- drawFlashAlert()
- end
- local cwinindex = 1
- window = class()
- function window:init(x, y, w, h, t, i)
- for i, v in pairs(ui) do self[i] = ui[i] end
- -- you can accept and set parameters here
- self.x = x
- self.y = y
- self.w = w
- self.h = h
- self.t = t
- self.i = i
- self.touches = {}
- self.index = cwinindex -- A unique identifier
- self.cindex = #wins + 1 --self.index
- cwinindex = cwinindex + 1
- self.__CONTENTS = image(self.w, self.h)
- self.clip = function() clip(self.x + 1, HEIGHT - self.y - self.h + 2, self.w - 2, self.h - 2) end
- self.translate = function() translate(self.x + 1, HEIGHT - self.y - self.h + 1) end
- self.mousex, self.mousey, self.pmousex, self.pmousey = nil
- table.insert(wins, self)
- end
- function window:optimize()
- self.main = self.main or function() end
- self.background = self.background or function() end
- self.onclose = self.onclose or function() end
- ---[=[
- if not self.i then
- self.i = image(27, 27)
- --[[
- setContext(self.i)
- font("HelveticaNeue-Light")
- fontSize(28)
- textMode(CENTER)
- fill(0)
- background(255)
- text(self.t, 10, 13)
- setContext()
- --]]
- end
- --]=]
- if not self.ismall then self.ismall = self.i end
- end
- function window:draw()
- popStyle()
- titlebar[math.floor(1/self.cindex)](self)
- fill(self.closehover and color(175,50,50) or color(230, 30, 30))
- rrect(self.x + self.w - 30, HEIGHT - self.y + 3, 27, 14, 4, vec3(50,70,70))
- local r, g, b = fill()
- fill(r-40,g-60,b-60)
- rrect(self.x + self.w - 7, HEIGHT - self.y + 3, 4, 4, 0, vec3(5,10,10))
- --smooth()
- pushStyle()
- end
- function window:run()
- --if self.done then return end
- local x, y = CurrentTouch.x, CurrentTouch.y
- local onTop = isOnTop[math.floor(1/self.cindex)](self, x, y)
- --if self.cindex > 1 then
- --[[
- for n = 1, self.cindex - 1 do
- if
- bounds(x, wins[n].x, wins[n].x + wins[n].w) and
- bounds(y, HEIGHT - wins[n].y - wins[n].h, HEIGHT - wins[n].y + 20) and
- wins[n].active
- then
- onTop = false
- break
- end
- end
- --end
- --]]
- if bounds(x, self.x, self.x + self.w) and bounds(y, HEIGHT - self.y - self.h, HEIGHT - self.y) and onTop then
- self:show()
- adjustcindex()
- end
- if
- (bounds(x, self.x + self.w - 30, self.x + self.w - 3) and
- bounds(y, HEIGHT - self.y + 3, HEIGHT - self.y + 17) and onTop)
- or self.done
- then
- if self.closed then else
- if (CurrentTouch.state == ENDED and ctended) then
- self.closed = true
- local persist = self:hide()
- if not persist then
- return
- else
- self.active = true
- self.done = false
- self.closed = true
- end
- elseif self.done then
- local persist = self:hide()
- self.done = false
- return
- else
- self.closehover = true
- end
- end
- else
- self.closed = false
- self.closehover = false
- if bounds(x, self.x, self.x + self.w) and bounds(y, HEIGHT - self.y, HEIGHT - self.y + 20) and
- not(self.dragx and self.dragy) and CurrentTouch.state == BEGAN and onTop
- then
- moved = 1
- self.dragx = x
- self.dragy = y
- self.sdx = self.x
- self.sdy = self.y
- table.remove(wins, self.cindex)
- table.insert(wins, 1, self)
- adjustcindex()
- --[[
- for i, v in ipairs(wins) do
- winIndexes[wins[i].index] = wins[i].cindex
- end
- --]]
- if self.onFocus then
- self.onFocus()
- end
- elseif self.dragx and self.dragy then
- moved = 1
- if CurrentTouch.state == ENDED then
- self.dragx, self.dragy = nil
- self.clip = function() clip(self.x + 1, HEIGHT - self.y - self.h + 2, self.w - 2, self.h - 2) end
- self.translate = function() translate(self.x + 1, HEIGHT - self.y - self.h + 1) end
- else
- self.x = math.floor(self.sdx + (x - self.dragx))
- self.y = math.floor(self.sdy - (y - self.dragy))
- self.clip = function() clip(self.x + 1, HEIGHT - self.y - self.h + 2, self.w - 2, self.h - 2) end
- self.translate = function() translate(self.x + 1, HEIGHT - self.y - self.h + 1) end
- end
- end
- end
- pushStyle()
- fill(237, 237, 237, 255)
- stroke(127)
- strokeWidth(1/ContentScaleFactor)
- rect(self.x, HEIGHT - self.y - self.h + 1, self.w, self.h)
- stroke(150)
- rect(self.x + 1/ContentScaleFactor, HEIGHT - self.y - self.h + 1 + 1/ContentScaleFactor, self.w-1, self.h-1)
- --Run window
- --if self.main then
- --clip()
- 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)
- self.mousex, self.mousey = CurrentTouch.x - self.x - 1, CurrentTouch.y - (HEIGHT - self.y - self.h + 1)
- --pmousex, pmousey = CurrentTouch.prevX - self.x - 1, CurrentTouch.prevY - (HEIGHT - self.y - self.h + 1)
- if onTop then
- mousex, mousey, pmousex, pmousey = self.mousex, self.mousey, self.pmousex, self.pmousey
- else
- mousex, mousey, pmousex, pmousey = 0,0,0,0
- end
- clip(self.x + 1, HEIGHT - self.y - self.h + 2, self.w - 2, self.h - 2)
- pushMatrix()
- popStyle()
- translate(self.x + 1, HEIGHT - self.y - self.h + 1)
- self.main()
- clip()
- popMatrix()
- --end
- --if self.background then
- self.background()
- --end
- --self:draw()
- end
- function window:show()
- --adjustcindex()
- table.remove(wins, self.cindex)
- table.insert(wins, 1, self)
- adjustcindex()
- self.active = true
- awins[self.index] = self
- moved = 1
- --self.done = false
- end
- function window:hide()
- moved = 1
- if self.active then
- self.active = false
- if self.temp then
- adjustcindex()
- table.remove(wins, self.cindex)
- adjustcindex()
- return
- end
- return self.onclose()
- end
- end
- function window:mhide()
- self.active = false
- awins[self.index] = nil
- moved = 1
- self.done = true
- end
- function window:destroy()
- --adjustcindex()
- for i = 1, #wins do
- if wins[i] and wins[i].index == self.index then
- table.remove(wins, i)
- end
- end
- awins[self.index] = nil
- self.active = false
- self.done = true
- self.draw = function() end
- moved = 1
- end
- function window:newInstance()
- adjustcindex()
- table.insert(wins, cwindex, {})
- for i, v in pairs(wins[self.cindex]) do
- wins[cwindex][i] = v
- end
- table.insert(winsOrig, wins[#wins])
- wins[n + 1].temp = true
- wins[n + 1].cindex = #wins
- wins[n + 1].index = cwinindex
- winsOrig[n + 1].temp = true
- winsOrig[n + 1].cindex = #winsOrig
- winsOrig[n + 1].index = cwinindex
- adjustcindex()
- end
- function new(i)
- return wins[i]:newInstance()
- end
- function window:extensions(...)
- for i, v in ipairs{...} do
- ftypes[v] = self
- end
- end
- --# Filesys
- --UPLOADED_TAB:Filesys
- file = file or {}
- file.open = function(f, ...)
- if not readText("Documents:" .. f) then
- saveText("Documents:" .. f, "")
- end
- return {
- ["file"] = f,
- ["contents"] = readText("Documents:" .. f),
- ["write"] = function(self, text)
- self.contents = self.contents .. text
- end,
- ["commit"] = function(self)
- saveText("Documents:" .. self.file, self.contents)
- end
- }
- end
- file.list = function(type)
- return assetList("Documents", type or TEXT)
- end
- file.sep = ":"
- --# Alert
- --UPLOADED_TAB:Alert
- ui.OKAY_CANCEL = 0
- ui.alerttypes = {}
- ui.alerttypes[ui.OKAY_CANCEL] = function(win, title, contents, f_okay, f_cancel)
- font("SourceSansPro-Regular")
- fontSize(13.5)
- local x, y = textSize(contents)
- win.calert = window(WIDTH / 2 - x / 2 + 20, HEIGHT / 2 - (y + 20 + 24) / 2, x + 20, y + 20 + 24, title)
- win.calert.hidden = true
- --ui.calert.w_ = ui.calert.w
- --ui.calert.h_ = ui.calert.h
- win.calert.i = readImage("Documents:gear")
- win.calert.done = false
- local okay = win.calert:button(10, 10, 50, 16, "Okay", function()
- adjustcindex()
- table.remove(wins, win.calert.cindex)
- win.calert = nil
- adjustcindex()
- f_okay()
- end)
- local cancel = win.calert:button(70, 10, 50, 16, "Cancel", function()
- adjustcindex()
- table.remove(wins, win.calert.cindex)
- win.calert = nil
- adjustcindex()
- f_cancel()
- end)
- win.calert.main = function()
- fill(0)
- textMode(CORNER)
- font("SourceSansPro-Regular")
- fontSize(13.5)
- text(contents, 10, y)
- okay:draw()
- cancel:draw()
- end
- win.calert:optimize()
- win.calert:show()
- end
- function ui.alert(win, alert_type, ...)
- ui.alerttypes[alert_type](win, ...)
- end
- ---[[
- --]]
- --# FileBrowser
- deficon = image(10,10)
- ui.filebrowser = function(win, callback)
- local numFiles = #(file.list())
- win.browse = window(WIDTH / 2 - 150, HEIGHT / 2 - (numFiles * 20 + 30) / 2, 300, (numFiles * 20 + 30), "Choose a file...")
- win.browse.hidden = true
- win.browse.i = win.i
- win.browse.done = false
- win.browse.files = file.list()
- local fv = win.browse:textedit(5, 5, win.browse.w - 40, 16, "", "Enter file name...")
- local fb = win.browse:button(win.browse.w - 30, 5, 20, 16, "Go",
- function()
- win.selectedfile = fv.t[1]
- if callback then callback(fv.t[1]) end
- adjustcindex()
- table.remove(wins, win.browse.cindex)
- win.browse = nil
- adjustcindex()
- end
- )
- for i, v in ipairs(win.browse.files) do
- local ov = v
- local tpos = v:find(file.sep) and v:find(file.sep) - 1 or 0
- local ft
- if tpos > 0 then
- ft = v:sub(1, tpos)
- v = v:sub(tpos + 2, -1)
- else
- ft = "null"
- end
- win.browse.files[i] = win.browse:link(5, 20 * i + 5, win.browse.w - 10, 20, ft .. ":\t" .. v,
- function()
- for i_, v in ipairs(win.browse.files) do
- if i_ ~= i then
- v.selected = 0
- end
- end
- fv.t = {ov}
- end,
- ftypes[ft] and ftypes[ft].i or deficon
- )
- end
- function win.browse.main()
- for i, v in ipairs(win.browse.files) do
- win.browse.files[i]:draw()
- end
- fb:draw()
- fv:draw()
- end
- win.browse:optimize()
- win.browse:show()
- end
- --# LoadWindows
- --UPLOADED_TAB:LoadWindows
- local programs = readGlobalData("CodeOS_AppProj")
- print(listProjectTabs(programs))
- if not(programs) or (not(listProjectTabs(programs))) or not(#(listProjectTabs(programs)) > 0) then
- if not(programs) or programs == "" then
- cerror = "No program source file found"
- ferror = "Sorry, there doesn't seem to be a set source project.\nPlease enter a project name..."
- else
- cerror = "Project " .. programs .. " does not exist"
- ferror = "Sorry, the project " .. programs .. " doesn't exist."
- end
- flash("Error: " .. cerror, 3) --Probably won't work, but just in case...
- local i = readImage("Documents:ngear")
- sfw = window(0, 100, WIDTH - 100, HEIGHT - 100, "Source Project...", i)
- setSource = function()
- saveGlobalData("CodeOS_AppProj", ri.t[1])
- restart()
- end
- rb = sfw:button(WIDTH / 2 - 100, HEIGHT / 2 - 8, 200, 16, "Set source project", setSource)
- ri = sfw:textedit(WIDTH / 2 - 100, HEIGHT / 2 + 13, 200, 16, programs or "", "Enter source project...")
- function sfw:draw()
- self:show()
- background(255)
- fill(0)
- textMode(CORNER)
- text(ferror, WIDTH / 2 - 100, HEIGHT / 2 + 34)
- rb:draw()
- ri:draw()
- drawFlashAlert()
- end
- sfw:show()
- else
- _tabs = listProjectTabs(programs)
- --print(_tabs)
- ---[[
- print(pcall(function()
- --_tabs = {_tabs[3], _tabs[5], _tabs[6], _tabs[7]
- for i, v in pairs(_tabs) do
- if v ~= "Main" then
- print(pcall(loadstring(readProjectTab(programs .. ":" .. v))))
- --dofile(os.getenv("HOME") .. "/Documents/" .. programs .. ".codea/" .. v .. ".lua")
- end
- end
- end))
- --]]
- end
- --# ProgramRun
- --UPLOADED_TAB:ProgramRun
- --[[
- run = window(450, 200, 170, 72, "Run")
- run.i = readImage("Documents:ui")
- local p = run:textedit(10, 10, 150, 24, "", "Program...")
- local b = run:button(10, 44, 150, 16, "Run program",
- function()
- local s, t = pcall(listProjectTabs, p:text())
- if t then
- for i, v in ipairs(t) do
- if v ~= "Main" then
- s, err = pcall(loadstring(readProjectTab(p:text() .. ":" .. v)))
- if not s then
- print(err)
- end
- end
- end
- end
- end
- )
- run.main = function()
- b:draw()
- p:draw()
- end
- --]]
- --# SetUpWindows
- --UPLOADED_TAB:SetUpWindows
- ---[[
- winsOrig, winIndexes = {}, {}
- for i, v in ipairs(wins) do
- wins[i]:optimize()
- if not wins[i].hidden then
- table.insert(winsOrig, v)
- end
- winIndexes[i] = i
- end
- --]]
- --# Print
- _print = print
- print = function(...)
- local arg = {...}
- for i, v in ipairs(arg) do arg[i] = tostring(v) end
- local msg = table.concat(arg, "\t")
- local d = debug.getinfo(2, "Sl")
- if d then
- msg = ("\nSource: " .. (d.short_src):sub(1, (d.short_src:find("\n") or 0) - 1) .. ", line " .. d.currentline .. ":\n" .. msg)
- else
- msg = ("Data unavailable!\n" .. msg)
- end
- ui.alerttypes[0]({}, "Message", msg, function() end, function() end)
- end
Advertisement
Add Comment
Please, Sign In to add comment