MeshLib Documentation
Loading...
Searching...
No Matches
MRTouchesController.h
Go to the documentation of this file.
1#pragma once
3#include "MRViewerFwd.h"
5#include "MRMesh/MRVector2.h"
7#include "MRMouse.h"
8#include <vector>
9#include <optional>
10#include <functional>
11
12namespace MR
13{
14// class to operate with touches
15// only overrides signals
16class MRVIEWER_CLASS TouchesController : public MultiListener<TouchStartListener,TouchMoveListener,TouchEndListener>
17{
18public:
20
21 // set callback to modify view transform before it is applied to viewport
22 void setTrasformModifierCb( std::function<void( AffineXf3f& )> cb ) { transformModifierCb_ = cb; }
23
24 // bit meaning for mode mask
25 enum class ModeBit : unsigned char
26 {
27 Translate = 0b001,
28 Rotate = 0b010,
29 Zoom = 0b100,
30 All = Translate | Rotate | Zoom,
31 Any = All
32 };
34
35 // mode mask can block some modes when two finger controll camera
36 ModeBit getModeMask() const { return touchModeMask_; }
37 void setModeMask( ModeBit mask ){ touchModeMask_ = mask; }
38private:
39 virtual bool onTouchStart_( int id, int x, int y ) override;
40 virtual bool onTouchMove_( int id, int x, int y ) override;
41 virtual bool onTouchEnd_( int id, int x, int y ) override;
42
43 struct Info
44 {
45 int id{-1};
46 Vector2f position;
47 };
48
49 class MultiInfo
50 {
51 public:
52 bool update( Info info, bool remove = false );
53 enum class Finger
54 {
55 First,
56 Second
57 };
58 std::optional<Vector2f> getPosition( Finger fing ) const;
59 std::optional<Vector2f> getPosition( int id ) const;
60 std::optional<Finger> getFingerById( int id ) const;
61 std::optional<int> getIdByFinger( Finger fing ) const;
62 int getNumPressed() const;
63 private:
64 std::array<Info,2> info_;
65 };
66
67 MultiInfo multiInfo_;
68 MultiInfo multiPrevInfo_;
69 bool mouseMode_{ false };
70 ModeBit touchModeMask_{ ModeBit::All };
71
72 std::function<void( AffineXf3f& )> transformModifierCb_;
73};
74
75}
#define MR_MAKE_FLAG_OPERATORS_IN_CLASS(T)
Definition MRFlagOperators.h:9
Definition MRTouchesController.h:17
MR_ADD_CTOR_DELETE_MOVE(TouchesController)
void setModeMask(ModeBit mask)
Definition MRTouchesController.h:37
void setTrasformModifierCb(std::function< void(AffineXf3f &)> cb)
Definition MRTouchesController.h:22
ModeBit
Definition MRTouchesController.h:26
Definition MRCameraOrientationPlugin.h:8
Definition MRViewerEventsListener.h:29