Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions app/scripts/CatLab/Easelbone/EaselJS/DisplayObjects/Background.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ define(
return this.childBounds;
}

if (!this.displayobject.getBounds()) {
var bounds = this.displayobject.getBounds();
if (!bounds) {
return null;
}

return {
width: this.displayobject.getBounds().width,
height: this.displayobject.getBounds().height
width: bounds.width,
height: bounds.height
};
};

Expand Down Expand Up @@ -105,12 +106,15 @@ define(
width = bounds.width;
height = bounds.height
}
} else if (this.getBounds()) {
width = this.getBounds().width;
height = this.getBounds().height;
} else {
width = 100;
height = 100;
bounds = this.getBounds();
if (bounds) {
width = bounds.width;
height = bounds.height;
} else {
width = 100;
height = 100;
}
}

return {width: width, height: height};
Expand Down
46 changes: 23 additions & 23 deletions app/scripts/CatLab/Easelbone/EaselJS/DisplayObjects/BigText.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,19 @@ define(
};

p.getAvailableSpace = function () {
var bounds;

if (this.limits !== null) {
return this.limits;
} else if (this._bounds) {
width = this._bounds.width;
height = this._bounds.height;
} else if (this.parent && this.parent.getBounds()) {
width = this.parent.getBounds().width;
height = this.parent.getBounds().height
} else if (this.getBounds()) {
width = this.getBounds().width;
height = this.getBounds().height;
} else if (this.parent && (bounds = this.parent.getBounds())) {
width = bounds.width;
height = bounds.height;
} else if ((bounds = this.getBounds())) {
width = bounds.width;
height = bounds.height;
} else {
width = 0;
height = 0;
Expand Down Expand Up @@ -266,42 +267,41 @@ define(

/**
* Find the largest font size that fits the available space using binary search.
* Reuses a single measurement text object to avoid creating one per iteration.
* @param textstring
* @param availableWidth
* @param availableHeight
*/
p.goBigOrGoHomeBinary = function (textstring, availableWidth, availableHeight) {
var minFontSize = this.minFontSize;
var maxFontSize = availableHeight;
var bestFit = null;
var bestFontSize = minFontSize;

// Reuse a single text object for measurement instead of creating one per step
var measureObj = this.createTextObject(textstring, minFontSize, this._font, this._color);
measureObj.lineWidth = availableWidth;

var steps = 0;
while (minFontSize <= maxFontSize) {
var midFontSize = Math.floor((minFontSize + maxFontSize) / 2);
var textObj = this.createTextObject(textstring, midFontSize, this._font, this._color);
textObj.lineWidth = availableWidth;
textObj.lineHeight = getFontLineheight(textObj, this._font);
updateCurrentSize(textObj);
measureObj.font = midFontSize + "px " + this._font;
measureObj.lineHeight = getFontLineheight(measureObj, this._font);
updateCurrentSize(measureObj);

if (currentSize.height <= availableHeight && currentSize.width <= availableWidth) {
bestFit = textObj;
bestFontSize = midFontSize;
minFontSize = midFontSize + 1;
} else {
maxFontSize = midFontSize - 1;
}

steps ++;
}

if (!bestFit) {
// Could not find a fit, return smallest possible
bestFit = this.createTextObject(textstring, this.minFontSize, this._font, this._color);
bestFit.lineWidth = availableWidth;
bestFit.lineHeight = getFontLineheight(bestFit, this._font);
updateCurrentSize(bestFit);
}
// Create the final text object at the best size found
var bestFit = this.createTextObject(textstring, bestFontSize, this._font, this._color);
bestFit.lineWidth = availableWidth;
bestFit.lineHeight = getFontLineheight(bestFit, this._font);
updateCurrentSize(bestFit);

this.fontsize = parseInt(bestFit.font.split('px')[0]);
this.fontsize = bestFontSize;
return bestFit;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ define (
};

element._tick = function() {
this.updateZIndex();
// Only check z-index if parent has children (skip orphaned elements)
if (element.parent && element.parent.children) {
this.updateZIndex();
}

return element.original_tick.apply(element, arguments);
};
Expand Down
32 changes: 29 additions & 3 deletions app/scripts/CatLab/Easelbone/Utilities/MovieClipHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ define(
// This is a simple 1-dimensional map: name -> child.
container._mh_named_children_map = {};

// Create a deep map of all descendants by name for O(1) lookups.
// This is a 1-dimensional map: name -> [child, child, ...]
container._mh_deep_named_children_map = {};

// Create a map of timeline labels.
// This is a 2-dimensional map: label -> [child, child, ...]
// A label can have multiple children; grandchildren are included as well
Expand Down Expand Up @@ -127,6 +131,22 @@ define(
}
}

// Build the deep map: add this child under its own name
if (typeof(container._mh_deep_named_children_map[name]) === 'undefined') {
container._mh_deep_named_children_map[name] = [];
}
container._mh_deep_named_children_map[name].push(child);

// Merge child's deep map into container's deep map
for (var dk in child._mh_deep_named_children_map) {
if (child._mh_deep_named_children_map.hasOwnProperty(dk)) {
if (typeof(container._mh_deep_named_children_map[dk]) === 'undefined') {
container._mh_deep_named_children_map[dk] = [];
}
container._mh_deep_named_children_map[dk] = container._mh_deep_named_children_map[dk].concat(child._mh_deep_named_children_map[dk]);
}
}

}.bind(this));

}
Expand All @@ -153,14 +173,20 @@ define(
// Cache a container map for faster lookups.
this.buildNamedChildMap(container);

// Direct child lookup (O(1))
if (typeof(container._mh_named_children_map[name]) !== 'undefined') {
results.push(container._mh_named_children_map[name]);
}

// Deep lookup using pre-built map instead of recursive search
if (results.length === 0 || options.all) {
for (var k in container._mh_named_children_map) {
if (container._mh_named_children_map.hasOwnProperty(k)) {
this.findFromNameInContainer(container._mh_named_children_map[k], name, options, results);
if (container._mh_deep_named_children_map && container._mh_deep_named_children_map[name]) {
var deepResults = container._mh_deep_named_children_map[name];
for (var i = 0; i < deepResults.length; i++) {
// Avoid duplicates from direct child lookup
if (results.indexOf(deepResults[i]) === -1) {
results.push(deepResults[i]);
}
}
}
}
Expand Down
Loading