I have this scroll pane piece of code working really well, but i can't figure out how lineOffset is working.For example:
lines$(50)
lineOffset = 500 * value#
but if change lines$ to 500 like this:
lines$(500)
I found that i need to adjust this line to this or the scrolling becomes wierd:
lineOffset = 7700 * value#
I can't determine the value in lineOffset so it can adjust properly to array of any size.
Here is the code:
REM /////////////////////////////////////
REM Title: Scroll Pane
REM Author: Phaelax
REM /////////////////////////////////////
set display mode 1024,768,32
set window on
dim lines$(50)
for i = 1 to 50
lines$(i) = "This is some dummy text."
next i
thumbY = 100
startP = 0
endP = 18
sync on
DO
cls
if mouseclick() = 1 and clickFlag = 0
rem check if mouse clicked on scrollbar thumb
if mouseWithin(500,thumbY,516,thumbY+20) = 1 and clickFlag = 0
isScrolling = 1
offsetY = mousey() - thumbY
clickFlag = 1
endif
clickFlag = 1
endif
rem reset flags
if mouseclick() = 0
clickFlag = 0
isScrolling = 0
endif
rem window is being scrolled
if isScrolling = 1
thumbY = mousey() - offsetY
if thumbY < 100 then thumbY = 100
if thumbY > 380 then thumbY = 380
value# = (thumbY - 100) / 280.0
lineOffset = 500 * value#
startP = ceil((500 * value#) / 16.0)
endP = startP + 17
if endP > 49 then endP = 49
endif
rem draw the scroll pane and bar
ink rgb(255,255,255),0
box 100,100,500,400
ink rgb(200,200,200),0
box 500,100,516,400
ink rgb(96,96,96),0
box 500,thumbY,516,thumbY+20
rem display the text
ink rgb(0,100,0),0
for i = startP to endP
ty = i*16 - lineOffset
text 100, 100+ty, str$(i+1)+". "+lines$(i+1)
next i
set cursor 0,0
print screen fps()
print value#
sync
LOOP
function mouseWithin(x1,y1,x2,y2)
mx = mousex()
my = mousey()
if mx>=x1 and mx<=x2 and my>=y1 and my<=y2 then exitfunction 1
endfunction 0
Coding is My Kung Fu!
And My Kung Fu is better than Yours!