LibraryDropDown.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using bs;
  4. namespace bs.Editor
  5. {
  6. /** @addtogroup Library
  7. * @{
  8. */
  9. /// <summary>
  10. /// Drop down window that displays options used by the library window.
  11. /// </summary>
  12. [DefaultSize(150, 30)]
  13. internal class LibraryDropDown : DropDownWindow
  14. {
  15. private LibraryWindow parent;
  16. /// <summary>
  17. /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before
  18. /// use.
  19. /// </summary>
  20. /// <param name="parent">Libary window that this drop down window is a part of.</param>
  21. internal void Initialize(LibraryWindow parent)
  22. {
  23. this.parent = parent;
  24. GUIToggleGroup group = new GUIToggleGroup();
  25. GUIToggle list16 = new GUIToggle(new LocEdString("16"), group, EditorStyles.Button, GUIOption.FixedWidth(30));
  26. GUIToggle grid32 = new GUIToggle(new LocEdString("32"), group, EditorStyles.Button, GUIOption.FixedWidth(30));
  27. GUIToggle grid48 = new GUIToggle(new LocEdString("48"), group, EditorStyles.Button, GUIOption.FixedWidth(30));
  28. GUIToggle grid64 = new GUIToggle(new LocEdString("64"), group, EditorStyles.Button, GUIOption.FixedWidth(30));
  29. ProjectViewType activeType = parent.ViewType;
  30. switch (activeType)
  31. {
  32. case ProjectViewType.List16:
  33. list16.Value = true;
  34. break;
  35. case ProjectViewType.Grid32:
  36. grid32.Value = true;
  37. break;
  38. case ProjectViewType.Grid48:
  39. grid48.Value = true;
  40. break;
  41. case ProjectViewType.Grid64:
  42. grid64.Value = true;
  43. break;
  44. }
  45. list16.OnToggled += (active) =>
  46. {
  47. if (active)
  48. ChangeViewType(ProjectViewType.List16);
  49. };
  50. grid32.OnToggled += (active) =>
  51. {
  52. if (active)
  53. ChangeViewType(ProjectViewType.Grid32);
  54. };
  55. grid48.OnToggled += (active) =>
  56. {
  57. if (active)
  58. ChangeViewType(ProjectViewType.Grid48);
  59. };
  60. grid64.OnToggled += (active) =>
  61. {
  62. if (active)
  63. ChangeViewType(ProjectViewType.Grid64);
  64. };
  65. GUILayoutY vertLayout = GUI.AddLayoutY();
  66. vertLayout.AddFlexibleSpace();
  67. GUILayoutX contentLayout = vertLayout.AddLayoutX();
  68. contentLayout.AddFlexibleSpace();
  69. contentLayout.AddElement(list16);
  70. contentLayout.AddElement(grid32);
  71. contentLayout.AddElement(grid48);
  72. contentLayout.AddElement(grid64);
  73. contentLayout.AddFlexibleSpace();
  74. vertLayout.AddFlexibleSpace();
  75. }
  76. /// <summary>
  77. /// Changes the icon view type in the library window.
  78. /// </summary>
  79. /// <param name="viewType">Type of icons to display in the library window.</param>
  80. private void ChangeViewType(ProjectViewType viewType)
  81. {
  82. parent.ViewType = viewType;
  83. }
  84. }
  85. /** @} */
  86. }