View.Set ("offscreenonly, graphics:700;300,position:center;center,nobuttonbar")
var scroll : real := 0
var scrollbar : int := 29
var scrollingLeft : boolean := false
var scrollingRight : boolean := false
var scrollbuffer : int := 0
var font : int
font := Font.New ("serif:10")
var x : string
var mx, my, mb : int %mouse variables
var s : int %if user clicks in scroll bar, this counts how many pixels right of "scrollbar" the user clicked
var locked : boolean := false
var key : array char of boolean
%-----------------
var space := 5
%-----------------
procedure input
Mouse.Where (mx, my, mb)
Input.KeyDown (key)
end input
procedure scrolling
if scrollbuffer = 0 then
if scroll > 0 then
if key (KEY_LEFT_ARROW) then
scroll -= 15
scrollbuffer += 2
scrollbar := round (1 / 20395 * scroll * (maxx - 27 - 27) + 29)
scrollingLeft := true
else
scrollingLeft := false
end if
end if
if scroll + 700 < 20395 then
if key (KEY_RIGHT_ARROW) then
scroll += 15
scrollbuffer += 2
scrollbar := round (1 / 20395 * scroll * (maxx - 27 - 27) + 29)
scrollingRight := true
end if
end if
end if
if scrollbuffer = 0 then
if locked = false and mb = 1 and mx >= 11 and mx <= 24 and my >= 11 and my <= 24 and scroll > 0 then
scroll -= 15
scrollbuffer += 2
scrollbar := round (1 / 20395 * scroll * (maxx - 27 - 27) + 29)
scrollingLeft := true
elsif locked = false and mb = 1 and mx >= maxx - 25 and mx <= maxx - 10 and my >= 11 and my <= 24 and scroll + 700 < 20395 then
scroll += 15
scrollbuffer += 2
scrollbar := round (1 / 20395 * scroll * (maxx - 27 - 27) + 29)
scrollingRight := true
else
scrollingRight := false
end if
end if
%locks mouse onto or unlocks mouse from the scroll bar
if mb = 0 then
locked := false
end if
if locked = false and mb = 1 and mx >= scrollbar and mx <= scrollbar + 22 and my >= 12 and my <= 23 then
locked := true
s := mx - scrollbar
end if
if locked = true then
if mx - s > 29 and mx + (22 - s) < maxx - 25 then
scrollbar := mx - s
scroll := round ((scrollbar - 29) / (1 / 20395 * (maxx - 27 - 27)))
end if
end if
end scrolling
procedure draw
Font.Draw ("Scroll by using arrow keys, clicking the arrows, or dragging the bar", 10, 290, font, black)
for i : 1 .. 255
if i * 80 - 80 - scroll < maxx and i * 80 - space - scroll > 0 then
x := intstr (i)
drawfillbox (round (i * 80 - 80 - scroll), 50, round (i * 80 - space - scroll), 286, i)
Font.Draw (x, round (i * 80 - 40 - scroll - Font.Width (x, font) / 2), 175, font, Rand.Int (1, 255))
end if
end for
%scrolling left box
if scroll > 0 and not scrollingLeft then
drawfillbox (11, 11, 24, 24, gray)
else
drawfillbox (12, 12, 23, 23, blue)
end if
Draw.Box (10, 10, 25, 25, black)
Font.Draw ("<", 15, 13, font, 2)
%scrolling right box
if scroll + 700 < 255 * 80 - space and not scrollingRight then
drawfillbox (maxx - 24, 11, maxx - 11, 24, gray)
else
drawfillbox (maxx - 23, 12, maxx - 12, 23, blue)
end if
Draw.Box (maxx - 25, 10, maxx - 10, 25, black)
Font.Draw (">", maxx - 20, 13, font, 2)
%scroll bar
Draw.Box (8, 8, maxx - 8, 27, black) %outer
Draw.Box (27, 10, maxx - 27, 25, black) %inner
%inner scroll bar
drawfillbox (scrollbar, 12, scrollbar + 22, 23, blue)
end draw
% 20395 = total pixels for 255 colors
%bar takes up 22 pixels according to this-> put round((700/20395)*(maxx - 27 - 27))
loop
input
scrolling
draw
if scrollbuffer > 0 then
scrollbuffer -= 1
end if
View.Update
cls
delay (15)
end loop
|