SDXFrameWork
0.13
SDXFrameWork
Main Page
Related Pages
Classes
All
Classes
Namespaces
Functions
Variables
Enumerations
Enumerator
Pages
Multimedia
Touch.h
1
//Copyright © 2014 SDXFramework
2
//[License]GNU Affero General Public License, version 3
3
//[Contact]http://sourceforge.jp/projects/dxframework/
4
#pragma once
5
#include <Multimedia/Key.h>
6
#include <Multimedia/Window.h>
7
8
namespace
SDX
9
{
12
class
Touch
13
{
14
friend
class
Input
;
15
private
:
16
MONO_STATE(
Touch
)
17
18
bool
press =
false
;
19
double
xBuffer;
20
double
yBuffer;
21
22
void
Position(
double
X座標,
double
Y座標)
23
{
24
//event.tfinger.x等は0.0~1.0の範囲になるので、押した位置を画面の解像度に合わせて計算する
25
const
double
aspA =
Window::activeWindow
->aspect;
26
const
double
aspB = (double)
Window::GetWidth
() /
Window::GetHeight
();
27
28
if
(aspA == aspB)
29
{
30
xBuffer = int(X座標 *
Window::GetWidth
());
31
yBuffer = int(Y座標 *
Window::GetHeight
());
32
}
33
else
if
(aspA > aspB){
34
//横が余る
35
double
rate = aspA / aspB;
36
double
pos = (X座標 - (rate - 1) / rate / 2) * rate;
37
xBuffer = int(pos *
Window::GetWidth
());
38
yBuffer = int(Y座標 *
Window::GetHeight
());
39
}
40
else
{
41
//上が余る
42
double
rate = aspB / aspA;
43
double
pos = (Y座標 - (rate - 1) / rate / 2) * rate;
44
xBuffer = int(X座標 *
Window::GetWidth
());
45
yBuffer = int(pos *
Window::GetHeight
());
46
}
47
}
48
49
public
:
50
double
x
= 0;
51
double
y
= 0;
52
53
double
moveX
= 0;
54
double
moveY
= 0;
55
56
bool
on
=
false
;
57
bool
off
=
false
;
58
bool
hold
=
false
;
59
60
unsigned
int
holdCount
= 0;
61
63
void
Update
()
64
{
65
on
= (!
hold
&& press);
66
off
= (
hold
&& !press);
67
68
hold
= press;
69
if
(press)
70
{
71
++
holdCount
;
72
}
73
else
74
{
75
holdCount
= 0;
76
}
77
78
if
(!
on
)
79
{
80
moveX
= xBuffer -
x
;
81
moveY
= yBuffer -
y
;
82
}
83
else
84
{
85
moveX
= 0;
86
moveY
= 0;
87
}
88
89
x
= xBuffer;
90
y
= yBuffer;
91
}
92
94
void
Reset
()
95
{
96
x
= 0;
97
y
= 0;
98
99
moveX
= 0;
100
moveY
= 0;
101
102
press =
false
;
103
104
on
=
false
;
105
off
=
false
;
106
hold
=
false
;
107
holdCount
= 0;
108
}
109
110
};
111
}
SDX::Window::GetWidth
static int GetWidth()
ウィンドウ幅の取得.
Definition:
Window.h:65
SDX::Window::GetHeight
static int GetHeight()
ウィンドウ高さの取得.
Definition:
Window.h:71
SDX::Touch::moveX
double moveX
前回更新時からの移動量
Definition:
Touch.h:53
SDX::Touch::hold
bool hold
タッチしている間は true
Definition:
Touch.h:58
SDX::Touch::y
double y
タッチしている座標
Definition:
Touch.h:51
SDX::Touch::off
bool off
指を離した直後は true
Definition:
Touch.h:57
SDX::Touch::holdCount
unsigned int holdCount
押されている時間
Definition:
Touch.h:60
SDX::Touch::Reset
void Reset()
状態のリセット.
Definition:
Touch.h:94
SDX::Touch::moveY
double moveY
前回更新時からの移動量
Definition:
Touch.h:54
SDX::Touch::x
double x
タッチしている座標
Definition:
Touch.h:50
SDX::Input
キーやマウスによる入力をまとめて管理するクラス.
Definition:
Input.h:17
SDX::Touch::on
bool on
タッチされた直後は true
Definition:
Touch.h:56
SDX::Touch::Update
void Update()
状態の更新.
Definition:
Touch.h:63
SDX::Touch
タッチ操作.
Definition:
Touch.h:12
SDX::Window::activeWindow
static SubWindow * activeWindow
現在アクティブなウィンドウ
Definition:
Window.h:24
Generated on Sun Jun 28 2015 09:15:35 for SDXFrameWork by
1.8.7