Advertisement
Rakoonic

Code to put borders over letterbox stretched display

Jun 12th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. --------------------------------------------------------------
  2. -- LETTERBOXBORDER -------------------------------------------
  3.  
  4. -- Blocks out the original screen resolution for devices with a different aspect ratio.
  5. -- Note it is designed to work for apps with scale mode of "letterbox".
  6. -- As a result it is impossible that both the screenOriginX and screenOriginY ~= 0, only 1 can be
  7. -- This should always be the last thing called if used, so that it goes on top of anything else,
  8. --   although if borders are created, it returns a display group containing the bars, so you can use
  9. --   this later with :toFront() should it be needed.
  10. function letterboxBorder(params)
  11.  
  12.     -- Missed parameters
  13.     if not params.r then params.r = 0; end
  14.     if not params.g then params.g = 0; end
  15.     if not params.b then params.b = 0; end
  16.    
  17.     -- Use display resolution information to block out areas if needed - makes the letter box thing nicer
  18.     -- Should probably use images in the future...
  19.     if display.screenOriginX ~= 0 then
  20.         local group = display.newGroup()
  21.        
  22.         local leftBar = display.newRect(0, 0, -display.screenOriginX, display.contentHeight)
  23.         leftBar:setFillColor(params.r, params.g, params.b)
  24.         leftBar.x     = display.screenOriginX * 0.5
  25.         group:insert(leftBar)
  26.        
  27.         local rightBar = display.newRect(0, 0, -display.screenOriginX, display.contentHeight)
  28.         rightBar:setFillColor(params.r, params.g, params.b)
  29.         rightBar.x     = display.contentWidth - display.screenOriginX * 0.5
  30.         group:insert(rightBar)
  31.  
  32.         return group
  33.        
  34.     elseif displayscreenOriginY ~= 0 then
  35.         local group = display.newGroup()
  36.        
  37.         local topBar = display.newRect(0, 0, display.contentWidth, -display.screenOriginY)
  38.         topBar:setFillColor(params.r, params.g, params.b)
  39.         topBar.y     = display.screenOriginY * 0.5
  40.         group:insert(topBar)
  41.  
  42.         local bottomBar = display.newRect(0, 0, display.contentWidth, -display.screenOriginY)
  43.         bottomBar:setFillColor(params.r, params.g, params.b)
  44.         bottomBar.y     = display.contentHeight - display.screenOriginY * 0.5
  45.         group:insert(bottomBar)
  46.  
  47.         return group
  48.     end
  49.  
  50.     -- Desired screen resolution fills the device's screen
  51.     return false
  52.    
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement