Would someone be so kind as to take a look and point out where my problem is before I go permanently cross-eyed trying to find it myself?
Code: Select all
function love.load()
-- Load font
fontSize = 48
font = love.graphics.newFont("calibri.ttf",fontSize)
love.graphics.setFont(font)
wordList = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
scrollBar = {x = 760, y = 0, width = 30, height = 160, position = 1, active = false}
listStart = scrollBar.position
windowWidth,windowHeight = love.window.getMode()
end
function love.draw()
local listEnd
-- Determine which lines will be displayed
-- 13 lines of text fit on the screen
if #wordList <=13 then
listEnd = #wordList
else
listEnd = listStart + 13
if listEnd > #wordList then
listEnd = #wordList
end
end
-- Display word list
local dy = 0
if #wordList > 0 then
for w = listStart,listEnd do
love.graphics.print(wordList[w],0,dy)
dy = dy + 42
end
end
-- Display scroll bar
love.graphics.rectangle("fill",scrollBar.x,scrollBar.y,scrollBar.width,scrollBar.height)
end
function love.update(dt)
end
function love.mousepressed(x, y, button)
if button == 1 then
-- Is the scroll bar being clicked on?
if (x >= scrollBar.x and x <= scrollBar.x+scrollBar.width) then
if (y >= scrollBar.y and y <= scrollBar.y+scrollBar.height) then
scrollBar.active = true
end
end
end
end
function love.mousereleased(x,y,button)
scrollBar.active = false
end
function love.mousemoved(x, y, dx, dy)
-- Is the scrollbar active while the mouse is moving?
if scrollBar.active == true then
-- Keep the scrollbar on the screen
if scrollBar.y + dy >= 0 and scrollBar.y + dy <= windowHeight-scrollBar.height then
scrollBar.y = scrollBar.y + dy
local factor
factor = math.floor((windowHeight-scrollBar.height)/#wordList)
scrollBar.position = math.floor(scrollBar.y/factor)+1
listStart = scrollBar.position
end
end
end