UiWidget.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <iostream>
  16. #include <OgreMath.h>
  17. #include <OgreRoot.h>
  18. #include <OgreViewport.h>
  19. #include "common/VGearsApplication.h"
  20. #include "core/ConfigVar.h"
  21. #include "core/CameraManager.h"
  22. #include "core/DebugDraw.h"
  23. #include "core/Logger.h"
  24. #include "core/ScriptManager.h"
  25. #include "core/Timer.h"
  26. #include "core/UiWidget.h"
  27. ConfigVar cv_debug_ui("debug_ui", "Draw ui debug info", "0");
  28. UiWidget::UiWidget(const Ogre::String& name): name_(name), path_name_(name), parent_(nullptr)
  29. {Initialise();}
  30. UiWidget::UiWidget(const Ogre::String& name, const Ogre::String& path_name, UiWidget* parent):
  31. name_(name), path_name_(path_name), parent_(parent)
  32. {Initialise();}
  33. UiWidget::~UiWidget(){
  34. for (unsigned int i = 0; i < animations_.size(); ++ i) delete animations_[i];
  35. ScriptManager::getSingleton().RemoveEntity(ScriptManager::UI, path_name_);
  36. RemoveAllChildren();
  37. }
  38. void UiWidget::Initialise(){
  39. Ogre::Viewport *viewport(CameraManager::getSingleton().getViewport());
  40. screen_width_ = static_cast<float>(viewport->getActualWidth());
  41. screen_height_ = static_cast<float>(viewport->getActualHeight());
  42. visible_ = false;
  43. align_ = LEFT;
  44. vertical_align_ = TOP;
  45. update_transformation_ = true;
  46. final_z_ = 0;
  47. final_origin_ = Ogre::Vector2::ZERO;
  48. final_translate_ = Ogre::Vector2::ZERO;
  49. final_size_ = Ogre::Vector2(screen_width_, screen_height_);
  50. final_scale_ = Ogre::Vector2(1, 1);
  51. final_rotation_ = 0;
  52. origin_x_percent_ = 0;
  53. origin_x_ = 0;
  54. origin_y_percent_ = 0;
  55. origin_y_ = 0;
  56. x_percent_ = 0;
  57. x_ = 0;
  58. y_percent_ = 0;
  59. y_ = 0;
  60. z_ = 0;
  61. width_percent_ = 100;
  62. width_ = 0;
  63. height_percent_ = 100;
  64. height_ = 0;
  65. scale_ = Ogre::Vector2(1.0f, 1.0f);
  66. rotation_ = 0.0f;
  67. scissor_ = false;
  68. local_scissor_ = false;
  69. global_scissor_ = true;
  70. scissor_top_ = 0;
  71. scissor_x_percent_top_ = 0;
  72. scissor_x_top_ = 0;
  73. scissor_bottom_ = screen_height_;
  74. scissor_x_percent_bottom_ = 100;
  75. scissor_x_bottom_ = 0;
  76. scissor_left_ = 0;
  77. scissor_y_percent_left_ = 0;
  78. scissor_y_left_ = 0;
  79. scissor_right_ = screen_width_;
  80. scissor_y_percent_right_ = 100;
  81. scissor_y_right_ = 0;
  82. animation_current_ = nullptr;
  83. animation_default_ = "";
  84. animation_state_ = UiAnimation::DEFAULT;
  85. colour_1_ = Ogre::ColourValue(1, 1, 1, 1);
  86. colour_2_ = Ogre::ColourValue(1, 1, 1, 1);
  87. colour_3_ = Ogre::ColourValue(1, 1, 1, 1);
  88. colour_4_ = Ogre::ColourValue(1, 1, 1, 1);
  89. ScriptManager::getSingleton().AddEntity(ScriptManager::UI, path_name_, nullptr);
  90. }
  91. void UiWidget::Update(){
  92. if (visible_ != true) return;
  93. if (animation_current_ != nullptr){
  94. float delta_time = Timer::getSingleton().GetGameTimeDelta();
  95. float time = animation_current_->GetTime();
  96. // If animation has ended.
  97. if (time + delta_time >= animation_end_time_){
  98. if (time != animation_end_time_)
  99. animation_current_->AddTime(animation_end_time_ - time);
  100. for (unsigned int i = 0; i < animation_sync_.size(); ++ i)
  101. ScriptManager::getSingleton().ContinueScriptExecution(animation_sync_[i]);
  102. animation_sync_.clear();
  103. if (animation_state_ == UiAnimation::DEFAULT && animation_default_ != ""){
  104. // In case of cycled default, it's required to sync with end.
  105. time = time + delta_time - animation_current_->GetLength();
  106. PlayAnimation(animation_default_, UiAnimation::DEFAULT, time, -1);
  107. }
  108. else animation_current_ = NULL;
  109. }
  110. else animation_current_->AddTime(delta_time);
  111. }
  112. else if (
  113. animation_current_ == NULL && animation_state_ == UiAnimation::DEFAULT
  114. && animation_default_ != ""
  115. ){
  116. PlayAnimation(animation_default_, UiAnimation::DEFAULT, 0, -1);
  117. }
  118. if (update_transformation_ == true) UpdateTransformation();
  119. for (unsigned int i = 0; i < children_.size(); ++ i) children_[i]->Update();
  120. // Debug output
  121. if (cv_debug_ui.GetI() >= 1){
  122. float local_x1 = -final_origin_.x;
  123. float local_y1 = -final_origin_.y;
  124. float local_x2 = final_size_.x + local_x1;
  125. float local_y2 = final_size_.y + local_y1;
  126. float x = final_translate_.x;
  127. float y = final_translate_.y;
  128. DEBUG_DRAW.SetScreenSpace(true);
  129. DEBUG_DRAW.SetColour(Ogre::ColourValue(1, 0, 0, 1));
  130. int x1, y1, x2, y2, x3, y3, x4, y4;
  131. if (final_rotation_ != 0){
  132. float cos = Ogre::Math::Cos(Ogre::Radian(Ogre::Degree(final_rotation_)));
  133. float sin = Ogre::Math::Sin(Ogre::Radian(Ogre::Degree(final_rotation_)));
  134. x1 = static_cast<int>(local_x1 * cos - local_y1 * sin + x);
  135. y1 = static_cast<int>(local_x1 * sin + local_y1 * cos + y);
  136. x2 = static_cast<int>(local_x2 * cos - local_y1 * sin + x);
  137. y2 = static_cast<int>(local_x2 * sin + local_y1 * cos + y);
  138. x3 = static_cast<int>(local_x2 * cos - local_y2 * sin + x);
  139. y3 = static_cast<int>(local_x2 * sin + local_y2 * cos + y);
  140. x4 = static_cast<int>(local_x1 * cos - local_y2 * sin + x);
  141. y4 = static_cast<int>(local_x1 * sin + local_y2 * cos + y);
  142. }
  143. else{
  144. x1 = static_cast<int>(local_x1 + x);
  145. y1 = static_cast<int>(local_y1 + y);
  146. x2 = static_cast<int>(local_x2 + x);
  147. y2 = static_cast<int>(local_y1 + y);
  148. x3 = static_cast<int>(local_x2 + x);
  149. y3 = static_cast<int>(local_y2 + y);
  150. x4 = static_cast<int>(local_x1 + x);
  151. y4 = static_cast<int>(local_y2 + y);
  152. }
  153. // Slightly modify to let show things that are on board of screen.
  154. DEBUG_DRAW.Line(
  155. static_cast<float>(x1), static_cast<float>(y1 + 1),
  156. static_cast<float>(x2), static_cast<float>(y2 + 1)
  157. );
  158. DEBUG_DRAW.Line(
  159. static_cast<float>(x2 - 1), static_cast<float>(y2),
  160. static_cast<float>(x3 - 1), static_cast<float>(y3)
  161. );
  162. DEBUG_DRAW.Line(
  163. static_cast<float>(x3), static_cast<float>(y3),
  164. static_cast<float>(x4), static_cast<float>(y4)
  165. );
  166. DEBUG_DRAW.Line(
  167. static_cast<float>(x4), static_cast<float>(y4),
  168. static_cast<float>(x1), static_cast<float>(y1)
  169. );
  170. // Draw translation.
  171. DEBUG_DRAW.SetColour(Ogre::ColourValue(0, 1, 0, 1));
  172. Ogre::Vector2 area_origin
  173. = (parent_ != nullptr) ? parent_->GetFinalOrigin() : Ogre::Vector2::ZERO;
  174. Ogre::Vector2 area_translate
  175. = (parent_ != nullptr) ? parent_->GetFinalTranslate() : Ogre::Vector2::ZERO;
  176. Ogre::Vector2 pos = area_translate - area_origin;
  177. DEBUG_DRAW.Line(pos.x, pos.y, x, y);
  178. DEBUG_DRAW.Quad(x - 2, y - 2, x + 2, y - 2, x + 2, y + 2, x - 2, y + 2);
  179. if (cv_debug_ui.GetI() >= 2){
  180. DEBUG_DRAW.SetColour(Ogre::ColourValue::White);
  181. DEBUG_DRAW.SetTextAlignment(DEBUG_DRAW.LEFT);
  182. DEBUG_DRAW.Text(static_cast<float>(x1 + 3), static_cast<float>(y1), path_name_);
  183. DEBUG_DRAW.Text(
  184. static_cast<float>(x1 + 3), static_cast<float>(y1 + 12), GetCurrentAnimationName()
  185. );
  186. }
  187. // Draw the origin.
  188. DEBUG_DRAW.SetColour(Ogre::ColourValue(1, 0, 0, 1));
  189. DEBUG_DRAW.Line(x, y, static_cast<float>(x1), static_cast<float>(y1 + 1));
  190. }
  191. }
  192. void UiWidget::OnResize(){
  193. Ogre::Viewport *viewport(CameraManager::getSingleton().getViewport());
  194. screen_width_ = static_cast<float>(viewport->getActualWidth());
  195. screen_height_ = static_cast<float>(viewport->getActualHeight());
  196. for (size_t i = 0; i < children_.size(); ++ i) children_[i]->OnResize();
  197. update_transformation_ = true;
  198. }
  199. void UiWidget::Render(){
  200. if (visible_ == true) for (size_t i = 0; i < children_.size(); ++ i) children_[i]->Render();
  201. }
  202. void UiWidget::SetVisible(const bool visible){visible_ = visible;}
  203. bool UiWidget::IsVisible() const{return visible_;}
  204. const Ogre::String& UiWidget::GetName() const{return name_;}
  205. void UiWidget::AddChild(UiWidget *widget){children_.push_back(widget);}
  206. UiWidget* UiWidget::GetChild(const Ogre::String& name){
  207. for (unsigned int i = 0; i < children_.size(); ++ i)
  208. if (children_[i]->GetName() == name) return children_[i];
  209. return NULL;
  210. }
  211. UiWidget* UiWidget::GetChild(const unsigned int id){
  212. if (id >= children_.size()) return NULL;
  213. return children_[id];
  214. }
  215. unsigned int UiWidget::GetNumberOfChildren(){return children_.size();}
  216. void UiWidget::RemoveAllChildren(){
  217. for (size_t i = 0; i < children_.size(); ++ i) delete children_[i];
  218. children_.clear();
  219. }
  220. void UiWidget::AddAnimation(UiAnimation* animation){animations_.push_back(animation);}
  221. const Ogre::String& UiWidget::GetCurrentAnimationName() const{
  222. if (animation_current_ != nullptr) return animation_current_->GetName();
  223. return Ogre::BLANKSTRING;
  224. }
  225. void UiWidget::PlayAnimation(
  226. const Ogre::String& animation, UiAnimation::State state, const float start, const float end
  227. ){
  228. for (size_t i = 0; i < animations_.size(); ++ i){
  229. if (animations_[i]->GetName() == animation){
  230. animation_current_ = animations_[i];
  231. animation_current_->SetTime((start == -1) ? animation_current_->GetLength() : start);
  232. animation_current_->AddTime(0);
  233. animation_end_time_ = (end == -1) ? animation_current_->GetLength() : end;
  234. animation_state_ = state;
  235. return;
  236. }
  237. }
  238. // Stop current state and animation.
  239. animation_current_ = nullptr;
  240. animation_state_ = UiAnimation::ONCE;
  241. LOG_ERROR("Widget '" + name_ + "' doesn't has animation '" + animation + "'.");
  242. }
  243. void UiWidget::ScriptPlayAnimation(const char* name){
  244. PlayAnimation(Ogre::String(name), UiAnimation::DEFAULT, 0, -1);
  245. }
  246. void UiWidget::ScriptPlayAnimationStop(const char* name){
  247. PlayAnimation(Ogre::String(name), UiAnimation::ONCE, 0, -1);
  248. }
  249. void UiWidget::ScriptPlayAnimation(const char* name, const float start, const float end){
  250. PlayAnimation(Ogre::String(name), UiAnimation::DEFAULT, start, end);
  251. }
  252. void UiWidget::ScriptPlayAnimationStop(const char* name, const float start, const float end){
  253. PlayAnimation(Ogre::String(name), UiAnimation::ONCE, start, end);
  254. }
  255. void UiWidget::ScriptSetDefaultAnimation(const char* animation){
  256. animation_default_ = Ogre::String(animation);
  257. animation_state_ = UiAnimation::DEFAULT;
  258. }
  259. int UiWidget::ScriptAnimationSync(){
  260. ScriptId script = ScriptManager::getSingleton().GetCurrentScriptId();
  261. animation_sync_.push_back(script);
  262. return -1;
  263. }
  264. void UiWidget::SetUpdateTransformation(){
  265. for (unsigned int i = 0; i < children_.size(); ++ i) children_[i]->SetUpdateTransformation();
  266. update_transformation_ = true;
  267. }
  268. void UiWidget::UpdateTransformation(){
  269. Ogre::RenderWindow* window = VGears::Application::getSingleton().getRenderWindow();
  270. float res_width = static_cast<float>(window->getWidth());
  271. float res_height = static_cast<float>(window->getHeight());
  272. screen_width_ = res_width;
  273. screen_height_ = res_height;
  274. Ogre::Viewport *viewport(CameraManager::getSingleton().getViewport());
  275. viewport->setDimensions(0.0f, 0.0f, 1.0f, 1.0f);
  276. Ogre::Vector2 area_scale
  277. = (parent_ != nullptr) ? parent_->GetFinalScale() : Ogre::Vector2(1, 1);
  278. Ogre::Vector2 area_origin
  279. = (parent_ != nullptr) ? parent_->GetFinalOrigin() : Ogre::Vector2::ZERO;
  280. Ogre::Vector2 area_translate
  281. = (parent_ != nullptr) ? parent_->GetFinalTranslate() : Ogre::Vector2::ZERO;
  282. Ogre::Vector2 area_size
  283. = (parent_ != nullptr)
  284. ? parent_->GetFinalSize() : Ogre::Vector2(screen_width_, screen_height_);
  285. float area_rotation = (parent_ != nullptr) ? parent_->GetFinalRotation() : 0;
  286. float local_x
  287. = ((area_size.x * x_percent_) / 100.0f + (x_ * screen_height_ / 720.0f)
  288. * area_scale.x) - area_origin.x;
  289. float local_y
  290. = ((area_size.y * y_percent_) / 100.0f + (y_ * screen_height_ / 720.0f)
  291. * area_scale.y) - area_origin.y;
  292. float x = local_x;
  293. float y = local_y;
  294. if (area_rotation != 0){
  295. float cos = Ogre::Math::Cos(Ogre::Radian(Ogre::Degree(area_rotation)));
  296. float sin = Ogre::Math::Sin(Ogre::Radian(Ogre::Degree(area_rotation)));
  297. x = local_x * cos - local_y * sin;
  298. y = local_x * sin + local_y * cos;
  299. }
  300. final_translate_.x = area_translate.x;
  301. if (align_ == RIGHT) final_translate_.x = area_translate.x + area_size.x;
  302. else if (align_ == CENTER) final_translate_.x = area_translate.x + area_size.x / 2;
  303. final_translate_.x += x;
  304. final_translate_.y = area_translate.y;
  305. if (vertical_align_ == BOTTOM) final_translate_.y = area_translate.y + area_size.y;
  306. else if (vertical_align_ == MIDDLE) final_translate_.y = area_translate.y + area_size.y / 2;
  307. final_translate_.y += y;
  308. final_z_ = (parent_ != NULL) ? parent_->GetFinalZ() + z_ : z_;
  309. final_scale_ = area_scale * scale_;
  310. final_size_.x
  311. = (area_size.x * width_percent_ * scale_.x) / 100.0f
  312. + (width_ * screen_height_ / 720.0f) * final_scale_.x;
  313. final_size_.y
  314. = (area_size.y * height_percent_ * scale_.y) / 100.0f
  315. + (height_ * screen_height_ / 720.0f) * final_scale_.y;
  316. final_origin_.x
  317. = (final_size_.x * origin_x_percent_) / 100.0f + origin_x_
  318. * screen_height_ * final_scale_.x / 720.0f;
  319. final_origin_.y
  320. = (final_size_.y * origin_y_percent_) / 100.0f + origin_y_
  321. * screen_height_ * final_scale_.y / 720.0f;
  322. final_rotation_ = area_rotation + rotation_;
  323. // Scissor update
  324. if (local_scissor_ == true){
  325. float local_x1
  326. = final_size_.x * scissor_x_percent_top_ / 100.0f
  327. + scissor_x_top_ * screen_height_ * final_scale_.x / 720.0f - final_origin_.x;
  328. float local_y1
  329. = final_size_.y * scissor_y_percent_left_ / 100.0f
  330. + scissor_y_left_ * screen_height_ * final_scale_.y / 720.0f - final_origin_.y;
  331. float local_x2
  332. = final_size_.x * scissor_x_percent_bottom_ / 100.0f
  333. + scissor_x_bottom_ * screen_height_ * final_scale_.x / 720.0f - final_origin_.x;
  334. float local_y2
  335. = final_size_.y * scissor_y_percent_right_ / 100.0f
  336. + scissor_y_right_ * screen_height_ * final_scale_.y / 720.0f - final_origin_.y;
  337. x = final_translate_.x;
  338. y = final_translate_.y;
  339. int x1, y1, x2, y2, x3, y3, x4, y4;
  340. if (final_rotation_ != 0){
  341. float cos = Ogre::Math::Cos(Ogre::Radian(Ogre::Degree(final_rotation_)));
  342. float sin = Ogre::Math::Sin(Ogre::Radian(Ogre::Degree(final_rotation_)));
  343. x1 = static_cast<int>(local_x1 * cos - local_y1 * sin + x);
  344. y1 = static_cast<int>(local_x1 * sin + local_y1 * cos + y);
  345. x2 = static_cast<int>(local_x2 * cos - local_y1 * sin + x);
  346. y2 = static_cast<int>(local_x2 * sin + local_y1 * cos + y);
  347. x3 = static_cast<int>(local_x2 * cos - local_y2 * sin + x);
  348. y3 = static_cast<int>(local_x2 * sin + local_y2 * cos + y);
  349. x4 = static_cast<int>(local_x1 * cos - local_y2 * sin + x);
  350. y4 = static_cast<int>(local_x1 * sin + local_y2 * cos + y);
  351. }
  352. else{
  353. x1 = static_cast<int>(local_x1 + x);
  354. y1 = static_cast<int>(local_y1 + y);
  355. x2 = static_cast<int>(local_x2 + x);
  356. y2 = static_cast<int>(local_y1 + y);
  357. x3 = static_cast<int>(local_x2 + x);
  358. y3 = static_cast<int>(local_y2 + y);
  359. x4 = static_cast<int>(local_x1 + x);
  360. y4 = static_cast<int>(local_y2 + y);
  361. }
  362. scissor_ = true;
  363. scissor_top_ = std::min(std::min(y1 , y2), std::min(y3 , y4));
  364. scissor_bottom_ = std::max(std::max(y1 , y2), std::max(y3 , y4));
  365. scissor_left_ = std::min(std::min(x1 , x2), std::min(x3 , x4));
  366. scissor_right_ = std::max(std::max(x1 , x2), std::max(x3 , x4));
  367. }
  368. if (parent_ != NULL && global_scissor_ == true){
  369. bool use_scissor;
  370. Ogre::Vector4 scissor = parent_->GetFinalScissor(use_scissor);
  371. if (use_scissor == true){
  372. scissor_ = true;
  373. if (local_scissor_ == true){
  374. scissor_top_ = std::max((float) scissor_top_, scissor.x);
  375. scissor_bottom_ = std::min((float) scissor_bottom_, scissor.y);
  376. scissor_left_ = std::max((float) scissor_left_, scissor.z);
  377. scissor_right_ = std::min((float) scissor_right_, scissor.w);
  378. }
  379. else{
  380. scissor_top_ = scissor.x;
  381. scissor_bottom_ = scissor.y;
  382. scissor_left_ = scissor.z;
  383. scissor_right_ = scissor.w;
  384. }
  385. }
  386. }
  387. update_transformation_ = false;
  388. }
  389. void UiWidget::SetAlign(const UiWidget::Align align){align_ = align;}
  390. void UiWidget::SetVerticalAlign(const UiWidget::VerticalAlign valign){vertical_align_ = valign;}
  391. float UiWidget::GetFinalZ() const{return final_z_;}
  392. Ogre::Vector2 UiWidget::GetFinalOrigin() const{return final_origin_;}
  393. Ogre::Vector2 UiWidget::GetFinalTranslate() const{return final_translate_;}
  394. Ogre::Vector2 UiWidget::GetFinalSize() const{return final_size_;}
  395. Ogre::Vector2 UiWidget::GetFinalScale() const{return final_scale_;}
  396. Ogre::Vector4 UiWidget::GetFinalScissor(bool& scissor) const{
  397. if (scissor_ == true){
  398. scissor = true;
  399. return Ogre::Vector4(scissor_top_, scissor_bottom_, scissor_left_, scissor_right_);
  400. }
  401. scissor = false;
  402. return Ogre::Vector4::ZERO;
  403. }
  404. float UiWidget::GetFinalRotation() const{return final_rotation_;}
  405. void UiWidget::SetOriginX(const float percent, const float x){
  406. origin_x_percent_ = percent;
  407. origin_x_ = x;
  408. SetUpdateTransformation();
  409. }
  410. void UiWidget::SetOriginY(const float percent, const float y){
  411. origin_y_percent_ = percent;
  412. origin_y_ = y;
  413. SetUpdateTransformation();
  414. }
  415. void UiWidget::SetX(const float percent, const float x){
  416. x_percent_ = percent;
  417. x_ = x;
  418. SetUpdateTransformation();
  419. }
  420. void UiWidget::GetX(float& percent, float& x){
  421. percent = x_percent_;
  422. x = x_;
  423. }
  424. void UiWidget::SetY(const float percent, const float y){
  425. y_percent_ = percent;
  426. y_ = y;
  427. SetUpdateTransformation();
  428. }
  429. void UiWidget::GetY(float& percent, float& y){
  430. percent = y_percent_;
  431. y = y_;
  432. }
  433. void UiWidget::SetZ(const float z){
  434. z_ = z;
  435. SetUpdateTransformation();
  436. }
  437. void UiWidget::SetWidth(const float percent, const float width){
  438. width_percent_ = percent;
  439. width_ = width;
  440. SetUpdateTransformation();
  441. }
  442. void UiWidget::GetWidth(float& percent, float& width){
  443. percent = width_percent_;
  444. width = width_;
  445. }
  446. void UiWidget::SetHeight(const float percent, const float height){
  447. height_percent_ = percent;
  448. height_ = height;
  449. SetUpdateTransformation();
  450. }
  451. void UiWidget::GetHeight(float& percent, float& height){
  452. percent = height_percent_;
  453. height = height_;
  454. }
  455. void UiWidget::SetScale(const Ogre::Vector2& scale){
  456. scale_ = scale;
  457. SetUpdateTransformation();
  458. }
  459. void UiWidget::SetRotation(const float degree){
  460. rotation_ = degree;
  461. SetUpdateTransformation();
  462. }
  463. void UiWidget::SetScissorArea(
  464. const float percent_x1, const float x1, const float percent_y1, const float y1,
  465. const float percent_x2, const float x2, const float percent_y2, const float y2
  466. ){
  467. local_scissor_ = true;
  468. scissor_x_percent_top_ = percent_x1;
  469. scissor_x_top_ = x1;
  470. scissor_x_percent_bottom_ = percent_x2;
  471. scissor_x_bottom_ = x2;
  472. scissor_y_percent_left_ = percent_y1;
  473. scissor_y_left_ = y1;
  474. scissor_y_percent_right_ = percent_y2;
  475. scissor_y_right_ = y2;
  476. SetUpdateTransformation();
  477. }
  478. void UiWidget::SetGlobalScissor(const bool global){
  479. global_scissor_ = global;
  480. SetUpdateTransformation();
  481. }
  482. void UiWidget::SetColour(const float r, const float g, const float b){
  483. colour_1_.r = r; colour_1_.g = g; colour_1_.b = b;
  484. colour_2_.r = r; colour_2_.g = g; colour_2_.b = b;
  485. colour_3_.r = r; colour_3_.g = g; colour_3_.b = b;
  486. colour_4_.r = r; colour_4_.g = g; colour_4_.b = b;
  487. SetUpdateTransformation();
  488. }
  489. void UiWidget::SetColours(
  490. const float r1, const float g1, const float b1, const float r2, const float g2, const float b2,
  491. const float r3, const float g3, const float b3, const float r4, const float g4, const float b4
  492. ){
  493. colour_1_.r = r1; colour_1_.g = g1; colour_1_.b = b1;
  494. colour_2_.r = r2; colour_2_.g = g2; colour_2_.b = b2;
  495. colour_3_.r = r3; colour_3_.g = g3; colour_3_.b = b3;
  496. colour_4_.r = r4; colour_4_.g = g4; colour_4_.b = b4;
  497. SetUpdateTransformation();
  498. }
  499. void UiWidget::SetAlpha(const float a){
  500. colour_1_.a = a;
  501. colour_2_.a = a;
  502. colour_3_.a = a;
  503. colour_4_.a = a;
  504. SetUpdateTransformation();
  505. }
  506. void UiWidget::SetText(const char* text){}
  507. void UiWidget::SetImage(const char* image){}
  508. float UiWidget::ScriptGetWidth(){return width_;}
  509. void UiWidget::ScriptSetWidth(float width){
  510. width_ = width;
  511. SetUpdateTransformation();
  512. }
  513. float UiWidget::ScriptGetHeight(){return width_;}
  514. void UiWidget::ScriptSetHeight(float height){
  515. height_ = height;
  516. SetUpdateTransformation();
  517. }