Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MonitorObj = {}
- function MonitorObj:new(periph, scale)
- local obj = obj or {}
- setmetatable(obj, {__index = self})
- obj.mon = peripheral.find("monitor") or periph -- if nothing is put in, find nearest monitor
- obj.w, obj.h = obj.mon.getSize()
- obj.scale = scale or 1
- obj.mon.setTextScale(obj.scale)
- return obj
- end
- function MonitorObj:clear()
- local old = term.redirect(self.mon)
- self.mon.setCursorPos(1,1)
- self.mon.setTextScale(self.scale)
- self.mon.setTextColor(colors.white)
- self.mon.setBackgroundColor(colors.black)
- self.mon.clear()
- term.redirect(old)
- end
- function MonitorObj:write(txt, x, y, cBg, cTxt)
- local c1 = cBg or colors.black
- local c2 = cTxt or colors.white
- local old = term.redirect(self.mon)
- local oldTC = self.mon.getTextColor() -- old text color
- local oldBC = self.mon.getBackgroundColor() -- old background color
- self.mon.setCursorPos(x,y)
- self.mon.setBackgroundColor(c1)
- self.mon.setTextColor(c2)
- self.mon.write(txt)
- self.mon.setTextColor(oldTC)
- self.mon.setBackgroundColor(oldBC)
- term.redirect(old)
- end
- function MonitorObj:getMonitor()
- return self.mon
- end
- function MonitorObj:setMonitor(periph)
- self:clear()
- self.mon = periph
- self:updateSize()
- end
- function MonitorObj:getSize()
- self:updateSize()
- return self.w, self.h
- end
- function MonitorObj:updateSize()
- self.mon.setTextScale(self.scale)
- local x,y = self.mon.getSize()
- self.w = x
- self.h = y
- end
- function MonitorObj:setScale(scale)
- self.scale = scale or 1
- self:updateSize()
- end
- function MonitorObj:getScale()
- return self.scale
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement