Completed implementation of Controller Module.

dev
sigonasr2 7 years ago
parent 08191bb5eb
commit 4e03806a4a
  1. BIN
      sigIRCv2.jar
  2. 42
      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. 339
      src/sig/modules/ControllerModule.java

Binary file not shown.

@ -93,6 +93,16 @@ public class Axis extends Element{
pct_height*parent.getControllerImage().getHeight(sigIRC.panel));
}
}
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() {
return backgroundColor;
@ -224,18 +234,38 @@ public class Axis extends Element{
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);
}
}
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);
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)));
}
}
}
public String getSaveString() {
StringBuilder sb = new StringBuilder();
sb.append(pct_x);sb.append(",");

@ -30,6 +30,7 @@ import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
@ -41,6 +42,7 @@ import javax.swing.event.DocumentListener;
import sig.ColorPanel;
import sig.sigIRC;
import sig.modules.ControllerModule;
import sig.utils.TextUtils;
public class ControlConfigurationWindow extends JFrame implements WindowListener{
DialogType dialog;
@ -59,6 +61,8 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
int axis_width=32,axis_height=32;
JButton backgroundColor,indicatorColor;
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
JCheckBox width_invert,height_invert;
java.awt.Component extra_space;
@ -119,8 +123,9 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
ActionListener backgroundColorListener = new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
Color selectedcol = sigIRC.colorpanel.getBackgroundColor(null);
Color selectedcol = sigIRC.colorpanel.getBackgroundColor(lastpicked_back_col);
if (selectedcol!=null) {
lastpicked_back_col = selectedcol;
axis_background_col = selectedcol;
backgroundColor.setBackground(axis_background_col);
}
@ -129,8 +134,9 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
ActionListener indicatorColorListener = new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
Color selectedcol = sigIRC.colorpanel.getBackgroundColor(null);
Color selectedcol = sigIRC.colorpanel.getBackgroundColor(lastpicked_indicator_col);
if (selectedcol!=null) {
lastpicked_indicator_col = selectedcol;
axis_indicator_col = selectedcol;
indicatorColor.setBackground(axis_indicator_col);
}
@ -145,7 +151,8 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
ActionListener createbuttonListener = new ActionListener(){
@Override
public void actionPerformed(ActionEvent ev) {
if (DataIsValid()) {
DataValidationReason err_check = DataIsValid();
if (err_check == DataValidationReason.GOOD) {
Axis a = ConstructTemporaryAxis();
module.setTemporaryAxis(a);
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().setVisible(false);
//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() {
return true;
private DataValidationReason DataIsValid() {
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(){
@ -176,6 +213,7 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
switch (ev.getActionCommand()) {
case "add_button":{
module.setMode(EditMode.DRAGSELECTION);
//System.out.println("Called Drag Selection mode.");
sigIRC.panel.grabFocus();
module.getConfigurationWindow().dispatchEvent(new WindowEvent(module.getConfigurationWindow(),WindowEvent.WINDOW_CLOSING));
}break;
@ -554,8 +592,8 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
a = new Axis(new Rectangle2D.Double(),
module.getControllers().get(0),
ident,
Double.parseDouble(twowayAxis_range1.getTextField().getText()),
Double.parseDouble(twowayAxis_range2.getTextField().getText()),
Double.parseDouble((!TextUtils.isNumeric(twowayAxis_range1.getTextField().getText())?Double.toString(-1):twowayAxis_range1.getTextField().getText())),
Double.parseDouble((!TextUtils.isNumeric(twowayAxis_range2.getTextField().getText())?Double.toString(1):twowayAxis_range2.getTextField().getText())),
orientation,
axis_background_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 sig.sigIRC;
import sig.modules.ControllerModule;
public class Element {
protected double pct_x = 0;
@ -37,4 +38,14 @@ public class Element {
}
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.Point;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.geom.Rectangle2D;
@ -15,6 +16,7 @@ import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import org.lwjgl.glfw.GLFW;
@ -29,6 +31,7 @@ import sig.modules.Controller.Controller;
import sig.modules.Controller.EditMode;
import sig.modules.Controller.Element;
import sig.modules.Controller.Identifier;
import sig.modules.Controller.RepeatedKey;
import sig.modules.Controller.Type;
import sig.modules.Controller.clickablebutton.AddClickableButton;
import sig.modules.Controller.clickablebutton.CopyClickableButton;
@ -38,7 +41,7 @@ import sig.utils.FileUtils;
public class ControllerModule extends Module{
public final static String CONTROLLERPATH = sigIRC.BASEDIR+"sigIRC/controller/";
List<Controller> controllers = new ArrayList<Controller>();
Image controller_img;
Image controller_img,controller_overlay_img;
double imgratio = 1;
List<Button> buttons = new ArrayList<Button>();
List<Axis> axes = new ArrayList<Axis>();
@ -69,6 +72,8 @@ public class ControllerModule extends Module{
boolean resizing=false;
double xoffset=0,yoffset=0;
final static int RESIZE_BORDER = 5;
final static double MINIMUM_ELEMENT_SIZE=8;
boolean proportionalResize=false;
public ControllerModule(Rectangle2D bounds, String moduleName) {
super(bounds, moduleName);
@ -89,6 +94,7 @@ public class ControllerModule extends Module{
controllers.addAll(ca);
try {
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));
} catch (IOException e) {
e.printStackTrace();
@ -145,6 +151,13 @@ public class ControllerModule extends Module{
return stored_rect;
}
public List<Button> getButtons() {
return buttons;
}
public List<Axis> getAxes() {
return axes;
}
public void ApplyConfigWindowProperties() {
sigIRC.controllermodule_X=(int)position.getX();
sigIRC.controllermodule_Y=(int)position.getY();
@ -165,48 +178,50 @@ public class ControllerModule extends Module{
start_drag = mouse_position;
}
}break;
}
if (MODE==EditMode.DEFAULT) {
for (ClickableButton cb : click_buttons) {
cb.onClickEvent(ev);
}
}
if (selectedElement!=null && resizing_direction!=0 && !resizing && extendBoundaries(selectedElement.getPixelBounds(controller_img),3).contains(mouse_position)) {
resizing=true;
resize_refpoint=mouse_position;
} else
if (selectedElement!=null && !resizing && selectedElement.getPixelBounds(controller_img).contains(mouse_position)) {
dragging=true;
xoffset = selectedElement.getPixelBounds(controller_img).getX()-mouse_position.getX();
yoffset = selectedElement.getPixelBounds(controller_img).getY()-mouse_position.getY();
} else {
selectedElement=null;
for (Element e : buttons) {
//System.out.println("Checking bounds "+e.getPixelBounds(controller_img));
if (e.getPixelBounds(controller_img).contains(mouse_position)) {
selectedElement = e;
break;
case DEFAULT:{
for (ClickableButton cb : click_buttons) {
cb.onClickEvent(ev);
}
}
if (selectedElement==null) {
for (Element e : axes) {
//System.out.println("Checking bounds "+e.getPixelBounds(controller_img));
if (e.getPixelBounds(controller_img).contains(mouse_position)) {
selectedElement = e;
break;
}
if (selectedElement!=null && resizing_direction!=0 && !resizing && extendBoundaries(selectedElement.getPixelBounds(controller_img),3).contains(mouse_position)) {
resizing=true;
resize_refpoint=mouse_position;
} else
if (selectedElement!=null && !resizing && selectedElement.getPixelBounds(controller_img).contains(mouse_position)) {
dragging=true;
xoffset = selectedElement.getPixelBounds(controller_img).getX()-mouse_position.getX();
yoffset = selectedElement.getPixelBounds(controller_img).getY()-mouse_position.getY();
} else {
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) {
//System.out.println("Checking bounds "+e.getPixelBounds(controller_img));
if (e.getPixelBounds(controller_img).contains(mouse_position)) {
return e;
}
}
for (Element e : axes) {
//System.out.println("Checking bounds "+e.getPixelBounds(controller_img));
if (e.getPixelBounds(controller_img).contains(mouse_position)) {
return e;
}
}
return null;
}
public void mouseReleased(MouseEvent ev) {
//System.out.println("Mode before is "+MODE);
if (resizing) {
Point mouse_position = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY()));
PerformResize(mouse_position);
setConstraints();
resizing=false;
resizing_direction=0;
SaveElementData();
@ -218,6 +233,7 @@ public class ControllerModule extends Module{
(mouse_position.getY()+yoffset)/controller_img.getHeight(sigIRC.panel),
selectedElement.getBounds().getWidth(),
selectedElement.getBounds().getHeight()));
setConstraints();
dragging=false;
SaveElementData();
return;
@ -235,20 +251,26 @@ public class ControllerModule extends Module{
stored_rect = new Rectangle2D.Double(
(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),
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.getWidth(sigIRC.panel),Math.abs((end_drag.getX()-start_drag.getX())/controller_img.getWidth(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));
//resetDragPoints();
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
if (!inDragZone) {
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
//System.out.println(MODE);
if (MODE==EditMode.DRAGSELECTION) {
MODE=EditMode.BUTTONSET;
//System.out.println("Set Button");
} else
if (MODE==EditMode.DRAGAXISSELECTION) {
//System.out.println("Add Axis");
AddAxis();
MODE=EditMode.DEFAULT;
//System.out.println(MODE);
}
}
}
}break;
case POSITIONSELECTION:{
Point mouse_click = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY()));
stored_rect = new Rectangle2D.Double(
@ -260,9 +282,11 @@ public class ControllerModule extends Module{
}break;
}
}
//System.out.println("Mode after is "+MODE);
}
private void PerformResize(Point mouse_position) {
double aspectRatio = (double)selectedElement.getBounds().getWidth()/selectedElement.getBounds().getHeight();
switch (resizing_direction) {
case 1:{
AdjustY(mouse_position);
@ -293,20 +317,33 @@ public class ControllerModule extends Module{
AdjustY(mouse_position);
}break;
}
if (proportionalResize) {
resizeProportionally(aspectRatio);
}
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) {
selectedElement.setBounds(new Rectangle2D.Double(selectedElement.getBounds().getX(),
(mouse_position.getY()-resize_refpoint.getY()+selectedElement.getPixelBounds(controller_img).getY())/controller_img.getHeight(sigIRC.panel),
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) {
selectedElement.setBounds(new Rectangle2D.Double((mouse_position.getX()-resize_refpoint.getX()+selectedElement.getPixelBounds(controller_img).getX())/controller_img.getWidth(sigIRC.panel),
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()));
}
@ -314,13 +351,13 @@ public class ControllerModule extends Module{
selectedElement.setBounds(new Rectangle2D.Double(selectedElement.getBounds().getX(),
selectedElement.getBounds().getY(),
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) {
selectedElement.setBounds(new Rectangle2D.Double(selectedElement.getBounds().getX(),
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()));
}
@ -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()));
if (resizing) {
PerformResize(mouse_position);
setConstraints();
}
if (dragging) {
selectedElement.setBounds(new Rectangle2D.Double((mouse_position.getX()+xoffset)/controller_img.getWidth(sigIRC.panel),
(mouse_position.getY()+yoffset)/controller_img.getHeight(sigIRC.panel),
selectedElement.getBounds().getWidth(),
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 (!resizing) {
@ -423,7 +476,8 @@ public class ControllerModule extends Module{
}break;
default:
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));
}
}
@ -449,7 +503,7 @@ public class ControllerModule extends Module{
} else
if (selectedElement!=null) {
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));
}
}
@ -515,6 +569,14 @@ public class ControllerModule extends Module{
configure_window.run();
}
}
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() {
return controller_img;
@ -534,78 +596,84 @@ public class ControllerModule extends Module{
}*/
}
g.drawImage(controller_img, (int)(position.getX()), (int)(position.getY()), sigIRC.panel);
}
for (ClickableButton cb : click_buttons) {
cb.draw(g);
}
for (Axis a : axes) {
a.draw(g);
}
for (Button b : buttons) {
b.draw(g);
}
if (MODE==EditMode.DRAGSELECTION) {
if (start_drag!=null) {
Color color_identity = g.getColor();
g.setColor(Color.GRAY);
int width = sigIRC.panel.lastMouseX-
((int)position.getX()+(int)start_drag.getX());
int height = sigIRC.panel.lastMouseY-
((int)position.getY()+(int)start_drag.getY());
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);
for (ClickableButton cb : click_buttons) {
cb.draw(g);
}
} else
if (MODE==EditMode.POSITIONSELECTION) {
Color color_identity = g.getColor();
g.setColor(Color.GRAY);
int width = (int)((stored_rect.getWidth()*controller_img.getWidth(sigIRC.panel)));
int height = (int)((stored_rect.getHeight()*controller_img.getHeight(sigIRC.panel)));
g.fillOval(
sigIRC.panel.lastMouseX-width/2,
sigIRC.panel.lastMouseY-height/2,
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 {
for (Axis a : axes) {
a.draw(g);
}
for (Button b : buttons) {
b.draw(g);
}
if (MODE==EditMode.DRAGSELECTION) {
if (start_drag!=null) {
Color color_identity = g.getColor();
g.setColor(Color.GRAY);
int width = sigIRC.panel.lastMouseX-
((int)position.getX()+(int)start_drag.getX());
int height = sigIRC.panel.lastMouseY-
((int)position.getY()+(int)start_drag.getY());
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);
}
} else
if (MODE==EditMode.POSITIONSELECTION) {
Color color_identity = g.getColor();
g.setColor(Color.GRAY);
int width = (int)((stored_rect.getWidth()*controller_img.getWidth(sigIRC.panel)));
int height = (int)((stored_rect.getHeight()*controller_img.getHeight(sigIRC.panel)));
g.fillOval(
sigIRC.panel.lastMouseX-width/2,
sigIRC.panel.lastMouseY-height/2,
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);
}
}
}
if (selectedElement!=null) {
Rectangle2D.Double rect = selectedElement.getPixelBounds(controller_img);
Color color_identity = g.getColor();
g.setColor(DrawUtils.invertColor(selectedElement.getElementColor()));
for (int i=-1;i<2;i++) {
for (int j=-1;j<2;j++) {
g.draw3DRect((int)(rect.getX()+position.getX())+i, (int)(rect.getY()+position.getY())+j, (int)rect.getWidth(), (int)rect.getHeight(), true);
g.drawImage(controller_overlay_img, (int)(position.getX()), (int)(position.getY()), sigIRC.panel);
for (Axis a : axes) {
a.drawIndicator(g);
}
if (selectedElement!=null) {
Rectangle2D.Double rect = selectedElement.getPixelBounds(controller_img);
Color color_identity = g.getColor();
g.setColor(DrawUtils.invertColor(selectedElement.getElementColor()));
for (int i=-1;i<2;i++) {
for (int j=-1;j<2;j++) {
g.draw3DRect((int)(rect.getX()+position.getX())+i, (int)(rect.getY()+position.getY())+j, (int)rect.getWidth(), (int)rect.getHeight(), true);
}
}
g.setColor(color_identity);
}
g.setColor(color_identity);
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!");
}
DrawUtils.drawText(g, position.getX(), position.getY()+8, Color.BLACK, status);
}
private void LoadButtonAndAxisData() {
@ -629,6 +697,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() {
temporary_axis.setupBoundsRectangle(stored_rect);
@ -638,7 +766,7 @@ public class ControllerModule extends Module{
SaveAxisData();
}
private void SaveAxisData() {
public void SaveAxisData() {
StringBuilder sb = new StringBuilder();
for (Axis a : axes) {
sb.append(a.getSaveString()+"\n");
@ -651,7 +779,7 @@ public class ControllerModule extends Module{
SaveButtonData();
}
private void SaveButtonData() {
public void SaveButtonData() {
StringBuilder sb = new StringBuilder();
for (Button b : buttons) {
sb.append(b.getSaveString()+"\n");
@ -667,7 +795,8 @@ public class ControllerModule extends Module{
private Color PopupColorPanel() {
Color col=null;
do {
col=sigIRC.colorpanel.getBackgroundColor();
col=sigIRC.colorpanel.getBackgroundColor(ControlConfigurationWindow.lastpicked_back_col);
ControlConfigurationWindow.lastpicked_back_col=col;
} while (col==null);
return col;
}

Loading…
Cancel
Save