Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (592)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (645)
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 1241 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.

 
Za\'Anzabar (15 views)
2015-06-29 05:44:54

TritonDreyja (29 views)
2015-06-24 17:10:40

CopyableCougar4 (26 views)
2015-06-23 00:34:45

BurntPizza (32 views)
2015-06-21 20:36:46

cookiecompiler (74 views)
2015-06-11 15:42:53

cookiecompiler (38 views)
2015-06-11 15:41:14

NegativeZero (63 views)
2015-06-11 09:49:18

Fairy Tailz (88 views)
2015-06-11 01:59:47

chrislo27 (60 views)
2015-06-06 18:12:44

Burnsalan20 (72 views)
2015-06-05 03:00:51
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14
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!