Completed implementation of Controller Module.

dev
sigonasr2 7 years ago
parent 08191bb5eb
commit 4e03806a4a
  1. BIN
      sigIRCv2.jar
  2. 34
      src/sig/modules/Controller/Axis.java
  3. 52
      src/sig/modules/Controller/ControlConfigurationWindow.java
  4. 7
      src/sig/modules/Controller/DataValidationReason.java
  5. 11
      src/sig/modules/Controller/Element.java
  6. 79
      src/sig/modules/Controller/RepeatedKey.java
  7. 187
      src/sig/modules/ControllerModule.java

Binary file not shown.

@ -94,6 +94,16 @@ public class Axis extends Element{
} }
} }
public void drawIndicator(Graphics g) {
if (visible) {
GetAxisIndicatorDisplay(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 Color getSelectionColor() { public Color getSelectionColor() {
return backgroundColor; return backgroundColor;
} }
@ -224,14 +234,34 @@ public class Axis extends Element{
Color color_identity = g.getColor(); Color color_identity = g.getColor();
g.setColor(a.backgroundColor); g.setColor(a.backgroundColor);
g.fillOval((int)x, (int)y, (int)xscale, (int)yscale); g.fillOval((int)x, (int)y, (int)xscale, (int)yscale);
g.setColor(color_identity);
}
}
public static void GetAxisIndicatorDisplay(Graphics g, Axis a, double x, double y, double xscale, double yscale) {
if (!a.twoWayAxis) {
double xval=0;
double yval=0;
if (a.identifiers.size()>0 && a.identifiers.get(0)!=null) {
xval = a.parent_controller.getAxisValue(a.identifiers.get(0))*((a.x_invert)?-1:1);
}
if (a.identifiers.size()>1 && a.identifiers.get(1)!=null) {
yval = a.parent_controller.getAxisValue(a.identifiers.get(1))*((a.y_invert)?-1:1);
}
DrawIndicator(g, a, x, y, xscale, yscale, xval, yval);
}
}
private static void DrawIndicator(Graphics g, Axis a, double x, double y, double xscale, double yscale, double xval,
double yval) {
g.setColor(a.indicatorColor); g.setColor(a.indicatorColor);
for (int i=-1;i<2;i++) { for (int i=-1;i<2;i++) {
for (int j=-1;j<2;j++) { 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.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);
}
} }

@ -30,6 +30,7 @@ import javax.swing.JDialog;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JLayeredPane; import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JRadioButton; import javax.swing.JRadioButton;
import javax.swing.JTextField; import javax.swing.JTextField;
@ -41,6 +42,7 @@ import javax.swing.event.DocumentListener;
import sig.ColorPanel; import sig.ColorPanel;
import sig.sigIRC; import sig.sigIRC;
import sig.modules.ControllerModule; import sig.modules.ControllerModule;
import sig.utils.TextUtils;
public class ControlConfigurationWindow extends JFrame implements WindowListener{ public class ControlConfigurationWindow extends JFrame implements WindowListener{
DialogType dialog; DialogType dialog;
@ -59,6 +61,8 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
int axis_width=32,axis_height=32; int axis_width=32,axis_height=32;
JButton backgroundColor,indicatorColor; JButton backgroundColor,indicatorColor;
boolean x_invert,y_invert,axis_invert; boolean x_invert,y_invert,axis_invert;
public static Color lastpicked_back_col = Color.BLACK;
public static Color lastpicked_indicator_col = Color.WHITE;
int orientation=0; //0=Left-to-Right, 1=Right-to-Left, 2=Bottom-to-Top, 3=Top-to-Bottom int orientation=0; //0=Left-to-Right, 1=Right-to-Left, 2=Bottom-to-Top, 3=Top-to-Bottom
JCheckBox width_invert,height_invert; JCheckBox width_invert,height_invert;
java.awt.Component extra_space; java.awt.Component extra_space;
@ -119,8 +123,9 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
ActionListener backgroundColorListener = new ActionListener(){ ActionListener backgroundColorListener = new ActionListener(){
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Color selectedcol = sigIRC.colorpanel.getBackgroundColor(null); Color selectedcol = sigIRC.colorpanel.getBackgroundColor(lastpicked_back_col);
if (selectedcol!=null) { if (selectedcol!=null) {
lastpicked_back_col = selectedcol;
axis_background_col = selectedcol; axis_background_col = selectedcol;
backgroundColor.setBackground(axis_background_col); backgroundColor.setBackground(axis_background_col);
} }
@ -129,8 +134,9 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
ActionListener indicatorColorListener = new ActionListener(){ ActionListener indicatorColorListener = new ActionListener(){
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Color selectedcol = sigIRC.colorpanel.getBackgroundColor(null); Color selectedcol = sigIRC.colorpanel.getBackgroundColor(lastpicked_indicator_col);
if (selectedcol!=null) { if (selectedcol!=null) {
lastpicked_indicator_col = selectedcol;
axis_indicator_col = selectedcol; axis_indicator_col = selectedcol;
indicatorColor.setBackground(axis_indicator_col); indicatorColor.setBackground(axis_indicator_col);
} }
@ -145,7 +151,8 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
ActionListener createbuttonListener = new ActionListener(){ ActionListener createbuttonListener = new ActionListener(){
@Override @Override
public void actionPerformed(ActionEvent ev) { public void actionPerformed(ActionEvent ev) {
if (DataIsValid()) { DataValidationReason err_check = DataIsValid();
if (err_check == DataValidationReason.GOOD) {
Axis a = ConstructTemporaryAxis(); Axis a = ConstructTemporaryAxis();
module.setTemporaryAxis(a); module.setTemporaryAxis(a);
module.setMode(EditMode.DRAGAXISSELECTION); module.setMode(EditMode.DRAGAXISSELECTION);
@ -153,11 +160,41 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
module.getConfigurationWindow().dispatchEvent(new WindowEvent(module.getConfigurationWindow(),WindowEvent.WINDOW_CLOSING)); module.getConfigurationWindow().dispatchEvent(new WindowEvent(module.getConfigurationWindow(),WindowEvent.WINDOW_CLOSING));
//module.getConfigurationWindow().setVisible(false); //module.getConfigurationWindow().setVisible(false);
//module.getConfigurationWindow().dispose(); //module.getConfigurationWindow().dispose();
} else {
DisplayError(err_check);
}
}
private void DisplayError(DataValidationReason err_check) {
switch (err_check) {
case AXIS_MISSING:
JOptionPane.showMessageDialog(module.getConfigurationWindow(), "You did not select the correct number of axes to make this axis control!", "Error", JOptionPane.WARNING_MESSAGE);
break;
case INVALID_RANGE_SIZE:
JOptionPane.showMessageDialog(module.getConfigurationWindow(), "You did not specify valid range numbers for your axis. (Usually it's between -1.0 and 1.0. Make sure the box is not red.)", "Error", JOptionPane.WARNING_MESSAGE);
break;
} }
} }
private boolean DataIsValid() { private DataValidationReason DataIsValid() {
return true; if ((!TextUtils.isNumeric(twowayAxis_range1.getTextField().getText()) ||
!TextUtils.isNumeric(twowayAxis_range2.getTextField().getText())) &&
two_axis_button.isSelected()) {
return DataValidationReason.INVALID_RANGE_SIZE;
} else
{
int numb_checked = 0;
int requirement = (two_axis_button.isSelected())?1:2;
for (JCheckBox cb : analog_controller_component_labels) {
if (cb.isSelected()) {
numb_checked++;
}
}
if (numb_checked!=requirement) {
return DataValidationReason.AXIS_MISSING;
}
}
return DataValidationReason.GOOD;
} }
}; };
ActionListener invertListener = new ActionListener(){ ActionListener invertListener = new ActionListener(){
@ -176,6 +213,7 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
switch (ev.getActionCommand()) { switch (ev.getActionCommand()) {
case "add_button":{ case "add_button":{
module.setMode(EditMode.DRAGSELECTION); module.setMode(EditMode.DRAGSELECTION);
//System.out.println("Called Drag Selection mode.");
sigIRC.panel.grabFocus(); sigIRC.panel.grabFocus();
module.getConfigurationWindow().dispatchEvent(new WindowEvent(module.getConfigurationWindow(),WindowEvent.WINDOW_CLOSING)); module.getConfigurationWindow().dispatchEvent(new WindowEvent(module.getConfigurationWindow(),WindowEvent.WINDOW_CLOSING));
}break; }break;
@ -554,8 +592,8 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
a = new Axis(new Rectangle2D.Double(), a = new Axis(new Rectangle2D.Double(),
module.getControllers().get(0), module.getControllers().get(0),
ident, ident,
Double.parseDouble(twowayAxis_range1.getTextField().getText()), Double.parseDouble((!TextUtils.isNumeric(twowayAxis_range1.getTextField().getText())?Double.toString(-1):twowayAxis_range1.getTextField().getText())),
Double.parseDouble(twowayAxis_range2.getTextField().getText()), Double.parseDouble((!TextUtils.isNumeric(twowayAxis_range2.getTextField().getText())?Double.toString(1):twowayAxis_range2.getTextField().getText())),
orientation, orientation,
axis_background_col, axis_background_col,
axis_indicator_col, axis_indicator_col,

@ -0,0 +1,7 @@
package sig.modules.Controller;
public enum DataValidationReason {
GOOD,
INVALID_RANGE_SIZE,
AXIS_MISSING;
}

@ -5,6 +5,7 @@ import java.awt.Image;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import sig.sigIRC; import sig.sigIRC;
import sig.modules.ControllerModule;
public class Element { public class Element {
protected double pct_x = 0; protected double pct_x = 0;
@ -37,4 +38,14 @@ public class Element {
} }
return null; return null;
} }
public void remove(ControllerModule module) {
if (this instanceof Button) {
module.getButtons().remove(this);
module.SaveButtonData();
} else
if (this instanceof Axis) {
module.getAxes().remove(this);
module.SaveAxisData();
}
}
} }

@ -0,0 +1,79 @@
package sig.modules.Controller;
import sig.modules.ControllerModule;
import sig.utils.FileUtils;
public class RepeatedKey {
int keycode;
boolean isKeyPressed;
Thread schedulerThread;
Runnable action;
Element element;
ControllerModule module;
boolean held_down=false,repeat=false;
final static int HOLD_DELAY=500;
final static int REPEAT_DELAY=100;
public RepeatedKey(int keycode, ControllerModule module,
Runnable action) {
this.keycode=keycode;
this.module=module;
this.action=action;
}
public int getKeyCode() {
return keycode;
}
public boolean isKeyPressed() {
return this.isKeyPressed;
}
public void setHeldStatus(boolean heldDown) {
this.held_down=heldDown;
}
public void setRepeatStatus(boolean repeat) {
this.repeat = repeat;
}
public void setKeyPressed(boolean isPressed) {
this.isKeyPressed=isPressed;
if (!held_down) {
held_down=true;
schedulerThread = new Thread() {
public void run() {
try {
Thread.sleep(HOLD_DELAY);
if (!isKeyPressed()) {
setHeldStatus(false);
} else {
setRepeatStatus(true);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
} else {
if (repeat) {
schedulerThread = new Thread() {
public void run() {
try {
while (repeat) {
action.run();
Thread.sleep(REPEAT_DELAY);
if (!isKeyPressed()) {
repeat=false;
held_down=false;
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
}
}
}
}

@ -6,6 +6,7 @@ import java.awt.Graphics;
import java.awt.Image; import java.awt.Image;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
@ -15,6 +16,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
@ -29,6 +31,7 @@ import sig.modules.Controller.Controller;
import sig.modules.Controller.EditMode; import sig.modules.Controller.EditMode;
import sig.modules.Controller.Element; import sig.modules.Controller.Element;
import sig.modules.Controller.Identifier; import sig.modules.Controller.Identifier;
import sig.modules.Controller.RepeatedKey;
import sig.modules.Controller.Type; import sig.modules.Controller.Type;
import sig.modules.Controller.clickablebutton.AddClickableButton; import sig.modules.Controller.clickablebutton.AddClickableButton;
import sig.modules.Controller.clickablebutton.CopyClickableButton; import sig.modules.Controller.clickablebutton.CopyClickableButton;
@ -38,7 +41,7 @@ import sig.utils.FileUtils;
public class ControllerModule extends Module{ public class ControllerModule extends Module{
public final static String CONTROLLERPATH = sigIRC.BASEDIR+"sigIRC/controller/"; public final static String CONTROLLERPATH = sigIRC.BASEDIR+"sigIRC/controller/";
List<Controller> controllers = new ArrayList<Controller>(); List<Controller> controllers = new ArrayList<Controller>();
Image controller_img; Image controller_img,controller_overlay_img;
double imgratio = 1; double imgratio = 1;
List<Button> buttons = new ArrayList<Button>(); List<Button> buttons = new ArrayList<Button>();
List<Axis> axes = new ArrayList<Axis>(); List<Axis> axes = new ArrayList<Axis>();
@ -69,6 +72,8 @@ public class ControllerModule extends Module{
boolean resizing=false; boolean resizing=false;
double xoffset=0,yoffset=0; double xoffset=0,yoffset=0;
final static int RESIZE_BORDER = 5; final static int RESIZE_BORDER = 5;
final static double MINIMUM_ELEMENT_SIZE=8;
boolean proportionalResize=false;
public ControllerModule(Rectangle2D bounds, String moduleName) { public ControllerModule(Rectangle2D bounds, String moduleName) {
super(bounds, moduleName); super(bounds, moduleName);
@ -89,6 +94,7 @@ public class ControllerModule extends Module{
controllers.addAll(ca); controllers.addAll(ca);
try { try {
controller_img = ImageIO.read(new File(CONTROLLERPATH+"controller_template.png")).getScaledInstance((int)position.getWidth(), -1, 0); controller_img = ImageIO.read(new File(CONTROLLERPATH+"controller_template.png")).getScaledInstance((int)position.getWidth(), -1, 0);
controller_overlay_img = ImageIO.read(new File(CONTROLLERPATH+"controller_overlay.png")).getScaledInstance((int)position.getWidth(), -1, 0);
//System.out.println("Size of controller: "+controller_img.getWidth(sigIRC.panel)+","+controller_img.getHeight(sigIRC.panel)); //System.out.println("Size of controller: "+controller_img.getWidth(sigIRC.panel)+","+controller_img.getHeight(sigIRC.panel));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -145,6 +151,13 @@ public class ControllerModule extends Module{
return stored_rect; return stored_rect;
} }
public List<Button> getButtons() {
return buttons;
}
public List<Axis> getAxes() {
return axes;
}
public void ApplyConfigWindowProperties() { public void ApplyConfigWindowProperties() {
sigIRC.controllermodule_X=(int)position.getX(); sigIRC.controllermodule_X=(int)position.getX();
sigIRC.controllermodule_Y=(int)position.getY(); sigIRC.controllermodule_Y=(int)position.getY();
@ -165,12 +178,10 @@ public class ControllerModule extends Module{
start_drag = mouse_position; start_drag = mouse_position;
} }
}break; }break;
} case DEFAULT:{
if (MODE==EditMode.DEFAULT) {
for (ClickableButton cb : click_buttons) { for (ClickableButton cb : click_buttons) {
cb.onClickEvent(ev); cb.onClickEvent(ev);
} }
}
if (selectedElement!=null && resizing_direction!=0 && !resizing && extendBoundaries(selectedElement.getPixelBounds(controller_img),3).contains(mouse_position)) { if (selectedElement!=null && resizing_direction!=0 && !resizing && extendBoundaries(selectedElement.getPixelBounds(controller_img),3).contains(mouse_position)) {
resizing=true; resizing=true;
resize_refpoint=mouse_position; resize_refpoint=mouse_position;
@ -180,33 +191,37 @@ public class ControllerModule extends Module{
xoffset = selectedElement.getPixelBounds(controller_img).getX()-mouse_position.getX(); xoffset = selectedElement.getPixelBounds(controller_img).getX()-mouse_position.getX();
yoffset = selectedElement.getPixelBounds(controller_img).getY()-mouse_position.getY(); yoffset = selectedElement.getPixelBounds(controller_img).getY()-mouse_position.getY();
} else { } else {
selectedElement=null; selectedElement = findMouseoverElement(mouse_position);
}
}
}
//System.out.println("Selected element "+selectedElement+". Mouse Point: "+ev.getPoint());
}
super.mousePressed(ev);
}
private Element findMouseoverElement(Point mouse_position) {
for (Element e : buttons) { for (Element e : buttons) {
//System.out.println("Checking bounds "+e.getPixelBounds(controller_img)); //System.out.println("Checking bounds "+e.getPixelBounds(controller_img));
if (e.getPixelBounds(controller_img).contains(mouse_position)) { if (e.getPixelBounds(controller_img).contains(mouse_position)) {
selectedElement = e; return e;
break;
} }
} }
if (selectedElement==null) {
for (Element e : axes) { for (Element e : axes) {
//System.out.println("Checking bounds "+e.getPixelBounds(controller_img)); //System.out.println("Checking bounds "+e.getPixelBounds(controller_img));
if (e.getPixelBounds(controller_img).contains(mouse_position)) { if (e.getPixelBounds(controller_img).contains(mouse_position)) {
selectedElement = e; return e;
break;
}
}
} }
} }
//System.out.println("Selected element "+selectedElement+". Mouse Point: "+ev.getPoint()); return null;
}
super.mousePressed(ev);
} }
public void mouseReleased(MouseEvent ev) { public void mouseReleased(MouseEvent ev) {
//System.out.println("Mode before is "+MODE);
if (resizing) { if (resizing) {
Point mouse_position = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY())); Point mouse_position = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY()));
PerformResize(mouse_position); PerformResize(mouse_position);
setConstraints();
resizing=false; resizing=false;
resizing_direction=0; resizing_direction=0;
SaveElementData(); SaveElementData();
@ -218,6 +233,7 @@ public class ControllerModule extends Module{
(mouse_position.getY()+yoffset)/controller_img.getHeight(sigIRC.panel), (mouse_position.getY()+yoffset)/controller_img.getHeight(sigIRC.panel),
selectedElement.getBounds().getWidth(), selectedElement.getBounds().getWidth(),
selectedElement.getBounds().getHeight())); selectedElement.getBounds().getHeight()));
setConstraints();
dragging=false; dragging=false;
SaveElementData(); SaveElementData();
return; return;
@ -235,20 +251,26 @@ public class ControllerModule extends Module{
stored_rect = new Rectangle2D.Double( stored_rect = new Rectangle2D.Double(
(width<0)?end_drag.getX()/controller_img.getWidth(sigIRC.panel):start_drag.getX()/controller_img.getWidth(sigIRC.panel), (width<0)?end_drag.getX()/controller_img.getWidth(sigIRC.panel):start_drag.getX()/controller_img.getWidth(sigIRC.panel),
(height<0)?end_drag.getY()/controller_img.getHeight(sigIRC.panel):start_drag.getY()/controller_img.getHeight(sigIRC.panel), (height<0)?end_drag.getY()/controller_img.getHeight(sigIRC.panel):start_drag.getY()/controller_img.getHeight(sigIRC.panel),
Math.abs((end_drag.getX()-start_drag.getX())/controller_img.getWidth(sigIRC.panel)), Math.max(MINIMUM_ELEMENT_SIZE/controller_img.getWidth(sigIRC.panel),Math.abs((end_drag.getX()-start_drag.getX())/controller_img.getWidth(sigIRC.panel))),
Math.abs((end_drag.getY()-start_drag.getY())/controller_img.getHeight(sigIRC.panel))); Math.max(MINIMUM_ELEMENT_SIZE/controller_img.getHeight(sigIRC.panel),Math.abs((end_drag.getY()-start_drag.getY())/controller_img.getHeight(sigIRC.panel))));
//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)); //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(); //resetDragPoints();
if (!inDragZone) {
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
//System.out.println(MODE);
if (MODE==EditMode.DRAGSELECTION) { if (MODE==EditMode.DRAGSELECTION) {
MODE=EditMode.BUTTONSET; MODE=EditMode.BUTTONSET;
//System.out.println("Set Button");
} else } else
if (MODE==EditMode.DRAGAXISSELECTION) { if (MODE==EditMode.DRAGAXISSELECTION) {
//System.out.println("Add Axis");
AddAxis(); AddAxis();
MODE=EditMode.DEFAULT; MODE=EditMode.DEFAULT;
//System.out.println(MODE);
} }
} }
} }break;
case POSITIONSELECTION:{ case POSITIONSELECTION:{
Point mouse_click = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY())); Point mouse_click = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY()));
stored_rect = new Rectangle2D.Double( stored_rect = new Rectangle2D.Double(
@ -260,9 +282,11 @@ public class ControllerModule extends Module{
}break; }break;
} }
} }
//System.out.println("Mode after is "+MODE);
} }
private void PerformResize(Point mouse_position) { private void PerformResize(Point mouse_position) {
double aspectRatio = (double)selectedElement.getBounds().getWidth()/selectedElement.getBounds().getHeight();
switch (resizing_direction) { switch (resizing_direction) {
case 1:{ case 1:{
AdjustY(mouse_position); AdjustY(mouse_position);
@ -293,20 +317,33 @@ public class ControllerModule extends Module{
AdjustY(mouse_position); AdjustY(mouse_position);
}break; }break;
} }
if (proportionalResize) {
resizeProportionally(aspectRatio);
}
resize_refpoint=mouse_position; resize_refpoint=mouse_position;
} }
private void resizeProportionally(double aspectRatio) {
boolean xAxisLarger = false;
xAxisLarger = (selectedElement.getBounds().getWidth()>selectedElement.getBounds().getHeight());
selectedElement.setBounds(new Rectangle2D.Double(
selectedElement.getBounds().getX(),
selectedElement.getBounds().getY(),
(xAxisLarger)?selectedElement.getBounds().getWidth():(selectedElement.getBounds().getHeight()*aspectRatio),
(xAxisLarger)?selectedElement.getBounds().getWidth()*(1/aspectRatio):(selectedElement.getBounds().getHeight())));
}
private void AdjustY(Point mouse_position) { private void AdjustY(Point mouse_position) {
selectedElement.setBounds(new Rectangle2D.Double(selectedElement.getBounds().getX(), selectedElement.setBounds(new Rectangle2D.Double(selectedElement.getBounds().getX(),
(mouse_position.getY()-resize_refpoint.getY()+selectedElement.getPixelBounds(controller_img).getY())/controller_img.getHeight(sigIRC.panel), (mouse_position.getY()-resize_refpoint.getY()+selectedElement.getPixelBounds(controller_img).getY())/controller_img.getHeight(sigIRC.panel),
selectedElement.getBounds().getWidth(), selectedElement.getBounds().getWidth(),
(resize_refpoint.getY()-mouse_position.getY()+selectedElement.getPixelBounds(controller_img).getHeight())/controller_img.getHeight(sigIRC.panel))); Math.max(MINIMUM_ELEMENT_SIZE/controller_img.getHeight(sigIRC.panel),(resize_refpoint.getY()-mouse_position.getY()+selectedElement.getPixelBounds(controller_img).getHeight())/controller_img.getHeight(sigIRC.panel))));
} }
private void AdjustX(Point mouse_position) { private void AdjustX(Point mouse_position) {
selectedElement.setBounds(new Rectangle2D.Double((mouse_position.getX()-resize_refpoint.getX()+selectedElement.getPixelBounds(controller_img).getX())/controller_img.getWidth(sigIRC.panel), selectedElement.setBounds(new Rectangle2D.Double((mouse_position.getX()-resize_refpoint.getX()+selectedElement.getPixelBounds(controller_img).getX())/controller_img.getWidth(sigIRC.panel),
selectedElement.getBounds().getY(), selectedElement.getBounds().getY(),
(resize_refpoint.getX()-mouse_position.getX()+selectedElement.getPixelBounds(controller_img).getWidth())/controller_img.getWidth(sigIRC.panel), Math.max(MINIMUM_ELEMENT_SIZE/controller_img.getWidth(sigIRC.panel),(resize_refpoint.getX()-mouse_position.getX()+selectedElement.getPixelBounds(controller_img).getWidth())/controller_img.getWidth(sigIRC.panel)),
selectedElement.getBounds().getHeight())); selectedElement.getBounds().getHeight()));
} }
@ -314,13 +351,13 @@ public class ControllerModule extends Module{
selectedElement.setBounds(new Rectangle2D.Double(selectedElement.getBounds().getX(), selectedElement.setBounds(new Rectangle2D.Double(selectedElement.getBounds().getX(),
selectedElement.getBounds().getY(), selectedElement.getBounds().getY(),
selectedElement.getBounds().getWidth(), selectedElement.getBounds().getWidth(),
(mouse_position.getY()-resize_refpoint.getY()+selectedElement.getPixelBounds(controller_img).getHeight())/controller_img.getHeight(sigIRC.panel))); Math.max(MINIMUM_ELEMENT_SIZE/controller_img.getHeight(sigIRC.panel),(mouse_position.getY()-resize_refpoint.getY()+selectedElement.getPixelBounds(controller_img).getHeight())/controller_img.getHeight(sigIRC.panel))));
} }
private void AdjustWidth(Point mouse_position) { private void AdjustWidth(Point mouse_position) {
selectedElement.setBounds(new Rectangle2D.Double(selectedElement.getBounds().getX(), selectedElement.setBounds(new Rectangle2D.Double(selectedElement.getBounds().getX(),
selectedElement.getBounds().getY(), selectedElement.getBounds().getY(),
(mouse_position.getX()-resize_refpoint.getX()+selectedElement.getPixelBounds(controller_img).getWidth())/controller_img.getWidth(sigIRC.panel), Math.max(MINIMUM_ELEMENT_SIZE/controller_img.getWidth(sigIRC.panel),(mouse_position.getX()-resize_refpoint.getX()+selectedElement.getPixelBounds(controller_img).getWidth())/controller_img.getWidth(sigIRC.panel)),
selectedElement.getBounds().getHeight())); selectedElement.getBounds().getHeight()));
} }
@ -345,12 +382,28 @@ public class ControllerModule extends Module{
Point mouse_position = new Point((int)(sigIRC.panel.lastMouseX-getPosition().getX()),(int)(sigIRC.panel.lastMouseY-getPosition().getY())); Point mouse_position = new Point((int)(sigIRC.panel.lastMouseX-getPosition().getX()),(int)(sigIRC.panel.lastMouseY-getPosition().getY()));
if (resizing) { if (resizing) {
PerformResize(mouse_position); PerformResize(mouse_position);
setConstraints();
} }
if (dragging) { if (dragging) {
selectedElement.setBounds(new Rectangle2D.Double((mouse_position.getX()+xoffset)/controller_img.getWidth(sigIRC.panel), selectedElement.setBounds(new Rectangle2D.Double((mouse_position.getX()+xoffset)/controller_img.getWidth(sigIRC.panel),
(mouse_position.getY()+yoffset)/controller_img.getHeight(sigIRC.panel), (mouse_position.getY()+yoffset)/controller_img.getHeight(sigIRC.panel),
selectedElement.getBounds().getWidth(), selectedElement.getBounds().getWidth(),
selectedElement.getBounds().getHeight())); selectedElement.getBounds().getHeight()));
setConstraints();
}
if (!inDragZone && selectedElement==null) {
if (findMouseoverElement(mouse_position)!=null) {
int cursortype = sigIRC.panel.getCursor().getType();
if (cursortype!=Cursor.HAND_CURSOR) {
sigIRC.panel.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
} else {
int cursortype = sigIRC.panel.getCursor().getType();
if (cursortype!=Cursor.DEFAULT_CURSOR &&
!inDragZone) {
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
} }
if (selectedElement!=null && extendBoundaries(selectedElement.getPixelBounds(controller_img),3).contains(mouse_position)) { if (selectedElement!=null && extendBoundaries(selectedElement.getPixelBounds(controller_img),3).contains(mouse_position)) {
if (!resizing) { if (!resizing) {
@ -423,7 +476,8 @@ public class ControllerModule extends Module{
}break; }break;
default: default:
int cursortype = sigIRC.panel.getCursor().getType(); int cursortype = sigIRC.panel.getCursor().getType();
if (cursortype!=Cursor.DEFAULT_CURSOR) { if (cursortype!=Cursor.DEFAULT_CURSOR &&
!inDragZone) {
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
} }
} }
@ -449,7 +503,7 @@ public class ControllerModule extends Module{
} else } else
if (selectedElement!=null) { if (selectedElement!=null) {
int cursortype = sigIRC.panel.getCursor().getType(); int cursortype = sigIRC.panel.getCursor().getType();
if (cursortype!=Cursor.DEFAULT_CURSOR) { if (cursortype!=Cursor.DEFAULT_CURSOR && !inDragZone) {
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
} }
} }
@ -516,6 +570,14 @@ public class ControllerModule extends Module{
} }
} }
public void setConstraints() {
selectedElement.setBounds(new Rectangle2D.Double(Math.max(0, Math.min((this.getPosition().getWidth()/controller_img.getWidth(sigIRC.panel))-selectedElement.getBounds().getWidth(), selectedElement.getBounds().getX())),
Math.max(0, Math.min((this.getPosition().getHeight()/controller_img.getHeight(sigIRC.panel))-selectedElement.getBounds().getHeight(), selectedElement.getBounds().getY())),
selectedElement.getBounds().getWidth(),
selectedElement.getBounds().getHeight()));
//System.out.println(selectedElement.getBounds());
}
public Image getControllerImage() { public Image getControllerImage() {
return controller_img; return controller_img;
} }
@ -534,7 +596,6 @@ public class ControllerModule extends Module{
}*/ }*/
} }
g.drawImage(controller_img, (int)(position.getX()), (int)(position.getY()), sigIRC.panel); g.drawImage(controller_img, (int)(position.getX()), (int)(position.getY()), sigIRC.panel);
}
for (ClickableButton cb : click_buttons) { for (ClickableButton cb : click_buttons) {
cb.draw(g); cb.draw(g);
} }
@ -592,6 +653,11 @@ public class ControllerModule extends Module{
g.setColor(color_identity); g.setColor(color_identity);
} }
} }
g.drawImage(controller_overlay_img, (int)(position.getX()), (int)(position.getY()), sigIRC.panel);
for (Axis a : axes) {
a.drawIndicator(g);
}
if (selectedElement!=null) { if (selectedElement!=null) {
Rectangle2D.Double rect = selectedElement.getPixelBounds(controller_img); Rectangle2D.Double rect = selectedElement.getPixelBounds(controller_img);
@ -604,8 +670,10 @@ public class ControllerModule extends Module{
} }
g.setColor(color_identity); g.setColor(color_identity);
} }
DrawUtils.drawText(g, position.getX(), position.getY()+8, Color.BLACK, status); DrawUtils.drawText(g, position.getX(), position.getY()+8, Color.BLACK, status);
} else {
DrawUtils.drawText(g, position.getX(), position.getY()+8, Color.BLACK, "No controller detected!");
}
} }
private void LoadButtonAndAxisData() { private void LoadButtonAndAxisData() {
@ -630,6 +698,66 @@ public class ControllerModule extends Module{
} }
} }
public void keypressed(KeyEvent ev) {
if (ev.getKeyCode()==KeyEvent.VK_DELETE &&
selectedElement!=null) {
if (JOptionPane.showConfirmDialog(sigIRC.panel, "Are you sure you want to remove this "+((selectedElement instanceof Button)?"button":"axis")+"?","Confirm Delete",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION) {
selectedElement.remove(this);
selectedElement=null;
}
}
if (ev.getKeyCode()==KeyEvent.VK_SHIFT) {
proportionalResize = true;
}
/*for (RepeatedKey rk : repeatKeys) {
if (rk.getKeyCode()==ev.getKeyCode()) {
rk.setKeyPressed(true);
}
}*/
if (selectedElement!=null) {
boolean adjust=false;
int[] move = new int[]{0,0};
switch (ev.getKeyCode()) {
case (KeyEvent.VK_RIGHT):{
adjust=true;
move[0]+=1;
}break;
case (KeyEvent.VK_UP):{
adjust=true;
move[1]-=1;
}break;
case (KeyEvent.VK_DOWN):{
adjust=true;
move[1]+=1;
}break;
case (KeyEvent.VK_LEFT):{
adjust=true;
move[0]-=1;
}break;
}
if (adjust) {
selectedElement.setBounds(
new Rectangle2D.Double(selectedElement.getBounds().getX()+(move[0]*(1d/controller_img.getWidth(sigIRC.panel))),
selectedElement.getBounds().getY()+(move[1]*(1d/controller_img.getWidth(sigIRC.panel))),
selectedElement.getBounds().getWidth(),
selectedElement.getBounds().getHeight()));
setConstraints();
SaveElementData();
}
}
}
public void keyreleased(KeyEvent ev) {
if (ev.getKeyCode()==KeyEvent.VK_SHIFT) {
proportionalResize = false;
}
/*for (RepeatedKey rk : repeatKeys) {
if (rk.getKeyCode()==ev.getKeyCode()) {
rk.setKeyPressed(false);
}
}*/
}
private void AddAxis() { private void AddAxis() {
temporary_axis.setupBoundsRectangle(stored_rect); temporary_axis.setupBoundsRectangle(stored_rect);
temporary_axis.setVisible(true); temporary_axis.setVisible(true);
@ -638,7 +766,7 @@ public class ControllerModule extends Module{
SaveAxisData(); SaveAxisData();
} }
private void SaveAxisData() { public void SaveAxisData() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Axis a : axes) { for (Axis a : axes) {
sb.append(a.getSaveString()+"\n"); sb.append(a.getSaveString()+"\n");
@ -651,7 +779,7 @@ public class ControllerModule extends Module{
SaveButtonData(); SaveButtonData();
} }
private void SaveButtonData() { public void SaveButtonData() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Button b : buttons) { for (Button b : buttons) {
sb.append(b.getSaveString()+"\n"); sb.append(b.getSaveString()+"\n");
@ -667,7 +795,8 @@ public class ControllerModule extends Module{
private Color PopupColorPanel() { private Color PopupColorPanel() {
Color col=null; Color col=null;
do { do {
col=sigIRC.colorpanel.getBackgroundColor(); col=sigIRC.colorpanel.getBackgroundColor(ControlConfigurationWindow.lastpicked_back_col);
ControlConfigurationWindow.lastpicked_back_col=col;
} while (col==null); } while (col==null);
return col; return col;
} }

Loading…
Cancel
Save