Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
skitdev
Level 7

Problem with roScreen stack

Hey guys,

I'm building a program that switches between 2 different screens (one expensive to draw, the other not.) I create the screen that holds the cheap one to stack on top of the expensive one, and when I'm done try to pop it off of the stack and see the expensive screen without having to rerender everything. However, this doesn't seem to work. I've created a test program to illustrate the issue.

Any help would be greatly appreciated.
Thanks!



Function main () as void

player_rect = {x: 460, y: 36, w: 756, h: 425 }
player = CreateObject("roVideoPlayer")
player.SetPositionNotificationPeriod(1)
player.SetContentList([
{
Stream : { url :"http://video.ted.com/talks/podcast/ImogenHeap_WaitItOut_2009G_480.mp4" }
StreamFormat : "mp4"
}
])
player.SetDestinationRect( player_rect )
player.Play()

port = CreateObject("roMessagePort")

'set up first screen
screen0 = CreateObject("roScreen", true)
screen0.SetMessagePort(port)
screen0.setAlphaEnable(true)
screen0.Clear(&h00000000)
screen0.DrawRect( 0, 0, 300, 720, &hff0000ff )
screen0.SwapBuffers()
screen0.Clear(&h00000000)
screen0.DrawRect( 0, 0, 300, 720, &hff0000ff )
screen0.SwapBuffers()

msg = wait(0, port)
msg = wait(0, port)

'set up first screen
screen1 = CreateObject("roScreen", true)
screen1.SetMessagePort(port)
screen1.setAlphaEnable(true)
screen1.Clear(&h00000000)
screen1.DrawRect( 300, 0, 300, 720, &h00ff00ff )
screen1.SwapBuffers()
screen1.Clear(&h00000000)
screen1.DrawRect( 300, 0, 300, 720, &h00ff00ff )
screen1.SwapBuffers()

msg = wait(0, port)
msg = wait(0, port)

'destroy new screen
screen1 = invalid

while(true)
end while

End Function

0 Kudos
5 Replies
RokuMarkn
Level 7

Re: Problem with roScreen stack

In most cases an app should use only one roScreen. One way to do what you're trying to achieve would be to keep your predrawn screens in roBitmaps and draw the bitmaps to the roScreen singleton.

--Mark
0 Kudos
skitdev
Level 7

Re: Problem with roScreen stack

How would I do that? I only saw how to get a byteArray from the roScreen. Is there a way to cast it to a roBitmap or would I need to do something else?

Is the roScreen intended to be used like a singleton? I'm rather confused as the documentation seemed to strongly suggest otherwise.

Multiple roScreen components stack, and like other screen components only the top screen is viewable and gets events. An roScreen that is not the top most screen can still be drawn to. Once an roScreen is created, the display stack enters "Game Mode", and other screen components cannot be used. Other screen components cannot be intermixed with roScreens as the roScreen display stack is maintained independently from the main screen component display stack. When the final roScreen component is closed, other screen components can be used again.


http://sdkdocs.roku.com/display/sdkdoc/roScreen

The system internally maintains a stack of screens. Whenever a screen is created and displayed, it will be placed on the top of the screen stack. The top screen on the stack is the only one that is visible; all lower screens are hidden. All remote events are directed to the message port of the screen on top of the stack. When a screen is closed, it is removed from the stack and the screen which was below the top screen then becomes visible.


http://sdkdocs.roku.com/display/sdkdoc/ ... th+Screens


Thanks a bunch for the help!
-Skitdev
0 Kudos
RokuMarkn
Level 7

Re: Problem with roScreen stack

They do stack, but I believe that removing an roScreen from the stack doesn't automatically redraw the lower one. You need to redraw it manually. I'm not positive about this because I never use more than one roScreen. It's unnecessary and can be wasteful of resources.

I didn't understand your first question. All I'm proposing is that instead of drawing to two roScreens, you draw to two roBitmaps (using the exact same APIs). When you want to draw the screen you would draw the appropriate one using DrawObject. It sounds like you were asking for a way to copy from an roScreen to an roBitmap, which is also possible with DrawObject but not part of what I was proposing.

--Mark
0 Kudos
Rek
Level 7

Re: Problem with roScreen stack

"skitdev" wrote:
How would I do that? I only saw how to get a byteArray from the roScreen. Is there a way to cast it to a roBitmap or would I need to do something else?


roBitmap implements the ifDraw2D interface. That means you can call all the same draw*() methods on a bitmap as you do on the roScreen. Once you've drawn all your contents to the bitmap, you can draw the bitmap onto the screen:


width = 1920
height = 1080

screen = createObject("roScreen", true, width, height)
bitmap = createObject("roBitmap", { width: width, height: height, AlphaEnable: false })

' Fill the bitmap with red
bitmap.drawRect(0, 0, width, height &hff0000ff)

' Draw the bitmap to the screen
screen.drawObject(0, 0, bitmap)
0 Kudos
skitdev
Level 7

Re: Problem with roScreen stack

gotcha. Thanks!
0 Kudos