I can see that dialogs/frames can be dragged. Can buttons, textures, etc. be dragged??
No, they cannot be dragged without a trick. Basically there’re two ways. You can subclass the Label or Button Widget class and add support for dragging. See Frame class about how it is done. Or you can use a wrapping Frame Widget. But please first do a fresh checkout. I’ve fixed a few bugs in the Frame Widget.
try this test:
public class DraggingWidgets extends ExtRenderLoop implements WidgetActionListener
{
private class DraggingButton extends Frame
{
private Button button;
public Button getButton()
{
return( button );
}
public DraggingButton(float width, float height, String caption)
{
super( new Panel(width, height), false, null );
this.setPaneDraggingEnabled( true );
button = new Button( width, height, 1, caption );
this.getContentPane().addWidget( button );
}
}
private class DraggingLabel extends Frame
{
private Label label;
public Label getLabel()
{
return( label );
}
public DraggingLabel(float width, float height, String caption)
{
super( new Panel(width, height), false, null );
this.setPaneDraggingEnabled( true );
label = new Label( width, height, 1 );
label.setText( caption );
label.setAlignment( TextAlignment.CENTER_CENTER );
this.getContentPane().addWidget( label );
}
}
public void actionPerformed(String actionCommand)
{
if (actionCommand.equals( "TEST" ))
{
System.out.println( "you clicked the button" );
}
}
private HUD createHUD(Canvas3DWrapper canvas)
{
HUD hud = new HUD( canvas, this );
this.registerInputListener( hud );
DraggingButton db = new DraggingButton( 75, 30, "Test" );
db.getButton().setActionCommand( "TEST" );
db.getButton().addActionListener( this );
hud.addWidget( db, 100, 100 );
DraggingLabel dl = new DraggingLabel( 75, 30, "Bla bla" );
hud.addWidget( dl, 200, 200 );
return( hud );
}
public DraggingWidgets()
{
super( 128L );
Xith3DEnvironment env = new Xith3DEnvironment( this );
Canvas3DWrapper canvas = Canvas3DWrapper.createStandalone( Resolution.RES_800X600 );
env.addCanvas( canvas );
this.registerKeyboardAndMouse( canvas );
env.addParallelChild( createHUD(canvas) );
this.begin();
}
public static void main(String[] args)
{
new DraggingWidgets();
}
}
I would suggest to switch the paneDraggingEnabled flag of the wrapping frame with a modifier like CTRL or so. And dragging a Button is a bit problematic as you can see in the test class.
Marvin
EDIT: But if you’re talking about real drag/drop, then I must say, it is not yet implemented. And it certainly is one of the less important tasks.
Another possibility is to write a class:
public class DraggingLabel extends Label implements WidgetContainer
…and implement all the additional methods of WidgetContainer mostly empty and pass an instance of it to the Frame’s constructor.
But the cheapest solution would be (as mentioned above) to subclass e.g. Label and override the methods setLocation(Tuple2f), onMouseButtonPressed(int, int, int, boolean, boolean), onMouseButtonReleased(int, int, int, boolean, boolean) and onMouseMoved(int, int, boolean, boolean) like it is done in Frame.
I’ll see tomorrow, if I can add such a support directly to any Widget.
Marvin
Well… It’s done now. Just toggle the setDraggable( boolean ) method of any Widget.
Marvin