Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/gameclosure/timestep-priv
Browse files Browse the repository at this point in the history
…into develop

* 'develop' of https://github.com/gameclosure/timestep-priv:
  added isRunning to engine
  state is also accepted in opts
  arno's gridview padding fix
  instantiate image if typeof img=='string' (fixed slider and more)
  refactor setImage for ui.ImageScaleView
  correctly set device.width, device.screen.width for canvas
  buttonview fix, imageview fix
  • Loading branch information
Martin Hunt committed Feb 13, 2013
2 parents 643e22e + c4a0bd5 commit 16894a2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 46 deletions.
19 changes: 16 additions & 3 deletions src/ui/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,18 @@ var Application = exports = Class(Emitter, function(supr) {

// configure auto-layout in the browser (expand
// to fill the viewport)
if (!canvas && device.name == 'browser') {
var doc = device.get('doc');
if (doc) { doc.setEngine(this); }
if (device.name == 'browser') {
if (canvas) {
device.width = canvas.width;
device.height = canvas.height;
device.screen.width = canvas.width;
device.screen.height = canvas.height;
} else {
var doc = device.get('doc');
if (doc) {
doc.setEngine(this);
}
}
}

this.updateOpts(this._opts);
Expand Down Expand Up @@ -226,6 +235,10 @@ var Application = exports = Class(Emitter, function(supr) {
return this;
};

this.isRunning = function () {
return this._running;
};

this.doOnTick = function(cb) {
if (arguments.length > 1) { cb = bind.apply(this, arguments); }
this._onTick.push(cb);
Expand Down
54 changes: 36 additions & 18 deletions src/ui/ImageScaleView.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,29 +139,47 @@ exports = Class(ui.View, function (supr) {

this.setImage = function(img, opts) {
if (this._isSlice) {
var sw, sh, iw, ih;
var bounds;
if (typeof img == 'string') {
var bounds = GCResources.getMap()[img];
var iw = sw = bounds.w;
var ih = sh = bounds.h;
} else {
var bounds = img.getBounds();
var iw = sw = bounds.width;
var ih = sh = bounds.height;
bounds = GCResources.getMap()[img];
if (bounds) {
iw = sw = bounds.w;
ih = sh = bounds.h;
}
} else if (img instanceof Image && img.isLoaded()) {
bounds = img.getBounds();
iw = sw = bounds.width;
ih = sh = bounds.height;
}

if (!bounds) {
if (typeof img == 'string') {
img = new Image({url: img});
}

return img.doOnLoad(this, 'setImage', img, opts);
}

// scale slices based on image width
var sourceSlicesHor = this._sourceSlicesHor;
var sourceSlicesVer = this._sourceSlicesVer;
var i;

sourceSlicesHor && (sw = 0);
sourceSlicesVer && (sh = 0);
for (i = 0; i < 3; i++) {
sw += sourceSlicesHor ? sourceSlicesHor[i] : 0;
sh += sourceSlicesVer ? sourceSlicesVer[i] : 0;
if (sourceSlicesHor) {
sw = sourceSlicesHor[0] + sourceSlicesHor[1] + sourceSlicesHor[2];
var scale = iw / sw;
sourceSlicesHor[0] *= scale;
sourceSlicesHor[1] *= scale;
sourceSlicesHor[2] *= scale;
}
for (i = 0; i < 3; i++) {
sourceSlicesHor && (sourceSlicesHor[i] = (sourceSlicesHor[i] * iw / sw));
sourceSlicesVer && (sourceSlicesVer[i] = (sourceSlicesVer[i] * ih / sh));

if (sourceSlicesVer) {
sh = sourceSlicesVer[0] + sourceSlicesVer[1] + sourceSlicesVer[2];

var scale = ih / sh;
sourceSlicesVer[0] *= scale;
sourceSlicesVer[1] *= scale;
sourceSlicesVer[2] *= scale;
}
}

Expand Down Expand Up @@ -383,4 +401,4 @@ exports = Class(ui.View, function (supr) {
this.getTag = function() {
return 'ImageScaleView' + this.uid + ':' + (this._img && this._img._map.url.substring(0, 16));
};
});
});
27 changes: 3 additions & 24 deletions src/ui/widget/ButtonView.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var ButtonView = exports = Class(ImageScaleView, function (supr) {
var selected = false;

this.init = function (opts) {
this._state = opts.defaultState || states.UP;
this._state = opts.defaultState || opts.state || states.UP;

supr(this, "init", arguments);

Expand Down Expand Up @@ -122,29 +122,8 @@ var ButtonView = exports = Class(ImageScaleView, function (supr) {
}
};

this.onInputOver = function () {
//no action when disabled
if (this._state === states.DISABLED) {
return;
}

if (this._state !== states.DOWN) {
this._state = states.DOWN;
this._trigger(states.DOWN);
}
};

this.onInputOut = function () {
//no action when disabled
if (this._state === states.DISABLED) {
return;
}

if (this._state !== states.UP) {
this._state = states.UP;
this._trigger(states.UP);
}
};
//no action on these events
this.onInputOver = this.onInputOut = function () {};

//when this function is called from the constructor the dontPublish parameter to prevent publishing events on create...
this._trigger = function (state, dontPublish) {
Expand Down
6 changes: 5 additions & 1 deletion src/ui/widget/GridView.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ exports = GridView = Class(View, function (supr) {
var size = ((totalSize + gutterSize) / count) | 0;

var balance = 0;
var sizeSum = 0;

for (var i = 0; i < count; i++) {
var item = list[i];
if (!item) {
Expand All @@ -71,8 +73,10 @@ exports = GridView = Class(View, function (supr) {
var idealSize = size + balance;
var roundedSize = Math.round(globalScale * size) / globalScale;
balance = idealSize - roundedSize;
item.size = roundedSize;
item.size = size;
sizeSum += size;
}
list[count >> 1].size += (totalSize - sizeSum);

var pos = 0;
var start = 0;
Expand Down

0 comments on commit 16894a2

Please sign in to comment.