ROOT logo

// $Id: KeyHandling.h 2341 2010-01-24 01:28:32Z matevz $

// Copyright (C) 1999-2008, Matevz Tadel. All rights reserved.
// This file is part of GLED, released under GNU General Public License version 2.
// For the licensing terms see $GLEDSYS/LICENSE or http://www.gnu.org/.

#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
  {
    // map<int, Key*> ...
    virtual void RegisterKey  (Key* key);
    virtual void UnregisterKey(Key* key);

    // void Handle();
  };

  // integer key index, filled during dynamico init.

  // spiritio gets key up / down, dt in real time on rnr side. maybe also event
  // state (modifier buttons) has its own down state, separate from Rnr, which
  // also has its own state and can be told not to send auto-repeat.

  // basic key info on spiritio side


  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;    // Unique tag used in GL to build tag - index map.
    TString         fKeyDesc;   // Description to be displayed in key setup dialog.
    AKeyCallback   *fCallback;
    Int_t           fUserId;    // Id that can be specified by user to reuse callback foo.

    Int_t           fIndex;     // Index in "compressed" key/action list in Spiritio.

    UChar_t         fDownCount; // Number of activations (key, overlay button, ...).

    KeyInfo(const TString& tag, const TString& desc, AKeyCallback* foo, Int_t uid=0);

    ~KeyInfo();

    ClassDefNV(KeyInfo, 1);
  };

  //----------------------------------------------------------------------------

  // key info in the renderer. in principle could have to stages ... generic
  // and specialized -- with or without the function pointers.

  // then, there must be a switch somewhwere to choose between direct calls
  // and MIRs.

  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
 KeyHandling.h:1
 KeyHandling.h:2
 KeyHandling.h:3
 KeyHandling.h:4
 KeyHandling.h:5
 KeyHandling.h:6
 KeyHandling.h:7
 KeyHandling.h:8
 KeyHandling.h:9
 KeyHandling.h:10
 KeyHandling.h:11
 KeyHandling.h:12
 KeyHandling.h:13
 KeyHandling.h:14
 KeyHandling.h:15
 KeyHandling.h:16
 KeyHandling.h:17
 KeyHandling.h:18
 KeyHandling.h:19
 KeyHandling.h:20
 KeyHandling.h:21
 KeyHandling.h:22
 KeyHandling.h:23
 KeyHandling.h:24
 KeyHandling.h:25
 KeyHandling.h:26
 KeyHandling.h:27
 KeyHandling.h:28
 KeyHandling.h:29
 KeyHandling.h:30
 KeyHandling.h:31
 KeyHandling.h:32
 KeyHandling.h:33
 KeyHandling.h:34
 KeyHandling.h:35
 KeyHandling.h:36
 KeyHandling.h:37
 KeyHandling.h:38
 KeyHandling.h:39
 KeyHandling.h:40
 KeyHandling.h:41
 KeyHandling.h:42
 KeyHandling.h:43
 KeyHandling.h:44
 KeyHandling.h:45
 KeyHandling.h:46
 KeyHandling.h:47
 KeyHandling.h:48
 KeyHandling.h:49
 KeyHandling.h:50
 KeyHandling.h:51
 KeyHandling.h:52
 KeyHandling.h:53
 KeyHandling.h:54
 KeyHandling.h:55
 KeyHandling.h:56
 KeyHandling.h:57
 KeyHandling.h:58
 KeyHandling.h:59
 KeyHandling.h:60
 KeyHandling.h:61
 KeyHandling.h:62
 KeyHandling.h:63
 KeyHandling.h:64
 KeyHandling.h:65
 KeyHandling.h:66
 KeyHandling.h:67
 KeyHandling.h:68
 KeyHandling.h:69
 KeyHandling.h:70
 KeyHandling.h:71
 KeyHandling.h:72
 KeyHandling.h:73
 KeyHandling.h:74
 KeyHandling.h:75
 KeyHandling.h:76
 KeyHandling.h:77
 KeyHandling.h:78
 KeyHandling.h:79
 KeyHandling.h:80
 KeyHandling.h:81
 KeyHandling.h:82
 KeyHandling.h:83
 KeyHandling.h:84
 KeyHandling.h:85
 KeyHandling.h:86
 KeyHandling.h:87
 KeyHandling.h:88
 KeyHandling.h:89
 KeyHandling.h:90
 KeyHandling.h:91
 KeyHandling.h:92
 KeyHandling.h:93
 KeyHandling.h:94
 KeyHandling.h:95
 KeyHandling.h:96
 KeyHandling.h:97
 KeyHandling.h:98
 KeyHandling.h:99
 KeyHandling.h:100
 KeyHandling.h:101
 KeyHandling.h:102
 KeyHandling.h:103
 KeyHandling.h:104
 KeyHandling.h:105
 KeyHandling.h:106
 KeyHandling.h:107
 KeyHandling.h:108
 KeyHandling.h:109
 KeyHandling.h:110
 KeyHandling.h:111
 KeyHandling.h:112
 KeyHandling.h:113
 KeyHandling.h:114
 KeyHandling.h:115
 KeyHandling.h:116
 KeyHandling.h:117
 KeyHandling.h:118
 KeyHandling.h:119