PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/Scenes/UserInterfaces/Controls/Label.cs

#
C# | 907 lines | 455 code | 98 blank | 354 comment | 25 complexity | ca64271f95c50e3fc365232addecd217 MD5 | raw file
Possible License(s): Apache-2.0
  1. using System;
  2. using System.ComponentModel;
  3. using System.IO;
  4. using Delta.Engine;
  5. using Delta.Engine.SettingsNodes;
  6. using Delta.InputSystem;
  7. using Delta.Rendering.Basics.Drawing;
  8. using Delta.Rendering.Basics.Fonts;
  9. using Delta.Scenes.Enums;
  10. using Delta.Scenes.UserInterfaces.Designs;
  11. using Delta.Utilities;
  12. using Delta.Utilities.Datatypes;
  13. using Delta.Utilities.Datatypes.Advanced;
  14. using Delta.Utilities.Helpers;
  15. using NUnit.Framework;
  16. using Delta.ContentSystem.Xml;
  17. namespace Delta.Scenes.UserInterfaces.Controls
  18. {
  19. /// <summary>
  20. /// This is a simple label control for displaying (read-only) text on a
  21. /// screen.
  22. /// </summary>
  23. public class Label : BaseControl
  24. {
  25. #region Constants
  26. /// <summary>
  27. /// The current version of the implementation of this control class.
  28. /// </summary>
  29. private const int VersionNumber = 1;
  30. private const string TextElementName = "Label.TextContent";
  31. #endregion
  32. #region Delegates
  33. /// <summary>
  34. /// The delegate declaration for the text changed event.
  35. /// </summary>
  36. /// <param name="sender">Sender</param>
  37. public delegate void TextChangedEvent(Label sender);
  38. #endregion
  39. #region Text (Public)
  40. /// <summary>
  41. /// Text to display on this label.
  42. /// </summary>
  43. private string text;
  44. /// <summary>
  45. /// The displayed text, will be localized automatically (make sure you have
  46. /// an entry for this in your Localization.xml content file).
  47. /// </summary>
  48. [Browsable(true)]
  49. public string Text
  50. {
  51. get
  52. {
  53. return text;
  54. }
  55. set
  56. {
  57. // Note: If Localization.WarnIfLanguageKeyWasNotFound is on this might
  58. // produce warnings for text entries not found as language keys.
  59. text =
  60. String.IsNullOrEmpty(value)
  61. ? value
  62. : Localization.Get(value);
  63. }
  64. }
  65. #endregion
  66. #region TextContentElement (Public)
  67. /// <summary>
  68. /// The content element which
  69. /// </summary>
  70. /// <returns>Dockable element</returns>
  71. public AlignableElement TextContentElement
  72. {
  73. get;
  74. set;
  75. }
  76. #endregion
  77. #region IsTextElementAutoSizing
  78. /// <summary>
  79. /// Indicates if the TextContentElement applies the same size as the Label
  80. /// every time the size of this Label changes
  81. /// <para />
  82. /// Note: Default is 'true'.
  83. /// </summary>
  84. public bool IsTextElementAutoSizing
  85. {
  86. get;
  87. set;
  88. }
  89. #endregion
  90. #region TextDrawArea (Public)
  91. /// <summary>
  92. /// Text draw area
  93. /// </summary>
  94. public Rectangle TextDrawArea
  95. {
  96. get
  97. {
  98. return TextContentElement.DrawArea;
  99. } // get
  100. }
  101. #endregion
  102. #region Protected
  103. #region FallbackDesign (Protected)
  104. /// <summary>
  105. /// Defines the theme which will be used if no "Theme" was set explicitely.
  106. /// </summary>
  107. protected override ControlDesign FallbackDesign
  108. {
  109. get
  110. {
  111. return Theme.Current.LabelDesign;
  112. } // get
  113. }
  114. #endregion
  115. #region TextFont (Protected)
  116. /// <summary>
  117. /// The font which is used to displaying the text.
  118. /// </summary>
  119. /// <remarks>
  120. /// This value get updated everytime the design of the Label changes.
  121. /// </remarks>
  122. /// <returns>Font</returns>
  123. protected Font TextFont
  124. {
  125. get
  126. {
  127. // If we want to use the font right now but there is no valid one yet
  128. // then we just use the Engine fallback font
  129. return (labelDesign != null)
  130. ? labelDesign.TextFont
  131. : Font.Default;
  132. } // get
  133. }
  134. #endregion
  135. #endregion
  136. #region Private
  137. #region lastText (Private)
  138. /// <summary>
  139. /// The last set text of this element which is used to "detect" text
  140. /// changes of the element by the user.
  141. /// </summary>
  142. private string lastText;
  143. #endregion
  144. #region labelDesign (Private)
  145. /// <summary>
  146. /// Label design
  147. /// </summary>
  148. private ITextDesign labelDesign;
  149. #endregion
  150. #endregion
  151. #region Constructors
  152. /// <summary>
  153. /// Create label
  154. /// </summary>
  155. public Label()
  156. {
  157. TextContentElement = new AlignableElement
  158. {
  159. Name = TextElementName,
  160. };
  161. Add(TextContentElement);
  162. IsTextElementAutoSizing = true;
  163. }
  164. #endregion
  165. #region TextChanged (Event)
  166. /// <summary>
  167. /// Occurs every time the text of the label will be changed.
  168. /// </summary>
  169. public event TextChangedEvent TextChanged;
  170. #endregion
  171. #region Save (Public)
  172. /// <summary>
  173. /// Saves all data which are necessary to restore the object again.
  174. /// </summary>
  175. /// <param name="dataWriter">
  176. /// The writer which contains the stream where the data should be saved
  177. /// into now.
  178. /// </param>
  179. public override void Save(BinaryWriter dataWriter)
  180. {
  181. // At first we write the data of the base class
  182. base.Save(dataWriter);
  183. // and then save the version of the current data format
  184. dataWriter.Write(VersionNumber);
  185. // before we can finally save the properties
  186. Text.Save(dataWriter);
  187. }
  188. #endregion
  189. #region Load (Public)
  190. /// <summary>
  191. /// Loads and restores all previously saved values that belongs to this
  192. /// class only from the given data reader.
  193. /// </summary>
  194. /// <param name="dataReader">
  195. /// The reader which contains the stream with the saved data which needs to
  196. /// be loaded now.
  197. /// </param>
  198. public override void Load(BinaryReader dataReader)
  199. {
  200. // We have to remove the automatically created text area element because
  201. // we will load (and create) it by the saved data, but still remember it
  202. // to have the chance to restore it again in the case we will get an
  203. // error while loading
  204. AlignableElement orgTextAreaElement = TextContentElement;
  205. Remove(TextContentElement);
  206. TextContentElement = null;
  207. // At first we need to load all data of the base class
  208. base.Load(dataReader);
  209. // and then check which version of the data need to load now
  210. int version = dataReader.ReadInt32();
  211. switch (version)
  212. {
  213. // Version 1
  214. case VersionNumber:
  215. Text = dataReader.ReadString();
  216. // Look for the text area element we have to re-reference
  217. foreach (AlignableElement child in Children)
  218. {
  219. if (child.Name == TextElementName)
  220. {
  221. // we have found it, so reference it
  222. TextContentElement = child;
  223. // and finally dispose the old element
  224. orgTextAreaElement.Dispose();
  225. break;
  226. } // if
  227. } // foreach
  228. // If something went wrong
  229. if (TextContentElement == null)
  230. {
  231. // notify the user
  232. Log.Warning("The text area element couldn't be loaded.");
  233. // and restore the old element
  234. TextContentElement = orgTextAreaElement;
  235. Add(TextContentElement);
  236. } // if
  237. break;
  238. default:
  239. Log.InvalidVersionWarning(GetType().Name, version, VersionNumber);
  240. break;
  241. } // switch
  242. }
  243. #endregion
  244. #region Methods (Private)
  245. #region OnSizeChanging
  246. /// <summary>
  247. /// On size changing
  248. /// </summary>
  249. /// <param name="oldSize">Old size</param>
  250. /// <returns>
  251. /// 'True' if the new value can be used or 'false' if the change should be
  252. /// aborted.
  253. /// </returns>
  254. protected override bool OnSizeChanging(Size oldSize)
  255. {
  256. if (base.OnSizeChanging(oldSize))
  257. {
  258. if (IsTextElementAutoSizing)
  259. {
  260. TextContentElement.Size = Size;
  261. } // if
  262. return true;
  263. } // if
  264. return false;
  265. }
  266. #endregion
  267. #region OnDesignChanging
  268. /// <summary>
  269. /// On design changed
  270. /// </summary>
  271. /// <param name="oldDesign">Old design</param>
  272. /// <returns>
  273. /// 'True' if the new value can be used or 'false' if the change should be
  274. /// aborted.
  275. /// </returns>
  276. protected override bool OnDesignChanging(ControlDesign oldDesign)
  277. {
  278. if (base.OnDesignChanging(oldDesign))
  279. {
  280. // Check if the new design is a valid 'TextControlDesign' but
  281. // Note: Even 'null' will be accepted and handled here
  282. labelDesign = Design as ITextDesign;
  283. if (labelDesign == null)
  284. {
  285. Log.Warning(
  286. "The new design '" + Design + "' which will be set to the " +
  287. "control '" + this + "' is no kind of a '" +
  288. typeof(ITextDesign).Name +"' design which means that the text " +
  289. "won't be displayed correctly.");
  290. } // if
  291. return true;
  292. } // if
  293. return false;
  294. }
  295. #endregion
  296. #region OnTextChanging
  297. /// <summary>
  298. /// On text changing
  299. /// </summary>
  300. /// <param name="oldText">Old text</param>
  301. /// <returns>
  302. /// 'True' if the new value can be used or 'false' if the change should be
  303. /// aborted.
  304. /// </returns>
  305. protected virtual bool OnTextChanging(string oldText)
  306. {
  307. // Always accept the text change but determine if this "auto fallback"
  308. // decides it or we have an listener who can make a "real" decision
  309. return true;
  310. }
  311. #endregion
  312. #region DetectChanges
  313. /// <summary>
  314. /// This method implements the checks of the changes which are should be
  315. /// detected in this element. It also cares about triggering the events and
  316. /// the event handler methods.
  317. /// </summary>
  318. protected override void DetectChanges()
  319. {
  320. base.DetectChanges();
  321. if (Text != lastText)
  322. {
  323. // Check now if the new value should be set
  324. if (OnTextChanging(lastText))
  325. {
  326. lastText = Text;
  327. // After setting the new value also inform all external listeners
  328. // about the change
  329. if (TextChanged != null &&
  330. // but only if it isn't just the value initialization
  331. isRuntimeValueChange)
  332. {
  333. TextChanged.Invoke(this);
  334. } // if
  335. } // if
  336. else
  337. {
  338. // if the change is not ok, then just reset to old value again
  339. Text = lastText;
  340. } // else
  341. } // if
  342. }
  343. #endregion
  344. #region DrawData
  345. /// <summary>
  346. /// Draws all data of this Label which needs to be visualized.
  347. /// </summary>
  348. /// <remarks>
  349. /// This method will only be called if the Label is in a visible state.
  350. /// </remarks>
  351. protected override void DrawData()
  352. {
  353. base.DrawData();
  354. string displayText = GetDisplayText();
  355. if (String.IsNullOrEmpty(displayText))
  356. {
  357. // It only make sense to call 'Font.Draw()' if we really have a text
  358. return;
  359. } // if
  360. // Always draw the text even if the control is disabled
  361. // Note: If the control is invisible, the draw won't be called anyway
  362. Font textFont =
  363. State == ElementState.Disabled
  364. ? labelDesign.DisabledTextFont
  365. : labelDesign.TextFont;
  366. // but only draw text if there is a valid font set
  367. if (textFont != null)
  368. {
  369. textFont.Draw(displayText, TextContentElement.DrawArea, Rotation,
  370. Point.Zero);
  371. } // if
  372. }
  373. #endregion
  374. #region GetDisplayText
  375. /// <summary>
  376. /// Get display text
  377. /// </summary>
  378. protected virtual string GetDisplayText()
  379. {
  380. return Text;
  381. }
  382. #endregion
  383. #region DrawDebugInfo
  384. /// <summary>
  385. /// Draw debug info
  386. /// </summary>
  387. protected override void DrawDebugInfo()
  388. {
  389. base.DrawDebugInfo();
  390. // Only really detailed visual information about this element if the UI
  391. // profiling mode is enabled additional to the UI debug mode
  392. if (Settings.Debug.IsProfilingModeOn(ProfilingMode.UI))
  393. {
  394. Rect.DrawFilled(DrawArea, Color.Green);
  395. } // if
  396. // otherwise just use the simple version
  397. else
  398. {
  399. Rect.DrawOutline(DrawArea, Color.Green, Rotation);
  400. } // else
  401. }
  402. #endregion
  403. #region ShortElementInfo
  404. /// <summary>
  405. /// Short control info
  406. /// </summary>
  407. protected override string ShortElementInfo()
  408. {
  409. return base.ShortElementInfo() + ", Text=" + Text;
  410. }
  411. #endregion
  412. #endregion
  413. /// <summary>
  414. /// Tests for Label controls
  415. /// </summary>
  416. [NUnit.Framework.Category("Visual")]
  417. internal class LabelTests
  418. {
  419. #region Helpers
  420. #region TestLabelDesign
  421. /// <summary>
  422. /// Test label design
  423. /// </summary>
  424. private static readonly TextControlDesign TestLabelDesign =
  425. new TextControlDesign
  426. {
  427. Background = null,
  428. DisabledBackground = null,
  429. Hover = null,
  430. TextFont = new Font(Font.Default, Color.Gold),
  431. DisabledTextFont = new Font(Font.Default, Color.Black),
  432. TextBackground = BaseTheme.GetUIMaterial("DefaultLabel"),
  433. TextHoverBackground = BaseTheme.GetUIMaterial("DefaultLabel",
  434. Color.Yellow),
  435. DisabledTextBackground = BaseTheme.GetUIMaterial("DefaultLabel",
  436. Color.Grey),
  437. };
  438. #endregion
  439. #endregion
  440. #region Clone (Static)
  441. /// <summary>
  442. /// Clone
  443. /// </summary>
  444. [Test]
  445. public static void Clone()
  446. {
  447. using (Label testLabel = new Label
  448. {
  449. Name = "testButton",
  450. Text = "testing",
  451. })
  452. {
  453. Label clonedLabel = testLabel.Clone<Label>();
  454. Assert.NotEqual(testLabel, clonedLabel);
  455. Assert.NotEqual(testLabel.Children, clonedLabel.Children);
  456. Assert.Equal(testLabel.Name, clonedLabel.Name);
  457. Assert.Equal(testLabel.Text, clonedLabel.Text);
  458. } // using
  459. }
  460. #endregion
  461. #region DisplayLabel (Static)
  462. /// <summary>
  463. /// Display label
  464. /// </summary>
  465. [Test]
  466. public static void DisplayLabel()
  467. {
  468. const string LabelInitText = "Text";
  469. Label testLabel = new Label
  470. {
  471. LocalArea = Rectangle.FromCenter(0.35f, 0.35f, 0.4f, 0.125f),
  472. Text = LabelInitText,
  473. //Design = TestLabelDesign,
  474. };
  475. Screen testScene = new Screen();
  476. testScene.Add(testLabel);
  477. // Open now the scene to "activate" for the test
  478. testScene.Open();
  479. Application.Start(delegate
  480. {
  481. testLabel.Text =
  482. Input.Keyboard.SpaceIsPressed
  483. ? "loooooooooooooooooooooong Text"
  484. : LabelInitText;
  485. Point pos = new Point(0.5f, ScreenSpace.DrawArea.Top + 0.01f);
  486. const float LineGap = 0.02f;
  487. Font.Default.Draw("MousePos='" + Input.Mouse.Position + "'",
  488. Rectangle.FromCenter(pos, Size.Half));
  489. pos.Y += LineGap;
  490. Font.Default.Draw(
  491. "TextArea='" + testLabel.TextContentElement.DrawArea + "'",
  492. Rectangle.FromCenter(pos, Size.Half));
  493. pos.Y += LineGap;
  494. });
  495. }
  496. #endregion
  497. #region DisabledLabel (Static)
  498. /// <summary>
  499. /// Disabled label
  500. /// </summary>
  501. [Test]
  502. public static void DisabledLabel()
  503. {
  504. Label testLabel = new Label
  505. {
  506. LocalArea = new Rectangle(0.25f, 0.25f, 0.5f, 0.15f),
  507. //Design = TestLabelDesign,
  508. Text = "Enabled",
  509. };
  510. Screen testScene = new Screen();
  511. testScene.Add(testLabel);
  512. // Open now the scene to "activate" for the test
  513. testScene.Open();
  514. Application.Start(delegate
  515. {
  516. // Start the visual test to see the Label
  517. // Disable/enable the Label by pressing the keyboard "Space" button
  518. if (Input.Keyboard.SpaceReleased)
  519. {
  520. if (testLabel.State >= ElementState.Enabled)
  521. {
  522. testLabel.State = ElementState.Disabled;
  523. }
  524. else
  525. {
  526. testLabel.State =
  527. testLabel.IsInControl(Input.Mouse.Position)
  528. ? ElementState.Hovered
  529. : ElementState.Enabled;
  530. } // else
  531. testLabel.Text = testLabel.State.ToString();
  532. }
  533. });
  534. }
  535. #endregion
  536. #region TextAlignment (Static)
  537. /// <summary>
  538. /// Text alignment
  539. /// </summary>
  540. [Test]
  541. public static void TextAlignment()
  542. {
  543. // The used UI scene for the unit test
  544. Screen testScene = new Screen();
  545. Label testLabel = new Label
  546. {
  547. LocalArea = new Rectangle(0.15f, 0.3f, 0.4f, 0.15f),
  548. CustomDesign = TestLabelDesign,
  549. Text = "Please press 'Space'",
  550. };
  551. testScene.Add(testLabel);
  552. //testImage.Text = "Alignment=" + testImage.Alignment;
  553. // Open now the scene to "activate" for the test
  554. testScene.Open();
  555. Application.Start(delegate
  556. {
  557. // Cycling through all alignment modes by pressing the "Space" key
  558. if (Input.Keyboard.SpaceReleased)
  559. {
  560. ITextDesign textDesign = (ITextDesign)testLabel.CustomDesign;
  561. textDesign.TextFont = new Font(textDesign.TextFont,
  562. textDesign.TextFont.HorizontalAlignment.NextValue());
  563. testLabel.Text = textDesign.TextFont.HorizontalAlignment + " text";
  564. }
  565. });
  566. }
  567. #endregion
  568. #region DisplayMultilineText (Static)
  569. /// <summary>
  570. /// Display multiline text
  571. /// </summary>
  572. [Test]
  573. public static void DisplayMultilineText()
  574. {
  575. Screen testScene = new Screen();
  576. Label singleLineLabel = new Label
  577. {
  578. LocalArea = Rectangle.FromCenter(0.25f, 0.5f, 0.3f, 0.2f),
  579. Text = "Single line text",
  580. CustomDesign = TestLabelDesign,
  581. };
  582. testScene.Add(singleLineLabel);
  583. Label multiLineLabel = new Label
  584. {
  585. LocalArea = Rectangle.FromCenter(0.75f, 0.5f, 0.3f, 0.2f),
  586. Text = "Multi-\r\n" + "Line-\n" + "Text",
  587. CustomDesign = TestLabelDesign,
  588. };
  589. testScene.Add(multiLineLabel);
  590. // Open now the scene to "activate" for the test
  591. testScene.Open();
  592. Application.Start(delegate
  593. {
  594. // Cycling through all alignment modes by pressing the "Space" key
  595. if (Input.Keyboard.SpaceReleased)
  596. {
  597. // Grab the fonts
  598. ITextDesign singleTextDesign =
  599. singleLineLabel.CustomDesign as ITextDesign;
  600. ITextDesign multiTextDesign =
  601. multiLineLabel.CustomDesign as ITextDesign;
  602. // determine the next text alignment mode
  603. HorizontalAlignment newTextAlignment =
  604. singleTextDesign.TextFont.HorizontalAlignment.NextValue();
  605. // and set it
  606. singleTextDesign.TextFont =
  607. new Font(singleTextDesign.TextFont, newTextAlignment);
  608. multiTextDesign.TextFont =
  609. new Font(multiTextDesign.TextFont, newTextAlignment);
  610. }
  611. });
  612. }
  613. #endregion
  614. #region Docking (Static)
  615. /// <summary>
  616. /// Docking
  617. /// </summary>
  618. [Test]
  619. public static void Docking()
  620. {
  621. // // The used UI screen for the unit test
  622. // UserScreen testScene = new UserScreen();
  623. // Label testLabel = new Label
  624. // {
  625. // LocalArea = new Rectangle(0.15f, 0.3f, 0.4f, 0.15f),
  626. // Design = TestLabelDesign,
  627. // Size = new Size(0.1f, 0.02f),
  628. // //Docking
  629. // AnchorPoint = AnchorType.Middle,
  630. // };
  631. // testScene.Add(testLabel);
  632. // //testImage.Text = "Alignment=" + testImage.Alignment;
  633. // // Open now the scene to "activate" for the test
  634. // testScene.Open();
  635. // Application.Start(delegate
  636. // {
  637. // // Cycling through all alignment modes by pressing the "Space" key
  638. // if (Input.Keyboard.SpaceReleased)
  639. // {
  640. // testLabel.Alignment = EnumHelper.NextValue(testLabel.Alignment);
  641. // //testLabel.Text = testLabel.Alignment.ToString();
  642. // //testImage.Text = "Alignment=" + testImage.Alignment
  643. // testLabel.Text = "Alignment=" + testLabel.Alignment +
  644. // ", AnchorPoint= " + testLabel.AnchorPoint;
  645. // ;
  646. // }
  647. // // Cycling through all alignment modes by pressing the "Space" key
  648. // if (Input.Keyboard.EnterReleased)
  649. // {
  650. // testLabel.AnchorPoint =
  651. // EnumHelper.NextValue(testLabel.AnchorPoint);
  652. // //testLabel.Text = testLabel.Alignment.ToString();
  653. // testLabel.Text = "Alignment=" + testLabel.Alignment +
  654. // ", AnchorPoint= " + testLabel.AnchorPoint;
  655. // }
  656. // // By pressing the "Ctrl" key we change the scaling of the control to
  657. // // if the alignment still works
  658. // testLabel.Scaling = Input.Keyboard.IsPressed(InputButton.LeftControl) ?
  659. // 0.5f : 1.0f;
  660. // });
  661. }
  662. #endregion
  663. #region Alignment (Static)
  664. /// <summary>
  665. /// Alignment
  666. /// </summary>
  667. [Test]
  668. public static void Alignment()
  669. {
  670. // // The used UI scene for the unit test
  671. // UIScene testScene = new UIScene();
  672. // Label testLabel = new Label
  673. // {
  674. // LocalArea = new Rectangle(0.15f, 0.3f, 0.4f, 0.15f),
  675. // Design = TestLabelDesign,
  676. // //Scaling = 0.5f,
  677. // Size = new Size(0.1f, 0.02f),
  678. // AnchorPoint = AnchorType.Middle,
  679. // };
  680. // testScene.Add(testLabel);
  681. // //testImage.Text = "Alignment=" + testImage.Alignment;
  682. // // Open now the scene to "activate" for the test
  683. // testScene.Open();
  684. // Application.Start(delegate
  685. // {
  686. // // Cycling through all alignment modes by pressing the "Space" key
  687. // if (Input.Keyboard.SpaceReleased)
  688. // {
  689. // testLabel.Alignment = EnumHelper.NextValue(testLabel.Alignment);
  690. // //testLabel.Text = testLabel.Alignment.ToString();
  691. // //testImage.Text = "Alignment=" + testImage.Alignment
  692. // testLabel.Text = "Alignment=" + testLabel.Alignment +
  693. // ", AnchorPoint= " + testLabel.AnchorPoint; ;
  694. // }
  695. // // Cycling through all alignment modes by pressing the "Space" key
  696. // if (Input.Keyboard.EnterReleased)
  697. // {
  698. // testLabel.AnchorPoint =
  699. // EnumHelper.NextValue(testLabel.AnchorPoint);
  700. // //testLabel.Text = testLabel.Alignment.ToString();
  701. // testLabel.Text = "Alignment=" + testLabel.Alignment +
  702. // ", AnchorPoint= " + testLabel.AnchorPoint;
  703. // }
  704. // // By pressing the "Ctrl" key we change the scaling of the control to
  705. // // if the alignment still works
  706. // testLabel.Scaling = Input.Keyboard.IsPressed(InputButton.LeftControl) ?
  707. // 0.5f : 1.0f;
  708. // });
  709. }
  710. #endregion
  711. #region ChildAlignment (Static)
  712. /// <summary>
  713. /// Child alignment
  714. /// </summary>
  715. [Test]
  716. public static void ChildAlignment()
  717. {
  718. // // The used UI scene for the unit test
  719. // UIScene testScene = new UIScene();
  720. // Label parentLabel = new Label
  721. // {
  722. // LocalArea = new Rectangle(0.2f, 0.2f, 0.6f, 0.5f),
  723. // Design = TestLabelDesign,
  724. // //Scaling = 0.5f,
  725. // //Text = "No AutoSize", -> no text because of child control text
  726. // };
  727. // Label testLabel = new Label
  728. // {
  729. // //LocalArea = new Rectangle(0.15f, 0.3f, 0.4f, 0.15f),
  730. // LocalPosition = new Point(0.15f, 0.3f),
  731. // Size = new Size(0.1f, 0.02f),
  732. // AnchorPoint = AnchorType.TopRight,
  733. // Design = TestLabelDesign,
  734. // //Scaling = 0.5f,
  735. // };
  736. // parentLabel.Add(testLabel);
  737. // testScene.Add(parentLabel);
  738. // //testImage.Text = "Alignment=" + testImage.Alignment;
  739. // // Open now the scene to "activate" for the test
  740. // testScene.Open();
  741. // Application.Start(delegate
  742. // {
  743. // // Cycling through all alignment modes by pressing the "Space" key
  744. // if (Input.Keyboard.SpaceReleased)
  745. // {
  746. // testLabel.Alignment = EnumHelper.NextValue(testLabel.Alignment);
  747. // //testLabel.Text = testLabel.Alignment.ToString();
  748. // //testImage.Text = "Alignment=" + testImage.Alignment
  749. // testLabel.Text = "Alignment=" + testLabel.Alignment +
  750. // ", AnchorPoint= " + testLabel.AnchorPoint; ;
  751. // }
  752. // // Cycling through all alignment modes by pressing the "Space" key
  753. // if (Input.Keyboard.EnterReleased)
  754. // {
  755. // testLabel.AnchorPoint =
  756. // EnumHelper.NextValue(testLabel.AnchorPoint);
  757. // //testLabel.Text = testLabel.Alignment.ToString();
  758. // testLabel.Text = "Alignment=" + testLabel.Alignment +
  759. // ", AnchorPoint= " + testLabel.AnchorPoint;
  760. // }
  761. // // By pressing the "Ctrl" key we change the scaling of the control to
  762. // // if the alignment still works
  763. // testLabel.Scaling = Input.Keyboard.IsPressed(InputButton.LeftControl) ?
  764. // 0.5f : 1.0f;
  765. // });
  766. }
  767. #endregion
  768. #region DrawLabelDepthTest (Static)
  769. /// <summary>
  770. /// Draw Label Depth Test
  771. /// </summary>
  772. [Test]
  773. public static void DrawLabelDepthTest()
  774. {
  775. // // The used UI scene for the unit test
  776. // UIScene uiScene = Base.GameScreen.OverlayScreen.UIScene;
  777. // Label frontLabel = null;
  778. // Label backLabel = null;
  779. // Base.StartTest("Display Label", delegate
  780. // {
  781. // if (frontLabel == null)
  782. // {
  783. // frontLabel = new Label
  784. // {
  785. // LocalArea = new Rectangle(0.3f, 0.46f, 0.4f, 0.08f),
  786. // IsAutoSizing = false,
  787. // Text = "I AM IN FRONT!!! :D",
  788. // TextColor = Color.Red,
  789. // TextFont = Graphic.InfoFont,//new Font("Arial", 13),
  790. // DepthLayer = 2,
  791. // };
  792. // uiScene.Add(frontLabel);
  793. // backLabel = new Label
  794. // {
  795. // LocalArea = new Rectangle(0.27f, 0.415f, 0.4f, 0.08f),
  796. // IsAutoSizing = false,
  797. // Text = "I AM IN THE BACK :(",
  798. // TextColor = Color.Red,
  799. // TextFont = Graphic.InfoFont,//new Font("Arial", 13),
  800. // DepthLayer = 8,
  801. // };
  802. // uiScene.Add(backLabel);
  803. // }
  804. // });
  805. }
  806. #endregion
  807. }
  808. }
  809. }