forked from VIML/NIController
-
Notifications
You must be signed in to change notification settings - Fork 1
/
HandControl.cpp
181 lines (158 loc) · 3.69 KB
/
HandControl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include "HandControl.h"
// windows header
#include <Windows.h>
/**
* Keyboard simulator
*/
void SendKey( WORD key )
{
INPUT mWinEvent;
mWinEvent.type = INPUT_KEYBOARD;
mWinEvent.ki.time = 0;
mWinEvent.ki.dwFlags = 0;
mWinEvent.ki.wScan = 0;
mWinEvent.ki.wVk = key;
SendInput( 1, &mWinEvent, sizeof(mWinEvent) );
}
void QHandIcon::paint( QPainter *pPainter, const QStyleOptionGraphicsItem *option, QWidget *widget )
{
switch( m_eStatus )
{
case HS_GENERAL:
{
pPainter->setPen( m_penGeneral );
pPainter->drawArc( m_Rect, 0, 360 * 16 );
}
break;
case HS_FIXING:
{
pPainter->setPen( m_penFixingProgress );
pPainter->drawArc( m_Rect, 90*16, 360 * 16 * m_fProgress );
pPainter->setPen( m_penFixing );
pPainter->drawArc( m_Rect, 0, 360 * 16 );
}
break;
case HS_FIXED:
{
pPainter->setPen( m_penFixed );
pPainter->setBrush( m_brushFixed );
pPainter->drawEllipse( m_Rect );
}
break;
}
}
bool QHandControl::UpdateStatus( const QHandControl::EControlStatus& eStatus )
{
if( m_eControlStatus != eStatus )
{
m_eControlStatus = eStatus;
m_HandIcon.show();
switch( m_eControlStatus )
{
case NICS_NO_HAND:
HandReset();
m_HandIcon.hide();
m_qButtons.hide();
m_funcEndInput();
break;
case NICS_STANDBY:
m_HandIcon.SetStatus( QHandIcon::HS_GENERAL );
m_qButtons.hide();
m_funcEndInput();
break;
case NICS_FIXING:
m_HandIcon.SetStatus( QHandIcon::HS_FIXING );
m_FixPos = CurrentPos();
break;
case NICS_FIXED:
m_FixPos = CurrentPos();
m_HandIcon.SetStatus( QHandIcon::HS_FIXED );
m_qButtons.show();
m_itCurrentButton = m_vButtons.end();
m_funcStartInput();
break;
case NICS_INPUT:
m_FixPos = CurrentPos();
break;
}
return true;
}
return false;
}
void QHandControl::UpdateHandPoint( const QPointF& rPt2D, const QVector3D& rPt3D )
{
// add to points list
SHandPos mPos( rPt2D, rPt3D );
m_aTrackList.push_back( mPos );
// move hand icon
m_HandIcon.resetTransform();
m_HandIcon.translate( rPt2D.x(), rPt2D.y() );
// process
if( m_eControlStatus == NICS_NO_HAND )
UpdateStatus( NICS_STANDBY );
if( m_eControlStatus == NICS_STANDBY )
{
if( rPt3D.z() < -m_fHandForwardDistance )
{
// start float hand button if fix
if( Is2DPosFixFor( m_tdPreFixTime, m_fHandMoveThreshold ) )
{
UpdateStatus( NICS_FIXING );
}
}
}
// check if hand move out from button
if( m_eControlStatus == NICS_FIXING )
{
if( QLineF( m_FixPos.mPos2D, rPt2D ).length() > m_fHandMoveThreshold )
{
UpdateStatus( NICS_STANDBY );
}
else
{
float fProgress = ComputeProgress( mPos.tpTime - m_FixPos.tpTime, m_tdFixTime );
m_HandIcon.SetProgress( fProgress );
if( fProgress > 1 )
{
m_qButtons.resetTransform();
m_qButtons.translate( rPt2D.x(), rPt2D.y() + 50 );
UpdateStatus( NICS_FIXED );
}
}
}
if( m_eControlStatus == NICS_FIXED )
{
if( rPt3D.z() > -m_fHandForwardDistance )
UpdateStatus( NICS_STANDBY );
for( auto itBut = m_vButtons.begin(); itBut != m_vButtons.end(); ++ itBut )
{
if( (*itBut)->CheckInSide( rPt2D, rPt3D.z() ) )
{
}
}
}
if( m_eControlStatus == NICS_INPUT )
{
}
}
void QHandControl::BuildButtons()
{
QTimerButton* pBut1 = new QTimerButton();
pBut1->translate( 80, -50 );
pBut1->m_duTimeToPress = m_tdInvokeTime;
pBut1->m_funcPress = [](){
std::cout << "NEXT" << std::endl;
SendKey( VK_NEXT );
};
m_qButtons.addToGroup( pBut1 );
m_vButtons.push_back( pBut1 );
QTimerButton* pBut2 = new QTimerButton();
pBut2->translate( -80, -50 );
pBut2->m_duTimeToPress = m_tdInvokeTime;
pBut2->m_funcPress = [](){
std::cout << "previous" << std::endl;
SendKey( VK_PRIOR );
};
m_qButtons.addToGroup( pBut2 );
m_vButtons.push_back( pBut2 );
}