Skip to content

Instantly share code, notes, and snippets.

@chris-gc
Created February 1, 2014 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-gc/8745857 to your computer and use it in GitHub Desktop.
Save chris-gc/8745857 to your computer and use it in GitHub Desktop.
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