Implemented all axis options. Added modular display of axis to

controller template.
dev
sigonasr2 7 years ago
parent 52f2419a3d
commit 93e062ad42
  1. BIN
      sigIRCv2.jar
  2. 3
      src/sig/ColorPanel.java
  3. 222
      src/sig/modules/Controller/Axis.java
  4. 11
      src/sig/modules/Controller/Button.java
  5. 269
      src/sig/modules/Controller/ControlConfigurationWindow.java
  6. 1
      src/sig/modules/Controller/EditMode.java
  7. 50
      src/sig/modules/Controller/LinkedTextField.java
  8. 51
      src/sig/modules/Controller/ResizeTextField.java
  9. 6
      src/sig/modules/Controller/SizeType.java
  10. 1
      src/sig/modules/Controller/clickablebutton/CopyClickableButton.java
  11. 89
      src/sig/modules/ControllerModule.java
  12. 1
      src/sig/sigIRC.java

Binary file not shown.

@ -8,11 +8,10 @@ import javax.swing.JPanel;
public class ColorPanel extends JPanel{
public ColorPanel() {
}
public Color getBackgroundColor() {
return JColorChooser.showDialog(this, "Background Color Picker", sigIRC.backgroundcol);
return JColorChooser.showDialog(this, "Color Picker", sigIRC.backgroundcol);
}
public Dimension getPreferredSize() {

@ -0,0 +1,222 @@
package sig.modules.Controller;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.Component.Identifier;
import sig.sigIRC;
import sig.modules.ControllerModule;
public class Axis {
List<Identifier> identifiers = new ArrayList<Identifier>();
boolean twoWayAxis = false; //True = 4-way, False = 2-way
Color backgroundColor=Color.BLACK,indicatorColor=Color.WHITE;
double pct_x = 0;
double pct_y = 0;
double pct_width = 0;
double pct_height = 0;
Controller parent_controller;
ControllerModule parent;
double range1,range2; //Range of motion.
int orientation; //0=Left-to-Right, 1=Right-to-Left, 2=Bottom-to-Top, 3=Top-to-Bottom
boolean visible=false;
/**
* 4-way axis Constructor.
*/
public Axis(Rectangle2D.Double rect,
Controller parent_controller,
Identifier identifier,
Identifier identifier2,
Color background_color,
Color indicator_color,
ControllerModule module) {
this.twoWayAxis=false;
this.pct_x = rect.getX();
this.pct_y = rect.getY();
this.pct_width=rect.getWidth();
this.pct_height=rect.getHeight();
if (identifier!=null) {
identifiers.add(identifier);
}
if (identifier2!=null) {
identifiers.add(identifier2);
}
this.parent_controller = parent_controller;
this.parent = module;
this.backgroundColor = background_color;
this.indicatorColor = indicator_color;
}
/**
* 2-way axis Constructor.
*/
public Axis(Rectangle2D.Double rect,
Controller parent_controller,
Identifier identifier,
double starting_range,
double ending_range,
int orientation,
Color background_color,
Color indicator_color,
ControllerModule module) {
this.twoWayAxis=true;
this.pct_x = rect.getX();
this.pct_y = rect.getY();
this.pct_width=rect.getWidth();
this.pct_height=rect.getHeight();
if (identifier!=null) {
identifiers.add(identifier);
}
this.parent_controller = parent_controller;
this.parent = module;
this.range1 = starting_range;
this.range2 = ending_range;
this.orientation = orientation;
this.backgroundColor = background_color;
this.indicatorColor = indicator_color;
}
public void draw(Graphics g) {
if (visible) {
GetAxisDisplay(g,this,
parent.getPosition().getX()+pct_x*parent.getControllerImage().getWidth(sigIRC.panel),
parent.getPosition().getY()+pct_y*parent.getControllerImage().getHeight(sigIRC.panel),
pct_width*parent.getControllerImage().getWidth(sigIRC.panel),
pct_height*parent.getControllerImage().getHeight(sigIRC.panel));
}
}
public void setupBoundsRectangle(Rectangle2D.Double rect) {
this.pct_x = rect.getX();
this.pct_y = rect.getY();
this.pct_width=rect.getWidth();
this.pct_height=rect.getHeight();
}
public boolean isTwoWayAxis() {
return twoWayAxis;
}
public Color getBackgroundColor() {
return backgroundColor;
}
public List<Identifier> getIdentifiers() {
return identifiers;
}
public Color getIndicatorColor() {
return indicatorColor;
}
public double getPctX() {
return pct_x;
}
public double getPctY() {
return pct_y;
}
public double getPctWidth() {
return pct_width;
}
public double getPctHeight() {
return pct_height;
}
public Controller getController() {
return parent_controller;
}
public ControllerModule getModule() {
return parent;
}
public double getRange1() {
return range1;
}
public double getRange2() {
return range2;
}
public int getOrientation() {
return orientation;
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible=visible;
}
public static void GetAxisDisplay(Graphics g, Axis a, double x, double y, double xscale, double yscale) {
if (a.twoWayAxis) {
Color color_identity = g.getColor();
g.setColor(a.backgroundColor);
g.fillRect((int)x, (int)y, (int)xscale, (int)yscale);
g.setColor(a.indicatorColor);
double val = 0;
if (a.identifiers.size()>=1) {
val=a.parent_controller.getComponent(a.identifiers.get(0)).getPollData();
}
double val1 = a.range1;
double val2 = a.range2;
double range_of_motion = (Math.abs(val1)+Math.abs(val2));
double smallest_val = 0;
if (val1<0 || val2<0) {
smallest_val = Math.abs(Math.min(val1, val2));
}
double area_covered_x = (int)(((val+smallest_val)/range_of_motion)*xscale);
double area_covered_y = (int)(((val+smallest_val)/range_of_motion)*yscale);
switch (a.orientation) {
case 0:{
g.fillRect((int)x, (int)y, (int)area_covered_x, (int)yscale);
}break;
case 1:{
g.fillRect((int)(xscale-area_covered_x+x), (int)y, (int)area_covered_x, (int)yscale);
}break;
case 2:{
g.fillRect((int)x, (int)(yscale-area_covered_y+y), (int)xscale, (int)area_covered_y);
}break;
case 3:{
g.fillRect((int)x, (int)y, (int)xscale, (int)area_covered_y);
}break;
}
g.setColor(color_identity);
} else {
double xval=0;
double yval=0;
for (int i=0;i<a.identifiers.size();i++) {
Identifier ident = a.identifiers.get(i);
if (ident.getName().contains("x") ||
ident.getName().contains("X")) {
xval = a.parent_controller.getComponent(ident).getPollData();
} else
if (ident.getName().contains("y") ||
ident.getName().contains("Y")) {
yval = a.parent_controller.getComponent(ident).getPollData();
}
}
Color color_identity = g.getColor();
g.setColor(a.backgroundColor);
g.fillOval((int)x, (int)y, (int)xscale, (int)yscale);
g.setColor(a.indicatorColor);
for (int i=-1;i<2;i++) {
for (int j=-1;j<2;j++) {
g.drawOval((int)(((xval+1)*12*(xscale/32d))+i+x), (int)(((yval+1)*12*(yscale/32d))+j+y), (int)(8d*(xscale/32d)), (int)(8d*(yscale/32d)));
}
}
g.setColor(color_identity);
}
}
}

@ -51,12 +51,21 @@ public class Button {
if (parent_controller.getComponent(ident).getPollData()==value) {
Color col_identity = g.getColor();
g.setColor(pressed_col);
g.fillOval((int)(parent.getPosition().getX()
if (square) {
g.fillRect((int)(parent.getPosition().getX()
+parent.getControllerImage().getWidth(sigIRC.panel)*pct_x)
,(int)(parent.getPosition().getY()
+parent.getControllerImage().getHeight(sigIRC.panel)*pct_y)
,(int)(parent.getControllerImage().getWidth(sigIRC.panel)*pct_width),
(int)(parent.getControllerImage().getHeight(sigIRC.panel)*pct_height));
} else {
g.fillOval((int)(parent.getPosition().getX()
+parent.getControllerImage().getWidth(sigIRC.panel)*pct_x)
,(int)(parent.getPosition().getY()
+parent.getControllerImage().getHeight(sigIRC.panel)*pct_y)
,(int)(parent.getControllerImage().getWidth(sigIRC.panel)*pct_width),
(int)(parent.getControllerImage().getHeight(sigIRC.panel)*pct_height));
}
g.setColor(col_identity);
}
}

@ -6,10 +6,12 @@ import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
@ -17,9 +19,11 @@ import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
@ -27,9 +31,17 @@ import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import net.java.games.input.Component;
import net.java.games.input.Component.Identifier;
import net.java.games.input.Controller;
import sig.ColorPanel;
import sig.sigIRC;
import sig.modules.ControllerModule;
public class ControlConfigurationWindow extends JFrame implements WindowListener{
@ -40,6 +52,15 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
ControllerModule module;
DecimalFormat df = new DecimalFormat("0.000");
PreviewPanel previewpanel;
JRadioButton two_axis_button;
Container twowayAxis_adjustContainer;
Container twowayAxis_adjustOrientationContainer;
LinkedTextField twowayAxis_range1,twowayAxis_range2;
Color axis_background_col = Color.BLACK;
Color axis_indicator_col = Color.WHITE;
int axis_width=32,axis_height=32;
JButton backgroundColor,indicatorColor;
int orientation=0; //0=Left-to-Right, 1=Right-to-Left, 2=Bottom-to-Top, 3=Top-to-Bottom
ActionListener checkboxListener = new ActionListener(){
@Override
public void actionPerformed(ActionEvent ev) {
@ -64,11 +85,14 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
}
};
ActionListener axisListener = new ActionListener(){
@Override
public void actionPerformed(ActionEvent ev) {
switch (ev.getActionCommand()) {
case "four":{
previewpanel.setAxis(false);
twowayAxis_adjustContainer.setVisible(false);
twowayAxis_adjustOrientationContainer.setVisible(false);
}break;
case "two":{
previewpanel.setAxis(true);
@ -82,16 +106,74 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
}
}
}
twowayAxis_adjustContainer.setVisible(true);
twowayAxis_adjustOrientationContainer.setVisible(true);
}break;
}
}
};
ActionListener backgroundColorListener = new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
Color selectedcol = sigIRC.colorpanel.getBackgroundColor();
if (selectedcol!=null) {
axis_background_col = selectedcol;
backgroundColor.setBackground(axis_background_col);
}
}
};
ActionListener indicatorColorListener = new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
Color selectedcol = sigIRC.colorpanel.getBackgroundColor();
if (selectedcol!=null) {
axis_indicator_col = selectedcol;
indicatorColor.setBackground(axis_indicator_col);
}
}
};
ActionListener twoWayAxis_OrientationListener = new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
orientation=Integer.parseInt(e.getActionCommand());
}
};
ActionListener createbuttonListener = new ActionListener(){
@Override
public void actionPerformed(ActionEvent ev) {
if (DataIsValid()) {
Axis a = ConstructTemporaryAxis();
module.setTemporaryAxis(a);
module.setMode(EditMode.DRAGAXISSELECTION);
//module.setMouseWaitTimer(4);
module.getConfigurationWindow().dispatchEvent(new WindowEvent(module.getConfigurationWindow(),WindowEvent.WINDOW_CLOSING));
//module.getConfigurationWindow().setVisible(false);
//module.getConfigurationWindow().dispose();
}
}
private boolean DataIsValid() {
return true;
}
};
public ControlConfigurationWindow(DialogType type, ControllerModule parent_module) {
this.setVisible(true);
this.module = parent_module;
this.module.setConfigureWindow(this);
this.dialog = type;
JTextField twowayAxis_range1 = new JTextField("-1.0",2);
JTextField twowayAxis_range2 = new JTextField("1.0",2);
this.twowayAxis_range1 = new LinkedTextField(twowayAxis_range1);
this.twowayAxis_range2 = new LinkedTextField(twowayAxis_range2);
this.setTitle("Axis Configuration Window");
try {
this.setIconImage(ImageIO.read(new File(sigIRC.BASEDIR+"/sigIRC/sigIRCicon.png")));
} catch (IOException e1) {
e1.printStackTrace();
}
switch (dialog) {
case AXIS_OPTIONS:
@ -129,7 +211,7 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
four_axis_button.setActionCommand("four");
four_axis_button.addActionListener(axisListener);
selectionFrame.add(selectionPanel2);
JRadioButton two_axis_button = new JRadioButton("2-way Axis");
two_axis_button = new JRadioButton("2-way Axis");
two_axis_button.setActionCommand("two");
two_axis_button.addActionListener(axisListener);
axisSelection.add(four_axis_button);
@ -164,25 +246,139 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
container.add(selectionFrame);
JComponent previewLabelPanel = new JPanel();
twowayAxis_adjustContainer = new Container();
JPanel twowayAxis_adjustPanel1 = new JPanel();
JLabel twowayAxis_fromLabel = new JLabel("From");
JLabel twowayAxis_toLabel = new JLabel("to");
JPanel twowayAxis_adjustPanel2 = new JPanel();
twowayAxis_adjustContainer.setLayout(new BoxLayout(twowayAxis_adjustContainer,BoxLayout.PAGE_AXIS));
twowayAxis_adjustPanel2.setLayout(new BoxLayout(twowayAxis_adjustPanel2,BoxLayout.LINE_AXIS));
JLabel twowayAxis_label = new JLabel("Axis Range:",JLabel.LEFT);
twowayAxis_range1.getDocument().addDocumentListener(this.twowayAxis_range1);
twowayAxis_range2.getDocument().addDocumentListener(this.twowayAxis_range2);
twowayAxis_adjustPanel1.add(twowayAxis_label);
twowayAxis_adjustPanel2.add(twowayAxis_fromLabel);
twowayAxis_adjustPanel2.add(twowayAxis_range1);
twowayAxis_adjustPanel2.add(twowayAxis_toLabel);
twowayAxis_adjustPanel2.add(twowayAxis_range2);
twowayAxis_adjustContainer.add(twowayAxis_adjustPanel1);
twowayAxis_adjustContainer.add(twowayAxis_adjustPanel2);
JLabel previewLabel = new JLabel("Axis Preview: ");
previewLabel.setVerticalAlignment(JLabel.TOP);
previewLabel.setHorizontalAlignment(JLabel.RIGHT);
previewLabelPanel.setPreferredSize(new Dimension(120,24));
previewpanel = new PreviewPanel();
previewpanel.setWindow(this);
previewpanel.setPreferredSize(new Dimension(240,32));
previewpanel.setPreferredSize(new Dimension(32,32));
//Border previewBorder = BorderFactory.createEmptyBorder(axis_width, axis_height, axis_width, axis_height);
//previewLabelPanel.setBorder(BorderFactory.createTitledBorder("Axis Preview"));
//previewpanel.add(previewLabel);
if (!two_axis_button.isSelected()) {
twowayAxis_adjustContainer.setVisible(false);
}
Container sizePanel = new Container();
sizePanel.setLayout(new BoxLayout(sizePanel,BoxLayout.PAGE_AXIS));
JLabel widthLabel = new JLabel("Width: ");
JTextField width_field = new JTextField("32",3);
ResizeTextField width_field_listener = new ResizeTextField(width_field,this,SizeType.WIDTH);
width_field.getDocument().addDocumentListener(width_field_listener);
JLabel heightLabel = new JLabel("Height: ");
JTextField height_field = new JTextField("32",3);
ResizeTextField height_field_listener = new ResizeTextField(height_field,this,SizeType.HEIGHT);
height_field.getDocument().addDocumentListener(height_field_listener);
sizePanel.add(widthLabel);
sizePanel.add(width_field);
sizePanel.add(Box.createRigidArea(new Dimension(4,0)));
sizePanel.add(heightLabel);
sizePanel.add(height_field);
sizePanel.setPreferredSize(new Dimension(56,96));
ButtonGroup twoWayAxisOrientationGroup = new ButtonGroup();
JRadioButton twoWayAxis_LeftToRight = new JRadioButton("Left-to-Right",true);
twoWayAxis_LeftToRight.setActionCommand("0");
twoWayAxis_LeftToRight.addActionListener(twoWayAxis_OrientationListener);
JRadioButton twoWayAxis_RightToLeft = new JRadioButton("Right-to-Left");
twoWayAxis_RightToLeft.setActionCommand("1");
twoWayAxis_RightToLeft.addActionListener(twoWayAxis_OrientationListener);
JRadioButton twoWayAxis_BottomToTop = new JRadioButton("Bottom-to-Top");
twoWayAxis_BottomToTop.setActionCommand("2");
twoWayAxis_BottomToTop.addActionListener(twoWayAxis_OrientationListener);
JRadioButton twoWayAxis_TopToBottom = new JRadioButton("Top-to-Bottom");
twoWayAxis_TopToBottom.setActionCommand("3");
twoWayAxis_TopToBottom.addActionListener(twoWayAxis_OrientationListener);
twoWayAxisOrientationGroup.add(twoWayAxis_LeftToRight);
twoWayAxisOrientationGroup.add(twoWayAxis_RightToLeft);
twoWayAxisOrientationGroup.add(twoWayAxis_BottomToTop);
twoWayAxisOrientationGroup.add(twoWayAxis_TopToBottom);
twowayAxis_adjustOrientationContainer = new Container();
twowayAxis_adjustOrientationContainer.setLayout(new BoxLayout(twowayAxis_adjustOrientationContainer,BoxLayout.LINE_AXIS));
twowayAxis_adjustOrientationContainer.add(twoWayAxis_LeftToRight);
twowayAxis_adjustOrientationContainer.add(twoWayAxis_RightToLeft);
twowayAxis_adjustOrientationContainer.add(twoWayAxis_BottomToTop);
twowayAxis_adjustOrientationContainer.add(twoWayAxis_TopToBottom);
if (!two_axis_button.isSelected()) {
twowayAxis_adjustOrientationContainer.setVisible(false);
}
Container colorPickerContainer = new Container();
colorPickerContainer.setLayout(new BoxLayout(colorPickerContainer,BoxLayout.LINE_AXIS));
colorPickerContainer.setPreferredSize(new Dimension(640,64));
backgroundColor = new JButton("");
indicatorColor = new JButton("");
backgroundColor.setBackground(Color.BLACK);
backgroundColor.setPreferredSize(new Dimension(32,32));
backgroundColor.addActionListener(backgroundColorListener);
indicatorColor.setBackground(Color.WHITE);
indicatorColor.setPreferredSize(new Dimension(32,32));
indicatorColor.addActionListener(indicatorColorListener);
previewLabelPanel.add(previewLabel,BorderLayout.NORTH);
previewLabelPanel.add(previewpanel,BorderLayout.CENTER);
JPanel backgroundColorPanel = new JPanel();
backgroundColorPanel.setPreferredSize(new Dimension(32,32));
backgroundColorPanel.setBorder(BorderFactory.createTitledBorder("Background Color"));
JPanel indicatorColorPanel = new JPanel();
indicatorColorPanel.setPreferredSize(new Dimension(32,32));
indicatorColorPanel.setBorder(BorderFactory.createTitledBorder("Indicator Color"));
backgroundColorPanel.add(backgroundColor);
indicatorColorPanel.add(indicatorColor);
colorPickerContainer.add(Box.createHorizontalGlue());
colorPickerContainer.add(backgroundColorPanel);
colorPickerContainer.add(indicatorColorPanel);
colorPickerContainer.add(Box.createHorizontalGlue());
JPanel submitPanel = new JPanel();
submitPanel.setPreferredSize(new Dimension(640,32));
JButton createButton = new JButton("Create Axis");
submitPanel.add(createButton);
createButton.addActionListener(createbuttonListener);
createButton.setMaximumSize(new Dimension(64,24));
previewLabelPanel.add(twowayAxis_adjustContainer);
previewLabelPanel.add(Box.createRigidArea(new Dimension(10,1)));
previewLabelPanel.add(previewLabel);
previewLabelPanel.add(previewpanel);
previewLabelPanel.add(Box.createHorizontalBox());
previewLabelPanel.add(sizePanel);
previewLabelPanel.add(twowayAxis_adjustOrientationContainer);
previewLabelPanel.add(colorPickerContainer);
previewLabelPanel.add(submitPanel);
//previewLabelPanel.setBackground(Color.BLUE);
container.add(previewLabelPanel);
container.setLayout(new BoxLayout(container,BoxLayout.PAGE_AXIS));
this.setMinimumSize(new Dimension(640,480));
this.setMinimumSize(new Dimension(640,548));
this.add(container);
//this.pack();
this.repaint();
@ -243,6 +439,46 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
@Override
public void windowOpened(WindowEvent arg0) {
}
protected Axis ConstructTemporaryAxis() {
Axis a;
if (two_axis_button.isSelected()) {
Identifier ident=null;
for (int i=0;i<analog_controller_component_labels.size();i++) {
if (analog_controller_component_labels.get(i).isSelected()) {
ident=analog_controller_components.get(i).getIdentifier();
break;
}
}
a = new Axis(new Rectangle2D.Double(),
module.getControllers().get(0),
ident,
Double.parseDouble(twowayAxis_range1.getTextField().getText()),
Double.parseDouble(twowayAxis_range2.getTextField().getText()),
orientation,
axis_background_col,
axis_indicator_col,
module);
} else {
List<Identifier> ident=new ArrayList<Identifier>();
ident.add(null);
ident.add(null);
int count=0;
for (int i=0;i<analog_controller_component_labels.size();i++) {
if (analog_controller_component_labels.get(i).isSelected()) {
ident.set(count++,analog_controller_components.get(i).getIdentifier());
}
}
a = new Axis(new Rectangle2D.Double(),
module.getControllers().get(0),
ident.get(0),
ident.get(1),
axis_background_col,
axis_indicator_col,
module);
}
return a;
}
}
class PreviewPanel extends JPanel{
@ -256,27 +492,6 @@ class PreviewPanel extends JPanel{
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (twoAxis) {
g.fillRect(0, 0, 32, 32);
} else {
double xval=0;
double yval=0;
for (int i=0;i<window.analog_controller_component_labels.size();i++) {
if (window.analog_controller_component_labels.get(i).isSelected() &&
window.analog_controller_component_labels.get(i).getText().contains("X")) {
xval=window.analog_controller_components.get(i).getPollData();
} else
if (window.analog_controller_component_labels.get(i).isSelected() &&
window.analog_controller_component_labels.get(i).getText().contains("Y")) {
yval=window.analog_controller_components.get(i).getPollData();
}
}
Color color_identity = g.getColor();
g.setColor(Color.BLACK);
g.fillOval(0, 0, 32, 32);
g.setColor(Color.WHITE);
g.drawOval((int)((xval+1)*12), (int)((yval+1)*12), 8, 8);
g.setColor(color_identity);
}
Axis.GetAxisDisplay(g,window.ConstructTemporaryAxis(),0,0,window.axis_width,window.axis_height);
}
}

@ -2,6 +2,7 @@ package sig.modules.Controller;
public enum EditMode {
DRAGSELECTION, //Drag to set size of button.
DRAGAXISSELECTION, //Drag to set size of button.
SELECTION, //Selects a button for editing
DELETESELECTION, //Delete a button.
BUTTONSET, //Asks for a controller button to set this button to.

@ -0,0 +1,50 @@
package sig.modules.Controller;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import sig.utils.TextUtils;
public class LinkedTextField implements DocumentListener{
JTextField field;
public LinkedTextField(JTextField field) {
this.field=field;
}
public JTextField getTextField() {
return field;
}
public DocumentListener getListener() {
return this;
}
@Override
public void changedUpdate(DocumentEvent e) {
}
protected boolean fieldIsInvalid() {
return !TextUtils.isNumeric(field.getText());
}
@Override
public void insertUpdate(DocumentEvent e) {
ValidateForm();
}
protected void ValidateForm() {
if (fieldIsInvalid()) {
field.setBackground(Color.RED);
} else {
field.setBackground(Color.WHITE);
}
}
@Override
public void removeUpdate(DocumentEvent e) {
ValidateForm();
}
}

@ -0,0 +1,51 @@
package sig.modules.Controller;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
public class ResizeTextField extends LinkedTextField{
ControlConfigurationWindow window;
SizeType type;
public ResizeTextField(JTextField field,ControlConfigurationWindow window,SizeType type) {
super(field);
this.window=window;
this.type=type;
}
@Override
public void insertUpdate(DocumentEvent e) {
ValidateFormAndResizeComponent();
}
@Override
public void removeUpdate(DocumentEvent e) {
ValidateFormAndResizeComponent();
}
private void ValidateFormAndResizeComponent() {
ValidateForm();
ResizeComponent();
}
private void ResizeComponent() {
if (!fieldIsInvalid()) {
switch (type) {
case HEIGHT:
window.axis_height=Integer.parseInt(field.getText());
break;
case WIDTH:
window.axis_width=Integer.parseInt(field.getText());
break;
}
window.previewpanel.setPreferredSize(new Dimension(window.axis_width,window.axis_height));
}
}
}

@ -0,0 +1,6 @@
package sig.modules.Controller;
public enum SizeType {
WIDTH,
HEIGHT
}

@ -20,6 +20,7 @@ public class CopyClickableButton extends ClickableButton{
super.onClickEvent(ev);
if (mouseInsideBounds(ev)) {
window = new ControlConfigurationWindow(DialogType.BUTTON_AXIS_SELECTION,module);
module.resetDragPoints();
}
}
}

@ -22,6 +22,7 @@ import net.java.games.input.Controller.Type;
import net.java.games.input.ControllerEnvironment;
import sig.Module;
import sig.sigIRC;
import sig.modules.Controller.Axis;
import sig.modules.Controller.Button;
import sig.modules.Controller.ClickableButton;
import sig.modules.Controller.ControlConfigurationWindow;
@ -37,6 +38,7 @@ public class ControllerModule extends Module{
Image controller_img;
double imgratio = 1;
List<Button> buttons = new ArrayList<Button>();
List<Axis> axes = new ArrayList<Axis>();
List<ClickableButton> click_buttons = new ArrayList<ClickableButton>();
EditMode MODE = EditMode.DEFAULT;
String status = "";
@ -47,6 +49,8 @@ public class ControllerModule extends Module{
Color buttoncol;
Controller controller;
ControlConfigurationWindow configure_window;
Axis temporary_axis=null;
int mouseclickwait_timer=0;
public ControllerModule(Rectangle2D bounds, String moduleName) {
super(bounds, moduleName);
@ -89,11 +93,27 @@ public class ControllerModule extends Module{
this.end_drag=null;
}
public void setMouseWaitTimer(int ticks) {
this.mouseclickwait_timer=ticks;
}
public Axis getTemporaryAxis() {
return temporary_axis;
}
public void setTemporaryAxis(Axis a) {
this.temporary_axis=a;
}
public void setDragPoints(Point startpoint,Point endpoint) {
this.start_drag=startpoint;
this.end_drag=endpoint;
}
public ControlConfigurationWindow getConfigurationWindow() {
return configure_window;
}
public EditMode getMode() {
return MODE;
}
@ -112,26 +132,29 @@ public class ControllerModule extends Module{
public void mousePressed(MouseEvent ev) {
if (mouseInsideBounds(ev)) {
switch (MODE) {
case DRAGSELECTION:{
case DRAGSELECTION:
case DRAGAXISSELECTION:{
if (start_drag==null) {
start_drag = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY()));
}
}break;
}
}
super.mousePressed(ev);
if (MODE==EditMode.DEFAULT) {
for (ClickableButton cb : click_buttons) {
cb.onClickEvent(ev);
if (MODE==EditMode.DEFAULT) {
for (ClickableButton cb : click_buttons) {
cb.onClickEvent(ev);
}
}
}
super.mousePressed(ev);
}
public void mouseReleased(MouseEvent ev) {
super.mouseReleased(ev);
if (mouseInsideBounds(ev)) {
switch (MODE) {
case DRAGSELECTION:{
case DRAGSELECTION:
case DRAGAXISSELECTION:
{
if (start_drag!=null) {
end_drag = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY()));
double width = (end_drag.getX()-start_drag.getX())/controller_img.getWidth(sigIRC.panel);
@ -144,7 +167,13 @@ public class ControllerModule extends Module{
//buttons.add(new Button(pct_rect.getX(),pct_rect.getY(),pct_rect.getWidth(),pct_rect.getHeight(),controllers.get(0),Identifier.Button._3,Color.RED,this));
//resetDragPoints();
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
MODE=EditMode.BUTTONSET;
if (MODE==EditMode.DRAGSELECTION) {
MODE=EditMode.BUTTONSET;
} else
if (MODE==EditMode.DRAGAXISSELECTION) {
AddAxis();
MODE=EditMode.DEFAULT;
}
}
}
}
@ -152,7 +181,7 @@ public class ControllerModule extends Module{
}
protected boolean mouseInsideBounds(MouseEvent ev) {
return ev.getX()>=getPosition().getX() && ev.getX()<=getPosition().getX()+getPosition().getWidth() &&
return mouseclickwait_timer<=0 && ev.getX()>=getPosition().getX() && ev.getX()<=getPosition().getX()+getPosition().getWidth() &&
ev.getY()>=getPosition().getY() && ev.getY()<=getPosition().getY()+getPosition().getHeight();
}
@ -177,6 +206,9 @@ public class ControllerModule extends Module{
}
}*/
}
if (mouseclickwait_timer>0) {
mouseclickwait_timer--;
}
switch (MODE) {
case DRAGSELECTION:{
int cursortype = sigIRC.panel.getCursor().getType();
@ -191,6 +223,13 @@ public class ControllerModule extends Module{
case COLORSET:{
status="Select a color from the panel.";
}break;
case DRAGAXISSELECTION:{
int cursortype = sigIRC.panel.getCursor().getType();
if (cursortype!=Cursor.CROSSHAIR_CURSOR) {
sigIRC.panel.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
}
status="Drag the axis onto the controller template.";
}break;
default:{
status="";
}
@ -241,6 +280,9 @@ public class ControllerModule extends Module{
for (Button b : buttons) {
b.draw(g);
}
for (Axis a : axes) {
a.draw(g);
}
for (ClickableButton cb : click_buttons) {
cb.draw(g);
}
@ -258,6 +300,28 @@ public class ControllerModule extends Module{
Math.abs(width), Math.abs(height));
g.setColor(color_identity);
}
} else
if (MODE==EditMode.DRAGAXISSELECTION) {
if (start_drag!=null) {
Color color_identity = g.getColor();
g.setColor(temporary_axis.getBackgroundColor());
int width = sigIRC.panel.lastMouseX-
((int)position.getX()+(int)start_drag.getX());
int height = sigIRC.panel.lastMouseY-
((int)position.getY()+(int)start_drag.getY());
if (temporary_axis.isTwoWayAxis()) {
g.fillRect(
(width<0)?sigIRC.panel.lastMouseX:(int)position.getX()+(int)start_drag.getX(),
(height<0)?sigIRC.panel.lastMouseY:(int)position.getY()+(int)start_drag.getY(),
Math.abs(width), Math.abs(height));
} else {
g.fillOval(
(width<0)?sigIRC.panel.lastMouseX:(int)position.getX()+(int)start_drag.getX(),
(height<0)?sigIRC.panel.lastMouseY:(int)position.getY()+(int)start_drag.getY(),
Math.abs(width), Math.abs(height));
}
g.setColor(color_identity);
}
}
}
@ -272,6 +336,13 @@ public class ControllerModule extends Module{
}
}
private void AddAxis() {
temporary_axis.setupBoundsRectangle(stored_rect);
temporary_axis.setVisible(true);
axes.add(temporary_axis);
temporary_axis=null;
}
private void AddButton() {
buttons.add(new Button(stored_rect,controller,stored_controller_button,stored_controller_value,buttoncol,this));
StringBuilder sb = new StringBuilder();

@ -166,6 +166,7 @@ public class sigIRC{
usernameFont = config.getProperty("usernameFont","Gill Sans");
touhoumotherConsoleFont = config.getProperty("touhoumotherConsoleFont","Agency FB Bold");
touhoumothermodule_enabled = config.getBoolean("Module_touhoumother_Enabled",false);
controllermodule_enabled = config.getBoolean("Module_controller_Enabled",false);
twitchmodule_enabled = config.getBoolean("Module_twitch_Enabled",true);
chatlogmodule_enabled = config.getBoolean("Module_chatlog_Enabled",true);
twitchmodule_width = config.getInteger("TWITCH_module_width",500);

Loading…
Cancel
Save