Skip to content

File evabKeyReactor.h

File List > src > evabKeyReactor.h

Go to the documentation of this file

#pragma once

#include <evaHandler.h>

namespace evab
{
  template <class T, unsigned char kDec, unsigned char kInc>
  class KeyReactor : public T
  {
  public:
    template <typename... Args>
    KeyReactor(eva::IHandler *aListener, Args &&...args)
        : T(args...), mListener(aListener)
    {
    }

    bool OnKey(Keys aKey) override
    {
      if (T::OnKey(aKey))
        return true;

      if (aKey == kDec)
        T::Increment(-1);
      else if (aKey == kInc)
        T::Increment(+1);
      else
        return false;

      if (mListener)
        mListener->invoke((void *)this, {0, 0});
      return true;
    }

  private:
    eva::IHandler *mListener = nullptr; 
  };

}