SDXFrameWork 0.09 SDXFrameWork

- Main Page
- Related Pages
- Classes

All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Touch.h
1 #pragma once//☀SDL
2 #include <Multimedia/Key.h>
3 #include <Multimedia/Window.h>
4
5 namespace SDX
6 {
7 class Gesture
8 {
9 friend class Input;
10 private:
11 void Position(double X座標, double Y座標)
12 {
13 const double aspA = Window::Single().aspect;
14 const double aspB = (double)Window::GetWidth() / Window::GetHeight();
15
16 if (aspA == aspB)
17 {
18 xBuffer = int(X座標 * Window::GetWidth());
19 yBuffer = int(Y座標 * Window::GetHeight());
20 }
21 else if (aspA > aspB){
22 //横が余る
23 double rate = aspA / aspB;
24 double pos = (X座標 - (rate - 1) / rate / 2) * rate;
25 xBuffer = int(pos * Window::GetWidth());
26 yBuffer = int(Y座標 * Window::GetHeight());
27 }
28 else{
29 //上が余る
30 double rate = aspB / aspA;
31 double pos = (Y座標 - (rate - 1) / rate / 2) * rate;
32 xBuffer = int(X座標 * Window::GetWidth());
33 yBuffer = int(pos * Window::GetHeight());
34 }
35 }
36
37 bool press = false;
38 double xBuffer;
39 double yBuffer;
40 public:
41 bool on = false;
42
43 double rotate = 0;//回転ジェスチャー
44 double pinche = 0;//ピンチ操作
45
46 double x = 0;//ジェスチャー操作の中心点
47 double y = 0;
48
49 int fingerCount = 0;//ジェスチャーに使った指の本数
50
51 void Update()
52 {
53 on = press;
54 press = false;
55 }
56
57 void Reset()
58 {
59 press = false;
60 on = false;
61 rotate = 0;
62 pinche = 0;
63 x = 0;
64 y = 0;
65 fingerCount = 0;
66 }
67 };
68
69 class Touch
70 {
71 friend class Input;
72 private:
73 bool press = false;
74 double xBuffer;
75 double yBuffer;
76
77 void Position(double X座標 , double Y座標)
78 {
79 const double aspA = Window::Single().aspect;
80 const double aspB = (double)Window::GetWidth() / Window::GetHeight();
81
82 if (aspA == aspB)
83 {
84 xBuffer = int(X座標 * Window::GetWidth());
85 yBuffer = int(Y座標 * Window::GetHeight());
86 }else if (aspA > aspB){
87 //横が余る
88 double rate = aspA / aspB;
89 double pos = (X座標 - (rate - 1) / rate / 2) * rate;
90 xBuffer = int(pos * Window::GetWidth());
91 yBuffer = int(Y座標 * Window::GetHeight());
92 }else{
93 //上が余る
94 double rate = aspB / aspA;
95 double pos = ( Y座標 - (rate - 1) / rate / 2) * rate;
96 xBuffer = int(X座標 * Window::GetWidth());
97 yBuffer = int(pos * Window::GetHeight());
98 }
99 }
100
101 public:
102 double x = 0;
103 double y = 0;
104
105 double moveX = 0;
106 double moveY = 0;
107
108 bool on = false;
109 bool off = false;
110 bool hold = false;
111
112 unsigned int holdCount = 0;//押されている時間
113
115 void Reset()
116 {
117 x = 0;
118 y = 0;
119
120 moveX = 0;
121 moveY = 0;
122
123 on = false;
124 off = false;
125 hold = false;
126 press = false;
127 }
128
130 void Update()
131 {
132 on = (!hold && press);
133 off = (hold && !press);
134 hold = press;
135 if (press)
136 {
137 ++holdCount;
138 }else{
139 holdCount = 0;
140 }
141
142 if ( !on )
143 {
144 moveX = xBuffer - x;
145 moveY = yBuffer - y;
146 }
147 else
148 {
149 moveX = 0;
150 moveY = 0;
151 }
152
153 x = xBuffer;
154 y = yBuffer;
155 }
156 };
157 }
SDX::Window::GetWidth
static int GetWidth()
ウィンドウ幅の取得.
Definition: Window.h:67
SDX::Window::GetHeight
static int GetHeight()
ウィンドウ高さの取得.
Definition: Window.h:73
SDX::Gesture
Definition: Touch.h:7
SDX::Touch::Reset
void Reset()
状態のリセット.
Definition: Touch.h:115
SDX::Input
キーやマウスによる入力をまとめて管理するクラス.
Definition: Input.h:13
SDX::Touch::Update
void Update()
状態の更新.
Definition: Touch.h:130
SDX::Touch
Definition: Touch.h:69