fix: add proper highlighting of buttons in GamePadDialog.

This commit is contained in:
lantzelot-swe 2023-01-06 19:49:09 +01:00
parent 4594d8bd78
commit 1fefe0e229
6 changed files with 52 additions and 6 deletions

View File

@ -10,6 +10,7 @@ public class GamePadDialog extends BaseDialog
{
private GamepadBackgroundPanel panel;
private JoystickModel model;
private Dimension dialogSize = new Dimension(660, 790);
public GamePadDialog(Frame owner, JoystickModel model)
{
@ -18,8 +19,8 @@ public class GamePadDialog extends BaseDialog
this.model = new JoystickModel(model.isPort1());
setTitle("Edit joystick/gamepad configuration");
addContent(getGamepadBackgroundPanel());
this.setPreferredSize(new Dimension(660, 770));
this.setMinimumSize(new Dimension(660, 770));
this.setPreferredSize(dialogSize);
this.setResizable(false);
//Set initial values to the model
this.model.setConfigStringFromDb(model.getConfigString());
}
@ -32,7 +33,7 @@ public class GamePadDialog extends BaseDialog
}
return panel;
}
public String getJoyConfigString()
{
return this.model.getConfigString();

View File

@ -37,7 +37,7 @@ public class GamePadImagePanel extends JPanel
}
}
ImageIcon gamepadImage = new ImageIcon(getClass().getResource("/se/lantz/logitech320.png"));
ImageIcon gamepadImage = new ImageIcon(getClass().getResource("/se/lantz/logitech.png"));
private JLabel imageLabel;
private GamePadButton currentButton = null;
@ -103,10 +103,13 @@ public class GamePadImagePanel extends JPanel
graphics2D.fillRect(72, 57, 12, 20);
break;
case A:
graphics2D.drawOval(241, 94, 22, 22);
break;
case B:
graphics2D.drawOval(263, 72, 22, 22);
break;
case BACK_GUIDE:
graphics2D.drawOval(124, 55, 20, 16);
break;
case DOWN:
//Oval around dpad
@ -121,10 +124,13 @@ public class GamePadImagePanel extends JPanel
graphics2D.fillRect(54, 75, 20, 12);
break;
case LEFT_SHOULDER:
graphics2D.drawRect(242, 240, 35, 25);
break;
case LEFT_STICK:
graphics2D.fillOval(202, 126, 15, 15);
break;
case LEFT_TRIGGER:
graphics2D.drawOval(240, 270, 36, 36);
break;
case RIGHT:
//Oval around dpad
@ -133,14 +139,19 @@ public class GamePadImagePanel extends JPanel
graphics2D.fillRect(82, 75, 20, 12);
break;
case RIGHT_SHOULDER:
graphics2D.drawRect(48, 240, 35, 25);
break;
case RIGHT_STICK:
graphics2D.fillOval(114, 126, 15, 15);
break;
case RIGHT_TRIGGER:
graphics2D.drawOval(48, 270, 36, 36);
break;
case X:
graphics2D.drawOval(219, 72, 22, 22);
break;
case Y:
graphics2D.drawOval(241, 49, 22, 22);
break;
default:
break;

View File

@ -64,7 +64,7 @@ public class GamePadInfoPanel extends JPanel
if (extraButtonsInfoLabel == null) {
extraButtonsInfoLabel = new JLabel("<html>Notice the extra buttons <b>left shoulder</b>, <b>right shoulder</b>, <b>left stick</b> and <b>right stick</b>. \r\n" +
"They are not available on the joystick but are common on alternative USB controllers. \r\n" +
"The latter two are for controllers with two sticks that press down for additional button functions. Its up to you what you map to those buttons (if anything).</html>");
"The latter two are for controllers with two sticks that press down for additional button functions. Its up to you what you map to those buttons (if anything). Below are the functions for THEC64 Joystick shown in parenthesis for comparison.</html>");
}
return extraButtonsInfoLabel;
}

View File

@ -1,14 +1,19 @@
package se.lantz.gui.gamepad;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.Beans;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import se.lantz.gui.KeySelectionComboBox;
import se.lantz.gui.gamepad.GamePadImagePanel.GamePadButton;
@ -183,7 +188,22 @@ public class MappingComponent extends JPanel
@Override
public void mouseExited(MouseEvent e)
{
imagePanel.setCurrentButtonAndRepaint(null);
if (!keySelectionComboBox.hasFocus())
{
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (focusOwner instanceof KeySelectionComboBox)
{
MappingComponent focusedMappingComponent = (MappingComponent)SwingUtilities.getAncestorOfClass(MappingComponent.class, focusOwner);
if (focusedMappingComponent != null)
{
imagePanel.setCurrentButtonAndRepaint(focusedMappingComponent.button);
}
}
else
{
imagePanel.setCurrentButtonAndRepaint(null);
}
}
}
@Override
@ -192,6 +212,20 @@ public class MappingComponent extends JPanel
imagePanel.setCurrentButtonAndRepaint(button);
}
});
keySelectionComboBox.addFocusListener(new FocusAdapter()
{
@Override
public void focusGained(FocusEvent e)
{
imagePanel.setCurrentButtonAndRepaint(button);
}
@Override
public void focusLost(FocusEvent e)
{
imagePanel.setCurrentButtonAndRepaint(null);
}
});
}
return keySelectionComboBox;
}

Binary file not shown.

Before

(image error) Size: 99 KiB

After

(image error) Size: 113 KiB

Binary file not shown.

Before

(image error) Size: 113 KiB