• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

MyGUI_RotatingSkin.cpp

Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009 
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014 
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #include "MyGUI_Precompiled.h"
00024 #include "MyGUI_RotatingSkin.h"
00025 #include "MyGUI_RenderItem.h"
00026 #include "MyGUI_CommonStateInfo.h"
00027 
00028 namespace MyGUI
00029 {
00030 
00031     RotatingSkin::RotatingSkin() :
00032         SubSkin(),
00033         mAngle(0.)
00034     {
00035     }
00036 
00037     RotatingSkin::~RotatingSkin()
00038     {
00039     }
00040 
00041     void RotatingSkin::setAngle(float _angle)
00042     {
00043         mAngle = _angle;
00044         if (nullptr != mNode) mNode->outOfDate(mRenderItem);
00045     }
00046 
00047     void RotatingSkin::setCenter(const IntPoint &_center, bool _local)
00048     {
00049         mCenterPos = _center;
00050         mLocalCenter = _local;
00051         recalculateAngles();
00052         if (nullptr != mNode) mNode->outOfDate(mRenderItem);
00053     }
00054 
00055     IntPoint RotatingSkin::getCenter(bool _local) const
00056     {
00057         return mCenterPos + (_local ? IntPoint() : mCroppedParent->getAbsolutePosition());
00058     }
00059 
00060     void RotatingSkin::doRender()
00061     {
00062         if ((false == mVisible) || mEmptyView) return;
00063 
00064         VertexQuad* quad = (VertexQuad*)mRenderItem->getCurrentVertextBuffer();
00065 
00066         const RenderTargetInfo& info = mRenderItem->getRenderTarget()->getInfo();
00067 
00068         float vertex_z = info.maximumDepth;
00069 
00070         float vertex_left_base = ((info.pixScaleX * (float)(mCurrentCoord.left + mCroppedParent->getAbsoluteLeft() + mCenterPos.left) + info.hOffset) * 2) - 1;
00071         float vertex_top_base = -(((info.pixScaleY * (float)(mCurrentCoord.top + mCroppedParent->getAbsoluteTop() + mCenterPos.top) + info.vOffset) * 2) - 1);
00072 
00073         // FIXME: do it only when size changes
00074         recalculateAngles();
00075 
00076         quad->set(
00077             vertex_left_base + cos(-mAngle + mBaseAngles[0]) * mBaseDistances[0] * info.pixScaleX * -2,
00078             vertex_top_base + sin(-mAngle + mBaseAngles[0]) * mBaseDistances[0] * info.pixScaleY * -2,
00079             vertex_left_base + cos(-mAngle + mBaseAngles[3]) * mBaseDistances[3] * info.pixScaleX * -2,
00080             vertex_top_base + sin(-mAngle + mBaseAngles[3]) * mBaseDistances[3] * info.pixScaleY * -2,
00081             vertex_left_base + cos(-mAngle + mBaseAngles[2]) * mBaseDistances[2] * info.pixScaleX * -2,
00082             vertex_top_base + sin(-mAngle + mBaseAngles[2]) * mBaseDistances[2] * info.pixScaleY * -2,
00083             vertex_left_base + cos(-mAngle + mBaseAngles[1]) * mBaseDistances[1] * info.pixScaleX * -2,
00084             vertex_top_base + sin(-mAngle + mBaseAngles[1]) * mBaseDistances[1] * info.pixScaleY * -2,
00085             vertex_z,
00086             mCurrentTexture.left,
00087             mCurrentTexture.top,
00088             mCurrentTexture.right,
00089             mCurrentTexture.bottom,
00090             mCurrentAlpha
00091             );
00092 
00093         mRenderItem->setLastVertexCount(VertexQuad::VertexCount);
00094     }
00095 
00096     inline float len(float x, float y) { return sqrt(x*x + y*y); }
00097 
00098     void RotatingSkin::recalculateAngles()
00099     {
00100 #ifndef M_PI
00101             const float M_PI = 3.141593;
00102 #endif
00103         // FIXME mLocalCenter ignored
00104         float left_base = 0;
00105         float top_base = 0;
00106 
00107         if (!mLocalCenter)
00108         {
00109             left_base = (float)mCurrentCoord.width;
00110             top_base = (float)mCurrentCoord.height;
00111         }
00112 
00113         float width_base = (float)mCurrentCoord.width;
00114         float height_base = (float)mCurrentCoord.height;
00115 
00116         mBaseAngles[0] = atan2((float)           - mCenterPos.left,             - mCenterPos.top) + M_PI/2;
00117         mBaseAngles[1] = atan2((float)           - mCenterPos.left, height_base - mCenterPos.top) + M_PI/2;
00118         mBaseAngles[2] = atan2((float)width_base - mCenterPos.left, height_base - mCenterPos.top) + M_PI/2;
00119         mBaseAngles[3] = atan2((float)width_base - mCenterPos.left,             - mCenterPos.top) + M_PI/2;
00120 
00121         mBaseDistances[0] = len((float)           - mCenterPos.left,             - mCenterPos.top);
00122         mBaseDistances[1] = len((float)           - mCenterPos.left, height_base - mCenterPos.top);
00123         mBaseDistances[2] = len((float)width_base - mCenterPos.left, height_base - mCenterPos.top);
00124         mBaseDistances[3] = len((float)width_base - mCenterPos.left,             - mCenterPos.top);
00125 
00126     }
00127 
00128 } // namespace MyGUI

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1