Created
February 1, 2014 00:02
-
-
Save chris-gc/8745857 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import device; | |
exports.TARGET_WIDTH = 576; | |
// fixed aspect ratio for main content area | |
exports.CONTENT_RATIO = 2 / 3; | |
// maximum aspect ratio for background image | |
exports.BG_RATIO = 9 / 16; | |
// screen attributes | |
exports.ABS_WIDTH = device.screen.width; | |
exports.ABS_HEIGHT = device.screen.height; | |
exports.ABS_RATIO = exports.ABS_WIDTH / exports.ABS_HEIGHT; | |
// --- | |
exports.IS_LANDSCAPE = false; | |
if (exports.IS_LANDSCAPE) { | |
// TODO | |
} else { | |
// top-level scale | |
if (exports.ABS_RATIO > exports.CONTENT_RATIO) { | |
// shrink width, fit height | |
exports.CONTENT_HEIGHT = exports.TARGET_WIDTH / exports.CONTENT_RATIO; | |
exports.CONTENT_WIDTH = exports.CONTENT_HEIGHT * exports.CONTENT_RATIO; | |
exports.SCALE = exports.ABS_HEIGHT / exports.CONTENT_HEIGHT; | |
} else { | |
// shrink height, fit width | |
exports.SCALE = exports.ABS_WIDTH / exports.TARGET_WIDTH; | |
exports.CONTENT_WIDTH = exports.TARGET_WIDTH; | |
exports.CONTENT_HEIGHT = exports.CONTENT_WIDTH / exports.CONTENT_RATIO; | |
} | |
// for full screen views, compute the additional scale factor required to | |
// stretch the view's width to the width of the screen, if necessary | |
exports.FULL_SCREEN_SCALE_RELATIVE = exports.ABS_WIDTH / exports.TARGET_WIDTH / exports.SCALE; | |
// FULL_SCREEN_SCALE_RELATIVE is the scale to be applied on top of SCALE to scale | |
// a full-screen view. FULL_SCREEN_SCALE scales an absolute screen coordinate to the | |
// full screen scale | |
exports.FULL_SCREEN_SCALE = exports.FULL_SCREEN_SCALE_RELATIVE * exports.SCALE; | |
exports.FULL_SCREEN_WIDTH = exports.TARGET_WIDTH; | |
exports.FULL_SCREEN_HEIGHT = exports.ABS_HEIGHT / exports.FULL_SCREEN_SCALE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment