Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setup()
- displayMode(FULLSCREEN)
- debugging = {false, false}
- list1:init()
- end
- bar = {}
- function bar:draw()
- fill(0)
- noStroke()
- rect(0, HEIGHT-45, WIDTH, 46)
- font("Courier-Bold")
- fontSize(20)
- fill(255)
- text('Löve2d Reference', WIDTH/7*3, HEIGHT-22)
- end
- items1 = {
- {title="love", image=readImage("Blocks:Blank White"),
- description="Modules, Functions, Types and Callbacks"},
- {title="love.audio",image=readImage("Blocks:Brick Grey"),
- description="Interface to output sound"},
- {title="love.data",image=readImage("Blocks:Brick Red"),
- description="Provides functionality for creating and transforming data"},
- {title="love.event",image=readImage("Cargo Bot:Codea Icon"),
- description="Manages events, like keypresses"},
- {title="love.filesystem",image=readImage("Environments:Icon"),
- description="Interface to the filesystem"},
- {title="love.font",image=readImage("Environments:Night Back"),
- description="Work with and create fonts"},
- {title="love.graphics",image=readImage("Cargo Bot:Game Lower BG"),
- description="Drawing Shapes, Sprites and Styles"},
- {title="love.image",image=readImage("Cargo Bot:Made With Codea"),
- description="Decode encoded image data"},
- {title="love.joystick",image=readImage("Cargo Bot:Game Upper BG"),
- description="Interface to Connected Joysticks"},
- {title="love.keyboard",image=readImage("Cargo Bot:Level Select BG"),
- description="Interface to Connected Keyboard"},
- {title="love.math",image=readImage("Environments:Night Up"),
- description="System Independent Mathematical-Functions"},
- {title="love.mouse",image=readImage("Cargo Bot:Pack Hard"),
- description="Detect and React to Mouse Events"},
- {title="love.physics",image=readImage("Surfaces:Basic Bricks Color"),
- description="Binding to Box2d Physics"},
- {title="love.sound",image=readImage("Planet Cute:Water Block"),
- description="Encode and decode sounds! To play sounds, see love.audio"},
- {title="love.system",image=readImage("Blocks:Error"),
- description="Information about the user's system"},
- {title="love.thread",image=readImage("Cargo Bot:Play Solution Icon"),
- description="Create and use Threads and Channels"},
- {title="love.timer",image=readImage("Cargo Bot:Stop Button"),
- description="High resolution timing functions"},
- {title="love.touch",image=readImage("Cargo Bot:Icon"),
- description="Detecting and Reacting to Touches on the Screen"},
- {title="love.video",image=readImage("Cargo Bot:Play Button"),
- description="Decoding, controlling and streaming video files"},
- {title="love.window",image=readImage("Blocks:Missing"),
- description="Modifying and retrieving information on the Window"},
- {title="lua-enet",image=readImage("UI:Green Button 09"),
- description="Network Communication over UDP"},
- {title="luasocket",image=readImage("Environments:Sunny Front"),
- description="Networking on TCP/UDP"},
- {title="utf8",image=readImage("Environments:Sunny Up"),
- description="Handling UTF-8 Strings"};
- }
- do for i, v in ipairs(items1) do v.index = i end end
- list1={}
- function list1:init()
- self.y = HEIGHT - 46
- self.height = #items1*HEIGHT/9
- self.selected = {}
- self.touches = {}
- self.deltas = {}
- self.vel = vec2(0,0)
- self.friction = .976
- self.dt = 1
- end
- function list1:scroll()
- self.dt = self.dt + 1
- if self.deltas[11] then
- table.remove(self.deltas, 1)
- end
- if self.deltas[1] and self.dt % 2 == 0 then
- table.remove(self.deltas, 1)
- end
- self.y = self.y + self.vel.y
- self.vel.y = self.vel.y * self.friction
- if not self.maxY or not self.minY then return end
- if self.y > self.maxY + 32 then
- if self.tween then tween.stop(self.tween) end
- self.vel.y = 0
- self.tween = tween(.25,self,{y=self.maxY},tween.easing.quadOut)
- elseif self.y < self.minY - 32 then
- if self.tween then tween.stop(self.tween) end
- self.vel.y = 0
- self.tween = tween(.25,self,{y=self.minY},tween.easing.quadOut)
- end
- end
- function list1:draw(t)
- self:scroll()
- fill(0, 155)
- noStroke()
- rect(0, 0, WIDTH/7*2, HEIGHT-46)
- pushStyle()
- textMode(CORNER)
- textWrapWidth(WIDTH/7*2-80)
- lineCapMode(ROUND)
- smooth()
- for i,v in ipairs(items1) do
- local y = self.y - (i-.5) * HEIGHT/9 -- center point
- font("HelveticaNeue")
- fontSize(16)
- local tw, th = textSize(v.description)
- font("HelveticaNeue-CondensedBold")
- fontSize(20)
- local tw2, th2 = textSize(v.title)
- local textheight = th + th2 -- total height of title and description
- local topY = y + textheight/2
- local titleY = topY - th2
- local bottomY = y - textheight/2
- fill(255)
- text(v.title, 80, titleY)
- sprite(v.image, 40, y, 64, 64)
- fill(150)
- font("HelveticaNeue")
- fontSize(16)
- text(v.description, 80, bottomY)
- stroke(255,100)
- strokeWidth(1)
- line(80, self.y - i * HEIGHT/9, WIDTH / 7 * 2, self.y - i * HEIGHT/9)
- if debugging[1] then
- noFill()
- stroke(0,0,200)
- strokeWidth(2)
- rectMode(CORNERS)
- rect(80, bottomY, WIDTH/7*2, topY)
- end
- if debugging[2] then
- for k, touch in pairs(self.touches) do
- fill(touch.x, touch.y, (touch.x*touch.y)^.5)
- noStroke()
- ellipse(touch.x, touch.y, 64)
- end
- end
- end
- popStyle()
- end
- function list1:touched(touch)
- if touch.state == BEGAN and touch.x < WIDTH/7*2 then
- self:selectFromTouch(touch)
- self.deltas = {}
- list1.isTouched = true
- if self.tween then tween.stop(self.tween) end
- self.touches[touch.id] = touch
- end
- if not list1.isTouched then return end
- if touch.state == MOVING then
- if not self.touches[touch.id] then return end
- self.y = self.y + touch.deltaY
- table.insert(self.deltas, touch.deltaY)
- elseif touch.state == ENDED then
- if not self.touches[touch.id] then return end
- self.touches[touch.id] = nil
- local h, lh, h9 = HEIGHT-46, HEIGHT/9 * #items1, HEIGHT/9
- self.maxY = lh < h and h or lh > h and lh
- self.minY = h
- local newY = self.y + average(self.deltas)
- local minty = self.minY - h9 -- min target y, minty
- local maxty = self.maxY + h9 -- max target y, maxty
- local duration = newY < self.minY and .5 or newY > self.maxY and .5 or 4.0
- newY = newY < minty and self.minY or newY > maxty and self.maxY or nil
- if self.y < self.minY then
- if self.tween then tween.stop(self.tween) end
- self.tween = tween(0.5, self, {y=self.minY}, tween.easing.quadOut)
- elseif self.y > self.maxY then
- if self.tween then tween.stop(self.tween) end
- self.tween = tween(0.5, self, {y=self.maxY}, tween.easing.quadOut)
- elseif newY then
- self:edgeTween(newY,self.minY,self.maxY)
- else
- self:setVel()
- list1.isTouched = false
- end
- end
- end
- function list1:edgeTween(newY,minY,maxY)
- self.tween = tween(.5, self, {y=newY}, tween.easing.quadOut)
- end
- function list1:setVel()
- local v = average(self.deltas)
- self.deltas = {}
- self.vel.y = v/10
- end
- function average(t)
- local n = 0
- for i,v in ipairs(t) do n = n + v end
- return n
- end
- function list1:selectFromTouch(touch)
- local top=self.y
- local bottom=self.y-(#items1*HEIGHT/9)
- self.height=top-bottom
- local listY=touch.y-(top-self.height)
- if listY>top or listY<bottom then return end
- local index=math.ceil(listY/(HEIGHT/9))
- index=#items1-index+1
- self.selected=items1[index]
- self.selected.state = touch.state
- print("selected index: "..index, self.selected.title, "at pos:y - "..listY)
- end
- list2 = {}
- function list2:draw()
- fill(0, 155)
- noStroke()
- rect(WIDTH/7*2, 0, WIDTH/7*2, HEIGHT-46)
- for i,v in ipairs(list1.selected) do end
- end
- list3 = {}
- function list3:draw()
- fill(0,155)
- noStroke()
- rect(WIDTH/7*4, 0, WIDTH/7*3, HEIGHT-46)
- end
- -- This function gets called once every frame
- function draw()
- -- This sets a dark background color
- background(40, 40, 50)
- -- This sets the line thickness
- strokeWidth(5)
- -- Do your drawing here
- bar.draw()
- list1:draw()
- list2:draw()
- list3:draw()
- end
- function touched(touch)
- list1:touched(touch)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement