Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  HUD drag / drop  (Read 1121 times)
0 Members and 1 Guest are viewing this topic.
Offline hawkwind

Junior Devvie




Java games rock!


« Posted 2006-10-23 22:53:59 »

I can see that dialogs/frames can be dragged.  Can buttons, textures, etc. be dragged??
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #1 - Posted 2006-10-23 23:53:39 »

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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
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.
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #2 - Posted 2006-10-24 00:28:28 »

Another possibility is to write a class:
1  
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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Marvin Fröhlich

Senior Devvie




May the 4th, be with you...


« Reply #3 - Posted 2006-10-24 00:48:56 »

I'll see tomorrow, if I can add such a support directly to any Widget.

Well... It's done now. Just toggle the setDraggable( boolean ) method of any Widget.

Marvin
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

SHC (23 views)
2014-11-25 12:00:59

SHC (21 views)
2014-11-25 11:53:45

Norakomi (19 views)
2014-11-25 11:26:43

Gibbo3771 (22 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (41 views)
2014-11-12 21:09:33

kovacsa (67 views)
2014-11-07 19:57:14
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!