Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _selectBit = "000000"
- local guiX = 5
- local guiY = 4
- local running = true
- function bitSpecial(chbit)
- -- Add 5 bit binary to the index start of the
- -- "small" txt.
- if(chbit > 31)then
- chbit = (64+(chbit * -1))-1
- end
- return string.char(128 + chbit)
- end
- function draw()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- -- Draws the GUI for the mouse event stuff.
- paintutils.drawFilledBox(guiX,guiY,guiX+3,guiY+4,colors.red)
- paintutils.drawFilledBox(guiX+1,guiY+1,guiX+2,guiY+3,colors.gray)
- end
- function drawBit(ind)
- -- Bit position based on reverse index logic.
- if(ind > 2)then
- posX = (ind%2 *-1) + 2
- posY = ind/2 - ( (ind%2 *-1) +1)
- else
- posX = ind
- posY = 0
- end
- term.setCursorPos(guiX+posX,guiY+posY+1)
- if(_selectBit:sub(ind,ind) == "1")then
- term.blit(" ", "F","0")
- else
- term.blit(" ", "F","7")
- end
- term.setCursorPos(1,2)
- write("mX: " .. posX .. " mY: " .. posY)
- end
- function update(e)
- if(e[1] == "key")then running = false return end
- if(e[1] == "mouse_click" or e[1] == "mouse_drag")then
- local mb, mx, my = e[2], e[3], e[4]
- -- Figure location to insert into bits.
- if(mx >= guiX+1 and mx < guiX+3 and
- my >= guiY+1 and my < guiY+4)then
- -- Decode absolute mouse to relative bit
- -- offset.
- local indx = (mx-(guiX+1)+1) -- Offs.
- local indy = my-(guiY+1) -- Entry point.
- local ind = indx+(indy*2)
- -- Insert data for bit respective to button.
- local chg = "1"
- if(mb == 2)then chg = "0" end
- _selectBit = (_selectBit:sub(1,ind-1)
- .. chg .. _selectBit:sub(ind+1,-1) )
- drawBit(ind)
- -- Convert binary edit to decimal.
- local spStr = bitSpecial(tonumber(_selectBit:reverse(),2))
- term.setCursorPos(1,1)
- write("Index: " .. ind .. " :> " ..tonumber(_selectBit:reverse(),2) .. " ")
- term.setCursorPos(1,3)
- write("Char: " .. string.byte(spStr))
- term.setCursorPos(guiX+5,guiY+2)
- local cols = {colors.white,colors.gray}
- if(tonumber(_selectBit:reverse(),2) > 31)then
- local c1 = cols[1]
- local c2 = cols[2]
- cols[2] = c1
- cols[1] = c2
- end
- term.setTextColor(cols[1])
- term.setBackgroundColor(cols[2])
- write(spStr)
- end
- end
- end
- draw()
- while running do
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- local ev = {os.pullEvent()}
- update(ev)
- term.setCursorPos(12,10)
- write("Press any key to end demo.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement