LibraryDropDown.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using BansheeEngine;
  2. namespace BansheeEditor
  3. {
  4. /// <summary>
  5. /// Drop down window that displays options used by the library window.
  6. /// </summary>
  7. internal class LibraryDropDown : DropDownWindow
  8. {
  9. private LibraryWindow parent;
  10. /// <summary>
  11. /// Constructs the drop down window.
  12. /// </summary>
  13. public LibraryDropDown()
  14. : base(150, 30)
  15. { }
  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. }