Forum Discussion

bcoding's avatar
bcoding
Visitor
10 years ago

scrolling in roScreen, roBitmap, roRegion, roCompositor

Hi Guys,
Since the default listscreen doesnot meet my needs, I have trying to create a custom scroll area using roScreen, roBitmap, roRegion AND roCompositor. I want some text to be displayed at the top part of the screen then on the middle to bottom part, I want to present the user with the available offers which can be scrolled vertically. Therefore I drew some text on the top part of the screen. Then created a bitmap, drew text on the bitmap, used region and compositor to get the bitmap to the lower part of the screen.
It is scrolling but whenever I scroll, it will erase the text that I drew on the screen then if I scroll again it will display it again, I dont know the reason, Can any of you please help.


Library "v30/bslDefender.brs"
Function Main () AS void

'creating screen object
screen=CreateObject("roScreen",true)
screen.clear(&hff0000ff)

' font for the text
fontRegistry = CreateObject("roFontRegistry")
font = fontRegistry.GetDefaultFont(24,false,false)


'writing the text to the screen
screen.DrawText("Hi Customer",400,90, &h00FFFFFF ,font)
screen.DrawText("Your name is : John Doe",285,145,&h00FFFFFF,font)
screen.DrawText("__________________________________",400,180, &h00FFFFFF,font)
screen.DrawText("Here are your choices: ",270,225, &h00FFFFFF,font)

'creating compositor objects
compositor=CreateObject("roCompositor")
' compositor.SetDrawTo(screen, &hff0000ff)
compositor.SetDrawTo(screen,0)

'creaating bitmap and writing text to bitmap
srollBm=CreateObject("roBitmap",{ width: 650, height: 200, AlphaEnable: false })

srollBm.DrawText("Get a Macbook pro with 4GB ram and 250gb harddrive",0,0,&h00FFFFFF,font)
srollBm.DrawText("Get a Macbook pro with 8GB ram and 250gb harddrive",0,50,&h00FFFFFF,font)
srollBm.DrawText("Get a Macbook pro with 12GB ram and 250gb harddrive",0,100,&h00FFFFFF,font)


'creating region that will be used for scrolling
region=CreateObject("roRegion", srollBm, 0, 0, srollBm.getwidth(), srollBm.getheight())'size of scroll area

region.SetWrap(True)

'this will create new sprite
view_sprite=compositor.NewSprite(370,400, region)

'draw the sprites created
compositor.drawAll()
screen.SwapBuffers()

'creating port inorder to listen to user events
msgport = CreateObject("roMessagePort")
screen.SetMessagePort(msgport)
codes = bslUniversalControlEventCodes()

While True
msg=wait(0, msgport) ' wait for a button
print "Msg: "; type(msg); " event: "; msg.GetInt()
If type(msg)="roUniversalControlEvent" Then
If msg.GetInt()=codes.BUTTON_UP_PRESSED Then
Shift(screen, view_sprite, compositor, 0,-15) 'up 0,-15
Else If msg.GetInt()=codes.BUTTON_DOWN_PRESSED Then
Shift(screen, view_sprite, compositor, 0,+15) ' down 0,+15

Else If msg.GetInt() = codes.BUTTON_BACK_PRESSED ' back button
Exit While
End If
End If
End While
End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''' Shift Function To shift the bitmap region
''''''''''by the given numbers
''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Shift(screen, view_sprite, compositor, xd, yd)
view_sprite.OffsetRegion(xd,yd,0,0)
compositor.drawAll()
screen.SwapBuffers()
End Function

17 Replies