Results 1 to 20 of 20

Thread: Connecting slots

  1. #1
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default Connecting slots

    Hello, I want to connect for the close event. The code is like:
    Code:
    class App
    {
       public:
          static int main(...);
          static void onClose();
    };
    
    int App::main()
    {
          CL_DisplayWindow window("Wnd", width, height, fullscreen);     
          window.sig_window_close().connect(App::onClose); // This works for static function
          // ...
    }
    Everything is okay (builds, runs) except that the window doesn't have close button. When I don't connect at close event the button exists but doesn't work What's wrong?

  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    You need to store the connection in a CL_Slot.

    int App::main()
    {
    CL_DisplayWindow window("Wnd", width, height, fullscreen);
    CL_Slot slot_close = window.sig_window_close().connect(App:nClose); // This works for static function
    // ...
    }

    Non-static version:

    class App
    {
    public:
    int main(...);
    void onClose();
    };

    int App::main()
    {
    CL_DisplayWindow window("Wnd", width, height, fullscreen);
    CL_Slot slotClose = window.sig_window_close().connect(this, &App:nClose);
    // ...
    }

  3. #3
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default

    Still doesn't work Maybe, more code would help (The window still doesn't have close-button):
    Code:
    #include <ClanLib/core.h>
    #include <ClanLib/display.h>
    #include <ClanLib/gl.h>
    #include <ClanLib/application.h>
    
    // Application.hpp
    class GameApplication
    {
        public:
            static int main(const std::vector<CL_String> &args);
            static void onClose();
    };
    
    // --------------------------- (main.cpp)
    
    #include "Core/Application.hpp"
    
    void GameApplication::onClose() { }
    
    int GameApplication::main(const std::vector<CL_String> &args)
    {
        CL_SetupCore coreHandle;
        CL_SetupDisplay displayHandle;
        CL_SetupGL glHandle;
    
        try
        {
            short width = ...; short height = ...; bool fullscreen = ...;
    
            CL_DisplayWindow window("Window", width, height, fullscreen);
    
            CL_GraphicContext gc = window.get_gc();
            CL_InputDevice keyboard = window.get_ic().get_keyboard();
    
            // Connect onClose handle
            CL_Slot slot_close = window.sig_window_close().connect(GameApplication::onClose);
    
            while (/*Esc pressed*/)
            {
                frameManager.frameStarted();
                gc.clear(CL_Colorf::gray);
    
                CL_KeepAlive::process();
                window.flip(0);
                CL_System::sleep(10);
            }
        }
        catch(CL_Exception &error)
        {
            CL_ConsoleWindow console("Themisto console", 80, 160);
            CL_Console::write_line("Exception happened: " + error.get_message_and_stack_trace());
            console.display_close_message();
            return -1;
        }
    
        return 0;
    }
    
    CL_ClanApplication app(&GameApplication::main);

  4. #4
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Does the clanlib examples work for you?

    Are you running in fullscreen?

  5. #5
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default

    Yeah, examples work. No fullscreen (windowed mode).
    p.s. Arch Linux and (clanlib2 2.2.3-1)
    Last edited by Ockonal; 09-28-2010 at 12:21 PM.

  6. #6
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    What does GameApplication::onClose do ?

    Your while loop

    Code:
            while (/*Esc pressed*/)
            {
            }
    Does not contain "while( esc pressed OR close hit )

  7. #7
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default

    That's so important? The code is:
    Code:
    while (frameManager.getRunning())
    frameManager is upgraded code from frame_counter.h (found in examples).

    Code:
    #define frameManager (FrameManager::get_mutable_instance())
    // Boost singleton is used
    class FrameManager : public boost::serialization::singleton<FrameManager>
    {
        private:
            int mFps, mStartTime, mFrames;
            float mElapsed;
            bool mRunning; // Set's to the true in constructor of this class
        public:
            bool getRunning() { return mRunning; }
            void setRunning(bool state);
    };

  8. #8
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I mean, it is possible that GameApplication::onClose() is being called

    But it does not correctly trigger your application to quit.

    Put a breakpoint on onClose() to check that it is being called (or stick in a std::cout << "Hello World"; in there)

  9. #9
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default

    I wrote the cout there (it's not showable anyway). But the problem is in another side. The window doesn't have close button, so I can't close it anyway (I just kill the thread).

  10. #10
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Sorry,

    I don't think that I am understanding the problem correctly.

    A normal window has a close button (Like the basic 2d example). This should work, because it works on the Basic2D example

    A frameless window does not have a close button. Thus it cannot be closed because there is nothing to click!

    Unless you mean that your desktop manager has an alternative method to close a window. If so, that may be a problem, since http://standards.freedesktop.org/wm-...-spec-1.3.html does not appear to contain a signal anywhere that ClanLib can use.

    All ClanLib examples, either use "Escape" or the "Close Button"

  11. #11
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    Maybe you can post the entire code somewhere, and put up a screenshot. I think we're all little confused here

  12. #12
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default

    Okay, thanks. I'll try to build app from full start and look at the point when close button dissappears.

  13. #13
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default

    Oh okay, here is the screen:


    In a few minutes I'll post the link for the sources (Not much at all).
    ------------
    Sources: http://dl.dropbox.com/u/932520/Themisto.zip (Uses cmake)

  14. #14
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Just an idea, change:
    CL_DisplayWindow window("Themisto", width, height, fullscreen);
    to
    CL_DisplayWindow window("Themisto", 640, 480, false);

    To see if that works

  15. #15
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default

    Didn't help me.

  16. #16
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Maybe connected to the http://ubuntuforums.org/showthread.php?t=1117772 problem

  17. #17
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default

    No, that's decorator-related problems (When bar with title and buttons is dissapeared).

  18. #18
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I don't know. Since Basic2D example works, and your code looks the same.

    Maybe ask at ClanLib's IRC http://webchat.freenode.net/?channels=clanlib

    (I have not got time at the moment to run your example on linux)

  19. #19
    Lesser Knight
    Join Date
    Sep 2010
    Posts
    41

    Default

    Okay, thanks. I'll try to start example from full start. And, please, try to run it if I'll not post here about success, okay?

  20. #20
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    FYI, your code works fine under Windows.

Similar Threads

  1. proble with signals and slots
    By piotrek in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 06-27-2008, 12:00 PM
  2. Slots and Keyboard
    By azizmandar in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 01-03-2007, 03:19 AM
  3. Problems connecting to server/game.
    By Cakbeak in forum RTsoft Tavern
    Replies: 1
    Last Post: 12-18-2005, 02:43 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •