Touch.h
Go to the documentation of this file.
1 /****
2  * Touch.h
3  *
4  * Copyright 2021 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the Sming-Graphics Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  * @author: May 2021 - mikee47 <mike@sillyhouse.net>
19  *
20  ****/
21 
22 #pragma once
23 
24 #include "Types.h"
25 
26 namespace Graphics
27 {
28 class Device;
29 
30 class Touch
31 {
32 public:
33  struct State {
35  uint16_t pressure;
36  };
37 
38  struct Calibration {
39  Point origin{0, 0};
40  Point num{1, 1};
41  Point den{1, 1};
42 
44  {
45  IntPoint p(pt);
46  p -= origin;
47  p *= num;
48  p /= den;
49  return Point(p);
50  }
51  };
52 
56  using Callback = Delegate<void()>;
57 
58  Touch(Device* device = nullptr) : device(device)
59  {
60  }
61 
66 
71  virtual Size getNativeSize() const = 0;
72 
76  virtual State getState() const = 0;
77 
82  {
83  this->callback = callback;
84  }
85 
89  Size getSize() const
90  {
91  auto size = getNativeSize();
93  std::swap(size.w, size.h);
94  }
95  return size;
96  }
97 
102  {
103  return orientation;
104  }
105 
106  void setCalibration(const Calibration& cal)
107  {
108  calibration = cal;
109  }
110 
115  {
116  return calibration.translate(rawPos);
117  }
118 
119 protected:
124 };
125 
126 } // namespace Graphics
127 
String toString(Graphics::Touch::State state)
A physical display device.
Definition: Libraries/Graphics/src/include/Graphics/Device.h:33
Definition: Touch.h:31
void setCalibration(const Calibration &cal)
Definition: Touch.h:106
virtual bool setOrientation(Orientation orientation)
Set display orientation.
Orientation orientation
Definition: Touch.h:121
Callback callback
Definition: Touch.h:123
Device * device
Definition: Touch.h:120
virtual State getState() const =0
Get current state.
Calibration calibration
Definition: Touch.h:122
Size getSize() const
Get native dimensions for current orientation.
Definition: Touch.h:89
Point translate(Point rawPos)
Translate position into screen co-ordinates.
Definition: Touch.h:114
Orientation getOrientation()
Get current display orientation.
Definition: Touch.h:101
Touch(Device *device=nullptr)
Definition: Touch.h:58
virtual void setCallback(Callback callback)
Register callback to be invoked when state changes.
Definition: Touch.h:81
virtual Size getNativeSize() const =0
Get physical size of display.
The String class.
Definition: WString.h:137
Definition: Virtual.h:31
TPoint< int16_t > Point
Definition: Libraries/Graphics/src/include/Graphics/Types.h:280
Orientation
Defines orientation of display.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:47
Size of rectangular area (width x height)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:105
Definition: Touch.h:38
Point translate(Point pt)
Definition: Touch.h:43
Point den
Definition: Touch.h:41
Point num
Definition: Touch.h:40
Point origin
Definition: Touch.h:39
Definition: Touch.h:33
Point pos
Definition: Touch.h:34
uint16_t pressure
Definition: Touch.h:35