code_uilayout.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. // UILayout application source code
  2. #include <Atomic/UI/UIView.h>
  3. #include <Atomic/UI/UILayout.h>
  4. #include <Atomic/UI/UICheckBox.h>
  5. #include <Atomic/UI/UIRadioButton.h>
  6. #include <Atomic/UI/UITextField.h>
  7. #include <Atomic/UI/UIButton.h>
  8. #include <Atomic/UI/UIEditField.h>
  9. #include <Atomic/UI/UITabContainer.h>
  10. #include <Atomic/UI/UIWindow.h>
  11. #include "PeriodicApp.h"
  12. void PeriodicApp::setup_uilayout( UIWidget *layout, UIView *uiview )
  13. {
  14. PODVector<UIWidget*> dest;
  15. layout->SearchWidgetClass( "TBButton", dest );
  16. for (unsigned ii = 0; ii < dest.Size(); ii++)
  17. SubscribeToEvent(dest[ii], E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUilayoutEvent ));
  18. UILayout *myc = static_cast<UILayout *>(layout->GetWidget("uilayoutcontainer")); // get the container layout
  19. UIButton *tf0 = new UIButton(context_); // the layout-o-matic spawner
  20. tf0->SetText( "LAYOUT-O-MATIC");
  21. tf0->SetId( "go_layout_config");
  22. UILayout *lo0 = new UILayout(context_);
  23. lo0->SetId( "target_layout");
  24. lo0->SetLayoutConfig ( "-----" );
  25. lo0->Load("Scenes/simp_button.ui.txt");
  26. lo0->AddChildBefore(tf0, lo0->GetFirstChild() );
  27. myc->AddChild(lo0); // drop it in
  28. SubscribeToEvent(tf0, E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUilayoutEvent ));
  29. UITextField *tf1 = new UITextField(context_);
  30. tf1->SetText( "layout config XACAC");
  31. UILayout *lo1 = new UILayout(context_);
  32. lo1->SetLayoutConfig ( "XACAC" );
  33. lo1->Load("Scenes/simp_button.ui.txt");
  34. lo1->AddChildBefore(tf1, lo1->GetFirstChild() );
  35. myc->AddChild(lo1);
  36. UITextField *tf2 = new UITextField(context_);
  37. tf2->SetText( "layout config XGCAC");
  38. UILayout *lo2 = new UILayout(context_);
  39. lo2->SetLayoutConfig ( "XGCAC" );
  40. lo2->Load("Scenes/simp_button.ui.txt");
  41. lo2->AddChildBefore(tf2, lo2->GetFirstChild() );
  42. myc->AddChild(lo2);
  43. UITextField *tf3 = new UITextField(context_);
  44. tf3->SetText( "layout config XPCAC");
  45. UILayout *lo3 = new UILayout(context_);
  46. lo3->SetLayoutConfig ( "XPCAC" );
  47. lo3->Load("Scenes/simp_button.ui.txt");
  48. lo3->AddChildBefore(tf3, lo3->GetFirstChild() );
  49. myc->AddChild(lo3);
  50. UITextField *tf4 = new UITextField(context_);
  51. tf4->SetText( "layout config XACGC");
  52. UILayout *lo4 = new UILayout(context_);
  53. lo4->SetLayoutConfig ( "XACGC" );
  54. lo4->Load("Scenes/simp_button.ui.txt");
  55. lo4->AddChildBefore(tf4, lo4->GetFirstChild() );
  56. myc->AddChild(lo4);
  57. UITextField *tf5 = new UITextField(context_);
  58. tf5->SetText( "layout config XGRGC");
  59. UILayout *lo5 = new UILayout(context_);
  60. lo5->SetLayoutConfig ( "XGRGC" );
  61. lo5->Load("Scenes/simp_button.ui.txt");
  62. lo5->AddChildBefore(tf5, lo5->GetFirstChild() );
  63. myc->AddChild(lo5);
  64. UITextField *tf6 = new UITextField(context_);
  65. tf6->SetText( "layout config XPLGC");
  66. UILayout *lo6 = new UILayout(context_);
  67. lo6->SetLayoutConfig ( "XPLGC" );
  68. lo6->Load("Scenes/simp_button.ui.txt");
  69. lo6->AddChildBefore(tf6, lo6->GetFirstChild() );
  70. myc->AddChild(lo6);
  71. UITextField *tf7 = new UITextField(context_);
  72. tf7->SetText( "layout config XACPC");
  73. UILayout *lo7 = new UILayout(context_);
  74. lo7->SetLayoutConfig ( "XACPC" );
  75. lo7->Load("Scenes/simp_button.ui.txt");
  76. lo7->AddChildBefore(tf7, lo7->GetFirstChild() );
  77. myc->AddChild(lo7);
  78. UITextField *tf8 = new UITextField(context_);
  79. tf8->SetText( "layout config XGLPL");
  80. UILayout *lo8 = new UILayout(context_);
  81. lo8->SetLayoutConfig ( "XGLPL" );
  82. lo8->Load("Scenes/simp_button.ui.txt");
  83. lo8->AddChildBefore(tf8, lo8->GetFirstChild() );
  84. myc->AddChild(lo8);
  85. UITextField *tf9 = new UITextField(context_);
  86. tf9->SetText( "layout config XPCPR");
  87. UILayout *lo9 = new UILayout(context_);
  88. lo9->SetLayoutConfig ( "XPCPR" );
  89. lo9->Load("Scenes/simp_button.ui.txt");
  90. lo9->AddChildBefore(tf9, lo9->GetFirstChild() );
  91. myc->AddChild(lo9);
  92. context_->SetGlobalVar("layoutomaticstr", "XGCPC" ); // LAYOUT-O-MATIC string, cheating, using a globalvar
  93. }
  94. void PeriodicApp::HandleUilayoutEvent(StringHash eventType, VariantMap& eventData)
  95. {
  96. using namespace WidgetEvent;
  97. UIWidget* widget = static_cast<UIWidget*>(eventData[P_TARGET].GetPtr());
  98. if ( widget == NULL ) return;
  99. if (eventData[P_TYPE] == UI_EVENT_TYPE_CLICK)
  100. {
  101. if (widget->GetId() == "go_layout_config" ) // its LAYOUT-O-MATIC time.
  102. {
  103. AppLog( "UILayout action : " + widget->GetId() + " was pressed, its LAYOUT-O-MATIC time");
  104. UIView *someview = widget->GetView();
  105. UIWindow* window = new UIWindow(context_);
  106. window->SetSettings ( UI_WINDOW_SETTINGS_DEFAULT );
  107. window->SetText( "LAYOUT-O-MATIC(tm)");
  108. window->Load("Scenes/view_layout.ui.txt");
  109. window->ResizeToFitContent();
  110. someview->AddChild(window);
  111. UIWidget *okbutt = window->GetWidget("ok");
  112. SubscribeToEvent(okbutt, E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUilayoutEvent ));
  113. PODVector<UIWidget*> lox;
  114. window->SearchWidgetClass( "TBRadioButton", lox );
  115. for (unsigned ii = 0; ii < lox.Size(); ii++)
  116. SubscribeToEvent(lox[ii], E_WIDGETEVENT, ATOMIC_HANDLER(PeriodicApp, HandleUilayoutEvent ));
  117. }
  118. if (widget->GetId() == "ok" )
  119. {
  120. UIWindow *mywindow = static_cast<UIWindow *>(FindTheWindowParent(widget));
  121. if (mywindow)
  122. mywindow->Close();
  123. }
  124. if (widget->GetId() == "set_ax" )
  125. {
  126. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  127. UIRadioButton *setax = static_cast< UIRadioButton*>(widget); // who we are
  128. if (targetl && setax)
  129. {
  130. if ( setax->GetValue() == 1)
  131. {
  132. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  133. current.Replace (0, 1, "X");
  134. targetl->SetLayoutConfig(current);
  135. context_->SetGlobalVar("layoutomaticstr", current );
  136. }
  137. }
  138. }
  139. if (widget->GetId() == "set_ay" )
  140. {
  141. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  142. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  143. if (targetl && setay)
  144. {
  145. if ( setay->GetValue() == 1)
  146. {
  147. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  148. current.Replace (0, 1, "Y");
  149. targetl->SetLayoutConfig(current );
  150. context_->SetGlobalVar("layoutomaticstr", current );
  151. }
  152. }
  153. }
  154. if (widget->GetId() == "set_sza" )
  155. {
  156. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  157. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  158. if (targetl && setay)
  159. {
  160. if ( setay->GetValue() == 1)
  161. {
  162. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  163. current.Replace (1, 1, "A");
  164. targetl->SetLayoutConfig(current );
  165. context_->SetGlobalVar("layoutomaticstr", current );
  166. }
  167. }
  168. }
  169. if (widget->GetId() == "set_szg" )
  170. {
  171. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  172. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  173. if (targetl && setay)
  174. {
  175. if ( setay->GetValue() == 1)
  176. {
  177. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  178. current.Replace (1, 1, "G");
  179. targetl->SetLayoutConfig(current );
  180. context_->SetGlobalVar("layoutomaticstr", current );
  181. }
  182. }
  183. }
  184. if (widget->GetId() == "set_szp" )
  185. {
  186. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  187. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  188. if (targetl && setay)
  189. {
  190. if ( setay->GetValue() == 1)
  191. {
  192. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  193. current.Replace (1, 1, "P");
  194. targetl->SetLayoutConfig(current );
  195. context_->SetGlobalVar("layoutomaticstr", current );
  196. }
  197. }
  198. }
  199. if (widget->GetId() == "set_posc" )
  200. {
  201. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  202. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  203. if (targetl && setay)
  204. {
  205. if ( setay->GetValue() == 1)
  206. {
  207. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  208. current.Replace (2, 1, "C");
  209. targetl->SetLayoutConfig(current );
  210. context_->SetGlobalVar("layoutomaticstr", current );
  211. }
  212. }
  213. }
  214. if (widget->GetId() == "set_posg" )
  215. {
  216. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  217. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  218. if (targetl && setay)
  219. {
  220. if ( setay->GetValue() == 1)
  221. {
  222. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  223. current.Replace (2, 1, "G");
  224. targetl->SetLayoutConfig(current );
  225. context_->SetGlobalVar("layoutomaticstr", current );
  226. }
  227. }
  228. }
  229. if (widget->GetId() == "set_posl" )
  230. {
  231. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  232. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  233. if (targetl && setay)
  234. {
  235. if ( setay->GetValue() == 1)
  236. {
  237. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  238. current.Replace (2, 1, "L");
  239. targetl->SetLayoutConfig(current );
  240. context_->SetGlobalVar("layoutomaticstr", current );
  241. }
  242. }
  243. }
  244. if (widget->GetId() == "set_posr" )
  245. {
  246. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  247. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  248. if (targetl && setay)
  249. {
  250. if ( setay->GetValue() == 1)
  251. {
  252. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  253. current.Replace (2, 1, "R");
  254. targetl->SetLayoutConfig(current );
  255. context_->SetGlobalVar("layoutomaticstr", current );
  256. }
  257. }
  258. }
  259. if (widget->GetId() == "set_dista" )
  260. {
  261. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  262. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  263. if (targetl && setay)
  264. {
  265. if ( setay->GetValue() == 1)
  266. {
  267. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  268. current.Replace (3, 1, "A");
  269. targetl->SetLayoutConfig(current );
  270. context_->SetGlobalVar("layoutomaticstr", current );
  271. }
  272. }
  273. }
  274. if (widget->GetId() == "set_distg" )
  275. {
  276. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  277. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  278. if (targetl && setay)
  279. {
  280. if ( setay->GetValue() == 1)
  281. {
  282. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  283. current.Replace (3, 1, "G");
  284. targetl->SetLayoutConfig(current );
  285. context_->SetGlobalVar("layoutomaticstr", current );
  286. }
  287. }
  288. }
  289. if (widget->GetId() == "set_distp" )
  290. {
  291. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  292. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  293. if (targetl && setay)
  294. {
  295. if ( setay->GetValue() == 1)
  296. {
  297. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  298. current.Replace (3, 1, "P");
  299. targetl->SetLayoutConfig(current );
  300. context_->SetGlobalVar("layoutomaticstr", current );
  301. }
  302. }
  303. }
  304. if (widget->GetId() == "set_dpc" )
  305. {
  306. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  307. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  308. if (targetl && setay)
  309. {
  310. if ( setay->GetValue() == 1)
  311. {
  312. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  313. current.Replace (4, 1, "C");
  314. targetl->SetLayoutConfig(current );
  315. context_->SetGlobalVar("layoutomaticstr", current );
  316. }
  317. }
  318. }
  319. if (widget->GetId() == "set_dpl" )
  320. {
  321. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  322. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  323. if (targetl && setay)
  324. {
  325. if ( setay->GetValue() == 1)
  326. {
  327. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  328. current.Replace (4, 1, "L");
  329. targetl->SetLayoutConfig(current );
  330. context_->SetGlobalVar("layoutomaticstr", current );
  331. }
  332. }
  333. }
  334. if (widget->GetId() == "set_dpr" )
  335. {
  336. UILayout *targetl = static_cast<UILayout *>(widget->FindWidget("target_layout")); // who to operate on.
  337. UIRadioButton *setay = static_cast< UIRadioButton*>(widget); // who we are
  338. if (targetl && setay)
  339. {
  340. if ( setay->GetValue() == 1)
  341. {
  342. String current = context_->GetGlobalVar("layoutomaticstr").GetString();
  343. current.Replace (4, 1, "R");
  344. targetl->SetLayoutConfig(current );
  345. context_->SetGlobalVar("layoutomaticstr", current );
  346. }
  347. }
  348. }
  349. }
  350. }