Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "MyGUI_Precompiled.h"
00024 #include "MyGUI_ControllerEdgeHide.h"
00025 #include "MyGUI_Gui.h"
00026 #include "MyGUI_InputManager.h"
00027 #include "MyGUI_WidgetManager.h"
00028 #include "MyGUI_Widget.h"
00029
00030 namespace MyGUI
00031 {
00032
00033 ControllerEdgeHide::ControllerEdgeHide() :
00034 mTime(0),
00035 mRemainPixels(0),
00036 mShadowSize(0)
00037 {
00038 }
00039
00040 void ControllerEdgeHide::prepareItem(WidgetPtr _widget)
00041 {
00042 MYGUI_DEBUG_ASSERT(mTime > 0, "Time must be > 0");
00043
00044 float k = 0;
00045 const MyGUI::IntCoord& coord = _widget->getCoord();
00046 const MyGUI::IntSize& view_size = Gui::getInstance().getViewSize();
00047 if ((coord.left <= 0) && !(coord.right() >= view_size.width))
00048 {
00049 k = - (float) coord.left / (coord.width - mRemainPixels - mShadowSize);
00050 }
00051 if ((coord.top <= 0) && !(coord.bottom() >= view_size.height))
00052 {
00053 k = - (float)coord.top / (coord.height - mRemainPixels - mShadowSize);
00054 }
00055 if ((coord.right() >= view_size.width) && !(coord.left <= 0))
00056 {
00057 k = 1.f + (coord.left - view_size.width - mRemainPixels) / coord.width;
00058 }
00059 if ((coord.bottom() >= view_size.height) && !(coord.top <= 0))
00060 {
00061 k = 1.f + (coord.top - view_size.height - mRemainPixels) / coord.height;
00062 }
00063
00064 mElapsedTime = (asin(k) + 1./2) * mTime;
00065
00066
00067 eventPreAction(_widget);
00068 }
00069
00070 bool ControllerEdgeHide::addTime(WidgetPtr _widget, float _time)
00071 {
00072 WidgetPtr keyFocus = InputManager::getInstance().getKeyFocusWidget();
00073 WidgetPtr mouseFocus = InputManager::getInstance().getMouseFocusWidget();
00074
00075 while ((keyFocus != nullptr) && (_widget != keyFocus))
00076 keyFocus = keyFocus->getParent();
00077 while ((mouseFocus != nullptr) && (_widget != mouseFocus))
00078 mouseFocus = mouseFocus->getParent();
00079
00080
00081 bool haveFocus = ((keyFocus != nullptr) || (mouseFocus != nullptr)) || (_widget->isVisible() == false);
00082
00083 mElapsedTime += (1 - 2*haveFocus) * _time;
00084
00085 if (mElapsedTime >= mTime)
00086 {
00087 mElapsedTime = mTime;
00088 return true;
00089 }
00090 if (mElapsedTime <= 0)
00091 {
00092 mElapsedTime = 0.0f;
00093 return true;
00094 }
00095
00096 #ifndef M_PI
00097 const float M_PI = 3.141593;
00098 #endif
00099 float k = sin(M_PI * mElapsedTime/mTime - M_PI/2);
00100 if (k<0) k = (-pow((-k), (float)0.7) + 1)/2;
00101 else k = (pow((k), (float)0.7) + 1)/2;
00102
00103 MyGUI::IntCoord coord = _widget->getCoord();
00104 const MyGUI::IntSize& view_size = MyGUI::Gui::getInstance().getViewSize();
00105 bool nearBorder = false;
00106
00107 if ((coord.left <= 0) && !(coord.right() >= view_size.width))
00108 {
00109 coord.left = - int( float(coord.width - mRemainPixels - mShadowSize) * k);
00110 nearBorder = true;
00111 }
00112 if ((coord.top <= 0) && !(coord.bottom() >= view_size.height))
00113 {
00114 coord.top = - int( float(coord.height - mRemainPixels - mShadowSize) * k);
00115 nearBorder = true;
00116 }
00117 if ((coord.right() >= view_size.width) && !(coord.left <= 0))
00118 {
00119 coord.left = int(float(view_size.width) - float(mRemainPixels) - float(coord.width) * (float(1) - k));
00120 nearBorder = true;
00121 }
00122 if ((coord.bottom() >= view_size.height) && !(coord.top <= 0))
00123 {
00124 coord.top = int(float(view_size.height) - float(mRemainPixels) - float(coord.height) * (float(1) - k));
00125 nearBorder = true;
00126 }
00127
00128 if (!nearBorder) mElapsedTime = 0;
00129
00130 _widget->setCoord(coord);
00131
00132 eventUpdateAction(_widget);
00133
00134 return true;
00135 }
00136
00137 void ControllerEdgeHide::setProperty(const std::string& _key, const std::string& _value)
00138 {
00139 if (_key == "Time") setTime(utility::parseValue<float>(_value));
00140 else if (_key == "RemainPixels") setRemainPixels(utility::parseValue<int>(_value));
00141 else if (_key == "ShadowSize") setShadowSize(utility::parseValue<int>(_value));
00142 }
00143
00144 }