adonthell-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Adonthell-devel] I'm back !!!


From: Kenneth Gangstoe
Subject: Re: [Adonthell-devel] I'm back !!!
Date: Mon, 18 Feb 2002 14:43:01 +0100
User-agent: Mutt/1.3.24i

Quoting Kai Sterker (address@hidden):
> As for the key-callbacks:
> 
> Basically, each object that wants to recieve keyboard input implements the
> KeyListener interface
> (http://java.sun.com/j2se/1.4/docs/api/java/awt/event/KeyListener.html).
> 
> I'm not totally certain about it, but I guess the input handler has a list
> of KeyListeners, and if your object wants to get notified of keypresses,
> you register it with the handler.
> 
> And if a key is pressed, the handler would just call the keyPressed()
> method of each listener in it's list.
> 
> Then each object could check what key has been pressed, and react
> accordingly.
> 
> 
> Is that comparable to the signals you suggested, Sphair? I remember
> hearing the term, but I don't remember any details. (Isn't that what
> Qt/KDE does - slots and signals and all that?).

Yes, it is what Qt/KDE/ligsig/ClanLib all does.

I'm dumping some lines from the ClanLib input class:
(Im using ClanLib syntax here, since thats what I know, also the ClanLib
signal are just some header files you can include without the rest of ClanLib)

//: Signal emitted when key is pressed on the specified keyboard.
CL_Signal_v1<const CL_Key &> sig_key_down;
                
//: Signal emitted when key is released on the specified keyboard.
CL_Signal_v1<const CL_Key &> sig_key_up;
                                
//: Signal emitted when mouse is pressed on the specified mouse.
CL_Signal_v1<const CL_Key &> sig_mouse_down;
                                                
//: Signal emitted when mouse is released on the specified mouse.
CL_Signal_v1<const CL_Key &> sig_mouse_up;
                                                                
As you see it defines some signals on some specific input events. Looks cryptic,
but thats how templates do look like :)

the _v1 means it has one argument. Others would be _v0, _v2, _v3 etc.

Whenever a signal is fired, every function connected to the signal will be
run.

MyMapEngine::MyMapEngine()
{
        slots.connect(Input::sig_key_down, this, on_key_down);
        slots.connect(Input::sig_mouse_up, this, on_mouse_up);
}

void MyMapEngine::on_key_down(const CL_Key &key)
{
  std::cout << key.ascii << std::endl;
}

void MyMapEngine::on_mouse_up(const CL_Key &key)
{
  std::cout << "Mouse released at " << key.x << "," << key.y << std::endl;
}
  
Here, I'm hooked into the key-down and mouse_up signals, and they will be run
whenever these signals get fired.

Hope this was somewhat clear. If not, you can read a full overview here:
http://dark.x.dtu.dk/~sphair/cvs/Libs/ClanLib-0.5/Documentation/Overview/signals.html

- Sphair / Kenneth



reply via email to

[Prev in Thread] Current Thread [Next in Thread]