libGDX Mouse Input and scene2d -- Not Receiving Proper Input? - java

I am having trouble with buttons.
stage = new Stage();
Skin skin = new Skin(Gdx.files.internal("assets/uiskin.json"));
Table table = new Table();
table.setDebug(true);
table.setFillParent(true);
stage.addActor(table);
Button button = new Button(skin, "default");
table.add(button);
The code above creates a button with the proper text in center of the screen, but input is broken. When I click on the button, it does not register input. However when I click ABOVE the button, it registers input. What am I doing wrong?

Regarding the code that you posted, you will need to set the input processor to the stage. By doing this, libGDX will use this as a Listener to register events that happen. Try adding this to your block of code:
Gdx.input.setInputProcessor(stage);
Also, if you are not planning on adding other Actors to your Stage, I would just add the Button directly to the Stage.

Related

How to change color of a feature clicked on azure maps?

So i have a data source beeing loaded in a symbolLayer in Azure Maps, all its working fine. But i cant find a way to show to my user what feature is beeing clicked on the map.
Here is my code.
I cant get the information about the feature is beeing clicked, but i cant find the way to change the style of the feature.
Anything that can show the user that he clicked that feature its ok for me. Even a dot on top of the feature.
If you guys know what is doing my popup to appear not on top of my feature but overlapping him i would aprecciate too.
Popup popup = new Popup();
map.popups.add(popup);
//Add a click event to the layer.
map.events.add((OnFeatureClick)(feature) -> {
//Get the first feature and it's properties.
Feature f = feature.get(0);
JsonObject props = f.properties();
//Retrieve the custom layout for the popup.
View customView = LayoutInflater.from(this).inflate(R.layout.popup_text, null);
//Display the name and entity type information of the feature into the text view of the popup layout.
TextView tv = customView.findViewById(R.id.message);
tv.setText(f.getStringProperty("Name") + "\n" +
f.getStringProperty("Pvm"));
//Get the position of the clicked feature.
Position pos = MapMath.getPosition((Point)f.geometry());
//Set the options on the popup.
popup.setOptions(
//Set the popups position.
position(pos),
//Set the anchor point of the popup content.
anchor(AnchorType.BOTTOM),
//Set the content of the popup.
content(customView),
//add a button to close popup
closeButton(false)
);
//Open the popup.
popup.open();
map.events.add((OnClick) (lat, lon) -> {
//Map clicked.
popup.close(customView);
popup.setOptions(iconImage("ic_square_w"));
//Return true indicating if event should be consumed and not passed further to other listeners registered afterwards, false otherwise.
return true;
});
//Return a boolean indicating if event should be consumed or continue to bubble up.
return true;
});
The easiest way to add a visual highlight that shape has been selected, is to use a second datasource, and add a feature to it and render it with a layer differently.

JavaFX indeterminate progress dialog overlay

I have a WebView.
When loading stuff that takes a long time, I want the WebView to be overlaid with a loading dialog that looks like the progress dialog in phones - the one with the circular spinning thing, and darken the screen area that is not covered by the dialog.
Additionally, I want to make it impossible for the user to click on anything on the WebView until it is ready.
How do I achieve this effect in Java 8?
when you need the loading call this
private void inUrFace(){
Dialog<Void> dialog = new Dialog<>();
dialog.initModality(Modality.WINDOW_MODAL);
dialog.initOwner(stage);//stage here is the stage of your webview
dialog.initStyle(StageStyle.TRANSPARENT);
Label loader = new Label("LOADING");
loader.setContentDisplay(ContentDisplay.DOWN);
loader.setGraphic(new ProgressIndicator());
dialog.getDialogPane().setGraphic(loader);
DropShadow ds = new DropShadow();
ds.setOffsetX(1.3); ds.setOffsetY(1.3); ds.setColor(Color.DARKGRAY);
dialog.getDialogPane().setEffect(ds);
dialog.showAndWait();}
double check the code. should give you something of that sort.

Java (JFace Application Window) Setting external label text

I am looking to figure out how to set the text of a label on an external Application Window.
What I have:
I have two windows so far. The first one is the main application window that will appear when the user starts the program. The second window is another separate window that I have created specifically to display a custom error window.
The problem: I seem to be unable to call the label that I have created on the error window and set the text to something custom. Why? I want to be able to reuse this window many times! This window is aimed for things like error handling when there is invalid input or if the application cannot read/save to a file.
I was going to post screen shots but you need 10 rep for that. It would have explained everything better.
Here is the code for the label on the Error_dialog window:
Label Error_label = new Label(container, SWT.NONE);
Error_label.setBounds(10, 10, 348, 13);
Error_label.setText("Label I actively want to change!");
Here is the condition I would like to fire off when it is met:
if(AvailableSpaces == 10){
//Set the label text HERE and then open the window!
showError.open();
}
I have included this at the top of the class as well:
Error_dialog showError = new Error_dialog();
Just save the label as a field in your dialog class and add a 'setter' method. Something like:
public class ErrorDialog extends Dialog
{
private Label errorLabel;
... other code
public void setText(String text)
{
if (errorLabel != null && !errorLabel.isDisposed()) {
errorLabel.setText(text);
}
}
You will need to use your dialog like this:
ErrorDialog dialog = new ErrorDialog(shell);
dialog.create(); // Creates the controls
dialog.setText("Error message");
dialog.open();
Note: you should stick to the rules for Java variable names - they always start with lower case.
Further learn to use Layouts. Using setBounds will cause problems if the user is using different fonts.

setVolumeControlStream not working when a popup window is displayed

I have this.setVolumeControlStream(AudioManager.STREAM_MUSIC); at the start of all activities in my application so when the user presses the volume up or down buttons, he controls the media volume.
I have a popup window in my program and when that appears the user can no longer control the volume.
Looking at similar questions it seems that setting up onKeyup/down listeners can interfere with the process - but I have not set any up - the only listeners I have for the popup window are setOnClickListeners for the buttons and a setOnDismissListener for the window.
How can I fix this?
Looks like you have to call setOwnerActivity on the Dialog object.
Documentation from the method:
Sets the Activity that owns this dialog. An example use: This Dialog will use the suggested volume control stream of the Activity.
While not tested, this should do the trick. There is also the possibility to use setVolumeControlStream.
I had been creating the popup window with
my_popup_window = new PopupWindow(layout, x, y, true);
I then change it to this...
my_popup_window = new PopupWindow(layout);
my_popup_window.setWidth(x);
my_popup_window.setHeight(y);
and the volume control started to work again. I don't understand why - but it worked.
I just do this pop.setFocusable(false). and it worked.
though the Mick's answer didn't work for me, this is for posterity.
//Declaration
PopupWindow mWindow;
...
//Constructor
mWindow = new PopupWindow(context);
...
//Prepare to Show
mWindow.setContentView();
mWindow.setBackgroundDrawable();
mWindow.setFocusable(false);
...
setting setFocusable to false helped my activity capture onKeyDown() again.

Tripleplay Button: Dynamic text with proper alignment on an Image Button (say the text justified , centre)

I am creating a window with two image buttons (using TriplePlay in my playN game).
Now I need dynamic text on these buttons. But when I add buttons with images (setIcon), I am not able to add Text on it same time. Please check the following code block I use now.
Interface iface = new Interface(null);
pointer().setListener(iface.plistener);
Styles buttonStyles = Styles.none().add(Style.BACKGROUND.is(new NullBackground())).
addSelected(Style.BACKGROUND.is(Background.solid(0xFFCCCCCC)));
Stylesheet rootSheet = Stylesheet.builder().add(Button.class, buttonStyles).create();
Root buttonroot = iface.createRoot(AxisLayout.horizontal().gap(150), rootSheet);
buttonroot.setSize(width_needed, height_needed);
buttonroot.addStyles(Styles.make(Style.BACKGROUND.is(new NullBackground())));
graphics().rootLayer().add(buttonroot.layer);
Button you = new Button().setIcon(buttonImage);
Button friend = new Button().setIcon(buttonImage);
buttonroot.add(you).add(friend);
buttonroot.layer.setTranslation(x_needed, y_needed);
Root nameroot = iface.createRoot(AxisLayout.horizontal().gap(300), rootSheet);
nameroot.setSize(width_needed, height_needed);
nameroot.addStyles(Styles.make(Style.BACKGROUND.is(new NullBackground())));
graphics().rootLayer().add(nameroot.layer);
name = new Label("YOU");// we need the dynamic string variable instead
friendName = new Label("FRIEND"); // we need the dynamic string variable instead
nameroot.add(name).add(friendName);
nameroot.layer.setTranslation(x_needed, y_needed);
here I have tried making a root then add button with images to it then making another root and add labels on it so that it will be show like text on the image buttons. But I know this is a bad way of doing it, and the alignment will not be according to what needed as it a dynamic text. Is there anyway to add a button, with image and a label on it?
Thanks in anticipation
Creating a button with text and an icon is trivial:
Button button = new Button("Text").setIcon(iconImage);
You can then change the text on the button any time you like, like so:
button.text.update("New Text");
If you want a button with a background image with text rendered over the background, then do the following:
Button button = new Button("Text").
addStyles(Background.is(Background.image(bgImage)));
Note that you will need the latest TriplePlay code (from Github) to use the ImageBackground. The latest code also supports Flash-style "scale9" backgrounds:
Button button = new Button("Text").
addStyles(Background.is(Background.scale9(bgImage)));

Categories