UiWidget.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. #include <OgreMath.h>
  2. #include <OgreRoot.h>
  3. #include "core/ConfigVar.h"
  4. #include "core/CameraManager.h"
  5. #include "core/DebugDraw.h"
  6. #include "core/Logger.h"
  7. #include "core/ScriptManager.h"
  8. #include "core/Timer.h"
  9. #include "core/UiWidget.h"
  10. ConfigVar cv_debug_ui("debug_ui", "Draw ui debug info", "0");
  11. UiWidget::UiWidget(const Ogre::String& name):
  12. m_Name(name),
  13. m_PathName(name),
  14. m_Parent(nullptr)
  15. {
  16. Initialise();
  17. }
  18. UiWidget::UiWidget(const Ogre::String& name, const Ogre::String& path_name, UiWidget* parent):
  19. m_Name(name),
  20. m_PathName(path_name),
  21. m_Parent(parent)
  22. {
  23. Initialise();
  24. }
  25. UiWidget::~UiWidget()
  26. {
  27. for(unsigned int i = 0; i < m_Animations.size(); ++i)
  28. {
  29. delete m_Animations[i];
  30. }
  31. ScriptManager::getSingleton().RemoveEntity(ScriptManager::UI, m_PathName);
  32. RemoveAllChildren();
  33. }
  34. void
  35. UiWidget::Initialise()
  36. {
  37. Ogre::Viewport *viewport(CameraManager::getSingleton().getViewport());
  38. m_ScreenWidth = static_cast<float>(viewport->getActualWidth());
  39. m_ScreenHeight = static_cast<float>(viewport->getActualHeight());
  40. m_Visible = false;
  41. m_Align = LEFT;
  42. m_VerticalAlign = TOP;
  43. m_UpdateTransformation = true;
  44. m_FinalZ = 0;
  45. m_FinalOrigin = Ogre::Vector2::ZERO;
  46. m_FinalTranslate = Ogre::Vector2::ZERO;
  47. m_FinalSize = Ogre::Vector2(m_ScreenWidth, m_ScreenHeight);
  48. m_FinalScale = Ogre::Vector2(1, 1);
  49. m_FinalRotation = 0;
  50. m_OriginXPercent = 0;
  51. m_OriginX = 0;
  52. m_OriginYPercent = 0;
  53. m_OriginY = 0;
  54. m_XPercent = 0;
  55. m_X = 0;
  56. m_YPercent = 0;
  57. m_Y = 0;
  58. m_Z = 0;
  59. m_WidthPercent = 100;
  60. m_Width = 0;
  61. m_HeightPercent = 100;
  62. m_Height = 0;
  63. m_Scale = Ogre::Vector2(1.0f, 1.0f);
  64. m_Rotation = 0.0f;
  65. m_Scissor = false;
  66. m_ScissorTop = 0;
  67. m_ScissorBottom = static_cast<int>(m_ScreenHeight);
  68. m_ScissorLeft = 0;
  69. m_ScissorRight = static_cast<int>(m_ScreenWidth);
  70. m_AnimationCurrent = nullptr;
  71. m_AnimationDefault = "";
  72. m_AnimationState = UiAnimation::DEFAULT;
  73. m_Colour1 = Ogre::ColourValue(1, 1, 1, 1);
  74. m_Colour2 = Ogre::ColourValue(1, 1, 1, 1);
  75. m_Colour3 = Ogre::ColourValue(1, 1, 1, 1);
  76. m_Colour4 = Ogre::ColourValue(1, 1, 1, 1);
  77. ScriptManager::getSingleton().AddEntity(ScriptManager::UI, m_PathName, nullptr);
  78. }
  79. void
  80. UiWidget::Update()
  81. {
  82. if(m_Visible != true)
  83. {
  84. return;
  85. }
  86. if(m_AnimationCurrent != nullptr)
  87. {
  88. float delta_time = Timer::getSingleton().GetGameTimeDelta();
  89. float time = m_AnimationCurrent->GetTime();
  90. // if animation ended
  91. if(time + delta_time >= m_AnimationEndTime)
  92. {
  93. if(time != m_AnimationEndTime)
  94. {
  95. m_AnimationCurrent->AddTime(m_AnimationEndTime - time);
  96. }
  97. for(unsigned int i = 0; i < m_AnimationSync.size(); ++i)
  98. {
  99. ScriptManager::getSingleton().ContinueScriptExecution(m_AnimationSync[i]);
  100. }
  101. m_AnimationSync.clear();
  102. if(m_AnimationState == UiAnimation::DEFAULT && m_AnimationDefault != "")
  103. {
  104. // in case of cycled default we need to sync with end
  105. time = time + delta_time - m_AnimationCurrent->GetLength();
  106. PlayAnimation(m_AnimationDefault, UiAnimation::DEFAULT, time, -1);
  107. }
  108. }
  109. else
  110. {
  111. m_AnimationCurrent->AddTime(delta_time);
  112. }
  113. }
  114. else if(m_AnimationCurrent == nullptr && m_AnimationState == UiAnimation::DEFAULT && m_AnimationDefault != "")
  115. {
  116. PlayAnimation(m_AnimationDefault, UiAnimation::DEFAULT, 0, -1);
  117. }
  118. for(size_t i = 0; i < m_Children.size(); ++i)
  119. {
  120. m_Children[i]->Update();
  121. }
  122. if(m_UpdateTransformation == true)
  123. {
  124. UpdateTransformation();
  125. }
  126. // debug output
  127. if(cv_debug_ui.GetI() >= 1)
  128. {
  129. float local_x1 = -m_FinalOrigin.x;
  130. float local_y1 = -m_FinalOrigin.y;
  131. float local_x2 = m_FinalSize.x + local_x1;
  132. float local_y2 = m_FinalSize.y + local_y1;
  133. float x = m_FinalTranslate.x;
  134. float y = m_FinalTranslate.y;
  135. DEBUG_DRAW.SetScreenSpace(true);
  136. DEBUG_DRAW.SetColour(Ogre::ColourValue(1, 0, 0, 1));
  137. int x1, y1, x2, y2, x3, y3, x4, y4;
  138. if(m_FinalRotation != 0)
  139. {
  140. float cos = Ogre::Math::Cos(Ogre::Radian(Ogre::Degree(m_FinalRotation)));
  141. float sin = Ogre::Math::Sin(Ogre::Radian(Ogre::Degree(m_FinalRotation)));
  142. x1 = static_cast<int>(local_x1 * cos - local_y1 * sin + x);
  143. y1 = static_cast<int>(local_x1 * sin + local_y1 * cos + y);
  144. x2 = static_cast<int>(local_x2 * cos - local_y1 * sin + x);
  145. y2 = static_cast<int>(local_x2 * sin + local_y1 * cos + y);
  146. x3 = static_cast<int>(local_x2 * cos - local_y2 * sin + x);
  147. y3 = static_cast<int>(local_x2 * sin + local_y2 * cos + y);
  148. x4 = static_cast<int>(local_x1 * cos - local_y2 * sin + x);
  149. y4 = static_cast<int>(local_x1 * sin + local_y2 * cos + y);
  150. }
  151. else
  152. {
  153. x1 = static_cast<int>(local_x1 + x);
  154. y1 = static_cast<int>(local_y1 + y);
  155. x2 = static_cast<int>(local_x2 + x);
  156. y2 = static_cast<int>(local_y1 + y);
  157. x3 = static_cast<int>(local_x2 + x);
  158. y3 = static_cast<int>(local_y2 + y);
  159. x4 = static_cast<int>(local_x1 + x);
  160. y4 = static_cast<int>(local_y2 + y);
  161. }
  162. // slightly modify to let show things that are on board of screen
  163. DEBUG_DRAW.Line(static_cast<float>(x1), static_cast<float>(y1 + 1), static_cast<float>(x2), static_cast<float>(y2 + 1));
  164. DEBUG_DRAW.Line(static_cast<float>(x2 - 1), static_cast<float>(y2), static_cast<float>(x3 - 1), static_cast<float>(y3));
  165. DEBUG_DRAW.Line(static_cast<float>(x3), static_cast<float>(y3), static_cast<float>(x4), static_cast<float>(y4));
  166. DEBUG_DRAW.Line(static_cast<float>(x4), static_cast<float>(y4), static_cast<float>(x1), static_cast<float>(y1));
  167. // draw translation
  168. DEBUG_DRAW.SetColour(Ogre::ColourValue(0, 1, 0, 1));
  169. Ogre::Vector2 area_origin = (m_Parent != nullptr) ? m_Parent->GetFinalOrigin() : Ogre::Vector2::ZERO;
  170. Ogre::Vector2 area_translate = (m_Parent != nullptr) ? m_Parent->GetFinalTranslate() : Ogre::Vector2::ZERO;
  171. Ogre::Vector2 pos = area_translate - area_origin;
  172. DEBUG_DRAW.Line(pos.x, pos.y, x, y);
  173. DEBUG_DRAW.Quad(x - 2, y - 2, x + 2, y - 2, x + 2, y + 2, x - 2, y + 2);
  174. if(cv_debug_ui.GetI() >= 2)
  175. {
  176. DEBUG_DRAW.SetColour(Ogre::ColourValue::White);
  177. DEBUG_DRAW.SetTextAlignment(DEBUG_DRAW.LEFT);
  178. DEBUG_DRAW.Text(static_cast<float>(x1 + 3), static_cast<float>(y1), m_PathName);
  179. DEBUG_DRAW.Text(static_cast<float>(x1 + 3), static_cast<float>(y1 + 12), GetCurrentAnimationName());
  180. }
  181. // draw origin
  182. DEBUG_DRAW.SetColour(Ogre::ColourValue(1, 0, 0, 1));
  183. DEBUG_DRAW.Line(x, y, static_cast<float>(x1), static_cast<float>(y1 + 1));
  184. }
  185. }
  186. void
  187. UiWidget::OnResize()
  188. {
  189. Ogre::Viewport *viewport(CameraManager::getSingleton().getViewport());
  190. m_ScreenWidth = static_cast<float>(viewport->getActualWidth());
  191. m_ScreenHeight = static_cast<float>(viewport->getActualHeight());
  192. for(size_t i = 0; i < m_Children.size(); ++i)
  193. {
  194. m_Children[i]->OnResize();
  195. }
  196. m_UpdateTransformation = true;
  197. }
  198. void
  199. UiWidget::Render()
  200. {
  201. if(m_Visible == true)
  202. {
  203. for(size_t i = 0; i < m_Children.size(); ++i)
  204. {
  205. m_Children[i]->Render();
  206. }
  207. }
  208. }
  209. void
  210. UiWidget::SetVisible(const bool visible)
  211. {
  212. m_Visible = visible;
  213. }
  214. bool
  215. UiWidget::IsVisible() const
  216. {
  217. return m_Visible;
  218. }
  219. const Ogre::String&
  220. UiWidget::GetName() const
  221. {
  222. return m_Name;
  223. }
  224. void
  225. UiWidget::AddChild(UiWidget *widget)
  226. {
  227. m_Children.push_back(widget);
  228. }
  229. UiWidget*
  230. UiWidget::GetChild(const Ogre::String& name)
  231. {
  232. for(size_t i = 0; i < m_Children.size(); ++i)
  233. {
  234. if(m_Children[i]->GetName() == name)
  235. {
  236. return m_Children[i];
  237. }
  238. }
  239. return nullptr;
  240. }
  241. void
  242. UiWidget::RemoveAllChildren()
  243. {
  244. for(size_t i = 0; i < m_Children.size(); ++i)
  245. {
  246. delete m_Children[i];
  247. }
  248. m_Children.clear();
  249. }
  250. void
  251. UiWidget::AddAnimation(UiAnimation* animation)
  252. {
  253. m_Animations.push_back(animation);
  254. }
  255. const Ogre::String&
  256. UiWidget::GetCurrentAnimationName() const
  257. {
  258. if(m_AnimationCurrent != nullptr)
  259. {
  260. return m_AnimationCurrent->GetName();
  261. }
  262. return Ogre::StringUtil::BLANK;
  263. }
  264. void
  265. UiWidget::PlayAnimation(const Ogre::String& animation, UiAnimation::State state, const float start, const float end)
  266. {
  267. for(size_t i = 0; i < m_Animations.size(); ++i)
  268. {
  269. if(m_Animations[i]->GetName() == animation)
  270. {
  271. m_AnimationCurrent = m_Animations[i];
  272. m_AnimationCurrent->SetTime((start == -1) ? m_AnimationCurrent->GetLength() : start);
  273. m_AnimationCurrent->AddTime(0);
  274. m_AnimationEndTime = (end == -1) ? m_AnimationCurrent->GetLength() : end;
  275. m_AnimationState = state;
  276. return;
  277. }
  278. }
  279. // stop current state and animation
  280. m_AnimationCurrent = nullptr;
  281. m_AnimationState = UiAnimation::ONCE;
  282. LOG_ERROR("Widget '" + m_Name + "' doesn't has animation '" + animation + "'.");
  283. }
  284. void
  285. UiWidget::ScriptPlayAnimation(const char* name)
  286. {
  287. PlayAnimation(Ogre::String(name), UiAnimation::DEFAULT, 0, -1);
  288. }
  289. void
  290. UiWidget::ScriptPlayAnimationStop(const char* name)
  291. {
  292. PlayAnimation(Ogre::String(name), UiAnimation::ONCE, 0, -1);
  293. }
  294. void
  295. UiWidget::ScriptPlayAnimation(const char* name, const float start, const float end)
  296. {
  297. PlayAnimation(Ogre::String(name), UiAnimation::DEFAULT, start, end);
  298. }
  299. void
  300. UiWidget::ScriptPlayAnimationStop(const char* name, const float start, const float end)
  301. {
  302. PlayAnimation(Ogre::String(name), UiAnimation::ONCE, start, end);
  303. }
  304. void
  305. UiWidget::ScriptSetDefaultAnimation(const char* animation)
  306. {
  307. m_AnimationDefault = Ogre::String(animation);
  308. m_AnimationState = UiAnimation::DEFAULT;
  309. }
  310. int
  311. UiWidget::ScriptAnimationSync()
  312. {
  313. ScriptId script = ScriptManager::getSingleton().GetCurrentScriptId();
  314. m_AnimationSync.push_back(script);
  315. return -1;
  316. }
  317. void
  318. UiWidget::UpdateTransformation()
  319. {
  320. Ogre::Vector2 area_scale = (m_Parent != nullptr) ? m_Parent->GetFinalScale() : Ogre::Vector2(1, 1);
  321. Ogre::Vector2 area_origin = (m_Parent != nullptr) ? m_Parent->GetFinalOrigin() : Ogre::Vector2::ZERO;
  322. Ogre::Vector2 area_translate = (m_Parent != nullptr) ? m_Parent->GetFinalTranslate() : Ogre::Vector2::ZERO;
  323. Ogre::Vector2 area_size = (m_Parent != nullptr) ? m_Parent->GetFinalSize() : Ogre::Vector2(m_ScreenWidth, m_ScreenHeight);
  324. float area_rotation = (m_Parent != nullptr) ? m_Parent->GetFinalRotation() : 0;
  325. float local_x = ((area_size.x * m_XPercent) / 100.0f + (m_X * m_ScreenHeight / 720.0f) * area_scale.x) - area_origin.x;
  326. float local_y = ((area_size.y * m_YPercent) / 100.0f + (m_Y * m_ScreenHeight / 720.0f) * area_scale.y) - area_origin.y;
  327. float x = local_x;
  328. float y = local_y;
  329. if(area_rotation != 0)
  330. {
  331. float cos = Ogre::Math::Cos(Ogre::Radian(Ogre::Degree(area_rotation)));
  332. float sin = Ogre::Math::Sin(Ogre::Radian(Ogre::Degree(area_rotation)));
  333. x = local_x * cos - local_y * sin;
  334. y = local_x * sin + local_y * cos;
  335. }
  336. m_FinalTranslate.x = area_translate.x;
  337. if(m_Align == RIGHT)
  338. {
  339. m_FinalTranslate.x = area_translate.x + area_size.x;
  340. }
  341. else if(m_Align == CENTER)
  342. {
  343. m_FinalTranslate.x = area_translate.x + area_size.x / 2;
  344. }
  345. m_FinalTranslate.x += x;
  346. m_FinalTranslate.y = area_translate.y;
  347. if(m_VerticalAlign == BOTTOM)
  348. {
  349. m_FinalTranslate.y = area_translate.y + area_size.y;
  350. }
  351. else if(m_VerticalAlign == MIDDLE)
  352. {
  353. m_FinalTranslate.y = area_translate.y + area_size.y / 2;
  354. }
  355. m_FinalTranslate.y += y;
  356. m_FinalZ = (m_Parent != nullptr) ? m_Parent->GetFinalZ() + m_Z : m_Z;
  357. m_FinalScale = area_scale * m_Scale;
  358. m_FinalSize.x = (area_size.x * m_WidthPercent * m_Scale.x) / 100.0f + (m_Width * m_ScreenHeight / 720.0f) * m_FinalScale.x;
  359. m_FinalSize.y = (area_size.y * m_HeightPercent * m_Scale.y) / 100.0f + (m_Height * m_ScreenHeight / 720.0f) * m_FinalScale.y;
  360. m_FinalOrigin.x = (m_FinalSize.x * m_OriginXPercent) / 100.0f + m_OriginX * m_ScreenHeight * m_FinalScale.x / 720.0f;
  361. m_FinalOrigin.y = (m_FinalSize.y * m_OriginYPercent) / 100.0f + m_OriginY * m_ScreenHeight * m_FinalScale.y / 720.0f;
  362. m_FinalRotation = area_rotation + m_Rotation;
  363. // scissor update
  364. m_ScissorTop = (m_Parent != nullptr) ? m_Parent->GetScissorTop() : 0;
  365. m_ScissorBottom = (m_Parent != nullptr) ? m_Parent->GetScissorBottom() : static_cast<int>(m_ScreenHeight);
  366. m_ScissorLeft = (m_Parent != nullptr) ? m_Parent->GetScissorLeft() : 0;
  367. m_ScissorRight = (m_Parent != nullptr) ? m_Parent->GetScissorRight() : static_cast<int>(m_ScreenWidth);
  368. if(m_Scissor == true)
  369. {
  370. float local_x1 = -m_FinalOrigin.x;
  371. float local_y1 = -m_FinalOrigin.y;
  372. float local_x2 = m_FinalSize.x + local_x1;
  373. float local_y2 = m_FinalSize.y + local_y1;
  374. float x = m_FinalTranslate.x;
  375. float y = m_FinalTranslate.y;
  376. int x1, y1, x2, y2, x3, y3, x4, y4;
  377. if(m_FinalRotation != 0)
  378. {
  379. float cos = Ogre::Math::Cos(Ogre::Radian(Ogre::Degree(m_FinalRotation)));
  380. float sin = Ogre::Math::Sin(Ogre::Radian(Ogre::Degree(m_FinalRotation)));
  381. x1 = static_cast<int>(local_x1 * cos - local_y1 * sin + x);
  382. y1 = static_cast<int>(local_x1 * sin + local_y1 * cos + y);
  383. x2 = static_cast<int>(local_x2 * cos - local_y1 * sin + x);
  384. y2 = static_cast<int>(local_x2 * sin + local_y1 * cos + y);
  385. x3 = static_cast<int>(local_x2 * cos - local_y2 * sin + x);
  386. y3 = static_cast<int>(local_x2 * sin + local_y2 * cos + y);
  387. x4 = static_cast<int>(local_x1 * cos - local_y2 * sin + x);
  388. y4 = static_cast<int>(local_x1 * sin + local_y2 * cos + y);
  389. }
  390. else
  391. {
  392. x1 = static_cast<int>(local_x1 + x);
  393. y1 = static_cast<int>(local_y1 + y);
  394. x2 = static_cast<int>(local_x2 + x);
  395. y2 = static_cast<int>(local_y1 + y);
  396. x3 = static_cast<int>(local_x2 + x);
  397. y3 = static_cast<int>(local_y2 + y);
  398. x4 = static_cast<int>(local_x1 + x);
  399. y4 = static_cast<int>(local_y2 + y);
  400. }
  401. m_ScissorTop = std::max(m_ScissorTop, std::min(std::min(y1 , y2), std::min(y3 , y4)));
  402. m_ScissorBottom = std::min(m_ScissorBottom, std::max(std::max(y1 , y2), std::max(y3 , y4)));
  403. m_ScissorLeft = std::max(m_ScissorLeft, std::min(std::min(x1 , x2), std::min(x3 , x4)));
  404. m_ScissorRight = std::min(m_ScissorRight, std::max(std::max(x1 , x2), std::max(x3 , x4)));
  405. }
  406. m_UpdateTransformation = false;
  407. for(size_t i = 0; i < m_Children.size(); ++i)
  408. {
  409. m_Children[i]->UpdateTransformation();
  410. }
  411. }
  412. void
  413. UiWidget::SetAlign(const UiWidget::Align align)
  414. {
  415. m_Align = align;
  416. }
  417. void
  418. UiWidget::SetVerticalAlign(const UiWidget::VerticalAlign valign)
  419. {
  420. m_VerticalAlign = valign;
  421. }
  422. float
  423. UiWidget::GetFinalZ() const
  424. {
  425. return m_FinalZ;
  426. }
  427. Ogre::Vector2
  428. UiWidget::GetFinalOrigin() const
  429. {
  430. return m_FinalOrigin;
  431. }
  432. Ogre::Vector2
  433. UiWidget::GetFinalTranslate() const
  434. {
  435. return m_FinalTranslate;
  436. }
  437. Ogre::Vector2
  438. UiWidget::GetFinalSize() const
  439. {
  440. return m_FinalSize;
  441. }
  442. Ogre::Vector2
  443. UiWidget::GetFinalScale() const
  444. {
  445. return m_FinalScale;
  446. }
  447. float
  448. UiWidget::GetFinalRotation() const
  449. {
  450. return m_FinalRotation;
  451. }
  452. void
  453. UiWidget::SetOriginX(const float percent, const float x)
  454. {
  455. m_OriginXPercent = percent;
  456. m_OriginX = x;
  457. m_UpdateTransformation = true;
  458. }
  459. void
  460. UiWidget::SetOriginY(const float percent, const float y)
  461. {
  462. m_OriginYPercent = percent;
  463. m_OriginY = y;
  464. m_UpdateTransformation = true;
  465. }
  466. void
  467. UiWidget::SetX(const float percent, const float x)
  468. {
  469. m_XPercent = percent;
  470. m_X = x;
  471. m_UpdateTransformation = true;
  472. }
  473. void
  474. UiWidget::SetY(const float percent, const float y)
  475. {
  476. m_YPercent = percent;
  477. m_Y = y;
  478. m_UpdateTransformation = true;
  479. }
  480. void
  481. UiWidget::SetZ(const float z)
  482. {
  483. m_Z = z;
  484. m_UpdateTransformation = true;
  485. }
  486. void
  487. UiWidget::SetWidth(const float percent, const float width)
  488. {
  489. m_WidthPercent = percent;
  490. m_Width = width;
  491. m_UpdateTransformation = true;
  492. }
  493. void
  494. UiWidget::SetHeight(const float percent, const float height)
  495. {
  496. m_HeightPercent = percent;
  497. m_Height = height;
  498. m_UpdateTransformation = true;
  499. }
  500. void
  501. UiWidget::SetScale(const Ogre::Vector2& scale)
  502. {
  503. m_Scale = scale;
  504. m_UpdateTransformation = true;
  505. }
  506. void
  507. UiWidget::SetRotation(const float degree)
  508. {
  509. m_Rotation = degree;
  510. m_UpdateTransformation = true;
  511. }
  512. void
  513. UiWidget::SetScissor(bool scissor)
  514. {
  515. m_Scissor = scissor;
  516. m_UpdateTransformation = true;
  517. }
  518. int
  519. UiWidget::GetScissorTop() const
  520. {
  521. return m_ScissorTop;
  522. }
  523. int
  524. UiWidget::GetScissorBottom() const
  525. {
  526. return m_ScissorBottom;
  527. }
  528. int
  529. UiWidget::GetScissorLeft() const
  530. {
  531. return m_ScissorLeft;
  532. }
  533. int
  534. UiWidget::GetScissorRight() const
  535. {
  536. return m_ScissorRight;
  537. }
  538. void
  539. UiWidget::SetColour(const float r, const float g, const float b)
  540. {
  541. m_Colour1.r = r; m_Colour1.g = g; m_Colour1.b = b;
  542. m_Colour2.r = r; m_Colour2.g = g; m_Colour2.b = b;
  543. m_Colour3.r = r; m_Colour3.g = g; m_Colour3.b = b;
  544. m_Colour4.r = r; m_Colour4.g = g; m_Colour4.b = b;
  545. m_UpdateTransformation = true;
  546. }
  547. void
  548. UiWidget::SetColours(const float r1, const float g1, const float b1, const float r2, const float g2, const float b2, const float r3, const float g3, const float b3, const float r4, const float g4, const float b4)
  549. {
  550. m_Colour1.r = r1; m_Colour1.g = g1; m_Colour1.b = b1;
  551. m_Colour2.r = r2; m_Colour2.g = g2; m_Colour2.b = b2;
  552. m_Colour3.r = r3; m_Colour3.g = g3; m_Colour3.b = b3;
  553. m_Colour4.r = r4; m_Colour4.g = g4; m_Colour4.b = b4;
  554. m_UpdateTransformation = true;
  555. }
  556. void
  557. UiWidget::SetAlpha(const float a)
  558. {
  559. m_Colour1.a = a;
  560. m_Colour2.a = a;
  561. m_Colour3.a = a;
  562. m_Colour4.a = a;
  563. m_UpdateTransformation = true;
  564. }