cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

inputcallback.h (1819B)


      1/*
      2 * Gearboy - Nintendo Game Boy Emulator
      3 * Copyright (C) 2012  Ignacio Sanchez
      4 
      5 * This program is free software: you can redistribute it and/or modify
      6 * it under the terms of the GNU General Public License as published by
      7 * the Free Software Foundation, either version 3 of the License, or
      8 * any later version.
      9 
     10 * This program is distributed in the hope that it will be useful,
     11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     13 * GNU General Public License for more details.
     14 
     15 * You should have received a copy of the GNU General Public License
     16 * along with this program.  If not, see http://www.gnu.org/licenses/
     17 *
     18 */
     19
     20#pragma once
     21#ifndef _INPUTCALLBACK_H
     22#define	_INPUTCALLBACK_H
     23
     24#include "Vector.h"
     25
     26enum eInputCallbackType
     27{
     28
     29    PRESS_START,
     30    PRESS_MOVE,
     31    PRESS_END
     32};
     33
     34struct stInputCallbackParameter
     35{
     36    eInputCallbackType type;
     37    Vec3 vector;
     38};
     39
     40//////////////////////////
     41//////////////////////////
     42
     43class InputCallbackGeneric
     44{
     45
     46public:
     47
     48    virtual ~InputCallbackGeneric() { };
     49    virtual void Execute(stInputCallbackParameter parameter, int id) const = 0;
     50};
     51
     52//////////////////////////
     53//////////////////////////
     54
     55template <class Class>
     56class InputCallback : public InputCallbackGeneric
     57{
     58
     59public:
     60
     61    typedef void (Class::*Method)(stInputCallbackParameter, int);
     62
     63private:
     64
     65    Class* m_pClassInstance;
     66    Method m_theMethod;
     67
     68public:
     69
     70    InputCallback(Class* class_instance, Method method)
     71    {
     72        m_pClassInstance = class_instance;
     73        m_theMethod = method;
     74    };
     75
     76    virtual ~InputCallback() { };
     77
     78    virtual void Execute(stInputCallbackParameter parameter, int id) const
     79    {
     80        (m_pClassInstance->*m_theMethod)(parameter, id);
     81    };
     82};
     83
     84#endif	/* _INPUTCALLBACK_H */
     85