Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bar = {}
- function bar.new()
- local newBar = {}
- newBar.x = 0
- newBar.y = 0
- newBar.w = 0
- newBar.h = 0
- newBar.parent = nil
- newBar.value = 0
- newBar.highValue = 0
- newBar.color = colors.white
- setmetatable(newBar,{__index=bar})
- return newBar
- end
- function bar:setPos(x,y)
- self.x = x
- self.y = y
- end
- function bar:getPos()
- return self.x,self.y
- end
- function bar:setParent(newParent)
- self.parent = newParent
- end
- function bar:getParent()
- return self.parent
- end
- function bar:setSize(w,h)
- self.w = w
- self.h = h
- end
- function bar:getSize()
- return self.w,self.h
- end
- function bar:setValue(value)
- self.value = value
- end
- function bar:getValue()
- return self.value
- end
- function bar:setHighValue(hVal)
- self.highValue = hVal
- end
- function bar:getHighValue()
- return self.highValue
- end
- function bar:getColor()
- if type(self.color) == "number" then return self.color
- elseif type(self.color) == "table" then return self.color:getColor()
- else return self:color() end
- end
- function bar:setColor(newColor)
- self.color = newColor
- end
- function bar:draw()
- local perc = self.value / self.highValue
- local dH = math.floor(perc * self.h)
- local monitor = self.parent:getMonitor()
- local pW,pH = self.parent:getSize()
- local pX,pY = self.parent:getPos()
- monitor.setBackgroundColor(self:getColor())
- for i=1,dH,1 do
- monitor.setCursorPos(self.x+pX,self.y+pY+pH-i)
- monitor.write(string.rep(" ",self.w))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement