Skip to content

Commit

Permalink
hitTest type functions may return false positives when mouse hasnt moved
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Dec 6, 2023
1 parent 5d4ac18 commit e4113b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
7 changes: 5 additions & 2 deletions haxe/ui/backend/ComponentBase.hx
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,11 @@ class ComponentBase extends ComponentSurface implements IClonable<ComponentBase>
*Note*: `left` and `top` must be stage (screen) co-ords
**/
@:dox(group = "Size related properties and methods")
public function hitTest(left:Float, top:Float, allowZeroSized:Bool = false):Bool { // co-ords must be stage

public function hitTest(left:Null<Float>, top:Null<Float>, allowZeroSized:Bool = false):Bool { // co-ords must be stage
if (left == null || top == null) {
return false;
}

if (hasScreen == false) {
return false;
}
Expand Down
24 changes: 18 additions & 6 deletions haxe/ui/core/Screen.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class Screen extends ScreenImpl {
* A lower value means the mouse is at the left side of the screen,
* whie a higher value means the mouse is at the right side of the screen.
*/
public var currentMouseX:Float = 0;
public var currentMouseX:Null<Float> = null;

/**
* The `y` position of the mouse on screen.
*
* A lower value means the mouse is closer to the top of the screen,
* whie a higher value means the mouse is closer to the bottom of the screen.
*/
public var currentMouseY:Float = 0;
public var currentMouseY:Null<Float> = null;

/**
* Creates a new `Screen`.
Expand Down Expand Up @@ -165,7 +165,10 @@ class Screen extends ScreenImpl {
* @param type Used to filter all components that aren't of a specific type. `null` by default, which means no filter is applied.
* @return An array of all components that overlap the "global" position `(x, y)`
*/
public function findComponentsUnderPoint<T:Component>(screenX:Float, screenY:Float, type:Class<T> = null):Array<Component> {
public function findComponentsUnderPoint<T:Component>(screenX:Null<Float>, screenY:Null<Float>, type:Class<T> = null):Array<Component> {
if (screenX == null || screenY == null) {
return [];
}
var c:Array<Component> = [];
for (r in rootComponents) {
if (r.hitTest(screenX, screenY)) {
Expand All @@ -190,7 +193,10 @@ class Screen extends ScreenImpl {
* @param type Used to filter all components that aren't of a specific type. `null` by default, which means no filter is applied.
* @return `true` if there is a component that overlaps the global position `(x, y)`, `false` otherwise.
*/
public function hasComponentUnderPoint<T:Component>(screenX:Float, screenY:Float, type:Class<T> = null):Bool {
public function hasComponentUnderPoint<T:Component>(screenX:Null<Float>, screenY:Null<Float>, type:Class<T> = null):Bool {
if (screenX == null || screenY == null) {
return false;
}
for (r in rootComponents) {
if (r.hasComponentUnderPoint(screenX, screenY, type) == true) {
return true;
Expand All @@ -210,7 +216,10 @@ class Screen extends ScreenImpl {
* @param type Used to filter all components that aren't of a specific type. `null` by default, which means no filter is applied.
* @return An array of all solid components that overlap the "global" position `(x, y)`
*/
public function findSolidComponentUnderPoint<T:Component>(screenX:Float, screenY:Float, type:Class<T> = null):Array<Component> {
public function findSolidComponentUnderPoint<T:Component>(screenX:Null<Float>, screenY:Null<Float>, type:Class<T> = null):Array<Component> {
if (screenX == null || screenY == null) {
return [];
}
var solidComponents = [];
var components = findComponentsUnderPoint(screenX, screenY, type);
for (c in components) {
Expand All @@ -232,7 +241,10 @@ class Screen extends ScreenImpl {
* @param type Used to filter all components that aren't of a specific type. `null` by default, which means no filter is applied.
* @return `true` if there is a solid component that overlaps the global position `(x, y)`, `false` otherwise.
*/
public function hasSolidComponentUnderPoint<T:Component>(screenX:Float, screenY:Float, type:Class<T> = null):Bool {
public function hasSolidComponentUnderPoint<T:Component>(screenX:Null<Float>, screenY:Null<Float>, type:Class<T> = null):Bool {
if (screenX == null || screenY == null) {
return false;
}
return (findSolidComponentUnderPoint(screenX, screenY, type).length > 0);
}

Expand Down

0 comments on commit e4113b7

Please sign in to comment.