Skip to content

Commit

Permalink
Expose pixelRatio in size event
Browse files Browse the repository at this point in the history
  • Loading branch information
unconed committed Feb 26, 2015
1 parent 05237ef commit 165c890
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 12 deletions.
14 changes: 11 additions & 3 deletions build/threestrap-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ THREE.Bootstrap.registerPlugin('renderer', {
stencil: true,
preserveDrawingBuffer: true,
antialias: true,
devicePixelRatio: true,
pixelRatio: true,
},
},

Expand Down Expand Up @@ -513,7 +513,7 @@ THREE.Bootstrap.registerPlugin('renderer', {

// Apply pixel ratio
if (renderer.setPixelRatio) {
var ratio = this.options.devicePixelRatio ? window.devicePixelRatio : 1;
var ratio = this.options.pixelRatio ? event.pixelRatio : 1;
renderer.setPixelRatio(ratio);
}

Expand Down Expand Up @@ -619,7 +619,7 @@ THREE.Bootstrap.registerPlugin('size', {
var element = three.element;
var renderer = three.renderer;

var w, h, ew, eh, rw, rh, aspect, cut, style,
var w, h, ew, eh, rw, rh, aspect, cut, style, ratio,
ml = 0 , mt = 0;

// Measure element
Expand Down Expand Up @@ -665,13 +665,20 @@ THREE.Bootstrap.registerPlugin('size', {
style.marginLeft = ml + "px";
style.marginTop = mt + "px";

// Measure device pixel ratio
ratio = 1
if (typeof window != 'undefined') {
ratio = window.devicePixelRatio || 1
}

// Notify
_.extend(three.Size, {
renderWidth: rw,
renderHeight: rh,
viewWidth: w,
viewHeight: h,
aspect: aspect,
pixelRatio: ratio,
});

three.trigger({
Expand All @@ -681,6 +688,7 @@ THREE.Bootstrap.registerPlugin('size', {
viewWidth: w,
viewHeight: h,
aspect: aspect,
pixelRatio: ratio,
});
},

Expand Down
2 changes: 1 addition & 1 deletion build/threestrap-core.min.js

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions build/threestrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -7270,7 +7270,7 @@ THREE.Bootstrap.registerPlugin('renderer', {
stencil: true,
preserveDrawingBuffer: true,
antialias: true,
devicePixelRatio: true,
pixelRatio: true,
},
},

Expand Down Expand Up @@ -7299,7 +7299,7 @@ THREE.Bootstrap.registerPlugin('renderer', {

// Apply pixel ratio
if (renderer.setPixelRatio) {
var ratio = this.options.devicePixelRatio ? window.devicePixelRatio : 1;
var ratio = this.options.pixelRatio ? event.pixelRatio : 1;
renderer.setPixelRatio(ratio);
}

Expand Down Expand Up @@ -7405,7 +7405,7 @@ THREE.Bootstrap.registerPlugin('size', {
var element = three.element;
var renderer = three.renderer;

var w, h, ew, eh, rw, rh, aspect, cut, style,
var w, h, ew, eh, rw, rh, aspect, cut, style, ratio,
ml = 0 , mt = 0;

// Measure element
Expand Down Expand Up @@ -7451,13 +7451,20 @@ THREE.Bootstrap.registerPlugin('size', {
style.marginLeft = ml + "px";
style.marginTop = mt + "px";

// Measure device pixel ratio
ratio = 1
if (typeof window != 'undefined') {
ratio = window.devicePixelRatio || 1
}

// Notify
_.extend(three.Size, {
renderWidth: rw,
renderHeight: rh,
viewWidth: w,
viewHeight: h,
aspect: aspect,
pixelRatio: ratio,
});

three.trigger({
Expand All @@ -7467,6 +7474,7 @@ THREE.Bootstrap.registerPlugin('size', {
viewWidth: w,
viewHeight: h,
aspect: aspect,
pixelRatio: ratio,
});
},

Expand Down
4 changes: 2 additions & 2 deletions build/threestrap.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/core/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ THREE.Bootstrap.registerPlugin('renderer', {
stencil: true,
preserveDrawingBuffer: true,
antialias: true,
devicePixelRatio: true,
pixelRatio: true,
},
},

Expand Down Expand Up @@ -36,7 +36,7 @@ THREE.Bootstrap.registerPlugin('renderer', {

// Apply pixel ratio
if (renderer.setPixelRatio) {
var ratio = this.options.devicePixelRatio ? window.devicePixelRatio : 1;
var ratio = this.options.pixelRatio ? event.pixelRatio : 1;
renderer.setPixelRatio(ratio);
}

Expand Down
10 changes: 9 additions & 1 deletion src/core/size.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ THREE.Bootstrap.registerPlugin('size', {
var element = three.element;
var renderer = three.renderer;

var w, h, ew, eh, rw, rh, aspect, cut, style,
var w, h, ew, eh, rw, rh, aspect, cut, style, ratio,
ml = 0 , mt = 0;

// Measure element
Expand Down Expand Up @@ -94,13 +94,20 @@ THREE.Bootstrap.registerPlugin('size', {
style.marginLeft = ml + "px";
style.marginTop = mt + "px";

// Measure device pixel ratio
ratio = 1
if (typeof window != 'undefined') {
ratio = window.devicePixelRatio || 1
}

// Notify
_.extend(three.Size, {
renderWidth: rw,
renderHeight: rh,
viewWidth: w,
viewHeight: h,
aspect: aspect,
pixelRatio: ratio,
});

three.trigger({
Expand All @@ -110,6 +117,7 @@ THREE.Bootstrap.registerPlugin('size', {
viewWidth: w,
viewHeight: h,
aspect: aspect,
pixelRatio: ratio,
});
},

Expand Down
2 changes: 2 additions & 0 deletions test/core/size.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ describe("size", function () {

var h;
three.on('resize', h = function (event) {
expect(event.pixelRatio).toBeGreaterThan(0);

expect(event.viewWidth).toBe(options.size.width);
expect(event.viewHeight).toBe(options.size.height);

Expand Down

0 comments on commit 165c890

Please sign in to comment.