Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
payne911 committed Apr 18, 2020
2 parents 7d262e0 + 4ecf5f6 commit aa384c3
Show file tree
Hide file tree
Showing 53 changed files with 2,411 additions and 1,230 deletions.
15 changes: 13 additions & 2 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
[4.2.0]
- Fixed a bug related to the `globalAlphaMultiplier` attribute.
- Fixed a bug related to `centerOn` methods and some Viewports.
- Performance improvement: Events (Callbacks/Highlight/Selection/etc.) are now Pooled.
- Added a default Color (black) for the following `PieWidgetStyle` attributes: `separatorColor` and `circumferenceColor`.
- Added a Testing Menu so that Contributors can more easily test their implementations.
- Added the `NO_SELECTION` constant in `PieMenu`.
- Added a new "code example": `NestedClickDrag`.
- Minor JavaDoc tweaks and improvements.
- Updated `ShapeDrawer` version to `v2.3.0`.

[4.1.0]
- Added `AnimatedRadialGroup`
- Minor fixes in documentation
- Added `AnimatedRadialGroup`.
- Minor fixes in documentation.
- Updated `ShapeDrawer` version to `v2.1.0`.

[4.0.0]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ allprojects {
ext {
...
pieMenuVersion = '4.1.0' // add this line
pieMenuVersion = '4.2.0' // add this line
}
repositories {
...
maven { url 'https://jitpack.io' }
maven { url 'https://jitpack.io' } // add this line if it isn't there
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ apply from: 'publish.gradle'
sourceCompatibility = 1.8

def projectName = 'pie-menu'
version '4.1.0'
version '4.2.0'
group 'com.payne.games'

def gdxVersion = '1.9.10'
def shapedrawerVersion = '2.1.0'
def shapedrawerVersion = '2.3.0'

// Disable JDK 8's doclint
// http://blog.joda.org/2014/02/turning-off-doclint-in-jdk-8-javadoc.html
Expand Down
Binary file added media/nested_menu.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 56 additions & 29 deletions src/main/java/com/payne/games/piemenu/PieMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Pools;

Expand All @@ -32,27 +33,32 @@ public class PieMenu extends PieWidget {
*/
private InputListener pieMenuListener;

/**
* Used to denote a non-selected index, or canceled selection, for example.
*/
public static final int NO_SELECTION = -1;

/**
* The index that is used as a fallback value whenever a processed
* user-input does not map to a valid child index value.<br>
* This value can be negative, if you want nothing to be the default.
*/
private int defaultIndex = -1;
private int defaultIndex = NO_SELECTION;

/**
* Index of the currently selected item.
*/
private int selectedIndex = defaultIndex;
private int selectedIndex = NO_SELECTION;

/**
* Index of the currently highlighted item.
*/
private int highlightedIndex = defaultIndex;
private int highlightedIndex = NO_SELECTION;

/**
* Index of the currently highlighted item.
*/
private int hoveredIndex = -1;
private int hoveredIndex = NO_SELECTION;

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


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

Expand Down Expand Up @@ -369,7 +376,7 @@ public void resetSelection() {
* (if you had set it up).
*/
public void resetHover() {
hoveredIndex = -1;
hoveredIndex = NO_SELECTION;
}

@Override
Expand Down Expand Up @@ -550,7 +557,7 @@ public PieMenuStyle() {
*
* @param style a Style to copy the parameters from.
*/
public PieMenuStyle(PieMenu.PieMenuStyle style) {
public PieMenuStyle(PieMenuStyle style) {
super(style);
this.selectedColor = new Color(style.selectedColor);
this.downColor = new Color(style.downColor);
Expand Down Expand Up @@ -589,8 +596,12 @@ public void selectIndex(int newIndex) {

selectedIndex = newIndex;
highlightedIndex = newIndex;
if (newIndex != oldHighlightedIndex)
fire(new PieMenuHighlightChangeEvent(newIndex));
if (newIndex != oldHighlightedIndex) {
PieMenuHighlightChangeEvent highlightChangeEvent = Pools.obtain(PieMenuHighlightChangeEvent.class);
highlightChangeEvent.newIndex = newIndex;
fire(highlightChangeEvent);
Pools.free(highlightChangeEvent);
}

ChangeListener.ChangeEvent changeEvent = Pools.obtain(ChangeListener.ChangeEvent.class);
if (fire(changeEvent)) {
Expand Down Expand Up @@ -630,7 +641,10 @@ public void highlightIndex(int newIndex) {
if(newIndex != highlightedIndex) {
highlightedIndex = newIndex;
resetHover();
fire(new PieMenuHighlightChangeEvent(newIndex));
PieMenuHighlightChangeEvent highlightChangeEvent = Pools.obtain(PieMenuHighlightChangeEvent.class);
highlightChangeEvent.newIndex = newIndex;
fire(highlightChangeEvent);
Pools.free(highlightChangeEvent);
}
}

Expand Down Expand Up @@ -665,7 +679,10 @@ public void hoverIndex(int newIndex) {
newIndex = mapIndex(newIndex);
if(newIndex != hoveredIndex) {
hoveredIndex = newIndex;
fire(new PieMenuHoverChangeEvent(newIndex));
PieMenuHoverChangeEvent hoverChangeEvent = Pools.obtain(PieMenuHoverChangeEvent.class);
hoverChangeEvent.newIndex = newIndex;
fire(hoverChangeEvent);
Pools.free(hoverChangeEvent);
}
}

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

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

public PieMenuHighlightChangeEvent(int newIndex) {
this.newIndex = newIndex;
@Override
public void reset() {
super.reset();
newIndex = NO_SELECTION;
}
}

private static class PieMenuHoverChangeEvent extends Event {
private int newIndex;

public PieMenuHoverChangeEvent(int newIndex) {
this.newIndex = newIndex;
@Override
public void reset() {
super.reset();
newIndex = NO_SELECTION;
}
}

Expand Down Expand Up @@ -920,20 +941,26 @@ public void setInfiniteSelectionRange(boolean infiniteSelectionRange) {
}

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

/**
* Determines whether or not releasing a click within the inner-radius
* should cancel the selection.
* If {@code true} a release in the middle, even if {@link #infiniteSelectionRange}
* is set to {@code true}, will trigger a selection of the {@link #defaultIndex}.
* Determines whether or not releasing a click within the {@link #innerRadiusPercent
* inner-radius} should "cancel" the selection.
* If {@code true}, a click released in the middle will trigger a selection of the
* {@link #defaultIndex}.<br>
* As a corollary, this means that the {@link ChangeListener#changed(ChangeEvent, Actor)}
* will still be called, no matter the value given to this variable.<br>
* Only applies for the case where you have activated the {@link #infiniteSelectionRange} flag.
*/
public void setMiddleCancel(boolean middleCancel) {
this.middleCancel = middleCancel;
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/com/payne/games/piemenu/PieWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ public Color getColor(int index) {

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

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

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

/**
* <i>Recommended. Optional.</i><br>
* Determines how wide the lines that separate each slice will be.<br>
* If no {@link #separatorColor} was provided along with this value,
* no lines will be drawn.
* the default color will be black.
*/
public float separatorWidth;

/**
* <i>Optional.</i><br>
* Determines how wide the circumference line will be.<br>
* If no {@link #circumferenceColor} was provided along with this value,
* no circumference will be drawn.
* the default color will be black.
*/
public float circumferenceWidth;

Expand Down
29 changes: 23 additions & 6 deletions src/main/java/com/payne/games/piemenu/RadialGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,17 +520,32 @@ protected float pow2(float in) {
}

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

/**
* Positions the Widget's center right in the middle of the current screen size.
* Positions the Widget's center in the middle of the screen.<br>
* If there are no {@link com.badlogic.gdx.scenes.scene2d.Stage Stage}
* associated with the Widget, this is not guaranteed to work.
*/
public void centerOnScreen() {
setPosition(Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f, Align.center);
if (getStage() != null) {
getStage().screenToStageCoordinates(
vector2.set(Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f));
} else { // edge-case fallback
vector2.set(Gdx.graphics.getWidth()/2f, Gdx.graphics.getHeight()/2f);
}
setPosition(vector2.x, vector2.y, Align.center);
}

/**
Expand Down Expand Up @@ -570,7 +585,7 @@ public void drawRudimentaryDebug() {


/**
* @return The amount of Actors that are currently contained in the Widget.
* @return the amount of (first-layer) Actors that are currently contained in the Widget.
*/
public int getAmountOfChildren() {
return getChildren().size;
Expand All @@ -593,8 +608,10 @@ public float getGlobalAlphaMultiplier() {
* (slices, lines, drawables, etc.).
*/
public void setGlobalAlphaMultiplier(float globalAlphaMultiplier) {
float reversedMultiplier = 1/this.globalAlphaMultiplier;
this.globalAlphaMultiplier = globalAlphaMultiplier;
setColor(getColor().r, getColor().g, getColor().b, getColor().a * globalAlphaMultiplier);
float adjustedMultiplier = reversedMultiplier * globalAlphaMultiplier;
setColor(getColor().r, getColor().g, getColor().b, getColor().a * adjustedMultiplier);
}

/**
Expand Down
Loading

0 comments on commit aa384c3

Please sign in to comment.