Results 1 to 9 of 9

Thread: User input does not react

  1. #1

    Default User input does not react

    Hi everybody!
    So, according to topic im having some problems on receiving UI.
    In a class representing an Intro state i do the following:
    Code:
     clan::Slot slot_input_up = window->get_ic().get_keyboard().sig_key_up().connect(this, &IntroState::onInputUp);
    Method IntroState:nInputUp
    Code:
        void onInputUp(const clan::InputEvent &key)
        {
            if (key.id == clan::keycode_q)
            {
                std::string title;
                title = "Intro State: ";
                title += "Exit";
                window->set_title(title);
                st_man->quit();
            }
        }
    IDE: NetBeans 7.3.1
    OS: Fedora 3.10.11-200.fc19.x86_64

    Thank you in advice!

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

    Default

    Make sure clan::Slot slot_input_up does not go out of scope.

  3. #3

    Default

    How can it be done ?

  4. #4

    Default

    It seems that
    Code:
     clan::Slot slot_input_down = (window->get_ic().get_keyboard()).sig_key_down().connect(this, &IntroState::onInputDown);
    does nothing. Cuz when i set the BP to onInputDown it never hits the function.
    When i declare a clan::Slot i thought strange that i never need to refer it to some event receiver.
    As i understand the connect function has to set some event receiver for this.
    But i never initialized any event receivers.

    Also
    Code:
    clan::Slot slot_quit = window->sig_window_close().connect(this, &IntroState::onWindowClose);
    It never hits the function onWindowClose.
    It seems that arguments i pass is incorrect.
    I did NOT find ANY actual documentation/comments on ANY functionality. Only obvious comments like "here we declare a variable"

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

    Default

    It is important clan::Slot stays in scope. From your code snippet, you cannot tell.

    clan::Slot slot_quit = window->sig_window_close().connect(this, &IntroState::onWindowClose);
    The "slot_quit" contains the information "the callback IntroState::onWindowClose will be called on sig_window_close()".

    Thus when slot_quit goes out of scope (when the destructor is called), the callback will not be called.

    Yes, the documentation does not make it clear. I'm sure it used to. http://clanlib.org/documentation/3.0/Core.html "Signals and callbacks" is all that I can find.

    Note, some developers don't like having to keep multiple clan::Slots around. It's personal choice. The alternative it using clan::SlotContainer, that can contain multiple slots.

    If still unsure, run the Examples/Display/Basic2D example. ( https://github.com/sphair/ClanLib/bl...es/basic2d.cpp )

    And of course, your main loop must call clan::KeepAlive::process(0);
    Last edited by rombust; 09-26-2013 at 08:22 PM. Reason: annoying forum inserting smillies

  6. #6

    Default

    Well i know that clan is built with smart pointers. i know a little mistake in my code ive done before ive got to know about smart pointers in clan lib.
    But still, take a look at my State please:

    BTW: i wrote it using the basic2d example.
    Just added a simple StateManager
    Thank you

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

    Default

    Yeah error is as Sphair and myself stated.

    clan::Slot's are going out of scope.

    Change

    Code:
           clan::Slot slot_quit = window->sig_window_close().connect(this, &IntroState::onWindowClose);
            clan::Slot slot_input_down = (window->get_ic().get_keyboard()).sig_key_down().connect(this, &IntroState::onInputDown);
    To
    Code:
          slot_quit = window->sig_window_close().connect(this, &IntroState::onWindowClose);
           slot_input_down = (window->get_ic().get_keyboard()).sig_key_down().connect(this, &IntroState::onInputDown);
    And add:

    Code:
    protected:
        clan::DisplayWindow *window;
        clan::Image *spr_logo;
        clan::Canvas *canvas;
        Game::StateManager *st_man;
        clan::Slot slot_quit;  <---- This and
        clan::Slot slot_input;  <---- That

  8. #8
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    The official documentation for the slots can be found here:

    http://clanlib.org/documentation/3.0...Callbacks.html

    If it is confusing or needs additional clarification, the text is part of the ClanLib git repository and can be found in the following file: ClanLib-3.0/Documentation/Overview/template_callbacks.h

    We accept git pull requests.

  9. #9

    Default

    Damn that was some kind of easy if i kept in mind that clanlib uses smart pointers..
    Thank you!

Similar Threads

  1. Two questions regarding user input (callback functions)
    By haimat in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 09-30-2012, 09:17 PM
  2. Grab Input?
    By speeder in forum Novashell Game Creation System
    Replies: 3
    Last Post: 07-09-2010, 01:11 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
  •