@ -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 ( ) ;
@ -197,8 +336,98 @@ public class ControllerModule extends Module{
public void setConfigureWindow ( ControlConfigurationWindow window ) {
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 ( Clickable Button c b : click_ buttons) {
c b. 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,12 +648,21 @@ 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" ) ;
}
FileUtils . writetoFile ( new String [ ] { sb . toString ( ) } , CONTROLLERPATH + "button_data.txt" ) ;
}
private void SaveElementData ( ) {
SaveButtonData ( ) ;
SaveAxisData ( ) ;
}
private Color PopupColorPanel ( ) {
Color col = null ;