1+ #include " GestureNode.hpp"
2+ #include < Speedhack.hpp>
3+ #include < Utils.hpp>
4+
5+ using namespace geode ::prelude;
6+ using namespace qolmod ;
7+
8+ bool GestureNode::init ()
9+ {
10+ if (!CCNodeRGBA::init ())
11+ return false ;
12+
13+ setAnchorPoint (ccp (0 , 0 .5f ));
14+
15+ cornerTop = UserSprite::create (fmt::format (" <sprite>{}gesture-corner.png" , " " _spr));
16+ cornerBottom = UserSprite::create (fmt::format (" <sprite>{}gesture-corner.png" , " " _spr));
17+
18+ cornerTop->setAnchorPoint (ccp (0 , 0 ));
19+ cornerBottom->setAnchorPoint (ccp (0 , 0 ));
20+ cornerBottom->setRotation (90 );
21+
22+ sideFill = CCLayerColor::create (ccc4 (255 , 255 , 255 , 255 ));
23+ sideFill->ignoreAnchorPointForPosition (false );
24+ sideFill->setAnchorPoint (ccp (0 , 0 .5f ));
25+ sideFill->setPosition (CCPointZero);
26+
27+ gapFill = CCLayerColor::create (ccc4 (255 , 255 , 255 , 255 ));
28+ gapFill->ignoreAnchorPointForPosition (false );
29+ gapFill->setAnchorPoint (ccp (0 , 0 .5f ));
30+ gapFill->setPosition (CCPointZero);
31+
32+ anchor = GestureAnchor::Left;
33+ realPosition = ccp (0 , CCDirector::get ()->getWinSize ().height * 0 .75f );
34+
35+ scheduleUpdate ();
36+ setContentSize (ccp (4 , 50 ));
37+ setOpacity (100 );
38+
39+ this ->addChild (cornerTop);
40+ this ->addChild (cornerBottom);
41+ this ->addChild (sideFill);
42+ this ->addChild (gapFill);
43+ return true ;
44+ }
45+
46+ void GestureNode::update (float dt)
47+ {
48+ dt = Speedhack::get ()->getRealDeltaTime ();
49+ auto winSize = CCDirector::get ()->getWinSize ();
50+
51+ switch (anchor)
52+ {
53+ case GestureAnchor::Left:
54+ setRotation (0 );
55+ setPosition (ccp (0 , displayedPosition.y ));
56+ break ;
57+
58+ case GestureAnchor::Top:
59+ setRotation (90 );
60+ setPosition (ccp (displayedPosition.x , winSize.height ));
61+ break ;
62+
63+ case GestureAnchor::Right:
64+ setRotation (180 );
65+ setPosition (ccp (winSize.width , displayedPosition.y ));
66+ break ;
67+
68+ case GestureAnchor::Bottom:
69+ setRotation (270 );
70+ setPosition (ccp (displayedPosition.x , 0 ));
71+ break ;
72+ }
73+
74+ float t = 10 * Speedhack::get ()->getRealDeltaTime ();
75+
76+ displayedPosition = ccp (
77+ std::lerp<double >(displayedPosition.x , realPosition.x , t),
78+ std::lerp<double >(displayedPosition.y , realPosition.y , t)
79+ );
80+ }
81+
82+ bool GestureNode::touchBegan (qolmod::Touch* touch)
83+ {
84+ auto local = convertToNodeSpace (touch->location );
85+ log::info (" local: {}" , local);
86+
87+ if (CCRectMake (0 , 0 , getContentWidth (), getContentHeight ()).containsPoint (local))
88+ {
89+ return true ;
90+ }
91+
92+ return false ;
93+ }
94+
95+ void GestureNode::touchMoved (qolmod::Touch* touch)
96+ {
97+ realPosition = touch->location ;
98+ }
99+
100+ void GestureNode::touchEnded (qolmod::Touch* touch)
101+ {
102+
103+ }
104+
105+ void GestureNode::touchCancelled (qolmod::Touch* touch)
106+ {
107+ touchEnded (touch);
108+ }
109+
110+ void GestureNode::setContentSize (const CCSize& contentSize)
111+ {
112+ CCNode::setContentSize (contentSize);
113+
114+ gapFill->setContentSize (ccp (contentSize.width - cornerTop->getContentWidth (), contentSize.height ));
115+ gapFill->setPositionY (contentSize.height / 2 );
116+
117+ sideFill->setContentSize (ccp (cornerTop->getContentWidth (), contentSize.height - cornerTop->getContentHeight () * 2 ));
118+ sideFill->setPosition (ccp (contentSize.width - cornerTop->getContentWidth (), contentSize.height / 2 ));
119+
120+ cornerTop->setPosition (contentSize.width - cornerTop->getContentWidth (), contentSize.height - cornerTop->getContentHeight ());
121+ cornerBottom->setPosition (contentSize.width - cornerTop->getContentWidth (), cornerBottom->getContentHeight ());
122+ }
123+
124+ void GestureNode::setOpacity (GLubyte opacity)
125+ {
126+ CCNodeRGBA::setOpacity (opacity);
127+
128+ cornerTop->setOpacity (opacity);
129+ cornerBottom->setOpacity (opacity);
130+ sideFill->setOpacity (opacity);
131+ gapFill->setOpacity (opacity);
132+ }
133+
134+ void GestureNode::setColor (const ccColor3B& color)
135+ {
136+ CCNodeRGBA::setColor (color);
137+
138+ cornerTop->setColor (color);
139+ cornerBottom->setColor (color);
140+ sideFill->setColor (color);
141+ gapFill->setColor (color);
142+ }
143+
144+ void GestureNode::setAnchor (qolmod::GestureAnchor anchor)
145+ {
146+ if (this ->anchor == anchor)
147+ return ;
148+
149+ auto winSize = CCDirector::get ()->getWinSize ();
150+ auto prev = this ->anchor ;
151+ this ->anchor = anchor;
152+
153+ switch (prev)
154+ {
155+ case GestureAnchor::Top:
156+ displayedPosition.y = winSize.height ;
157+ break ;
158+
159+ case GestureAnchor::Bottom:
160+ displayedPosition.y = 0 ;
161+ break ;
162+
163+ case GestureAnchor::Left:
164+ displayedPosition.y = 0 ;
165+ break ;
166+
167+ case GestureAnchor::Right:
168+ displayedPosition.y = winSize.width ;
169+ break ;
170+ }
171+ }
0 commit comments