Skip to content

Commit

Permalink
WIP on hit test bounds updating and culling
Browse files Browse the repository at this point in the history
  • Loading branch information
nadako committed Oct 17, 2019
1 parent 996fc9a commit 2fd0ee7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/openfl/display/Bitmap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Bitmap extends DisplayObject {
}


private override function __getBounds (rect:Rectangle, matrix:Matrix):Void {
private override function __getOwnBounds (rect:Rectangle, matrix:Matrix):Void {

if (__bitmapData != null) {

Expand Down
20 changes: 20 additions & 0 deletions src/openfl/display/DisplayObject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable {
private var __children:Array<DisplayObject>;
private var __filters:Array<BitmapFilter>;
private var __graphics:Graphics;
private var __hitTestBounds:Rectangle;
private var __isMask:Bool;
private var __loaderInfo:LoaderInfo;
private var __mask:DisplayObject;
Expand Down Expand Up @@ -139,6 +140,7 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable {
__scaleX = 1;
__scaleY = 1;

__hitTestBounds = new Rectangle ();
__worldAlpha = 1;
__worldBlendMode = NORMAL;
__worldTransform = new Matrix ();
Expand Down Expand Up @@ -497,6 +499,13 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable {

private function __getBounds (rect:Rectangle, matrix:Matrix):Void {

__getOwnBounds (rect, matrix);

}


private function __getOwnBounds (rect:Rectangle, matrix:Matrix):Void {

if (__graphics != null) {

__graphics.__getBounds (rect, matrix);
Expand All @@ -506,6 +515,14 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable {
}


function __updateHitTestBounds () {

__hitTestBounds.setEmpty ();
__getOwnBounds (__hitTestBounds, __worldTransform);

}


private function __getCursor ():MouseCursor {

return null;
Expand Down Expand Up @@ -657,6 +674,8 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable {

private function __hitTest (x:Float, y:Float, shapeFlag:Bool, stack:Array<DisplayObject>, interactiveOnly:Bool, hitObject:DisplayObject, hitTestWhenMouseDisabled:Bool = false):Bool {

if (!__hitTestBounds.contains(x, y)) return false;

if (__graphics != null) {

if (!hitObject.visible || __isMask) return false;
Expand Down Expand Up @@ -1207,6 +1226,7 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable {

__calculateAbsoluteTransform (local, parent.__worldTransform, __worldTransform);
__calculateAbsoluteTransform (local, parent.__renderTransform, __renderTransform);
__updateHitTestBounds (); // TODO: scrollRect should clip this

} else {

Expand Down
9 changes: 9 additions & 0 deletions src/openfl/display/DisplayObjectContainer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ class DisplayObjectContainer extends InteractiveObject {
private override function __hitTest (x:Float, y:Float, shapeFlag:Bool, stack:Array<DisplayObject>, interactiveOnly:Bool, hitObject:DisplayObject, hitTestWhenMouseDisabled:Bool = false):Bool {

if (!hitObject.visible || __isMask || (!hitTestWhenMouseDisabled && interactiveOnly && !mouseEnabled && !mouseChildren)) return false;
if (!__hitTestBounds.contains(x, y)) return false;
if (mask != null && !mask.__hitTestMask (x, y)) return false;

if (!__isPointInScrollRect (x, y)) {
Expand Down Expand Up @@ -877,9 +878,14 @@ class DisplayObjectContainer extends InteractiveObject {

} else if (__updateTraverse) {

__updateHitTestBounds ();

for (child in __children) {

child.__traverse ();

var childBounds = child.__hitTestBounds;
__hitTestBounds.__expand (childBounds.x, childBounds.y, childBounds.width, childBounds.height);

}

Expand All @@ -904,6 +910,9 @@ class DisplayObjectContainer extends InteractiveObject {
for (child in __children) {

child.__update (transformOnly, true, resetUpdateDirty);

var childBounds = child.__hitTestBounds;
__hitTestBounds.__expand (childBounds.x, childBounds.y, childBounds.width, childBounds.height);

}

Expand Down
1 change: 1 addition & 0 deletions src/openfl/display/Sprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Sprite extends DisplayObjectContainer {
private override function __hitTest (x:Float, y:Float, shapeFlag:Bool, stack:Array<DisplayObject>, interactiveOnly:Bool, hitObject:DisplayObject, hitTestWhenMouseDisabled:Bool = false):Bool {

if (!hitObject.visible || __isMask) return false;
if (!__hitTestBounds.contains(x, y)) return false;

if (interactiveOnly && !mouseEnabled && !mouseChildren) {

Expand Down
2 changes: 1 addition & 1 deletion src/openfl/text/TextField.hx
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ class TextField extends InteractiveObject {
}


private override function __getBounds (rect:Rectangle, matrix:Matrix):Void {
private override function __getOwnBounds (rect:Rectangle, matrix:Matrix):Void {

__updateLayout ();

Expand Down

0 comments on commit 2fd0ee7

Please sign in to comment.