Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 10:23 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Oct 03, 2012 3:47 pm 
Offline

Joined: Wed Oct 03, 2012 2:34 pm
Posts: 7
Issue description
I tried to add TWL gui to my project. I followed this and changed my main app file. After that (application starts fine) I tried to append button to my app start screen, and what I saw: I can see a button. It changes colour from blue to green (I used theme from twl.zip-TWLExamples-src-test) when I move mouse on it. Everything seemed to be fine, but when I clicked on this button (It changed colour to red) it did not changed back.
When I create two buttons, after the first click on any of the buttons clicked button starts to be red and click or move on another button don't work.

Further information:

While I trying to resolve this issue I used breakpoints in TWLInputAdapter and found that whan I click on button mouseReleased do not invoked. Otherwise when I click on the empty space near buttons, breakpoints show me that it works.

I create buttons in overrided init method
Code:
    @Override
    public void init(GameContainer gc) throws SlickException {
        // construct & configure root widget
        root = new Widget();
        root.setTheme("");

        // save Slick's GL state while loading the theme
        GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
        try {
            lwjglRenderer = new LWJGLRenderer();
            theme = ThemeManager.createThemeManager(
                    Client.class.getResource("guiTheme.xml"), lwjglRenderer);
            gui = new GUI(root, lwjglRenderer);
            gui.applyTheme(theme);
        } catch (LWJGLException e) {
            log.error(e);
        } catch (IOException e) {
            log.error(e);
        } finally {
            // restore Slick's GL state
            GL11.glPopAttrib();
        }

        // connect input
        twlInputAdapter = new TWLInputAdapter(gui, gc.getInput());
        gc.getInput().addPrimaryListener(twlInputAdapter);

        CmdArgs cmdArgs = CmdArgs.parseArgs(gc.getCmdLineArgs());
        host = cmdArgs.getHost();
        port = cmdArgs.getPort();
        locale = cmdArgs.getLocale();
        initialization(gc);
        currentMenu = MenuManager.getAuthorizationMenu();

        final Button b = new Button("test");
        b.setPosition(200, 200);
        b.setSize(100, 40);

        final Button b2 = new Button("test2");
        b2.setPosition(200, 250);
        b2.setSize(100, 40);

        root.add(b);
        root.add(b2);
    }


If you find there any mistakes, tell me about it, please, because english is not my native language. :oops:


Top
 Profile  
 
PostPosted: Wed Oct 03, 2012 6:48 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
From what you posted I can't see what is causing this. Are you saying that mouseReleased of the TWLInputAdapter is not called at all?

But there are a few things I saw:
a) you should not call setSize/setPosition on widgets outside the layout() method of their direct parents - eg subclass Widget for your root and override the layout method there.
b) do you add other slick input listeners?

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Wed Oct 03, 2012 8:18 pm 
Offline

Joined: Wed Oct 03, 2012 2:34 pm
Posts: 7
Yes, if I click on the button, mouseReleased of the TWLInputAdapter is not called.

a) I wrote this, no changes...
  • New class TWLMenu with overrided layout();
    Code:
    package islands.client.menu;

    import de.matthiasmann.twl.Button;
    import de.matthiasmann.twl.Widget;

    public class TWLMenu extends Widget {
        private Button button;
       
        public TWLMenu() {
            createButton();
        }

        private void createButton() {
            button = new Button("Epic button");
            button.setTheme("button");
            add(button);
        }

        @Override
        protected void layout() {
            button.setPosition(100, 100);
            button.setSize(200, 33);
        }
    }
  • init now starts with
    Code:
        @Override
        public void init(GameContainer gc) throws SlickException {
            // construct & configure root widget
            root = new TWLMenu();
            root.setTheme("");
    ...
b) no, there are no Input.addSomething() methods in our code except gc.getInput().addPrimaryListener(twlInputAdapter);
I tried
Code:
        gc.getInput().removeAllListeners();
        gc.getInput().addPrimaryListener(twlInputAdapter);

No changes.


Top
 Profile  
 
PostPosted: Thu Oct 04, 2012 6:10 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
Hmm - no idea. Currently I have no idea what could cause Slick to not call this method.

Can you attach a ZIP file with a minimal project based on latest SVN of Slick and latest HG of TWL but only include the your source and possible modified files.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Thu Oct 04, 2012 6:29 am 
Offline

Joined: Wed Oct 03, 2012 2:34 pm
Posts: 7
The reason for this issue is that I have created a few components from org.newdawn.slick.gui on the background. When I remove this components all works fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group