#ifndef Var1_KeyHandling_H
#define Var1_KeyHandling_H
#include <Rtypes.h>
#include <TString.h>
#include <Gled/GTime.h>
class ZGlass;
namespace KeyHandling
{
class EventHandler;
class KeyHandler;
struct Key
{
Bool_t fIsDown;
KeyHandler *fHandler;
};
struct KeyHandler
{
virtual void KeyUp (Key* key) = 0;
virtual void KeyDown(Key* key) = 0;
};
struct EventHandler
{
virtual void RegisterKey (Key* key);
virtual void UnregisterKey(Key* key);
};
class AKeyCallback
{
public:
virtual ~AKeyCallback() {}
virtual void Invoke(ZGlass*, Int_t, Bool_t, UInt_t) = 0;
};
template <typename T>
class KeyCallback : public AKeyCallback
{
typedef void (T::*Foo_t)(Int_t, Bool_t, UInt_t);
Foo_t mFunction;
public:
KeyCallback(Foo_t foo) : mFunction(foo) {}
virtual ~KeyCallback() {}
virtual void Invoke(ZGlass* lens, Int_t key, Bool_t downp, UInt_t elapsed)
{
((((T*)lens)->*mFunction)(key, downp, elapsed));
}
};
class KeyInfo
{
public:
TString fKeyTag;
TString fKeyDesc;
AKeyCallback *fCallback;
Int_t fUserId;
Int_t fIndex;
UChar_t fDownCount;
KeyInfo(const TString& tag, const TString& desc, AKeyCallback* foo, Int_t uid=0);
~KeyInfo();
ClassDefNV(KeyInfo, 1);
};
class KeyInfoRep
{
public:
Int_t fIndex;
Bool_t fIsDown;
GTime fLastTime;
KeyInfoRep() : fIndex(-1), fIsDown(kFALSE), fLastTime() {}
KeyInfoRep(Int_t idx) : fIndex(idx), fIsDown(kFALSE), fLastTime() {}
};
}
#endif