Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hittest bounds #154

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/openfl/display/Bitmap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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 @@ -138,6 +139,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 @@ -489,6 +491,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 @@ -498,6 +507,14 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable {
}


function __updateHitTestBounds () {

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

}


private function __getCursor ():MouseCursor {

return null;
Expand Down Expand Up @@ -643,6 +660,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 @@ -1194,6 +1213,7 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable {

__calculateAbsoluteTransform (__transform, parent.__worldTransform, __worldTransform);
__calculateAbsoluteTransform (__transform, 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 @@ -504,6 +504,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 @@ -866,9 +867,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 @@ -894,6 +900,9 @@ class DisplayObjectContainer extends InteractiveObject {

child.__update (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 @@ -977,7 +977,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