18 const float M_PI = 3.141593f;
33 void ControllerEdgeHide::prepareItem(
Widget* _widget)
35 recalculateTime(_widget);
40 bool ControllerEdgeHide::addTime(Widget* _widget,
float _time)
42 const IntSize& view_size = _widget->getParentSize();
44 if (view_size.width <= 1 && view_size.height <= 1)
50 while ((keyFocus !=
nullptr) && (_widget != keyFocus))
52 while ((mouseFocus !=
nullptr) && (_widget != mouseFocus))
56 bool haveFocus = ((keyFocus !=
nullptr) || (mouseFocus !=
nullptr)) || (_widget->getVisible() ==
false);
58 mElapsedTime += haveFocus ? -_time : _time;
60 if (mElapsedTime >= mTime)
64 if (mElapsedTime <= 0)
70 float k = sin(
M_PI * mElapsedTime / mTime -
M_PI / 2);
71 if (k < 0) k = (-pow(-k, 0.7f) + 1) / 2;
72 else k = (pow(k, 0.7f) + 1) / 2;
76 if (coord != mLastCoord)
82 recalculateTime(_widget);
85 bool nearBorder =
false;
87 if ((coord.
left <= 0) && !(coord.
right() >= view_size.width - 1))
89 coord.
left = - int(
float(coord.
width - mRemainPixels - mShadowSize) * k);
92 if ((coord.
top <= 0) && !(coord.
bottom() >= view_size.height - 1))
94 coord.
top = - int(
float(coord.
height - mRemainPixels - mShadowSize) * k);
97 if ((coord.
right() >= view_size.width - 1) && !(coord.
left <= 0))
99 coord.
left = int(
float(view_size.width - 1) -
float(mRemainPixels) * k -
float(coord.
width) * (1.f - k));
102 if ((coord.
bottom() >= view_size.height - 1) && !(coord.
top <= 0))
104 coord.
top = int(
float(view_size.height - 1) -
float(mRemainPixels) * k -
float(coord.
height) * (1.f - k));
110 _widget->setCoord(coord);
126 setTime(utility::parseValue<float>(_value));
127 else if (_key ==
"RemainPixels")
129 else if (_key ==
"ShadowSize")
133 void ControllerEdgeHide::recalculateTime(
Widget* _widget)
142 k = - (float) coord.
left / (coord.
width - mRemainPixels - mShadowSize);
144 else if ((coord.
top <= 0) && !(coord.
bottom() >= view_size.
height - 1))
146 k = - (float)coord.
top / (coord.
height - mRemainPixels - mShadowSize);
148 else if ((coord.
right() >= view_size.
width - 1) && !(coord.
left <= 0))
150 k = (float)(coord.
right() - view_size.
width + 1 ) / (coord.
width - mRemainPixels);
152 else if ((coord.
bottom() >= view_size.
height - 1) && !(coord.
top <= 0))
160 mElapsedTime = (asin( pow( 2 * k - 1, 1 / 0.7f)) /
M_PI + 1.f / 2) * mTime;
162 mElapsedTime = (asin(-pow(-2 * k + 1, 1 / 0.7f)) /
M_PI + 1.f / 2) * mTime;
172 mRemainPixels = _value;
177 mShadowSize = _value;