Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
coredump
Visitor

2D API - roCompositor , Screen Stacking

I am using an roCompositor to draw a custom screen. I am wondering what the recommended way to transition from drawing one screen to another.

In one case, I may have a screen completely custom drawn and need to transition to another custom screen:

(custom) Home Screen -> (custom) Detailed View

In the other case, I would have a custom layout but transition to a built in screen

(custom) Home Screen -> roSearchScreen

I know that normally, you would just call
 screen.show() 
stacking one screen on top of the other one. However, I am not sure what to do with a compositor. Do I create a new screen object and pass it to a compositor ? or just clear the screen somehow and draw the next one ?
0 Kudos
10 REPLIES 10
NewManLiving
Visitor

Re: 2D API - roCompositor , Screen Stacking

I use only one compositor and one screen. My approach is modular. The main module downloads to tmp:\
(roUrlTransfer.AsyncGetToFile) all bitmaps needed for the main menu system (If you start out with a grid then this approach will not work). The compositor and screen should be global or passed to additional modules as needed based upon the user's selection from the main menu. The main module (if a simple menu system) should be able to completely unload (remove all sprites and bitmaps, but retain it's event loop suspended (blocked) as the new module is used) and pass control to the newly selected module. The selected module if resource intensive would create a loading screen and retrieve all resources it needs that are not saved to tmp, build its interface and when done, completely release all resources and pass control back to the main module where the main menu interface is quickly reconstructed from tmp. State is kept in member or global variables and restored. I highly recommend an object oriented approach using Associative Arrays to build yourself a framework. Without a decent framework it is hard to manage and you end up with spaghetti code. If you are using sprites it is important to call roSprite.Remove(). They do not remove themselves. You can either remove all sprites or roSprite.SetZ( -1 ) to hide them. Calling compositor.DrawAll(), screen.SwapBuffers() completey clears the screen once sprites are removed or hidden. Looks just like your loading multiple screens, but you are not. Popups or interactive dialogs should be created/destroyed as needed and Z Ordered on top of the module interface. But all interface objects share the same screen and compositor
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
coredump
Visitor

Re: 2D API - roCompositor , Screen Stacking

What about built in screens, such as, the roSearchScreen ?
0 Kudos
NewManLiving
Visitor

Re: 2D API - roCompositor , Screen Stacking

Two separate stacks are maintained so you cannot load a built in screen over an roScreen
Beside the fact that the look and feel would be different. You can switch between the two
Types by getting rid of the roscreen, loading/closing
A built in screen and then create the roscreen again but there is a flash of black between changes
At least from what I have read. There may be some other stacking order you can use don't remember. I would create my own
Your looking at a lot of work. I spent over a year building a component framework
So I can develop applications. Just really began a month ago to take on a project
But I have grids, menus, video/audio/trackbar/trick play/sliders, graphic, text, utility components and more
My biggest hurdle being a texture managed poster grid which is now done
I don't have a keyboard search screen yet although I have seen one a developer on here wrote
Pretty nice. So anything is possible. Once you have a good toolbox you can quickly
Put together a channel. But if your working at it and have to produce something
Then you do not have the luxury of time on your side to create a nice framework
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
coredump
Visitor

Re: 2D API - roCompositor , Screen Stacking

I am trying to "hack in" screen staking into NewManLiving's virtual grid example, just to see if I can get it to work but I am doing something wrong:

Here is the code that pops up a search screen and then return to the original screen


if l_index = m.Channel.kp_OK

m.Channel.Screen = Invalid
m.Channel.Clear()
m.Channel = Invalid

port = CreateObject("roMessagePort")
screen = CreateObject("roSearchScreen")
screen.SetMessagePort(port)
screen.Show()

print "Waiting for a message from the screen..."
' search screen main event loop
done = false
while done = false

msg = wait(0, screen.GetMessagePort())
if type(msg) = "roSearchScreenEvent"
if msg.isScreenClosed()
print "screen closed"
screen.Close()
done = true
else if msg.isCleared()
print "search terms cleared"
history.Clear()
else if msg.isPartialResult()
print "partial search: "; msg.GetMessage()
if not displayHistory
screen.SetSearchTerms((msg.GetMessage()))
endif
else if msg.isFullResult()
print "full search: "; msg.GetMessage()
history.Push(msg.GetMessage())
if displayHistory
screen.AddSearchTerm(msg.GetMessage())
end if
else
print "Unknown event: "; msg.GetType(); " msg: ";sg.GetMessage()
endif
endif
endwhile

m.Channel = NewChannel()
m.Channel.Initialize()
m.Channel.Compositor.SetDrawTo( m.Channel.Screen, m.Channel.ScrBkgClr )

VirtualGridTest()


This crashes at :


Type Mismatch. (runtime error &h18) in pkg:/source/main.brs(1702)
1702: Function GetVCBitmaps(number As Integer, row As String, width As Integer, height As Integer) As Object
Backtrace:
#4 Function getvcbitmaps(number As Integer, row As String, width As Integer, height As Integer) As Object
file/line: pkg:/source/main.brs(1702)
#3 Function virtualgridtest() As Void
file/line: pkg:/source/main.brs(256)
#2 Function virtual_grid_eventloop() As Integer
file/line: pkg:/source/main.brs(1120)
#1 Function virtualgridtest() As Void
file/line: pkg:/source/main.brs(276)
#0 Function main() As Void
file/line: pkg:/source/main.brs(14)
Local Variables:
number Integer val:10
row roString (2.1 was String) refcnt=1 val:"A"
width Invalid
height Invalid
global rotINTERFACE:ifGlobal
m roAssociativeArray refcnt=5 count:1


My guess is that I am not clearing something properly but not sure the correct way to attempt this
0 Kudos
NewManLiving
Visitor

Re: 2D API - roCompositor , Screen Stacking

look at your values for width and height in the function call. What are you sending to the function. The error is type mismatch, the values for width and height
should be integer
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
coredump
Visitor

Re: 2D API - roCompositor , Screen Stacking

Here is where is is called:


test_values.Push( GetVCBitmaps( max_number, chr(65 + i), CellWidth, CellHeight) )


Here are the values:



max_number = 10
nc.CELL_WIDTH = 240
nc.CELL_HEIGHT = 327



Which, seem reasonable since it draws everything correctly when the channel starts. It is just when I hit the 'ok' button to launch the Search screen then dismiss with the <- button that something is wonky
0 Kudos
NewManLiving
Visitor

Re: 2D API - roCompositor , Screen Stacking

max_number = 10
nc.CELL_WIDTH = 240
nc.CELL_HEIGHT = 327

test_values.Push( GetVCBitmaps( max_number, chr(65 + i), CellWidth, CellHeight) )

CellWidth and CellHeight are not nc.CELL_WIDTH and nc.CELL_HEIGHT they are invalid
either
CellWidth = nc.CELL_WIDTH
CellHeight = nc.CELL_HEIGHT

or
test_values.Push( GetVCBitmaps( max_number, chr(65 + i), nc.CELL_WIDTH , nc.CELL_HEIGHT) )
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
NewManLiving
Visitor

Re: 2D API - roCompositor , Screen Stacking

Also your variable i must be defined somewhere as well. When a variable is invalid you have to make sure it is assigned properly. Type mismatches are more often invalid vs valid type rather than different types
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
coredump
Visitor

Re: 2D API - roCompositor , Screen Stacking

Here is where they are assigned to CellWidth and CellHeight, I will go through the code and see if it is getting squashed somewhere else.

Inside VirtualGridTest()

 
CellWidth = m.Channel.CELL_WIDTH
CellHeight = m.Channel.CELL_HEIGHT


inside NewChannel()


nc.CELL_WIDTH = 240
nc.CELL_HEIGHT = 327


and I am calling


m.Channel = NewChannel()
m.Channel.Initialize()
m.Channel.Compositor.SetDrawTo( m.Channel.Screen, m.Channel.ScrBkgClr )

VirtualGridTest()


so that is why I am confused as to why it would be invalid. NewChannel() and Initialize() should assign everything, shouldn't it ?
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.