Just because.... I made another demo that shows scrolling working based on mouse position.
setVirtualResolution(640,480)
Type ScrollParams
offsetX as integer
offsetY as integer
timestamp as integer
EndType
GLOBAL _ScrollParams as ScrollParams
// Create a text object to scroll
TextToScroll = createText("This is a scrolling example.")
setTextSize(TextToScroll, 18)
scrollWidth = 200
scrollHeight = 100
// Initialize the scrolling box
setTextScrollBox(textToScroll, 100, 10, scrollWidth, scrollHeight)
do
// show viewable scrollable area
drawBox(100, 10, scrollWidth, scrollHeight, 255,255,255)
// scroll the text
scrollText(textToScroll, 100, 10, scrollWidth, scrollHeight, 10, sx#, sy#)
drawBox(300, 300, 100, 100, 255,255,255)
mx = getrawmousex()
my = getrawmousey()
if mx < 300 then mx = 300
if mx > 400 then mx = 400
if my < 300 then my = 300
if my > 400 then my = 400
drawLine(350,350, mx, my,255,255,255)
sx# = (mx - 350) / 50.0
sy# = (my - 350) / 50.0
sync()
loop
function setTextScrollBox(txtId, x, y, width, height)
setTextPosition(txtId, x, y)
setTextScissor(txtId, x, y, x+width, y+height)
endfunction
function scrollText(txtId, x, y, width, height, delay, horizontal, vertical)
if _ScrollParams.timestamp + delay < getMilliseconds()
tx = getTextX(txtId)+horizontal
ty = getTextY(txtId)+vertical
if tx+getTextTotalWidth(txtId) < x then tx = x + width
if tx > x+width then tx = x - getTextTotalWidth(txtId)
if ty > y+height then ty = y - getTextTotalHeight(txtId)
if ty < y-getTextTotalHeight(txtId) then ty = y + height
setTextPosition(txtId, tx, ty)
_ScrollParams.timestamp = getMilliseconds()
endif
endfunction
function drawBox(x, y, width, height, r, g, b)
drawLine(x, y, x+width, y, r,g,b)
drawLine(x, y+height, x+width, y+height, r,g,b)
drawLine(x, y, x, y+height, r,g,b)
drawLine(x+width, y, x+width, y+height, r,g,b)
endfunction
"You're all wrong. You're all idiots." ~Fluffy Rabbit