Skip to content

Commit 37d9bb3

Browse files
committed
Finalized the hit rework.
1 parent 1358733 commit 37d9bb3

File tree

3 files changed

+30
-24
lines changed

3 files changed

+30
-24
lines changed

CHANGES

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
- Fixed `RadialGroup` containing other `PieMenu`.
1111
- Fixed non-regular width and height values on Animated widgets.
1212
- Fixed `centerOnActor` method used on an Actor that was contained within a `Group`.
13-
todo: should PieWidget `hit` return `this` when hitting a background ? (define "isBackgroundHit()" method for custom approach without duplicating `hit`)
1413

1514
[3.1.0]
1615
- Fixed the "floating" `Group` that contained `RadialGroup`.

src/main/java/com/payne/games/piemenu/PieWidget.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,13 @@ protected int estimateSidesRequired(float radiusX, float radiusY) {
358358
return true;
359359
}
360360

361+
@Override
362+
public boolean isBackgroundHit(float x, float y) {
363+
if(style.background == null && style.backgroundColor == null)
364+
return false;
365+
return isWithinInnerRadius(x - getWidth()/2, y - getHeight()/2);
366+
}
367+
361368
@Override
362369
public void draw(Batch batch, float parentAlpha) {
363370
drawWithShapeDrawer(batch, parentAlpha, totalDegreesDrawn);
@@ -407,7 +414,6 @@ protected void drawWithShapeDrawer(Batch batch, float parentAlpha, float degrees
407414
float restoreAlpha = bc.a;
408415
batch.setColor(bc.r, bc.g, bc.b, bc.a * globalAlphaMultiplier);
409416
if(style.background instanceof TransformDrawable) {
410-
// todo: can "getX()" screw up because relative to parent? (TO TEST)
411417
((TransformDrawable)(style.background)).draw(batch,
412418
getX(Align.center) - getCurrentRadius(),
413419
getY(Align.center) - getCurrentRadius(),
@@ -416,7 +422,6 @@ protected void drawWithShapeDrawer(Batch batch, float parentAlpha, float degrees
416422
getScaleX(), getScaleY(),
417423
getRotation());
418424
} else {
419-
// todo: can "getX()" screw up because relative to parent? (TO TEST)
420425
style.background.draw(batch,
421426
getX(Align.center) - getCurrentRadius(),
422427
getY(Align.center) - getCurrentRadius(),

src/main/java/com/payne/games/piemenu/RadialGroup.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ protected void updateOrigin() {
341341
}
342342

343343
/**
344-
* @param x x-coordinate relative to the origin (bottom left) of the widget
345-
* @param y y-coordinate relative to the origin (bottom left) of the widget
344+
* @param x x-coordinate relative to the bottom-left of the widget.
345+
* @param y y-coordinate relative to the bottom-left of the widget.
346346
* @param touchable if {@code true}, hit detection will respect the
347347
* {@link #setTouchable(Touchable) touchability}.
348348
* @return deepest child's hit at (x,y). Else, the widget itself if it's
@@ -359,34 +359,36 @@ public Actor hit(float x, float y, boolean touchable) {
359359
continue;
360360
child.parentToLocalCoordinates(vector2.set(x,y));
361361
Actor hit = child.hit(vector2.x, vector2.y, touchable);
362-
if(hit != null) {
363-
// System.out.println("hit");
362+
if(hit != null)
364363
return hit;
365-
}
366364
}
367365

368366
/* Then we want to consider the widget's boundaries itself. */
369367
localToStageCoordinates(vector2.set(x,y));
370368
int childIndex = findChildIndexAtStage(vector2.x,vector2.y);
371-
if(isValidIndex(childIndex)) {
372-
// System.out.println("this valid");
369+
if(isValidIndex(childIndex))
373370
return this;
374-
}
375371

376-
// // todo: shouldn't return `null` if hitting background
377-
// if(isBackgroundHit(x,y)) {
378-
// System.out.println("this background");
379-
// return this;
380-
// }
372+
/* And ultimately whether some background element is hit. */
373+
if(isBackgroundHit(x,y))
374+
return this;
381375

382-
// System.out.println("null");
383376
return null;
384377
}
385378

386-
// public boolean isBackgroundHit(float x, float y) {
387-
// stageToLocalCoordinates(vector2.set(x,y));
388-
// return isWithinInnerRadius(vector2.x - getWidth()/2, vector2.y - getHeight()/2);
389-
// }
379+
/**
380+
* Determines whether or not the background is being hit.
381+
*
382+
* @see #hit(float, float, boolean)
383+
* @param x x-coordinate relative to the bottom-left of the widget.
384+
* @param y y-coordinate relative to the bottom-left of the widget.
385+
* @return {@code true} only if some background element of the widget
386+
* is being hit. (For example, if there are no background
387+
* image or color, then this always returns {@code false}.)
388+
*/
389+
public boolean isBackgroundHit(float x, float y) {
390+
return false;
391+
}
390392

391393
/**
392394
* Given a coordinate, find the index of the child (if any).
@@ -447,7 +449,7 @@ public float angleAtStage(float x, float y) {
447449
* @return The total rotation value.
448450
*/
449451
protected float getTotalRotation() {
450-
float rotation = super.getRotation();
452+
float rotation = getRotation();
451453
Group parent = getParent();
452454
if(parent == null)
453455
return rotation;
@@ -479,8 +481,8 @@ public boolean isValidIndex(int index) {
479481
/**
480482
* Checks whether or not the input coordinate is in between (inclusively)
481483
* the inner-radius and the current radius of the widget (which can
482-
* be bigger than {@link #preferredRadius} if you use {@link #setFillParent(boolean)},
483-
* for example).
484+
* be bigger than {@link #preferredRadius} if you use
485+
* {@link #setFillParent(boolean)}, for example).
484486
*
485487
* @param x x-coordinate relative to the center of the widget.
486488
* @param y y-coordinate relative to the center of the widget.

0 commit comments

Comments
 (0)