Skip to content

Commit aa384c3

Browse files
committed
Merge branch 'dev'
2 parents 7d262e0 + 4ecf5f6 commit aa384c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2411
-1230
lines changed

CHANGES

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
[4.2.0]
2+
- Fixed a bug related to the `globalAlphaMultiplier` attribute.
3+
- Fixed a bug related to `centerOn` methods and some Viewports.
4+
- Performance improvement: Events (Callbacks/Highlight/Selection/etc.) are now Pooled.
5+
- Added a default Color (black) for the following `PieWidgetStyle` attributes: `separatorColor` and `circumferenceColor`.
6+
- Added a Testing Menu so that Contributors can more easily test their implementations.
7+
- Added the `NO_SELECTION` constant in `PieMenu`.
8+
- Added a new "code example": `NestedClickDrag`.
9+
- Minor JavaDoc tweaks and improvements.
10+
- Updated `ShapeDrawer` version to `v2.3.0`.
11+
112
[4.1.0]
2-
- Added `AnimatedRadialGroup`
3-
- Minor fixes in documentation
13+
- Added `AnimatedRadialGroup`.
14+
- Minor fixes in documentation.
415
- Updated `ShapeDrawer` version to `v2.1.0`.
516

617
[4.0.0]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ allprojects {
6363
6464
ext {
6565
...
66-
pieMenuVersion = '4.1.0' // add this line
66+
pieMenuVersion = '4.2.0' // add this line
6767
}
6868
6969
repositories {
7070
...
71-
maven { url 'https://jitpack.io' }
71+
maven { url 'https://jitpack.io' } // add this line if it isn't there
7272
}
7373
}
7474
```

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ apply from: 'publish.gradle'
1919
sourceCompatibility = 1.8
2020

2121
def projectName = 'pie-menu'
22-
version '4.1.0'
22+
version '4.2.0'
2323
group 'com.payne.games'
2424

2525
def gdxVersion = '1.9.10'
26-
def shapedrawerVersion = '2.1.0'
26+
def shapedrawerVersion = '2.3.0'
2727

2828
// Disable JDK 8's doclint
2929
// http://blog.joda.org/2014/02/turning-off-doclint-in-jdk-8-javadoc.html

media/nested_menu.gif

274 KB
Loading

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

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.badlogic.gdx.scenes.scene2d.Touchable;
1313
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
1414
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
15+
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent;
1516
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
1617
import com.badlogic.gdx.utils.Pools;
1718

@@ -32,27 +33,32 @@ public class PieMenu extends PieWidget {
3233
*/
3334
private InputListener pieMenuListener;
3435

36+
/**
37+
* Used to denote a non-selected index, or canceled selection, for example.
38+
*/
39+
public static final int NO_SELECTION = -1;
40+
3541
/**
3642
* The index that is used as a fallback value whenever a processed
3743
* user-input does not map to a valid child index value.<br>
3844
* This value can be negative, if you want nothing to be the default.
3945
*/
40-
private int defaultIndex = -1;
46+
private int defaultIndex = NO_SELECTION;
4147

4248
/**
4349
* Index of the currently selected item.
4450
*/
45-
private int selectedIndex = defaultIndex;
51+
private int selectedIndex = NO_SELECTION;
4652

4753
/**
4854
* Index of the currently highlighted item.
4955
*/
50-
private int highlightedIndex = defaultIndex;
56+
private int highlightedIndex = NO_SELECTION;
5157

5258
/**
5359
* Index of the currently highlighted item.
5460
*/
55-
private int hoveredIndex = -1;
61+
private int hoveredIndex = NO_SELECTION;
5662

5763
/**
5864
* Determines whether or not selection should only happen if the mouse is
@@ -62,12 +68,13 @@ public class PieMenu extends PieWidget {
6268

6369

6470
/**
65-
* Determines whether or not releasing a click within the inner-radius
66-
* should cancel the selection.<br>
67-
* If {@code true}, a click released in the middle will trigger a selection
68-
* of the {@link #defaultIndex}.<br>
69-
* Only applies for the case where you have activated the
70-
* {@link #infiniteSelectionRange} flag.
71+
* Determines whether or not releasing a click within the {@link #innerRadiusPercent
72+
* inner-radius} should "cancel" the selection.
73+
* If {@code true}, a click released in the middle will trigger a selection of the
74+
* {@link #defaultIndex}.<br>
75+
* As a corollary, this means that the {@link ChangeListener#changed(ChangeEvent, Actor)}
76+
* will still be called, no matter the value given to this variable.<br>
77+
* Only applies for the case where you have activated the {@link #infiniteSelectionRange} flag.
7178
*/
7279
private boolean middleCancel = false;
7380

@@ -369,7 +376,7 @@ public void resetSelection() {
369376
* (if you had set it up).
370377
*/
371378
public void resetHover() {
372-
hoveredIndex = -1;
379+
hoveredIndex = NO_SELECTION;
373380
}
374381

375382
@Override
@@ -550,7 +557,7 @@ public PieMenuStyle() {
550557
*
551558
* @param style a Style to copy the parameters from.
552559
*/
553-
public PieMenuStyle(PieMenu.PieMenuStyle style) {
560+
public PieMenuStyle(PieMenuStyle style) {
554561
super(style);
555562
this.selectedColor = new Color(style.selectedColor);
556563
this.downColor = new Color(style.downColor);
@@ -589,8 +596,12 @@ public void selectIndex(int newIndex) {
589596

590597
selectedIndex = newIndex;
591598
highlightedIndex = newIndex;
592-
if (newIndex != oldHighlightedIndex)
593-
fire(new PieMenuHighlightChangeEvent(newIndex));
599+
if (newIndex != oldHighlightedIndex) {
600+
PieMenuHighlightChangeEvent highlightChangeEvent = Pools.obtain(PieMenuHighlightChangeEvent.class);
601+
highlightChangeEvent.newIndex = newIndex;
602+
fire(highlightChangeEvent);
603+
Pools.free(highlightChangeEvent);
604+
}
594605

595606
ChangeListener.ChangeEvent changeEvent = Pools.obtain(ChangeListener.ChangeEvent.class);
596607
if (fire(changeEvent)) {
@@ -630,7 +641,10 @@ public void highlightIndex(int newIndex) {
630641
if(newIndex != highlightedIndex) {
631642
highlightedIndex = newIndex;
632643
resetHover();
633-
fire(new PieMenuHighlightChangeEvent(newIndex));
644+
PieMenuHighlightChangeEvent highlightChangeEvent = Pools.obtain(PieMenuHighlightChangeEvent.class);
645+
highlightChangeEvent.newIndex = newIndex;
646+
fire(highlightChangeEvent);
647+
Pools.free(highlightChangeEvent);
634648
}
635649
}
636650

@@ -665,7 +679,10 @@ public void hoverIndex(int newIndex) {
665679
newIndex = mapIndex(newIndex);
666680
if(newIndex != hoveredIndex) {
667681
hoveredIndex = newIndex;
668-
fire(new PieMenuHoverChangeEvent(newIndex));
682+
PieMenuHoverChangeEvent hoverChangeEvent = Pools.obtain(PieMenuHoverChangeEvent.class);
683+
hoverChangeEvent.newIndex = newIndex;
684+
fire(hoverChangeEvent);
685+
Pools.free(hoverChangeEvent);
669686
}
670687
}
671688

@@ -780,7 +797,7 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
780797

781798
/* Reset the hover only when the mouse exits the PieMenu. */
782799
if(toActor != pieMenu && (toActor == null || !(toActor.isDescendantOf(pieMenu))))
783-
pieMenu.hoverIndex(-1);
800+
pieMenu.hoverIndex(NO_SELECTION);
784801
super.exit(event, x, y, pointer, toActor);
785802
}
786803
}
@@ -789,16 +806,20 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
789806
private static class PieMenuHighlightChangeEvent extends Event {
790807
private int newIndex;
791808

792-
public PieMenuHighlightChangeEvent(int newIndex) {
793-
this.newIndex = newIndex;
809+
@Override
810+
public void reset() {
811+
super.reset();
812+
newIndex = NO_SELECTION;
794813
}
795814
}
796815

797816
private static class PieMenuHoverChangeEvent extends Event {
798817
private int newIndex;
799818

800-
public PieMenuHoverChangeEvent(int newIndex) {
801-
this.newIndex = newIndex;
819+
@Override
820+
public void reset() {
821+
super.reset();
822+
newIndex = NO_SELECTION;
802823
}
803824
}
804825

@@ -920,20 +941,26 @@ public void setInfiniteSelectionRange(boolean infiniteSelectionRange) {
920941
}
921942

922943
/**
923-
* Determines whether or not releasing a click within the inner-radius
924-
* should cancel the selection.
925-
* If {@code true} a release in the middle, even if {@link #infiniteSelectionRange}
926-
* is set to {@code true}, will trigger a selection of the {@link #defaultIndex}.
944+
* Determines whether or not releasing a click within the {@link #innerRadiusPercent
945+
* inner-radius} should "cancel" the selection.
946+
* If {@code true}, a click released in the middle will trigger a selection of the
947+
* {@link #defaultIndex}.<br>
948+
* As a corollary, this means that the {@link ChangeListener#changed(ChangeEvent, Actor)}
949+
* will still be called, no matter the value given to this variable.<br>
950+
* Only applies for the case where you have activated the {@link #infiniteSelectionRange} flag.
927951
*/
928952
public boolean isMiddleCancel() {
929953
return middleCancel;
930954
}
931955

932956
/**
933-
* Determines whether or not releasing a click within the inner-radius
934-
* should cancel the selection.
935-
* If {@code true} a release in the middle, even if {@link #infiniteSelectionRange}
936-
* is set to {@code true}, will trigger a selection of the {@link #defaultIndex}.
957+
* Determines whether or not releasing a click within the {@link #innerRadiusPercent
958+
* inner-radius} should "cancel" the selection.
959+
* If {@code true}, a click released in the middle will trigger a selection of the
960+
* {@link #defaultIndex}.<br>
961+
* As a corollary, this means that the {@link ChangeListener#changed(ChangeEvent, Actor)}
962+
* will still be called, no matter the value given to this variable.<br>
963+
* Only applies for the case where you have activated the {@link #infiniteSelectionRange} flag.
937964
*/
938965
public void setMiddleCancel(boolean middleCancel) {
939966
this.middleCancel = middleCancel;

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ public Color getColor(int index) {
511511

512512
protected void drawChild(Vector2 vector2, int index, float startAngle, float radian) {
513513
propagateAlpha(sd, getColor(index));
514-
sd.arc(vector2.x, vector2.y, (getCurrentRadius()+ getInnerRadiusLength())/2,
515-
startAngle, radian, getCurrentRadius()- getInnerRadiusLength());
514+
sd.arc(vector2.x, vector2.y, (getCurrentRadius() + getInnerRadiusLength())/2,
515+
startAngle, radian, getCurrentRadius() - getInnerRadiusLength());
516516

517517
/* Circumferences */
518518
drawChildCircumference(vector2, startAngle, radian, getCurrentRadius() - style.circumferenceWidth/2);
@@ -624,10 +624,9 @@ public static class PieWidgetStyle {
624624
* The color used by the separating lines between each item.<br>
625625
* It is recommended mostly for the case where you are not defining an
626626
* {@link #alternateSliceColor}.<br>
627-
* If you do not define a {@link #separatorWidth} along with this value,
628-
* no lines will be visible.
627+
* Defaults to black.
629628
*/
630-
public Color separatorColor;
629+
public Color separatorColor = new Color(0,0,0,1);
631630

632631
/**
633632
* <i>Recommended. Optional.</i><br>
@@ -652,24 +651,24 @@ public static class PieWidgetStyle {
652651
* applied along the partial circumference.<br>
653652
* If you have set a non-zero {@link #innerRadiusPercent} value, this will
654653
* also apply to the "inner radius" of your Widget.<br>
655-
* If you do not define a {@link #circumferenceWidth} along with this
656-
* value, no circumference will be visible.
654+
* Defaults to black.
655+
* @see #circumferenceWidth
657656
*/
658-
public Color circumferenceColor;
657+
public Color circumferenceColor = new Color(0,0,0,1);
659658

660659
/**
661660
* <i>Recommended. Optional.</i><br>
662661
* Determines how wide the lines that separate each slice will be.<br>
663662
* If no {@link #separatorColor} was provided along with this value,
664-
* no lines will be drawn.
663+
* the default color will be black.
665664
*/
666665
public float separatorWidth;
667666

668667
/**
669668
* <i>Optional.</i><br>
670669
* Determines how wide the circumference line will be.<br>
671670
* If no {@link #circumferenceColor} was provided along with this value,
672-
* no circumference will be drawn.
671+
* the default color will be black.
673672
*/
674673
public float circumferenceWidth;
675674

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,17 +520,32 @@ protected float pow2(float in) {
520520
}
521521

522522
/**
523-
* Centers the Widget on the current position of the mouse.
523+
* Centers the Widget on the current position of the mouse.<br>
524+
* If there are no {@link com.badlogic.gdx.scenes.scene2d.Stage Stage}
525+
* associated with the Widget, this is not guaranteed to work.
524526
*/
525527
public void centerOnMouse() {
526-
setPosition(Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), Align.center);
528+
if (getStage() != null) {
529+
getStage().screenToStageCoordinates(vector2.set(Gdx.input.getX(), Gdx.input.getY()));
530+
} else { // edge-case fallback
531+
vector2.set(Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY());
532+
}
533+
setPosition(vector2.x, vector2.y, Align.center);
527534
}
528535

529536
/**
530-
* Positions the Widget's center right in the middle of the current screen size.
537+
* Positions the Widget's center in the middle of the screen.<br>
538+
* If there are no {@link com.badlogic.gdx.scenes.scene2d.Stage Stage}
539+
* associated with the Widget, this is not guaranteed to work.
531540
*/
532541
public void centerOnScreen() {
533-
setPosition(Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f, Align.center);
542+
if (getStage() != null) {
543+
getStage().screenToStageCoordinates(
544+
vector2.set(Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f));
545+
} else { // edge-case fallback
546+
vector2.set(Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f);
547+
}
548+
setPosition(vector2.x, vector2.y, Align.center);
534549
}
535550

536551
/**
@@ -570,7 +585,7 @@ public void drawRudimentaryDebug() {
570585

571586

572587
/**
573-
* @return The amount of Actors that are currently contained in the Widget.
588+
* @return the amount of (first-layer) Actors that are currently contained in the Widget.
574589
*/
575590
public int getAmountOfChildren() {
576591
return getChildren().size;
@@ -593,8 +608,10 @@ public float getGlobalAlphaMultiplier() {
593608
* (slices, lines, drawables, etc.).
594609
*/
595610
public void setGlobalAlphaMultiplier(float globalAlphaMultiplier) {
611+
float reversedMultiplier = 1/this.globalAlphaMultiplier;
596612
this.globalAlphaMultiplier = globalAlphaMultiplier;
597-
setColor(getColor().r, getColor().g, getColor().b, getColor().a * globalAlphaMultiplier);
613+
float adjustedMultiplier = reversedMultiplier * globalAlphaMultiplier;
614+
setColor(getColor().r, getColor().g, getColor().b, getColor().a * adjustedMultiplier);
598615
}
599616

600617
/**

0 commit comments

Comments
 (0)