"NewManLiving" wrote:
Did not have time to clean it up . Have to go to work but this is essentially what I am talking about. Copy and paste into a new project brs an run it
it should work . It works for me. using roku 3 hi def lastest everything if you have a problem just let me know. should work if I copy/pasted correctly
did not have time to show how only one rescreen is needed for an entire application
Function Main() As Void
ne = NewExample()
ne.Initialize()
ne.Show()
ne.Clear()
ne = Invalid
End Function
' Create an example object
Function NewExample() As Object
ne = CreateObject("roAssociativeArray")
' Takes an optional roScreen - This way you can create
' an entire application my swapping out compositors
ne.Screen = Invalid
ne.Device = Invalid
ne.VP = Invalid
ne.Timer = Invalid
ne.Port = Invalid
ne.Compositor = Invalid
' Registry and fonts declarations
ne.DefaultRegistry = Invalid
ne.FontMedium = Invalid
' Bitmaps to be used in our example
ne.VideoBitmap = Invalid
ne.BehindBitmap = Invalid
ne.BehindRegion = Invalid
ne.BehindSprite = Invalid
ne.FrontBitmap = Invalid
ne.FrontSprite = Invalid
ne.FrontRegion = Invalid
' Sprite Z order or layers
ne.LOWEST_Z = 0
ne.VIDEOPLAYER_Z = 3
ne.BEHIND_Z = 2
ne.FRONT_Z = 4
' Our colors - you may see some roInt leak messages
' upon exit in the debugger
' I believe it has to do with wrapping or boxing
' of these hex values. I was told it is not a memory leak ????
ne.Transparent = &h00000000
ne.ScrBkgClr = &hE0DFDFFF
ne.OrangeClr = &hAD4F0FFF
ne.GreenClr = &h324D1FFF
ne.TextClr = &h000000FF
ne.Initialize = example_initialize
ne.Show = example_show
ne.EventLoop = example_eventloop
ne.Draw = example_draw
ne.DrawAll = example_drawall
return ne
End Function
Function example_initialize() As Void
' Create all objects to be used
m.Device = CreateObject("roDeviceInfo")
m.VP = CreateObject("roVideoPlayer")
m.Timer = CreateObject("roTimeSpan")
m.Port = CreateObject("roMessagePort")
m.Compositor = CreateObject("roCompositor")
' Create a default registry and get our font
m.DefaultRegistry = CreateObject("roFontRegistry")
m.FontMedium = m.DefaultRegistry.GetDefaultFont(28, False, False)
' Calculate size and position of the video player
l_device_rect = m.Device.GetDisplaySize()
l_vp_width = 350
l_vp_height = 250
l_vp_x = int(l_device_rect.w / 2 - l_vp_width / 2)
l_vp_y = int(l_device_rect.h / 2 - l_vp_height / 2)
l_vp_rect = {x: l_vp_x, y: l_vp_y, w: l_vp_width, h: l_vp_height}
' set the video players destination rectangle
m.VP.SetDestinationRect(l_vp_rect)
' Create the video players transparent view.
m.VideoBitmap = CreateObject("roBitmap", {width: l_vp_width, height: l_vp_height, AlphaEnable: True})
' Clear to transparent so we can see the videoplayer
m.VideoBitmap.Clear(m.Transparent)
' Create the region into the video players bitmap that we want to see. Of course this would
' be the entire videoplayer. But you can do some intresting things with regions - slides, special effects etc
l_region = CreateObject("roRegion", m.VideoBitmap, 0, 0 , l_vp_width, l_vp_height)
' Create the videoplayer sprite at x,y coordinates. You can save the handle if you want to move it later
' Place it at the predefined z order (layer) and directly over the videoplayer itself
' this now becomes the video players layer in the sprite
m.Compositor.NewSprite(l_vp_x, l_vp_y, l_region, m.VIDEOPLAYER_Z)
' Create the behind video player text box bitmap
l_text_box_margin = 25
l_text_box_w = 500 + l_text_box_margin
l_text_box_h = 100
m.BehindBitmap = CreateObject("roBitmap", {width: l_text_box_w, height: l_text_box_h, AlphaEnable: false})
' Draw some text centered within the behind text box
l_text = "This Layer Is Behind The Video Player"
l_text_w = m.FontMedium.GetOneLineWidth(l_text, l_text_box_w)
l_text_h = m.FontMedium.GetOneLineHeight()
l_x = 0
l_y = int(l_text_box_h / 2 - l_text_h / 2 )
m.BehindBitmap.Clear(m.GreenClr)
m.BehindBitmap.DrawText(l_text, l_x, l_y, m.TextClr, m.FontMedium)
' Now put it in a layer behind the video player. Since we will be scrolling the text
' we need to save the handle to the region. We dont need the handle to the sprite
' unles we want to move the text box x, y pos. A region is a view into the bitmap
' once again we want to see the entire area of the bitmap. But we want to scroll the
' region
l_w = m.BehindBitmap.GetWidth()
l_h = m.BehindBitmap.GetHeight()
m.BehindRegion = CreateObject("roRegion", m.BehindBitmap, 0, 0 ,l_w, l_h)
m.BehindRegion.SetWrap(True) ' Wrap around scrolling
' lets put this text a little above the top left of the video player, but behind it
m.Compositor.NewSprite(l_vp_rect.x - 225, l_vp_rect.y - 25, m.BehindRegion, m.BEHIND_Z)
' Create the front video player text box bitmap
l_text_box_margin = 25
l_text_box_w = 550 + l_text_box_margin
l_text_box_h = 100
m.FrontBitmap = CreateObject("roBitmap", {width: l_text_box_w, height: l_text_box_h, AlphaEnable: false})
' Draw some text centered within the front text box
l_text = "This Layer Is In Front Of The Video Player"
l_text_w = m.FontMedium.GetOneLineWidth(l_text, l_text_box_w)
l_text_h = m.FontMedium.GetOneLineHeight()
l_x = 0
l_y = int(l_text_box_h / 2 - l_text_h / 2 )
m.FrontBitmap.Clear(m.OrangeClr)
m.FrontBitmap.DrawText(l_text, l_x, l_y, m.TextClr, m.FontMedium)
' Put this text box in front of the video player
l_w = m.FrontBitmap.GetWidth()
l_h = m.FrontBitmap.GetHeight()
m.FrontRegion = CreateObject("roRegion", m.FrontBitmap, 0, 0 ,l_w, l_h)
m.FrontRegion.SetWrap(True)
' lets put this text a little above the top left of the video player, but behind it
m.Compositor.NewSprite(l_vp_rect.x + 125, l_vp_rect.y + l_vp_rect.h - 100, m.FrontRegion, m.FRONT_Z)
return
End Function
Function example_show() As Void
' Set up video player stuff port, position notification etc
' Create the screen. You can use one roScreen . A composite is
' similar to a window once setdrawto is called. Just create
' compositors and swap them in/out of one instance of roScreen
' THis example does not do this
m.Screen = CreateObject("roScreen", True)
m.Screen.SetMessagePort(m.Port)
'm.Screen.SetAlphaEnable(True)
m.Compositor.SetDrawTo(m.Screen, m.ScrBkgClr)
m.DrawAll()
m.EventLoop()
End Function
Function example_drawall() As Void
m.Compositor.DrawAll()
m.Screen.SwapBuffers()
End Function
Function example_draw() As Void
m.Compositor.Draw()
m.Screen.SwapBuffers()
End Function
Function example_eventloop() As Void
l_msg = ""
l_running = true
l_index = 0
l_kp_BK = 0
while(l_running)
l_msg = wait(100, m.port)
if m.Timer.TotalMilliseconds() >= 100
m.FrontRegion.Offset(20, 0, 0, 0)
m.BehindRegion.Offset(20, 0, 0, 0)
m.DrawAll()
m.Timer.Mark()
end if
if type(l_msg) = "roUniversalControlEvent"
l_index = l_msg.GetInt()
if l_index = l_kp_BK then l_running = False
else if type(l_msg) = "roVideoPlayerEvent"
' To DO
end if
end while
End Function
Thanks NewManLiving! I will try your code and then reply again...