Skip to content

Commit

Permalink
Retina support via options flag (false by default)
Browse files Browse the repository at this point in the history
Removed build file since putting a gzipped version in the repo seems unecessary
Updated tests to better account for lag when testing (using waitsFor instead of wait)
  • Loading branch information
soulwire committed May 23, 2013
1 parent 0ae74ef commit fb280f5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 19 deletions.
Binary file added .DS_Store
Binary file not shown.
7 changes: 0 additions & 7 deletions build.sh

This file was deleted.

3 changes: 1 addition & 2 deletions examples/particles.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ <h3>Start drawing!</h3>
var pool = [];

var demo = Sketch.create({
container: document.getElementById( 'container' ),
retina: true
container: document.getElementById( 'container' )
});

demo.setup = function() {
Expand Down
Binary file added js/.DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions js/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var Sketch = (function() {
container: doc.body,
interval: 1,
globals: true,
retina: false,
type: CANVAS
};

Expand Down Expand Up @@ -155,6 +156,7 @@ var Sketch = (function() {
var counter = 0;
var touches = [];
var setup = false;
var ratio = win.devicePixelRatio;
var isDiv = context.type == DOM;
var is2D = context.type == CANVAS;

Expand Down Expand Up @@ -254,6 +256,17 @@ var Sketch = (function() {
target.height = context.height + suffix;
target.width = context.width + suffix;

if ( context.retina && is2D && ratio ) {

target.height = context.height * ratio;
target.width = context.width * ratio;

target.style.height = context.height + 'px';
target.style.width = context.width + 'px';

context.scale( ratio, ratio );
}

if ( setup ) trigger( context.resize );
}

Expand Down
2 changes: 1 addition & 1 deletion js/sketch.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 35 additions & 9 deletions tests/spec/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ describe( 'setup and teardown', function() {
updated = true;
};

waits( 100 );
waitsFor(function() {
return setup;
}, 'Setup never fired', 10000 );

runs( function() {
expect( setup ).toBe( true );
Expand All @@ -254,7 +256,9 @@ describe( 'setup and teardown', function() {
expect( setups ).toBe( 1 );
expect( updates ).toBe( 1 );

waits( 100 );
waitsFor(function() {
return updates > 1;
}, 'Update failed', 10000 );

runs( function() {
expect( updates ).toBeGreaterThan( 1 );
Expand All @@ -274,12 +278,18 @@ describe( 'setup and teardown', function() {
update: function() { updated = true; }
});

waits( 100 ), runs( function() {
runs( function() {
expect( setup ).toBe( true );
expect( updated ).toBe( false );
});

runs( sketch.start ), waits( 100 ), runs( function() {
runs( sketch.start );

waitsFor(function() {
return updated;
}, 'Update failed', 10000 );

runs( function() {
expect( updated ).toBe( true );
});
});
Expand All @@ -292,24 +302,40 @@ describe( 'setup and teardown', function() {

sketch = Sketch.create({
update: function() { updates++; }
});
});

waitsFor( function() { return updates > 0; }, 'Update failed', 10000 );

runs( sketch.stop ), waits( 100 ), runs( function() {
runs( sketch.stop );

runs( function() {
expect( updates ).toBe( 1 );
});

runs( sketch.start ), waits( 100 ), runs( function() {
runs( sketch.start );

waitsFor( function() { return updates > 1; }, 'Update failed', 10000 );

runs( function() {
expect( updates ).toBeGreaterThan( 1 );
});

runs( function() {
count = updates;
sketch.toggle();
}), waits( 100 ), runs( function() {
});

waits( 1000 );

runs( function() {
expect( updates ).toBe( count );
});

runs( sketch.toggle ), waits( 100 ), runs( function() {
runs( sketch.toggle );

waitsFor( function() { return updates > count; }, 'Update failed', 10000 );

runs( function() {
expect( updates ).toBeGreaterThan( count );
});
});
Expand Down

0 comments on commit fb280f5

Please sign in to comment.