Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Set up variables
- local attachedMonitor = peripheral.wrap("top")
- local defaultBackgroundColor =colors.black
- local defaultTextColor=colors.white
- local backgroundColorNormal = colors.blue
- local backgroundColorPressed = colors.red
- local textColorNormal = colors.white
- local textColorPressed = colors.yellow
- local width=10
- local height = 3
- local label="Button"
- local startColumn=3
- local startRow=3
- local labelPad = 2
- -- Set up Monitor
- if not attachedMonitor.isColor() then
- attachedMonitor.setBackgroundColor(colors.black)
- attachedMonitor.setTextColor(colors.white)
- else
- attachedMonitor.setBackgroundColor(defaultBackgroundColor)
- attachedMonitor.setTextColor(defaultTextColor)
- end
- --attachedMonitor.setTextScale(.5)
- attachedMonitor.clear()
- -- set the button/label color to normal (not pressed) colors
- if not attachedMonitor.isColor() then
- attachedMonitor.setBackgroundColor(colors.black)
- attachedMonitor.setTextColor(colors.white)
- else
- attachedMonitor.setBackgroundColor(backgroundColorNormal)
- attachedMonitor.setTextColor(textColorNormal)
- end
- -- Display the button Background
- for row = startRow,startRow+height-1 do
- attachedMonitor.setCursorPos(startColumn,row)
- attachedMonitor.write(string.rep(" ",width))
- end
- -- prepare label, truncate label if necessary
- if width < 3 then
- labelPad = 0
- end
- if #label > width - labelPad then
- label = label:sub(1,width - labelPad)
- end
- --Display the label (auto centered)
- attachedMonitor.setCursorPos(startColumn + math.floor((width - #label)/2),startRow + math.floor((height-1)/2))
- attachedMonitor.write(label)
- -- reset to original text/background colors
- if not attachedMonitor.isColor() then
- attachedMonitor.setBackgroundColor(colors.black)
- attachedMonitor.setTextColor(colors.white)
- else
- attachedMonitor.setBackgroundColor(defaultBackgroundColor)
- attachedMonitor.setTextColor(defaultTextColor)
- end
- -- sleep and then let's do it again with our "pressed" colors.
- sleep(3)
- -- set button/label colors to pressed colors
- if not attachedMonitor.isColor() then
- attachedMonitor.setBackgroundColor(colors.white)
- attachedMonitor.setTextColor(colors.black)
- else
- attachedMonitor.setBackgroundColor(backgroundColorPressed)
- attachedMonitor.setTextColor(textColorPressed)
- end
- -- Display the button Background
- for row = startRow,startRow+height-1 do
- attachedMonitor.setCursorPos(startColumn,row)
- attachedMonitor.write(string.rep(" ",width))
- end
- -- prepare label, truncate label if necessary
- if width < 3 then
- labelPad = 0
- end
- if #label > width - labelPad then
- label = label:sub(1,width - labelPad)
- end
- --Display the label (auto centered)
- attachedMonitor.setCursorPos(startColumn + math.floor((width - #label)/2),startRow + math.floor((height-1)/2))
- attachedMonitor.write(label)
- -- reset monitor
- if not attachedMonitor.isColor() then
- attachedMonitor.setBackgroundColor(colors.black)
- attachedMonitor.setTextColor(colors.white)
- else
- attachedMonitor.setBackgroundColor(defaultBackgroundColor)
- attachedMonitor.setTextColor(defaultTextColor)
- end
- attachedMonitor.setCursorPos(1,8)
- attachedMonitor.write("Done.")
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement