7e9eb1
#pragma once
7e9eb1
49945e
#ifndef INPUTMANAGER_INCLUDED
49945e
#define INPUTMANAGER_INCLUDED
49945e
49945e
// TnzTools includes
49945e
#include <tools tooltimer.h=""></tools>
49945e
#include <tools inputstate.h=""></tools>
49945e
#include <tools track.h=""></tools>
49945e
49945e
// TnzCore includes
49945e
#include <tcommon.h></tcommon.h>
9cf8be
#include <tgeometry.h></tgeometry.h>
49945e
#include <tsmartpointer.h></tsmartpointer.h>
49945e
49945e
// Qt includes
49945e
#include <qobject></qobject>
49945e
#include <qkeyevent></qkeyevent>
49945e
49945e
// std includes
49945e
#include <vector></vector>
49945e
#include <algorithm></algorithm>
49945e
49945e
49945e
#undef DVAPI
49945e
#undef DVVAR
49945e
#ifdef TNZTOOLS_EXPORTS
49945e
#define DVAPI DV_EXPORT_API
49945e
#define DVVAR DV_EXPORT_VAR
49945e
#else
49945e
#define DVAPI DV_IMPORT_API
49945e
#define DVVAR DV_IMPORT_VAR
49945e
#endif
49945e
49945e
49945e
//====================================================
49945e
49945e
//  Forward declarations
49945e
9cf8be
class TTool;
49945e
class TInputModifier;
49945e
class TInputManager;
49945e
49945e
typedef TSmartPointerT<tinputmodifier> TInputModifierP;</tinputmodifier>
49945e
49945e
//===================================================================
49945e
49945e
49945e
//*****************************************************************************************
49945e
//    TInputModifier definition
49945e
//*****************************************************************************************
49945e
6be163
class DVAPI TInputModifier: public TSmartObject {
49945e
private:
49945e
  TInputManager *m_manager;
49945e
49945e
public:
49945e
  typedef std::vector<tinputmodifierp> List;</tinputmodifierp>
49945e
49945e
  TInputManager* getManager() const
49945e
    { return m_manager; }
49945e
  void setManager(TInputManager *manager);
49945e
  virtual void onSetManager() { }
49945e
49945e
  virtual void activate() { }
49945e
49945e
  virtual void modifyTrack(
c3c215
    const TTrack &track,
7e9eb1
    TTrackList &outTracks );
49945e
  virtual void modifyTracks(
49945e
    const TTrackList &tracks,
49945e
    TTrackList &outTracks );
49945e
49945e
  virtual void modifyHover(
49945e
    const TPointD &hover,
7e9eb1
    THoverList &outHovers );
49945e
  virtual void modifyHovers(
49945e
    const THoverList &hovers,
49945e
    THoverList &outHovers );
49945e
c3c215
  virtual TRectD calcDrawBoundsHover(const TPointD &hover) { return TRectD(); }
c3c215
  virtual TRectD calcDrawBoundsTrack(const TTrack &track) { return TRectD(); }
c3c215
  virtual TRectD calcDrawBounds(const TTrackList &tracks, const THoverList &hovers);
c3c215
c3c215
  virtual void drawTrack(const TTrack &track) { }
9cf8be
  virtual void drawHover(const TPointD &hover) { }
9cf8be
  virtual void drawTracks(const TTrackList &tracks);
9cf8be
  virtual void drawHovers(const THoverList &hovers);
49945e
  virtual void draw(const TTrackList &tracks, const THoverList &hovers);
49945e
49945e
  virtual void deactivate() { }
49945e
};
49945e
49945e
49945e
//*****************************************************************************************
49945e
//    TInputHandler definition
49945e
//*****************************************************************************************
49945e
49945e
class TInputHandler {
49945e
public:
49945e
  virtual void inputLeftButtonDown(const TTrackPoint&, const TTrack&) { }
49945e
  virtual void inputLeftButtonDrag(const TTrackPoint&, const TTrack&) { }
49945e
  virtual void inputLeftButtonUp(const TTrackPoint&, const TTrack&) { }
49945e
  virtual void inputMouseMove(const TPointD&, const TInputState&) { }
49945e
  virtual void inputRightButtonDown(const TPointD&, const TInputState&) { }
49945e
  virtual bool inputKeyDown(QKeyEvent *) { return false; }
49945e
49945e
  virtual void inputSetBusy(bool) { }
49945e
  
49945e
  virtual bool inputKeyEvent(
49945e
    bool press,
49945e
    TInputState::Key key,
49945e
    QKeyEvent *event,
49945e
    const TInputManager &manager );
49945e
  
49945e
  virtual void inputButtonEvent(
49945e
    bool press,
49945e
    TInputState::DeviceId device,
49945e
    TInputState::Button button,
49945e
    const TInputManager &manager );
49945e
  
49945e
  virtual void inputHoverEvent(const TInputManager &manager);
49945e
f278a5
  virtual void inputPaintTracksBegin() { }
f278a5
  virtual void inputPaintTrackPoint(const TTrackPoint &point, const TTrack &track, bool firstTrack, bool preview);
f278a5
  virtual void inputPaintTracksEnd() { }
49945e
  virtual void inputPaintTracks(const TTrackList &tracks);
f278a5
c3c215
  virtual void inputInvalidateRect(const TRectD &bounds) { }
9cf8be
  
362052
  virtual TTool* inputGetTool() { return nullptr; };
49945e
};
49945e
49945e
49945e
//*****************************************************************************************
49945e
//    TInputManager definition
49945e
//*****************************************************************************************
49945e
6be163
class DVAPI TInputManager {
49945e
private:
d8eddc
  TTimerTicks m_lastTicks;
49945e
  TInputHandler *m_handler;
49945e
  TInputModifier::List m_modifiers;
49945e
  std::vector<ttracklist> m_tracks;</ttracklist>
49945e
  std::vector<thoverlist> m_hovers;</thoverlist>
7a5892
  TRectD m_prevBounds;
7a5892
  TRectD m_nextBounds;
7a5892
  bool m_started;
49945e
49945e
  static TInputState::TouchId m_lastTouchId;
49945e
49945e
49945e
public:
49945e
  TInputState state;
dba7b5
  bool drawPreview;
49945e
49945e
49945e
public:
49945e
  TInputManager();
49945e
49945e
private:
d8eddc
  inline TTimerTicks fixTicks(TTimerTicks ticks) {
d8eddc
    if (ticks <= m_lastTicks) ticks = m_lastTicks + 1;
d8eddc
    return m_lastTicks = ticks;
d8eddc
  }
d8eddc
  
49945e
  void paintTracks();
49945e
49945e
  int trackCompare(
49945e
    const TTrack &track,
49945e
    TInputState::DeviceId deviceId,
d8eddc
    TInputState::TouchId touchId ) const;
49945e
  const TTrackP& createTrack(
49945e
    int index,
49945e
    TInputState::DeviceId deviceId,
49945e
    TInputState::TouchId touchId,
49945e
    TTimerTicks ticks,
49945e
    bool hasPressure,
49945e
    bool hasTilt );
49945e
  const TTrackP& getTrack(
49945e
    TInputState::DeviceId deviceId,
49945e
    TInputState::TouchId touchId,
49945e
    TTimerTicks ticks,
49945e
    bool hasPressure,
49945e
    bool hasTilt );
49945e
  void addTrackPoint(
49945e
    const TTrackP& track,
49945e
    const TPointD &position,
49945e
    double pressure,
49945e
    const TPointD &tilt,
49945e
    double time,
49945e
    bool final );
49945e
  void touchTracks(bool finish = false);
49945e
49945e
  void modifierActivate(const TInputModifierP &modifier);
49945e
  void modifierDeactivate(const TInputModifierP &modifier);
49945e
49945e
public:
49945e
  inline const TTrackList& getInputTracks() const
49945e
    { return m_tracks.front(); }
49945e
  inline const TTrackList& getOutputTracks() const
49945e
    { return m_tracks.back(); }
49945e
49945e
  inline const THoverList& getInputHovers() const
49945e
    { return m_hovers.front(); }
49945e
  inline const THoverList& getOutputHovers() const
49945e
    { return m_hovers.back(); }
49945e
49945e
  void processTracks();
49945e
  void finishTracks();
49945e
  void reset();
49945e
49945e
  TInputHandler* getHandler() const
49945e
    { return m_handler; }
49945e
  void setHandler(TInputHandler *handler);
49945e
49945e
  int getModifiersCount() const
49945e
    { return (int)m_modifiers.size(); }
49945e
  const TInputModifierP& getModifier(int index) const
49945e
    { return m_modifiers[index]; }
49945e
  int findModifier(const TInputModifierP &modifier) const;
49945e
  void insertModifier(int index, const TInputModifierP &modifier);
49945e
  void addModifier(const TInputModifierP &modifier)
49945e
    { insertModifier(getModifiersCount(), modifier); }
da847a
  void addModifiers(const TInputModifier::List &modifiers) {
da847a
    for(TInputModifier::List::const_iterator i = modifiers.begin(); i != modifiers.end(); ++i)
da847a
      addModifier(*i);
da847a
  }
49945e
  void removeModifier(int index);
49945e
  void removeModifier(const TInputModifierP &modifier)
49945e
    { removeModifier(findModifier(modifier)); }
49945e
  void clearModifiers();
49945e
49945e
  void trackEvent(
49945e
    TInputState::DeviceId deviceId,
49945e
    TInputState::TouchId touchId,
49945e
    const TPointD &position,
fa009d
    const double pressure,
fa009d
    const TPointD &tilt,
fa009d
    bool hasPressure,
fa009d
    bool hasTilt,
49945e
    bool final,
49945e
    TTimerTicks ticks );
49945e
  bool keyEvent(
49945e
    bool press,
49945e
    TInputState::Key key,
49945e
    TTimerTicks ticks,
49945e
    QKeyEvent *event );
49945e
  void buttonEvent(
49945e
    bool press,
49945e
    TInputState::DeviceId deviceId,
49945e
    TInputState::Button button,
49945e
    TTimerTicks ticks);
49945e
  void hoverEvent(const THoverList &hovers);
49945e
c3c215
  TRectD calcDrawBounds();
49945e
  void draw();
49945e
49945e
  static TInputState::TouchId genTouchId();
49945e
};
49945e
49945e
16421e
//*****************************************************************************************
16421e
//    export template implementations for win32
16421e
//*****************************************************************************************
16421e
16421e
#ifdef _WIN32
16421e
template class DVAPI TSmartPointerT<tinputmodifier>;</tinputmodifier>
16421e
#endif
16421e
16421e
49945e
#endif