Forum Discussion

BinaryMadman's avatar
13 years ago

Need help with slightly modified Scroll SDK example

I'm almost done with my pet BrightScript project (a folder-based comic viewer). I am able to generate a list of image files on an external drive then display them to the Screen one by one by using the Fast Forward and Reverse keys on the Roku Remote. The problem is i can only go through about half of the image files before i get an error stating that 'bigbm', the roBitmap being displayed on the screen, is invalid. I think it's because i'm using a GOTO call to change the image file sent to 'bigbm'. I need a fresh set of eyes to point me in the right direction on this. If my method is misguided i would appreciate any suggestions you all might have. I am aware this might be too much code to have you all look through. Giving it a shot anyways because i'm stumped!


' ******
' ****** Scroll a view around a large plane, double buffered
' ******

Library "v30/bslCore.brs"

Function IsHD()
di = CreateObject("roDeviceInfo")
if di.GetDisplayType() = "HDTV" then return true
return false
End Function

sub main()
viewComic("ext1:/Comics/Batman/Batman 001")
end sub

function viewComic(path as string)

'Check if the screen is in HD or not.
if IsHD()
screen=CreateObject("roScreen", true, 1280, 720) 'try this to see zoom
else
screen=CreateObject("roScreen", true)
endif

ImageIndex = 0
imagefiles = matchfiles(path,"*.jpg")


NewFile:
filepath = path + "/" + imagefiles[ImageIndex]
print filepath

'Load comic page with jpg of comic.
bigbm=CreateObject("roBitmap", filepath)
'Check if comic was unable to be created.
if bigbm = invalid
print "bigbm create failed"
stop
endif

'Set background region to that of the image loaded in bigbm.
backgroundRegion=CreateObject("roRegion", bigbm, 0, 0, screen.getwidth(), screen.getheight())
'Check if background region was unable to be loaded.
if backgroundRegion = invalid
print "create region failed"
stop
endif

'Prevent image from overscrolling. Stops at image edges.
backgroundRegion.SetWrap(false)

'Output image to screen.
screen.drawobject(0, 0, backgroundRegion)
screen.SwapBuffers()

msgport = CreateObject("roMessagePort")
screen.SetPort(msgport)

movedelta = 16
if (screen.getwidth() <= 720)
movedelta = 8
endif

codes = bslUniversalControlEventCodes()

pressedState = -1 ' If > 0, is the button currently in pressed state
while true
if pressedState = -1 then
msg=wait(0, msgport) ' wait for a button press
else
msg=wait(1, msgport) ' wait for a button release or move in current pressedState direction
endif
if type(msg)="roUniversalControlEvent" then
keypressed = msg.GetInt()
print "keypressed=";keypressed
if keypressed=codes.BUTTON_UP_PRESSED then
Zip(screen, backgroundRegion, 0,-movedelta) 'up button pressed
pressedState = codes.BUTTON_UP_PRESSED
else if keypressed=codes.BUTTON_DOWN_PRESSED then
Zip(screen, backgroundRegion, 0,+movedelta) ' down button pressed
pressedState = codes.BUTTON_DOWN_PRESSED
else if keypressed=codes.BUTTON_RIGHT_PRESSED then
Zip(screen, backgroundRegion, +movedelta,0) ' right button pressed
pressedState = codes.BUTTON_RIGHT_PRESSED
else if keypressed=codes.BUTTON_LEFT_PRESSED then
Zip(screen, backgroundRegion, -movedelta, 0) ' left button pressed
pressedState = codes.BUTTON_LEFT_PRESSED
else if keypressed = 8 then
print "Rewind"
if ImageIndex = 0 then
'Ignore reverse page request if at end of imagelist.
else
ImageIndex = ImageIndex - 1
GOTO NewFile
end if
else if keypressed = 9 then
print "Fast Forward"
if ImageIndex = ImageFiles.count() then
'Ignore forward page request if at end of imagelist.
else
ImageIndex = ImageIndex + 1
GOTO NewFile
end if
else if keypressed=codes.BUTTON_BACK_PRESSED then
pressedState = -1
exit while
else if keypressed=codes.BUTTON_UP_RELEASED or keypressed=codes.BUTTON_DOWN_RELEASED or keypressed=codes.BUTTON_RIGHT_RELEASED or keypressed=codes.BUTTON_LEFT_RELEASED then
pressedState = -1
end if
else if msg = invalid then
print "eventLoop timeout pressedState = "; pressedState
if pressedState=codes.BUTTON_UP_PRESSED then
Zip(screen, backgroundRegion, 0,-movedelta) 'up button released
else if pressedState=codes.BUTTON_DOWN_PRESSED then
Zip(screen, backgroundRegion, 0,+movedelta) ' down button released
else if pressedState=codes.BUTTON_RIGHT_PRESSED then
Zip(screen, backgroundRegion, +movedelta,0) ' right button released
else if pressedState=codes.BUTTON_LEFT_PRESSED then
Zip(screen, backgroundRegion, -movedelta, 0) ' left button released
end if
end if
end while

end function

function Zip(screen, region, xd, yd)
region.Offset(xd,yd,0,0)
screen.drawobject(0, 0, region)
screen.SwapBuffers()
end function

17 Replies