Forum Discussion

coredump's avatar
coredump
Visitor
11 years ago

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 ?

9 Replies

  • 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
  • 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
  • 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
  • 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
  • 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) )
  • 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
  • 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 ?
  • The channel object is responsible for channel-wide globals. It has nothing to do with the grid. The grid and other objects use the channel object for various things but not for their own internal state. See the SimpleGrid example in the continuous button-down thread for a more simpler way to understand how objects work. You can see what variables are invalid in your own code simply by print variable, eg print, i, CellWidth, CellHeight before calling the function. If anyone prints invalid then you have your culprit