Libgdx Dialog buttons cannot be clicked - input

I have trouble properly implementing a dialog. It does not recognize button clicks - even the button down animation does not happen. However, it does recognize key presses (e.g. enter or esc in my case). Dialog does appear to be on top of the stage objects, so I'm confused why it isn't registering my clicks.
I have an InputMultiplexer with processors InputHandler class (implements InputProcessor) and stage, in that order:
InputMultiplexer im = new InputMultiplexer();
im.addProcessor(new InputHandler(stage));
im.addProcessor(stage);//trying to make dialog work by doing this
Gdx.input.setInputProcessor(im);
Here's my showDialog method defined in stage:
public void showDialog() {
Dialog dialog = new Dialog("Quit?", skin) {
#Override
protected void result(Object object) {
boolean exit = (Boolean) object;
if (exit) {
Gdx.app.exit();
} else {
remove();
}
}
};
dialog.button("Yes", true);
dialog.button("No", false);
dialog.key(Input.Keys.ENTER, true);
dialog.key(Input.Keys.ESCAPE, false);
dialog.show(this);
}
The showDialog() method is called from InputHandler when it recognizes that the game is over (I have it set so that the game state is checked and updated on touch up, since it's a touch based game). My understanding is that since the multiplexer receives false return from the InputHandler methods when the game is over, it then goes to the stage for input, which seems to be working only when I use key presses on the dialog, i.e. enter quits the game, esc removes the dialog, but clicking the buttons do nothing.
Here is my Screen's render function in case it's relevant:
#Override
public void render(float delta) {
Gdx.gl.glClearColor(1,1,1,1);
Gdx.graphics.getGL20().glEnable(GL20.GL_BLEND);
Gdx.graphics.getGL20().glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT | (Gdx.graphics.getBufferFormat().coverageSampling?GL20.GL_COVERAGE_BUFFER_BIT_NV:0));
stage.act();
stage.getCamera().update();
stage.draw();
}

Related

How to close ComboBox list items when moving application window of my WinRT/C++ UWP application?

I have a pair of ComboBox controls having IsEditable() true as well as false.
When I am scrolling through my application or moving my application window (by clicking on the title bar) with list popup open, I would like to close the ComboBox list popup as otherwise there would be a weird delay in aligning the list correctly below the control.
Is this possible in UWP with WinRT/C++? If so, kindly suggest how to.
I did an investigation to find if any events are there to handle in such a scenario when ComboBox control is essentially displaced from initial position while moving the app window/scrolling the app, but couldn't find any help.
Edit: Adding ComboBox image from XAML Controls Gallery to demonstrate the behaviour. In case if IsEditable set as true, when popup is opened and application is scrolled then popup goes outside the window. Instead I would like to dismiss the popup itself. However, if IsEditable is set as false then we cannot scroll until the popup is dismissed.
Update: The code I tested for PointerWheelChanged
void CBFile2022X::OnPointerWheelChangedHandler( Windows::Foundation::IInspectable const& sender,
Windows::UI::Xaml::Input::PointerRoutedEventArgs const& eventargs )
{
OutputDebugString( L"PointerWheelChanged" );
if( ComboBox != nullptr )
{
ComboBox.IsEnabled( false );
ComboBox.IsEnabled( true );
}
}
I have to say that currently there is no event to detect if the application window is moved or changed its location.
Update:
You could handle the UIElement.PointerWheelChanged Event which will be fired when users scroll the mouse wheel. You could set the IsEnabled property of the ComboBox to false first and then set it to true, this will make the ComboBox lose its focus. Like:
private void Mypanel_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
FontsCombo.IsEnabled = false;
FontsCombo.IsEnabled = true;
}
Update2:
If you are using a ScrollViewer you could try to handle the ScrollViewer.ViewChanging Event.
private void ScrollViewer_ViewChanging(object sender, ScrollViewerViewChangingEventArgs e)
{
FontsCombo.IsEnabled = false;
FontsCombo.IsEnabled = true;
}

Vb.net mouse double click event for button [duplicate]

Rather than making an event occur when a button is clicked once, I would like the event to occur only when the button is double-clicked. Sadly the double-click event doesn't appear in the list of Events in the IDE.
Anyone know a good solution to this problem? Thank you!
No the standard button does not react to double clicks. See the documentation for the Button.DoubleClick event. It doesn't react to double clicks because in Windows buttons always react to clicks and never to double clicks.
Do you hate your users? Because you'll be creating a button that acts differently than any other button in the system and some users will never figure that out.
That said you have to create a separate control derived from Button to event to this (because SetStyle is a protected method)
public class DoubleClickButton : Button
{
public DoubleClickButton()
{
SetStyle(ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, true);
}
}
Then you'll have to add the DoubleClick event hanlder manually in your code since it still won't show up in the IDE:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
doubleClickButton1.DoubleClick += new EventHandler(doubleClickButton1_DoubleClick);
}
void doubleClickButton1_DoubleClick(object sender, EventArgs e) {
}
}
Use this. Code works.
public class DoubleClickButton : Button
{
public DoubleClickButton()
{
SetStyle(ControlStyles.StandardClick |
ControlStyles.StandardDoubleClick, true);
}
}
DoubleClickButton button = new DoubleClickButton();
button.DoubleClick += delegate (object sender, EventArgs e)
{
//codes
};
i used to add MouseDoubleClick event on my object like:
this.pictureBox.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.pictureBox_MouseDoubleClick);
A double click is simply two regular click events within a time t of each other.
Here is some pseudo code for that assuming t = 0.5 seconds
button.on('click' , function(event) {
if (timer is off or more than 0.5 milliseconds)
restart timer
if (timer is between 0 and 0.5 milliseconds)
execute double click handler
})

Modeless dialog created by modal dialog in Compact Framework

I am working on a Compact Framework application. This particular hardware implementation has a touchscreen, but its Soft Input Panel has buttons that are simply too small to be useful. There are more than one form where typed input is required, so I created a form with buttons laid out like a keypad. The forms that use this "keypad" form are modal dialogs. When a dialog requiring this "keypad" loads, I load the "keypad" form as modeless:
private void CardInputForm_Load(object sender, EventArgs e)
{
...
keypadForm = new KeypadForm();
keypadForm.Owner = this;
keypadForm.SetCallback(keyHandler);
keypadForm.Show();
}
The SetCallback method tells the "keypad" form where to send the keystrokes (as a Delegate).
The problem I'm having is that the modeless "keypad" form does not take input. It is displayed as I expect, but I get a beep when I press any of its buttons, and its caption is grayed-out. It seems like the modal dialog is blocking it.
I've read other posts on this forum that says modal dialogs can create & use modeless dialogs. Can anyone shed light on this situation? Is there a problem with my implementation?
I found the answer: Set the keypad form's Parent property, not its Owner property, to the form instance wanting the keystrokes. The keypad dialog's title bar stays grayed out, but the form is active.
private void CardInputForm_Load(object sender, EventArgs e)
{
// (do other work)
keypadForm = new KeypadForm();
keypadForm.Parent = this;
keypadForm.Top = 190; // set as appropriate
keypadForm.Show();
}
Be sure to clean up when done with the parent form. This can be in the parent's Closing or Closed events.
private void CardInputForm_Closing(object sender, CancelEventArgs e)
{
// (do other work)
keypadForm.Close();
keypadForm.Dispose();
}
There are two panels on the keypad form, one with numerals and one with letters and punctuation that I want. There is also an area not on a panel that is common to both, containing buttons for clear, backspace, enter/OK, and cancel. Each panel has a button to hide itself and unhide its counterpart ('ABC', '123', for example). I have all the buttons for input on the keypadForm fire a common event. All it does is send the button instance to the parent. The parent is responsible for determining what action or keystroke is desired. In my case I named the buttons "btnA", "btnB", "btn0", "btn1", "btnCancel", etc. For keystrokes, the parent form takes the last character of the name to determine what key is desired. This is a bit messy but it works. Any form wishing to use the keypad form inherits from a base class, defining a method for callback.
public partial class TimeClockBase : Form
{
public TimeClockBase()
{
InitializeComponent();
}
// (other implementation-specific base class functionality)
public virtual void KeyCallback(Button button)
{
}
}
The click event on the keypad form looks like this.
private void btnKey_Click(object sender, EventArgs e)
{
// play click sound if supported
(Parent as TimeClockBase).KeyCallback(sender as Button);
}
The method in the parent form looks like this.
public override void KeyCallback(Button button)
{
switch (button.Name)
{
case "btnCancel":
// setting result will cause form to close
DialogResult = DialogResult.Cancel;
break;
case "btnClear":
txtCardID.Text = string.Empty;
break;
// (handle other cases)
}
}

How to add clickhandler to the subrow of the celltablebuilder

I am able to build custom rows with celltablebuilder. When clicking on a particular anchor cell, I am able to build additional subrows for that row. This subrow has buttons, when clicking on the button I have do some action. I am able to add buttons with clickhandler in the subrow, but when clicking on the button nothing is happening clickhandler is not firing.
Can anybody please help.
protected void buildRowImpl(GridDTO rowValue, int absRowIndex ) {
buildRows(rowValue, absRowIndex, true);
if (showingFriends.contains(rowValue.getComponentId())) {
buildAdditonalRows( absRowIndex, gridDTO);
}
}
private void buildAdditonalRows(int index, GridDTO rowValue, ){
TableRowBuilder row = startRow();
td = row.startTD();
if(rowValue.getXpath() != null){
//td.text(rowValue.getXpath());
renderCell(td, createContext(1), cellTable.getColumn(1), rowValue);
}else{
td.text("");
}
td.endTD();
td = row.startTD();
Button button = new Button ();
button.setText("Save");
button.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Window.alert("ssss");
}
});
DivBuilder div = td.startDiv();
div.html(new afeHtmlBuilder().appendHtmlConstant(button.toString()).toSafeHtml());
div.end();
td.endTD();
row.endTR();
}
CellPreviewEvent provides subindex. You can use it to get subrow value.
Example usage :
dataGrid.addCellPreviewHandler(new CellPreviewEvent.Handler<TreeItem>() {
#Override
public void onCellPreview(final CellPreviewEvent<TreeItem> event) {
if(event.getNativeEvent().getType().equals(BrowserEvents.CLICK)){
if(event.getContext().getSubIndex()>0){
event.getValue().getChild(event.getContext().getSubIndex()-1);
}
}
}
});
Or you can provide custom CellPreviewEvent.Handler implementation with selectionMode. For more details you can look at AbstractHasData
I had a similar situation where i needed a widget inside a cell to listen for click events... What i found out is that the widget doesn't respond to events once you inserted it into a cell (In other words, only the actual HTML that makes up for the widget gets put into the cell, any kind of event handling isn't included). The work around is to add the events to the Cell (You can make a custom cell class for that particular cell-widget and override OnBrowserEvent to listen for events.)
See GWT: On adding custom widget to celltable losing events of the custom widgets for a more eloquent explanation and example code.

Eclipse Plug-in:Focus lost after activating a view via (controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE));

I have a view which is initialised via OleControlSite and invoked via OleAutomation. It is actually a media player which I call in a view after user right clicks the file and calls Play in the context menu. Whenever I play a file by first right clicking and calling Play, it plays absolutely fine. The problem is when user displays the view before doing a right click(Window->Show View->Other->MyView) and then tries to do a right click and Play, at this point of time ISelection returns null and hence nothing plays.
IWorkbenchPage iwPage=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ISelection selection=iwPage.getSelection();
The problem is the selections somehow loses focus if the view has been invoked in the fashion described.
This is how the view is initialised when the plugin is loaded
public void createPartControl(Composite parent) {
frame = new OleFrame(parent, SWT.APPLICATION_MODAL);
// OleControlSite controlSite;
try {
controlSite = new OleControlSite(frame, SWT.APPLICATION_MODAL,"WMPlayer.OCX.7");
controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
oleAutomation = new OleAutomation(controlSite);
makeActions();
fillActionBars();
} catch (SWTException ex) {
MessageBox box = new MessageBox(getSite().getShell(),SWT.ICON_INFORMATION);
box.setMessage("Failed to Initialise Media Player.");
box.setText("Error");
box.open();
ex.printStackTrace();
return;
}
}
Is there a way where we can force the focus to the Project Explorer where the current file is selected ?