Skip to content

Commit

Permalink
Update rc2.
Browse files Browse the repository at this point in the history
  • Loading branch information
payne911 committed Oct 19, 2019
1 parent 57eed06 commit b1404bc
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Fixed a few `Animated` constructors.
- The `ShapeDrawer` is now instantiated internally.
- The default rules used by `ShapeDrawer` to determine the amount of sides to draw is now internally overridden with an improved algorithm.
- Added an example for adding Keyboard-Key-Mapping (selection through keyboard) on a `PieMenu`.

[3.0.0-rc1]
- Refactored the Style so that most of the `float` values (`radius` and the likes) have become class-attributes instead.
Expand Down
Binary file added media/keyboard.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 10 additions & 13 deletions src/main/java/com/payne/games/piemenu/RadialGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,30 +391,32 @@ public RadialGroup(final Batch batch, final TextureRegion whitePixel,


/**
* @return The current diameter of the widget.
* This might not be {@link #minRadius}.
* The current diameter of the widget.<br>
* This might not be twice the {@link #minRadius}.
*
* @return {@code Math.min(getWidth(), getHeight())}
*/
protected float getMaxDiameter() {
return Math.min(getWidth(), getHeight());
}

/**
* @return The current radius of the widget.
* This might not be {@link #minRadius}.
* The current radius of the widget.<br>
* This might not be {@link #minRadius}.
*
* @return {@code Math.min(getWidth(), getHeight()) / 2}
*/
protected float getMaxRadius() {
return getMaxDiameter()/2;
}

@Override
public float getPrefWidth() {
validate(); // todo: useful?
return getMaxDiameter();
}

@Override
public float getPrefHeight() {
validate(); // todo: useful?
return getMaxDiameter();
}

Expand Down Expand Up @@ -598,8 +600,6 @@ protected void propagateAlpha(ShapeDrawer sd, Color input) {
*/
protected void drawWithShapeDrawer(Batch batch, float parentAlpha, float degreesToDraw) {

validate(); // todo: useful?

/* Pre-calculating */
float bgRadian = MathUtils.degreesToRadians*degreesToDraw;
float tmpOffset = MathUtils.degreesToRadians*(startDegreesOffset + getRotation());
Expand All @@ -611,11 +611,9 @@ protected void drawWithShapeDrawer(Batch batch, float parentAlpha, float degrees
Color bc = batch.getColor();
float restoreAlpha = bc.a;
batch.setColor(bc.r, bc.g, bc.b, bc.a * globalAlphaMultiplier);
// todo: fix rotation of Drawable (see FillParent test)
System.out.println(getOriginX() - getMaxRadius() + " | " + (getOriginY() - getMaxRadius()));
style.background.draw(batch,
getOriginX() - getMaxRadius(), getOriginY() - getMaxRadius(),
getOriginX(), getOriginY(),
getX(Align.center) - getMaxRadius(), getY(Align.center) - getMaxRadius(),
getMaxRadius(), getMaxRadius(),
getMaxDiameter(), getMaxDiameter(),
getScaleX(), getScaleY(),
getRotation());
Expand Down Expand Up @@ -688,7 +686,6 @@ public Color getColor(int index) {
}

protected void drawChild(Vector2 vector2, int index, float startAngle, float radian) {
// todo: possibly integrate buffer here too since Background has one? (or remove from bg, and do +BUFFER here?)
propagateAlpha(sd, getColor(index));
sd.arc(vector2.x, vector2.y, (getMaxRadius()+ getInnerRadiusLength())/2,
startAngle, radian, getMaxRadius()- getInnerRadiusLength());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.payne.games.piemenu.genericTests;
package com.payne.games.piemenu.individuals;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
Expand All @@ -14,13 +14,17 @@
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.payne.games.piemenu.PieMenu;

import java.util.HashSet;


public class KeyMap extends ApplicationAdapter {
private Skin skin;
Expand Down Expand Up @@ -71,43 +75,53 @@ public void modifyActor(Actor actor, float degreesPerChild, float actorDistanceF
menu.setInfiniteSelectionRange(true);
menu.setPieMenuListener(new PieMenu.PieMenuClickListener() {

private int counter = 0;
private int keyPressed = 0;
private HashSet<Integer> pressed = new HashSet<>();
private int currentKey;

@Override
public boolean keyDown(InputEvent event, int keycode) {
System.out.println("down " + keycode);
switch(keycode) {
case Input.Keys.NUM_1:
case Input.Keys.NUMPAD_1:
System.out.println("1");
counter++;
break;
default:
System.out.println(keycode);
break;
if(!(event.getListenerActor() instanceof PieMenu))
return false;
PieMenu pie = (PieMenu)event.getListenerActor();

boolean numPressed = keycode >= Input.Keys.NUM_0 && keycode <= Input.Keys.NUM_9;
boolean padPressed = keycode >= Input.Keys.NUMPAD_0 && keycode <= Input.Keys.NUMPAD_9;
boolean valid = numPressed || padPressed;
if(valid) {
if(numPressed)
currentKey = keycode - Input.Keys.NUM_0;
else
currentKey = keycode - Input.Keys.NUMPAD_0;
pie.highlightIndex(currentKey);
pressed.add(currentKey);
}

return true;
}

/* This is to be able to detect keyboard keys pressed. */
@Override
public boolean keyUp(InputEvent event, int keycode) {
System.out.println("up " + keycode);
switch(keycode) {
case Input.Keys.NUM_1:
case Input.Keys.NUMPAD_1:
System.out.println("1");
counter--;
break;
default:
System.out.println(keycode);
break;
if(!(event.getListenerActor() instanceof PieMenu))
return false;
PieMenu pie = (PieMenu)event.getListenerActor();

boolean numPressed = keycode >= Input.Keys.NUM_0 && keycode <= Input.Keys.NUM_9;
boolean padPressed = keycode >= Input.Keys.NUMPAD_0 && keycode <= Input.Keys.NUMPAD_9;
boolean valid = numPressed || padPressed;

if(valid) {
if(numPressed)
currentKey = keycode - Input.Keys.NUM_0;
else
currentKey = keycode - Input.Keys.NUMPAD_0;
pressed.remove(currentKey);

if(pressed.isEmpty())
pie.selectIndex(currentKey);
else
pie.highlightIndex(pressed.iterator().next());
}

if(counter == 0) {
keyPressed = keycode;
}
return true;
}
});
Expand All @@ -118,22 +132,32 @@ public boolean keyUp(InputEvent event, int keycode) {
public void changed(ChangeEvent event, Actor actor) {
System.out.println("ChangeListener - newly selected index: " + menu.getSelectedIndex());
menu.setVisible(false);
stage.setKeyboardFocus(null);
menu.remove();
}
});

/* Populating the widget. */
Array<Image> imgs = new Array<>();
imgs.add(new Image(new Texture(Gdx.files.internal("heart-drop.png"))));
imgs.add(new Image(new Texture(Gdx.files.internal("beer-stein.png"))));
imgs.add(new Image(new Texture(Gdx.files.internal("coffee-mug.png"))));
imgs.add(new Image(new Texture(Gdx.files.internal("gooey-daemon.png"))));
imgs.add(new Image(new Texture(Gdx.files.internal("jeweled-chalice.png"))));
imgs.add(new Image(new Texture(Gdx.files.internal("coffee-mug.png"))));
int key = 0;
Array<Stack> imgs = new Array<>();
imgs.add(getNewStack("heart-drop.png", Integer.toString(key++)));
imgs.add(getNewStack("beer-stein.png", Integer.toString(key++)));
imgs.add(getNewStack("coffee-mug.png", Integer.toString(key++)));
imgs.add(getNewStack("gooey-daemon.png", Integer.toString(key++)));
imgs.add(getNewStack("jeweled-chalice.png", Integer.toString(key++)));
imgs.add(getNewStack("coffee-mug.png", Integer.toString(key++)));
for (int i = 0; i < imgs.size; i++)
menu.addActor(imgs.get(i));
}

private Stack getNewStack(String img, String key) {
Stack s = new Stack();
s.add(new Image(new Texture(Gdx.files.internal(img))));
Label.LabelStyle lbs = new Label.LabelStyle(skin.get("red", Label.LabelStyle.class));
s.add(new Label(" " + key, lbs));
return s;
}


@Override
public void render () {
Expand All @@ -156,6 +180,7 @@ public void render () {
stage.addActor(menu);
menu.centerOnMouse();
menu.resetSelection();
stage.setKeyboardFocus(menu);
menu.setVisible(true);
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/resources/skin.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ com.badlogic.gdx.graphics.Color: {
b: 1
a: 1
}
red: {
r: 1
g: 0
b: 0
a: 1
}
}
com.badlogic.gdx.scenes.scene2d.ui.Skin$TintedDrawable: {
round-dark-gray: {
Expand Down Expand Up @@ -140,6 +146,10 @@ com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
font: font
fontColor: white
}
red: {
font: font
fontColor: red
}
}
com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle: {
default: {
Expand Down

0 comments on commit b1404bc

Please sign in to comment.