MyGUI  3.0.1
MyGUI_RotatingSkin.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_RotatingSkin.h"
25 #include "MyGUI_RenderItem.h"
26 #include "MyGUI_CommonStateInfo.h"
27 
28 namespace MyGUI
29 {
30 
32  SubSkin(),
33  mAngle(0.0f),
34  mLocalCenter(false)
35  {
36  for (int i = 0; i<4; ++i)
37  {
38  mBaseAngles[i] = 0.0f;
39  mBaseDistances[i] = 0.0f;
40  }
41  }
42 
44  {
45  }
46 
47  void RotatingSkin::setAngle(float _angle)
48  {
49  mAngle = _angle;
50  if (nullptr != mNode) mNode->outOfDate(mRenderItem);
51  }
52 
53  void RotatingSkin::setCenter(const IntPoint &_center, bool _local)
54  {
55  mCenterPos = _center;
56  mLocalCenter = _local;
58  if (nullptr != mNode) mNode->outOfDate(mRenderItem);
59  }
60 
61  IntPoint RotatingSkin::getCenter(bool _local) const
62  {
63  return mCenterPos + (_local ? IntPoint() : mCroppedParent->getAbsolutePosition());
64  }
65 
67  {
68  if ((!mVisible) || mEmptyView) return;
69 
71 
73 
74  float vertex_z = info.maximumDepth;
75 
76  float vertex_left_base = ((info.pixScaleX * (float)(mCurrentCoord.left + mCroppedParent->getAbsoluteLeft() + mCenterPos.left) + info.hOffset) * 2) - 1;
77  float vertex_top_base = -(((info.pixScaleY * (float)(mCurrentCoord.top + mCroppedParent->getAbsoluteTop() + mCenterPos.top) + info.vOffset) * 2) - 1);
78 
79  // FIXME: do it only when size changes
81 
82  quad->set(
83  vertex_left_base + cos(-mAngle + mBaseAngles[0]) * mBaseDistances[0] * info.pixScaleX * -2,
84  vertex_top_base + sin(-mAngle + mBaseAngles[0]) * mBaseDistances[0] * info.pixScaleY * -2,
85  vertex_left_base + cos(-mAngle + mBaseAngles[3]) * mBaseDistances[3] * info.pixScaleX * -2,
86  vertex_top_base + sin(-mAngle + mBaseAngles[3]) * mBaseDistances[3] * info.pixScaleY * -2,
87  vertex_left_base + cos(-mAngle + mBaseAngles[2]) * mBaseDistances[2] * info.pixScaleX * -2,
88  vertex_top_base + sin(-mAngle + mBaseAngles[2]) * mBaseDistances[2] * info.pixScaleY * -2,
89  vertex_left_base + cos(-mAngle + mBaseAngles[1]) * mBaseDistances[1] * info.pixScaleX * -2,
90  vertex_top_base + sin(-mAngle + mBaseAngles[1]) * mBaseDistances[1] * info.pixScaleY * -2,
91  vertex_z,
97  );
98 
100  }
101 
102  inline float len(float x, float y) { return sqrt(x*x + y*y); }
103 
105  {
106 #ifndef M_PI
107  const float M_PI = 3.141593f;
108 #endif
109  // FIXME mLocalCenter ignored
110  float left_base = 0;
111  float top_base = 0;
112 
113  if (!mLocalCenter)
114  {
115  left_base = (float)mCurrentCoord.width;
116  top_base = (float)mCurrentCoord.height;
117  }
118 
119  float width_base = (float)mCurrentCoord.width;
120  float height_base = (float)mCurrentCoord.height;
121 
122  mBaseAngles[0] = atan2((float) - mCenterPos.left, - mCenterPos.top) + M_PI/2;
123  mBaseAngles[1] = atan2((float) - mCenterPos.left, height_base - mCenterPos.top) + M_PI/2;
124  mBaseAngles[2] = atan2((float)width_base - mCenterPos.left, height_base - mCenterPos.top) + M_PI/2;
125  mBaseAngles[3] = atan2((float)width_base - mCenterPos.left, - mCenterPos.top) + M_PI/2;
126 
127  mBaseDistances[0] = len((float) - mCenterPos.left, - mCenterPos.top);
128  mBaseDistances[1] = len((float) - mCenterPos.left, height_base - mCenterPos.top);
129  mBaseDistances[2] = len((float)width_base - mCenterPos.left, height_base - mCenterPos.top);
130  mBaseDistances[3] = len((float)width_base - mCenterPos.left, - mCenterPos.top);
131 
132  }
133 
134 } // namespace MyGUI