Skip to content

Commit

Permalink
Canvas Origin Top-Left Settings
Browse files Browse the repository at this point in the history
To enable set chesterGL.settings['canvasOriginTopLeft'] = true;
  • Loading branch information
coolhome committed Feb 21, 2013
1 parent 6d934c0 commit ba2e560
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -16,3 +16,6 @@ iOS/
.svn
closure-library/
*.flags

# remove build script
build.bat
3 changes: 2 additions & 1 deletion chesterGL/block.js
Expand Up @@ -794,6 +794,7 @@ chesterGL.Block.prototype.transform = function () {
this.isTransformDirty = true;
_px = this.position[0];
_py = this.position[1];
if(chesterGL.canvasOriginTopLeft) _py = (chesterGL.gl.viewportHeight / 2) - _py;
goog.vec.Mat4.makeIdentity(this.mvMatrix);
goog.vec.Mat4.translate(this.mvMatrix, _px, _py, this.position[2]);
goog.vec.Mat4.rotate(this.mvMatrix, this.rotation * -1, 0, 0, 1);
Expand Down Expand Up @@ -982,7 +983,7 @@ chesterGL.Block.prototype.render = function () {
gl.globalAlpha = this.color[3];
gl.setTransform(m[0], m[4], m[1], m[5],
m[12] + (0.5 - this.anchorPoint.x) * w,
gl.viewportHeight - (m[13] + (0.5 - this.anchorPoint.y) * h));
(chesterGL.canvasOriginTopLeft ? 0 : -gl.viewportHeight) + (m[13] + (0.5 - this.anchorPoint.y) * h));
if (this.program == chesterGL.Block.PROGRAM.TEXTURE) {
texture = chesterGL.getAsset('texture', this.texture);
var frame = this.frame;
Expand Down
11 changes: 10 additions & 1 deletion chesterGL/core.js
Expand Up @@ -147,6 +147,7 @@ chesterGL.onFakeWebGL = false;
* <li>useGoogleAnalytics: whether or not to track fps and send analytics. Will send every 5 seconds</li>
* <li>projection: "3d" or "2d" (ortho)</li>
* <li>webglMode: true to try for webGL, false to force canvas mode</li>
* <li>canvasOriginTopLeft: If true makes 0,0 the Top-Left corner. If false makes 0,0 the Bottom-Left</li>
* </ul>
* @type {Object.<string,string|boolean>}
* @example
Expand All @@ -160,7 +161,8 @@ chesterGL.settings = {
'projection': '3d',
'webglMode': true,
'usesOffscreenBuffer': false,
'basePath': ''
'basePath': '',
'canvasOriginTopLeft': false
};

/**
Expand Down Expand Up @@ -193,6 +195,12 @@ chesterGL.useGoogleAnalytics = false;
*/
chesterGL.basePath = "";

/**
* @type {boolean}
* @ignore
*/
chesterGL.canvasOriginTopLeft = false;

/**
* This is the WebGL context
*
Expand Down Expand Up @@ -353,6 +361,7 @@ chesterGL.setup = function (canvasId) {
chesterGL.useGoogleAnalytics = /** @type {boolean} */(settings['useGoogleAnalytics']);
chesterGL.usesOffscreenBuffer = /** @type {boolean} */(settings['usesOffscreenBuffer']);
chesterGL.basePath = /** @type {string} */(settings['basePath']);
chesterGL.canvasOriginTopLeft = /** @type {boolean} */(settings['canvasOriginTopLeft']);

chesterGL.initGraphics(canvas);
if (chesterGL.webglMode) {
Expand Down
5 changes: 5 additions & 0 deletions chesterGL/docs.js
@@ -0,0 +1,5 @@
// Strictly for generating documents.
// Place in chesterGL/

/** @namespace */
var chesterGL = {};
109 changes: 109 additions & 0 deletions compile.py
@@ -0,0 +1,109 @@
# compile.py
# - Version: 1.0
# - Replacement for the Makefile. This is cross-platform.
# - Requires Python 2.7+
import sys, argparse, subprocess, urllib2

externs = ['jquery-1.7.js', 'webkit_console.js', 'google_analytics_api.js', 'json.js']
src = ['chesterGL/core.js', 'chesterGL/block.js', 'chesterGL/blockFrames.js', 'chesterGL/blockGroup.js', 'chesterGL/actions.js', 'chesterGL/tmxBlock.js', 'chesterGL/GPUParticleSystem.js', 'chesterGL/primitivesBlock.js', 'chesterGL/labelBlock.js', 'chesterGL/bmFontLabelBlock.js']

parser = argparse.ArgumentParser(description='Compiler for ChesterGL')

group1 = parser.add_argument_group('Compile Options')
group1.add_argument('-mode', action='store', choices=['debug', 'release'], default='release', help='Set the flags for debug or release.')
group1.add_argument('-fetch', '-f', action='store_true', default=True, help='Fetch externs.')
group1.add_argument('-docs', action='store_true', help='Build documents using JSDoc.')
group1.add_argument('-output', '-o', action='store', default='./html', help='Output directory.')


group2 = parser.add_argument_group('Dependency Options')
group2.add_argument('-python', action='store', default='python', help='Location of python executable.')
group2.add_argument('-java', action='store', default='java', help='Location of java.')
group2.add_argument('-jsdoc', action='store', default='/Applications/jsdoc-toolkit', help='Location of JSDoc root directory.')
group2.add_argument('-ccompiler', action='store', default='/Applications/closure-compiler', help='Path to closure compiler folder.')
group2.add_argument('-clib', action='store', default='/Applications/closure-library', help='Path to closure library folder.')
group2.add_argument('-cjar', action='store', default='compiler.jar', help='Filename to closure compiler jar.')

args = parser.parse_args()

externsTmp = ''
for ext in externs:
externsTmp += '--externs ' + args.ccompiler +'/' + ext + ' '
compilerArgs = externsTmp + '--language_in=ECMASCRIPT5_STRICT --warning_level=VERBOSE --jscomp_warning=checkTypes --summary_detail_level=3 '

def dload(file, output):
response = urllib2.urlopen(file)
html = response.read()
o = open(output, 'w+')
o.write(html)
o.close()
return

# Fetch externs?
if args.fetch:
for file in externs:
dload('http://closure-compiler.googlecode.com/svn/trunk/contrib/externs/' + file, args.ccompiler + '/' + file)
print 'Downloaded: ' + file

# Write the flag files for compiling
flags = ''
flagFile = open(args.mode + '.flags', 'w+')
if args.mode == 'release': # Release flags
flags += compilerArgs
flags += '--externs deps.js '
flags += '--compilation_level ADVANCED_OPTIMIZATIONS '
flags += '--create_source_map=' + args.output +'/chester.js.map '
else: # Debug flags
flags += compilerArgs
flags += '--externs deps.js '
flags += '--compilation_level ADVANCED_OPTIMIZATIONS '
flags += '--formatting PRETTY_PRINT '
flags += '-D ENABLE_DEBUG=1 '
flags += '--create_source_map=' + args.output +'/chester.js.map '
flags += '--source_map_format=V3'
flagFile.write(flags)
flagFile.close()

# Compile
compileArgs = args.python + ' '
compileArgs += args.clib + '/closure/bin/build/closurebuilder.py '
compileArgs += '--root ' + args.clib + ' '
compileArgs += '--output_mode=compiled '
compileArgs += '--output_file=' + args.output + '/chester.js '
compileArgs += '--compiler_jar=' + args.ccompiler + '/' + args.cjar + ' '
compileArgs += '--root=chesterGL/ '
if args.mode == 'release':
compileArgs += '--compiler_flags="--flagfile=release.flags" '
else:
compileArgs += '--compiler_flags="--flagfile=debug.flags" '

for file in src:
compileArgs += '-i ' + file + ' '

if subprocess.call(compileArgs, shell=True) != 0:
print '================================'
print 'We had an error during the compile process.'
sys.exit()

# If debug, add source mapping comment to compiled file.
if args.mode == 'debug':
jsFile = open(args.output + '/chester.js', 'a+')
jsFile.write('//@ sourceMappingURL=chester.js.map');
jsFile.close()

# Generate doc?
if args.docs:
docs = args.java + ' '
docs += '-jar ' + args.jsdoc + '/jsrun.jar ' + args.jsdoc + '/app/run.js -w -version 170 -v -a '
docs += '-t=' + args.jsdoc + '/templates/jsdoc '
src.insert(0, 'chesterGL/docs.js')
for file in src:
docs += file + ' '
docs += '-d=' + args.output + '/docs'
if subprocess.call(docs, shell=True) != 0:
print '================================'
print 'We had an error during the compile process.'
sys.exit()

print '================================'
print 'Completed.'

0 comments on commit ba2e560

Please sign in to comment.