Finished implementing Draggable + Resizable Controller elements. Only
Data Validation + Bug testing remains.
This commit is contained in:
parent
e203715025
commit
08191bb5eb
@ -1,2 +1,2 @@
|
||||
cd "C:\Users\Joshua Sigona\git\sigIRCv2\"
|
||||
java -jar sigIRCv2.jar -Djinput.useDefaultPlugin=false -Djinput.plugins=net.java.games.input.DirectInputEnvironmentPlugin
|
||||
java -jar sigIRCv2.jar
|
BIN
sigIRCv2.jar
BIN
sigIRCv2.jar
Binary file not shown.
@ -14,6 +14,10 @@ public class ColorPanel extends JPanel{
|
||||
return JColorChooser.showDialog(this, "Color Picker", sigIRC.backgroundcol);
|
||||
}
|
||||
|
||||
public Color getBackgroundColor(Color defaultColor) {
|
||||
return JColorChooser.showDialog(this, "Color Picker", defaultColor);
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(640,480);
|
||||
}
|
||||
|
@ -9,14 +9,10 @@ import java.util.List;
|
||||
import sig.sigIRC;
|
||||
import sig.modules.ControllerModule;
|
||||
|
||||
public class Axis {
|
||||
public class Axis extends Element{
|
||||
List<Integer> identifiers = new ArrayList<Integer>();
|
||||
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.
|
||||
@ -98,6 +94,10 @@ public class Axis {
|
||||
}
|
||||
}
|
||||
|
||||
public Color getSelectionColor() {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
public boolean is_Xinverted() {
|
||||
return x_invert;
|
||||
}
|
||||
|
@ -7,11 +7,7 @@ import java.awt.geom.Rectangle2D;
|
||||
import sig.sigIRC;
|
||||
import sig.modules.ControllerModule;
|
||||
|
||||
public class Button {
|
||||
double pct_x = 0;
|
||||
double pct_y = 0;
|
||||
double pct_width = 0;
|
||||
double pct_height = 0;
|
||||
public class Button extends Element{
|
||||
int ident;
|
||||
byte value;
|
||||
Controller parent_controller;
|
||||
@ -42,6 +38,11 @@ public class Button {
|
||||
this.parent = module;
|
||||
this.square = square;
|
||||
this.value = button_val;
|
||||
module.setStoredRectangle(new Rectangle2D.Double(pct_x, pct_y, pct_width, pct_height));
|
||||
}
|
||||
|
||||
public Color getSelectionColor() {
|
||||
return pressed_col;
|
||||
}
|
||||
|
||||
public void draw(Graphics g) {
|
||||
|
@ -26,6 +26,7 @@ import javax.swing.ButtonGroup;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JLayeredPane;
|
||||
@ -118,7 +119,7 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
|
||||
ActionListener backgroundColorListener = new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Color selectedcol = sigIRC.colorpanel.getBackgroundColor();
|
||||
Color selectedcol = sigIRC.colorpanel.getBackgroundColor(null);
|
||||
if (selectedcol!=null) {
|
||||
axis_background_col = selectedcol;
|
||||
backgroundColor.setBackground(axis_background_col);
|
||||
@ -128,7 +129,7 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
|
||||
ActionListener indicatorColorListener = new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Color selectedcol = sigIRC.colorpanel.getBackgroundColor();
|
||||
Color selectedcol = sigIRC.colorpanel.getBackgroundColor(null);
|
||||
if (selectedcol!=null) {
|
||||
axis_indicator_col = selectedcol;
|
||||
indicatorColor.setBackground(axis_indicator_col);
|
||||
@ -169,10 +170,42 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
|
||||
}
|
||||
}
|
||||
};
|
||||
ActionListener addButtonListener = new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
switch (ev.getActionCommand()) {
|
||||
case "add_button":{
|
||||
module.setMode(EditMode.DRAGSELECTION);
|
||||
sigIRC.panel.grabFocus();
|
||||
module.getConfigurationWindow().dispatchEvent(new WindowEvent(module.getConfigurationWindow(),WindowEvent.WINDOW_CLOSING));
|
||||
}break;
|
||||
case "add_similar":{
|
||||
if (module.getStoredRectangle()!=null) {
|
||||
module.setMode(EditMode.POSITIONSELECTION);
|
||||
sigIRC.panel.grabFocus();
|
||||
module.getConfigurationWindow().dispatchEvent(new WindowEvent(module.getConfigurationWindow(),WindowEvent.WINDOW_CLOSING));
|
||||
} else {
|
||||
new JDialog(module.getConfigurationWindow(),"Please create a new button first.");
|
||||
}
|
||||
}break;
|
||||
case "add_axis":{
|
||||
new ControlConfigurationWindow(DialogType.BUTTON_AXIS_SELECTION,module);
|
||||
}break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void setDialogType(DialogType type) {
|
||||
this.dialog=type;
|
||||
}
|
||||
|
||||
public ControlConfigurationWindow(DialogType type, ControllerModule parent_module) {
|
||||
this.setVisible(true);
|
||||
this.module = parent_module;
|
||||
if (module.getConfigurationWindow()!=null) {
|
||||
module.getConfigurationWindow().dispatchEvent(new WindowEvent(module.getConfigurationWindow(),WindowEvent.WINDOW_CLOSING));
|
||||
module.setConfigureWindow(null);
|
||||
}
|
||||
this.module.setConfigureWindow(this);
|
||||
this.dialog = type;
|
||||
|
||||
@ -421,6 +454,35 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
|
||||
break;
|
||||
case BUTTON_OPTIONS:
|
||||
|
||||
break;
|
||||
case CREATE_CONTROL:
|
||||
container = new JPanel();
|
||||
|
||||
JButton newbutton = new JButton("Add new button");
|
||||
newbutton.setActionCommand("add_button");
|
||||
newbutton.addActionListener(addButtonListener);
|
||||
newbutton.setMinimumSize(new Dimension(320,24));
|
||||
JButton copybutton = new JButton("Add similar button");
|
||||
copybutton.setActionCommand("add_similar");
|
||||
copybutton.addActionListener(addButtonListener);
|
||||
copybutton.setMinimumSize(new Dimension(320,24));
|
||||
copybutton.setToolTipText("Adds a button with the same size as the previously created button, but lets you specify a new gamepad input and new color.");
|
||||
JButton newaxis = new JButton("Add new axis");
|
||||
newaxis.setActionCommand("add_axis");
|
||||
newaxis.addActionListener(addButtonListener);
|
||||
newaxis.setMinimumSize(new Dimension(320,24));
|
||||
|
||||
container.add(newbutton);
|
||||
container.add(copybutton);
|
||||
container.add(newaxis);
|
||||
|
||||
//container.setLayout(new BorderLayout());
|
||||
this.setMinimumSize(new Dimension(320,120));
|
||||
this.setPreferredSize(new Dimension(320,120));
|
||||
this.add(container);
|
||||
this.pack();
|
||||
//this.pack();
|
||||
this.repaint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -439,12 +501,14 @@ public class ControlConfigurationWindow extends JFrame implements WindowListener
|
||||
JCheckBox mycheckbox = analog_controller_component_labels.get(i);
|
||||
mycheckbox.setText(GetComponentValue(analog_controller_components.get(i)));
|
||||
}
|
||||
if (previewpanel!=null) {
|
||||
previewpanel.repaint();
|
||||
}
|
||||
break;
|
||||
case BUTTON_OPTIONS:
|
||||
break;
|
||||
}
|
||||
if (previewpanel!=null) {
|
||||
previewpanel.repaint();
|
||||
case CREATE_CONTROL:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,5 +3,6 @@ package sig.modules.Controller;
|
||||
public enum DialogType {
|
||||
BUTTON_AXIS_SELECTION,
|
||||
AXIS_OPTIONS,
|
||||
BUTTON_OPTIONS
|
||||
BUTTON_OPTIONS,
|
||||
CREATE_CONTROL
|
||||
}
|
||||
|
@ -7,5 +7,6 @@ public enum EditMode {
|
||||
DELETESELECTION, //Delete a button.
|
||||
BUTTONSET, //Asks for a controller button to set this button to.
|
||||
COLORSET,
|
||||
DEFAULT;
|
||||
DEFAULT,
|
||||
POSITIONSELECTION;
|
||||
}
|
||||
|
40
src/sig/modules/Controller/Element.java
Normal file
40
src/sig/modules/Controller/Element.java
Normal file
@ -0,0 +1,40 @@
|
||||
package sig.modules.Controller;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Image;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import sig.sigIRC;
|
||||
|
||||
public class Element {
|
||||
protected double pct_x = 0;
|
||||
protected double pct_y = 0;
|
||||
protected double pct_width = 0;
|
||||
protected double pct_height = 0;
|
||||
|
||||
public Rectangle2D.Double getBounds() {
|
||||
return new Rectangle2D.Double(pct_x,pct_y,pct_width,pct_height);
|
||||
}
|
||||
public Rectangle2D.Double getPixelBounds(Image controller_img) {
|
||||
return new Rectangle2D.Double(pct_x*controller_img.getWidth(sigIRC.panel),pct_y*controller_img.getHeight(sigIRC.panel),pct_width*controller_img.getWidth(sigIRC.panel),pct_height*controller_img.getHeight(sigIRC.panel));
|
||||
}
|
||||
|
||||
public void setBounds(Rectangle2D.Double rect) {
|
||||
this.pct_x = rect.getX();
|
||||
this.pct_y = rect.getY();
|
||||
this.pct_width = rect.getWidth();
|
||||
this.pct_height = rect.getHeight();
|
||||
}
|
||||
|
||||
public Color getElementColor() {
|
||||
if (this instanceof Button) {
|
||||
Button b = (Button)this;
|
||||
return b.getSelectionColor();
|
||||
} else
|
||||
if (this instanceof Axis) {
|
||||
Axis a = (Axis)this;
|
||||
return a.getSelectionColor();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -5,6 +5,8 @@ import java.awt.event.MouseEvent;
|
||||
|
||||
import sig.modules.ControllerModule;
|
||||
import sig.modules.Controller.ClickableButton;
|
||||
import sig.modules.Controller.ControlConfigurationWindow;
|
||||
import sig.modules.Controller.DialogType;
|
||||
import sig.modules.Controller.EditMode;
|
||||
|
||||
public class AddClickableButton extends ClickableButton{
|
||||
@ -15,9 +17,13 @@ public class AddClickableButton extends ClickableButton{
|
||||
|
||||
public void onClickEvent(MouseEvent ev) {
|
||||
super.onClickEvent(ev);
|
||||
if (mouseInsideBounds(ev)) {
|
||||
/*if (mouseInsideBounds(ev)) {
|
||||
module.setMode(EditMode.DRAGSELECTION);
|
||||
module.resetDragPoints();
|
||||
}*/
|
||||
if (mouseInsideBounds(ev)) {
|
||||
new ControlConfigurationWindow(DialogType.CREATE_CONTROL,module);
|
||||
module.resetDragPoints();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import sig.modules.Controller.DialogType;
|
||||
import sig.modules.Controller.EditMode;
|
||||
|
||||
public class CopyClickableButton extends ClickableButton{
|
||||
ControlConfigurationWindow window;
|
||||
|
||||
public CopyClickableButton(Rectangle position, String button_label, ControllerModule parent_module) {
|
||||
super(position, button_label, parent_module);
|
||||
@ -18,8 +17,7 @@ public class CopyClickableButton extends ClickableButton{
|
||||
|
||||
public void onClickEvent(MouseEvent ev) {
|
||||
super.onClickEvent(ev);
|
||||
if (mouseInsideBounds(ev)) {
|
||||
window = new ControlConfigurationWindow(DialogType.BUTTON_AXIS_SELECTION,module);
|
||||
if (mouseInsideBounds(ev)) {;
|
||||
module.resetDragPoints();
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import sig.modules.Controller.Component;
|
||||
import sig.modules.Controller.ControlConfigurationWindow;
|
||||
import sig.modules.Controller.Controller;
|
||||
import sig.modules.Controller.EditMode;
|
||||
import sig.modules.Controller.Element;
|
||||
import sig.modules.Controller.Identifier;
|
||||
import sig.modules.Controller.Type;
|
||||
import sig.modules.Controller.clickablebutton.AddClickableButton;
|
||||
@ -53,6 +54,21 @@ public class ControllerModule extends Module{
|
||||
ControlConfigurationWindow configure_window;
|
||||
Axis temporary_axis=null;
|
||||
int mouseclickwait_timer=0;
|
||||
Element selectedElement;
|
||||
boolean dragging=false;
|
||||
int resizing_direction=0;
|
||||
/*1=North
|
||||
3=North-east
|
||||
2=East
|
||||
6=South-east
|
||||
4=South
|
||||
12=South-west
|
||||
8=West
|
||||
9=North-west*/
|
||||
Point resize_refpoint;
|
||||
boolean resizing=false;
|
||||
double xoffset=0,yoffset=0;
|
||||
final static int RESIZE_BORDER = 5;
|
||||
|
||||
public ControllerModule(Rectangle2D bounds, String moduleName) {
|
||||
super(bounds, moduleName);
|
||||
@ -80,13 +96,7 @@ public class ControllerModule extends Module{
|
||||
//buttons.add(new Button(0.1,0.05,0.1,0.05,controllers.get(0),Identifier.Button._3,Color.RED,this));
|
||||
LoadButtonAndAxisData();
|
||||
click_buttons.add(new AddClickableButton(new Rectangle(
|
||||
0,(int)position.getHeight()-41,96,20),"Add Button",this));
|
||||
click_buttons.add(new CopyClickableButton(new Rectangle(
|
||||
97,(int)position.getHeight()-41,96,20),"Copy Button",this));
|
||||
click_buttons.add(new ClickableButton(new Rectangle(
|
||||
0,(int)position.getHeight()-20,96,20),"Delete Button",this));
|
||||
click_buttons.add(new ClickableButton(new Rectangle(
|
||||
97,(int)position.getHeight()-20,96,20),"Edit Button",this));
|
||||
0,(int)position.getHeight()-21,96,20),"Add Button",this));
|
||||
}
|
||||
|
||||
public List<Controller> getControllers() {
|
||||
@ -127,6 +137,14 @@ public class ControllerModule extends Module{
|
||||
MODE = mode;
|
||||
}
|
||||
|
||||
public void setStoredRectangle(Rectangle2D.Double rect) {
|
||||
this.stored_rect=rect;
|
||||
}
|
||||
|
||||
public Rectangle2D.Double getStoredRectangle() {
|
||||
return stored_rect;
|
||||
}
|
||||
|
||||
public void ApplyConfigWindowProperties() {
|
||||
sigIRC.controllermodule_X=(int)position.getX();
|
||||
sigIRC.controllermodule_Y=(int)position.getY();
|
||||
@ -135,12 +153,16 @@ public class ControllerModule extends Module{
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent ev) {
|
||||
if (dragging || resizing) {
|
||||
return;
|
||||
}
|
||||
if (mouseInsideBounds(ev)) {
|
||||
Point mouse_position = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY()));
|
||||
switch (MODE) {
|
||||
case DRAGSELECTION:
|
||||
case DRAGAXISSELECTION:{
|
||||
if (start_drag==null) {
|
||||
start_drag = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY()));
|
||||
start_drag = mouse_position;
|
||||
}
|
||||
}break;
|
||||
}
|
||||
@ -149,11 +171,57 @@ public class ControllerModule extends Module{
|
||||
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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//System.out.println("Selected element "+selectedElement+". Mouse Point: "+ev.getPoint());
|
||||
}
|
||||
super.mousePressed(ev);
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent ev) {
|
||||
if (resizing) {
|
||||
Point mouse_position = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY()));
|
||||
PerformResize(mouse_position);
|
||||
resizing=false;
|
||||
resizing_direction=0;
|
||||
SaveElementData();
|
||||
return;
|
||||
}
|
||||
if (dragging) {
|
||||
Point mouse_position = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY()));
|
||||
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()));
|
||||
dragging=false;
|
||||
SaveElementData();
|
||||
return;
|
||||
}
|
||||
super.mouseReleased(ev);
|
||||
if (mouseInsideBounds(ev)) {
|
||||
switch (MODE) {
|
||||
@ -181,10 +249,81 @@ public class ControllerModule extends Module{
|
||||
}
|
||||
}
|
||||
}
|
||||
case POSITIONSELECTION:{
|
||||
Point mouse_click = new Point((int)(ev.getX()-getPosition().getX()),(int)(ev.getY()-getPosition().getY()));
|
||||
stored_rect = new Rectangle2D.Double(
|
||||
(mouse_click.getX()-(stored_rect.getWidth()*controller_img.getWidth(sigIRC.panel))/2)/controller_img.getWidth(sigIRC.panel),
|
||||
(mouse_click.getY()-(stored_rect.getHeight()*controller_img.getHeight(sigIRC.panel))/2)/controller_img.getHeight(sigIRC.panel),
|
||||
stored_rect.getWidth(),
|
||||
stored_rect.getHeight());
|
||||
MODE=EditMode.BUTTONSET;
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PerformResize(Point mouse_position) {
|
||||
switch (resizing_direction) {
|
||||
case 1:{
|
||||
AdjustY(mouse_position);
|
||||
}break;
|
||||
case 2:{
|
||||
AdjustWidth(mouse_position);
|
||||
}break;
|
||||
case 3:{
|
||||
AdjustWidth(mouse_position);
|
||||
AdjustY(mouse_position);
|
||||
}break;
|
||||
case 6:{
|
||||
AdjustWidth(mouse_position);
|
||||
AdjustHeight(mouse_position);
|
||||
}break;
|
||||
case 4:{
|
||||
AdjustHeight(mouse_position);
|
||||
}break;
|
||||
case 12:{
|
||||
AdjustX(mouse_position);
|
||||
AdjustHeight(mouse_position);
|
||||
}break;
|
||||
case 8:{
|
||||
AdjustX(mouse_position);
|
||||
}break;
|
||||
case 9:{
|
||||
AdjustX(mouse_position);
|
||||
AdjustY(mouse_position);
|
||||
}break;
|
||||
}
|
||||
resize_refpoint=mouse_position;
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
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),
|
||||
selectedElement.getBounds().getHeight()));
|
||||
}
|
||||
|
||||
private void AdjustHeight(Point mouse_position) {
|
||||
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)));
|
||||
}
|
||||
|
||||
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),
|
||||
selectedElement.getBounds().getHeight()));
|
||||
}
|
||||
|
||||
protected boolean mouseInsideBounds(MouseEvent ev) {
|
||||
return mouseclickwait_timer<=0 && ev.getX()>=getPosition().getX() && ev.getX()<=getPosition().getX()+getPosition().getWidth() &&
|
||||
ev.getY()>=getPosition().getY() && ev.getY()<=getPosition().getY()+getPosition().getHeight();
|
||||
@ -198,7 +337,97 @@ public class ControllerModule extends Module{
|
||||
this.configure_window=window;
|
||||
}
|
||||
|
||||
Rectangle2D.Double extendBoundaries(Rectangle2D.Double rect, double amt) {
|
||||
return new Rectangle2D.Double(rect.getX()-amt, rect.getY()-amt, rect.getWidth()+amt*2, rect.getHeight()+amt*2);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Point mouse_position = new Point((int)(sigIRC.panel.lastMouseX-getPosition().getX()),(int)(sigIRC.panel.lastMouseY-getPosition().getY()));
|
||||
if (resizing) {
|
||||
PerformResize(mouse_position);
|
||||
}
|
||||
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()));
|
||||
}
|
||||
if (selectedElement!=null && extendBoundaries(selectedElement.getPixelBounds(controller_img),3).contains(mouse_position)) {
|
||||
if (!resizing) {
|
||||
resizing_direction=0;
|
||||
if (mouse_position.getY()-selectedElement.getPixelBounds(controller_img).getY()<=RESIZE_BORDER &&
|
||||
mouse_position.getY()-selectedElement.getPixelBounds(controller_img).getY()>=-RESIZE_BORDER) {
|
||||
resizing_direction+=1;
|
||||
} else
|
||||
if (mouse_position.getY()-(selectedElement.getPixelBounds(controller_img).getY()+selectedElement.getPixelBounds(controller_img).getHeight())<=RESIZE_BORDER &&
|
||||
mouse_position.getY()-(selectedElement.getPixelBounds(controller_img).getY()+selectedElement.getPixelBounds(controller_img).getHeight())>=-RESIZE_BORDER) {
|
||||
resizing_direction+=4;
|
||||
}
|
||||
if (mouse_position.getX()-selectedElement.getPixelBounds(controller_img).getX()<=RESIZE_BORDER &&
|
||||
mouse_position.getX()-selectedElement.getPixelBounds(controller_img).getX()>=-RESIZE_BORDER) {
|
||||
resizing_direction+=8;
|
||||
} else
|
||||
if (mouse_position.getX()-(selectedElement.getPixelBounds(controller_img).getX()+selectedElement.getPixelBounds(controller_img).getWidth())<=RESIZE_BORDER &&
|
||||
mouse_position.getX()-(selectedElement.getPixelBounds(controller_img).getX()+selectedElement.getPixelBounds(controller_img).getWidth())>=-RESIZE_BORDER) {
|
||||
resizing_direction+=2;
|
||||
}
|
||||
}
|
||||
switch (resizing_direction) {
|
||||
case 1:{
|
||||
int cursortype = sigIRC.panel.getCursor().getType();
|
||||
if (cursortype!=Cursor.N_RESIZE_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.N_RESIZE_CURSOR));
|
||||
}
|
||||
}break;
|
||||
case 2:{
|
||||
int cursortype = sigIRC.panel.getCursor().getType();
|
||||
if (cursortype!=Cursor.E_RESIZE_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.E_RESIZE_CURSOR));
|
||||
}
|
||||
}break;
|
||||
case 3:{
|
||||
int cursortype = sigIRC.panel.getCursor().getType();
|
||||
if (cursortype!=Cursor.NE_RESIZE_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.NE_RESIZE_CURSOR));
|
||||
}
|
||||
}break;
|
||||
case 6:{
|
||||
int cursortype = sigIRC.panel.getCursor().getType();
|
||||
if (cursortype!=Cursor.SE_RESIZE_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.SE_RESIZE_CURSOR));
|
||||
}
|
||||
}break;
|
||||
case 4:{
|
||||
int cursortype = sigIRC.panel.getCursor().getType();
|
||||
if (cursortype!=Cursor.S_RESIZE_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.S_RESIZE_CURSOR));
|
||||
}
|
||||
}break;
|
||||
case 12:{
|
||||
int cursortype = sigIRC.panel.getCursor().getType();
|
||||
if (cursortype!=Cursor.SW_RESIZE_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.SW_RESIZE_CURSOR));
|
||||
}
|
||||
}break;
|
||||
case 8:{
|
||||
int cursortype = sigIRC.panel.getCursor().getType();
|
||||
if (cursortype!=Cursor.W_RESIZE_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.W_RESIZE_CURSOR));
|
||||
}
|
||||
}break;
|
||||
case 9:{
|
||||
int cursortype = sigIRC.panel.getCursor().getType();
|
||||
if (cursortype!=Cursor.NW_RESIZE_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.NW_RESIZE_CURSOR));
|
||||
}
|
||||
}break;
|
||||
default:
|
||||
int cursortype = sigIRC.panel.getCursor().getType();
|
||||
if (cursortype!=Cursor.DEFAULT_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Controller c : controllers) {
|
||||
//System.out.println("Data for "+c.getName()+" ("+c.getType()+"):");
|
||||
c.poll();
|
||||
@ -211,6 +440,20 @@ public class ControllerModule extends Module{
|
||||
}
|
||||
}*/
|
||||
}
|
||||
if (resizing_direction==0) {
|
||||
if (selectedElement!=null && selectedElement.getPixelBounds(controller_img).contains(mouse_position)) {
|
||||
int cursortype = sigIRC.panel.getCursor().getType();
|
||||
if (cursortype!=Cursor.MOVE_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.MOVE_CURSOR));
|
||||
}
|
||||
} else
|
||||
if (selectedElement!=null) {
|
||||
int cursortype = sigIRC.panel.getCursor().getType();
|
||||
if (cursortype!=Cursor.DEFAULT_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mouseclickwait_timer>0) {
|
||||
mouseclickwait_timer--;
|
||||
}
|
||||
@ -235,6 +478,13 @@ public class ControllerModule extends Module{
|
||||
}
|
||||
status="Drag the axis onto the controller template.";
|
||||
}break;
|
||||
case POSITIONSELECTION:{
|
||||
status="Click where you want this new button placed.";
|
||||
int cursortype = sigIRC.panel.getCursor().getType();
|
||||
if (cursortype!=Cursor.CROSSHAIR_CURSOR) {
|
||||
sigIRC.panel.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
|
||||
}
|
||||
}break;
|
||||
default:{
|
||||
status="";
|
||||
}
|
||||
@ -285,15 +535,14 @@ public class ControllerModule extends Module{
|
||||
}
|
||||
g.drawImage(controller_img, (int)(position.getX()), (int)(position.getY()), sigIRC.panel);
|
||||
}
|
||||
DrawUtils.drawText(g, position.getX(), position.getY()+8, Color.BLACK, status);
|
||||
for (Button b : buttons) {
|
||||
b.draw(g);
|
||||
for (ClickableButton cb : click_buttons) {
|
||||
cb.draw(g);
|
||||
}
|
||||
for (Axis a : axes) {
|
||||
a.draw(g);
|
||||
}
|
||||
for (ClickableButton cb : click_buttons) {
|
||||
cb.draw(g);
|
||||
for (Button b : buttons) {
|
||||
b.draw(g);
|
||||
}
|
||||
if (MODE==EditMode.DRAGSELECTION) {
|
||||
if (start_drag!=null) {
|
||||
@ -310,6 +559,17 @@ public class ControllerModule extends Module{
|
||||
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();
|
||||
@ -332,6 +592,20 @@ public class ControllerModule extends Module{
|
||||
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.setColor(color_identity);
|
||||
}
|
||||
|
||||
DrawUtils.drawText(g, position.getX(), position.getY()+8, Color.BLACK, status);
|
||||
}
|
||||
|
||||
private void LoadButtonAndAxisData() {
|
||||
@ -361,6 +635,10 @@ public class ControllerModule extends Module{
|
||||
temporary_axis.setVisible(true);
|
||||
axes.add(temporary_axis);
|
||||
temporary_axis=null;
|
||||
SaveAxisData();
|
||||
}
|
||||
|
||||
private void SaveAxisData() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Axis a : axes) {
|
||||
sb.append(a.getSaveString()+"\n");
|
||||
@ -370,6 +648,10 @@ public class ControllerModule extends Module{
|
||||
|
||||
private void AddButton() {
|
||||
buttons.add(new Button(stored_rect,controller,stored_controller_button,(byte)stored_controller_value,buttoncol,this));
|
||||
SaveButtonData();
|
||||
}
|
||||
|
||||
private void SaveButtonData() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Button b : buttons) {
|
||||
sb.append(b.getSaveString()+"\n");
|
||||
@ -377,6 +659,11 @@ public class ControllerModule extends Module{
|
||||
FileUtils.writetoFile(new String[]{sb.toString()}, CONTROLLERPATH+"button_data.txt");
|
||||
}
|
||||
|
||||
private void SaveElementData() {
|
||||
SaveButtonData();
|
||||
SaveAxisData();
|
||||
}
|
||||
|
||||
private Color PopupColorPanel() {
|
||||
Color col=null;
|
||||
do {
|
||||
|
@ -94,4 +94,8 @@ public class DrawUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Color invertColor(Color c) {
|
||||
return new Color(255-c.getRed(),255-c.getGreen(),255-c.getBlue(),255);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user