20 const float M_PI = 3.141593f;
22 void ControllerEdgeHide::prepareItem(Widget* _widget)
24 recalculateTime(_widget);
25 eventPreAction(_widget,
this);
28 bool ControllerEdgeHide::addTime(Widget* _widget,
float _time)
30 const IntSize& view_size = _widget->getParentSize();
32 if (view_size.width <= 1 && view_size.height <= 1)
35 Widget* keyFocus = InputManager::getInstance().getKeyFocusWidget();
36 Widget* mouseFocus = InputManager::getInstance().getMouseFocusWidget();
38 while ((keyFocus !=
nullptr) && (_widget != keyFocus))
39 keyFocus = keyFocus->getParent();
40 while ((mouseFocus !=
nullptr) && (_widget != mouseFocus))
41 mouseFocus = mouseFocus->getParent();
44 bool haveFocus = ((keyFocus !=
nullptr) || (mouseFocus !=
nullptr)) || (!_widget->getVisible());
46 mElapsedTime += haveFocus ? -_time : _time;
48 if (mElapsedTime >= mTime)
52 if (mElapsedTime <= 0)
58 float k = std::sin(
M_PI * mElapsedTime / mTime -
M_PI / 2);
60 k = (-std::pow(-k, 0.7f) + 1) / 2;
62 k = (std::pow(k, 0.7f) + 1) / 2;
66 if (coord != mLastCoord)
71 recalculateTime(_widget);
74 bool nearBorder =
false;
76 bool behindLeft = coord.
left <= 0;
77 bool behindRight = coord.
right() >= view_size.width - 1;
78 bool behindTop = coord.
top <= 0;
79 bool behindBottom = coord.
bottom() >= view_size.height - 1;
80 if (behindLeft && !behindRight)
82 coord.
left = -int(
float(coord.
width - mRemainPixels - mShadowSize) * k);
85 if (behindTop && !behindBottom)
87 coord.
top = -int(
float(coord.
height - mRemainPixels - mShadowSize) * k);
90 if (behindRight && !behindLeft)
92 coord.
left = int(
float(view_size.width - 1) -
float(mRemainPixels) * k -
float(coord.
width) * (1.f - k));
95 if (behindBottom && !behindTop)
97 coord.
top = int(
float(view_size.height - 1) -
float(mRemainPixels) * k -
float(coord.
height) * (1.f - k));
103 _widget->setCoord(coord);
111 eventUpdateAction(_widget,
this);
116 void ControllerEdgeHide::setProperty(std::string_view _key, std::string_view _value)
120 else if (_key ==
"RemainPixels")
122 else if (_key ==
"ShadowSize")
126 void ControllerEdgeHide::recalculateTime(Widget* _widget)
132 bool behindLeft = coord.
left <= 0;
133 bool behindRight = coord.
right() >= view_size.
width - 1;
134 bool behindTop = coord.
top <= 0;
135 bool behindBottom = coord.
bottom() >= view_size.
height - 1;
137 if (behindLeft && !behindRight)
139 k = -(float)coord.
left / (coord.
width - mRemainPixels - mShadowSize);
141 else if (behindTop && !behindBottom)
143 k = -(float)coord.
top / (coord.
height - mRemainPixels - mShadowSize);
145 else if (behindRight && !behindLeft)
147 k = (float)(coord.
right() - view_size.
width + 1) / (coord.
width - mRemainPixels);
149 else if (behindBottom && !behindTop)
157 mElapsedTime = (std::asin(std::pow(2 * k - 1, 1 / 0.7f)) /
M_PI + 1.f / 2) * mTime;
159 mElapsedTime = (std::asin(-std::pow(-2 * k + 1, 1 / 0.7f)) /
M_PI + 1.f / 2) * mTime;
162 void ControllerEdgeHide::setTime(
float _value)
167 void ControllerEdgeHide::setRemainPixels(
int _value)
169 mRemainPixels = _value;
172 void ControllerEdgeHide::setShadowSize(
int _value)
174 mShadowSize = _value;
T parseValue(std::string_view value)
types::TCoord< int > IntCoord
types::TSize< int > IntSize