BsEngineGUI.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #include "BsEngineGUI.h"
  2. #include "BsGUIElementStyle.h"
  3. #include "BsGUILabel.h"
  4. #include "BsGUIWindowFrame.h"
  5. #include "BsGUIButton.h"
  6. #include "BsTextSprite.h"
  7. #include "BsSpriteTexture.h"
  8. #include "CmFont.h"
  9. #include "CmFontImportOptions.h"
  10. #include "CmImporter.h"
  11. #include "CmRTTIType.h"
  12. using namespace CamelotFramework;
  13. namespace BansheeEngine
  14. {
  15. const String EngineGUI::DefaultFontPath = "C:\\arial.ttf";
  16. const UINT32 EngineGUI::DefaultFontSize = 10;
  17. const String EngineGUI::WindowBackgroundTexture = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowBgTile.psd";
  18. const String EngineGUI::ButtonNormalTex = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\ButtonNormal.psd";
  19. const String EngineGUI::ButtonHoverTex = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\ButtonHover.psd";
  20. const String EngineGUI::WindowFrameNormal = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowFrameNormal.psd";
  21. const String EngineGUI::WindowFrameFocused = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowFrameFocused.psd";
  22. const String EngineGUI::WindowTitleBarBg = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowTitleBarBg.psd";
  23. const String EngineGUI::WindowCloseButtonNormal = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowCloseBtnNormal.psd";
  24. const String EngineGUI::WindowCloseButtonHover = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowCloseBtnHover.psd";
  25. const String EngineGUI::WindowMinButtonNormal = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowMinBtnNormal.psd";
  26. const String EngineGUI::WindowMinButtonHover = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowMinBtnHover.psd";
  27. const String EngineGUI::TabbedBarBtnNormal = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\TabbedButtonNormal.psd";
  28. const String EngineGUI::TabbedBarBtnActive = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\TabbedButtonActive.psd";
  29. EngineGUI::EngineGUI()
  30. {
  31. // TODO - Normally I want to load this from some file
  32. // Label
  33. // TODO - Instead of importing font every time, try to save a resource and then just load it?
  34. HFont font;
  35. {
  36. ImportOptionsPtr fontImportOptions = Importer::instance().createImportOptions(DefaultFontPath);
  37. if(rtti_is_of_type<FontImportOptions>(fontImportOptions))
  38. {
  39. FontImportOptions* importOptions = static_cast<FontImportOptions*>(fontImportOptions.get());
  40. vector<CamelotFramework::UINT32>::type fontSizes;
  41. fontSizes.push_back(DefaultFontSize);
  42. importOptions->setFontSizes(fontSizes);
  43. importOptions->setAntialiasing(false);
  44. }
  45. font = Importer::instance().import(DefaultFontPath, fontImportOptions);
  46. }
  47. GUIElementStyle labelStyle;
  48. labelStyle.font = font;
  49. labelStyle.fontSize = DefaultFontSize;
  50. labelStyle.fixedWidth = false;
  51. labelStyle.fixedHeight = true;
  52. labelStyle.height = 16;
  53. labelStyle.minWidth = 10;
  54. mSkin.setStyle(GUILabel::getGUITypeName(), labelStyle);
  55. // Window frame
  56. HTexture windowFrameNormalTex = static_resource_cast<Texture>(Importer::instance().import(WindowFrameNormal));
  57. HTexture windowFrameFocusedTex = static_resource_cast<Texture>(Importer::instance().import(WindowFrameFocused));
  58. GUIElementStyle windowFrameStyle;
  59. windowFrameStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(windowFrameNormalTex));
  60. windowFrameStyle.focused.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(windowFrameFocusedTex));
  61. windowFrameStyle.border.left = 1;
  62. windowFrameStyle.border.right = 1;
  63. windowFrameStyle.border.top = 1;
  64. windowFrameStyle.border.bottom = 1;
  65. mSkin.setStyle(GUIWindowFrame::getGUITypeName(), windowFrameStyle);
  66. // Button
  67. HTexture buttonNormalTex = static_resource_cast<Texture>(Importer::instance().import(ButtonNormalTex));
  68. HTexture buttonHoverTex = static_resource_cast<Texture>(Importer::instance().import(ButtonHoverTex));
  69. GUIElementStyle buttonStyle;
  70. buttonStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(buttonNormalTex));
  71. buttonStyle.hover.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(buttonHoverTex));
  72. buttonStyle.border.left = 5;
  73. buttonStyle.border.right = 5;
  74. buttonStyle.border.top = 5;
  75. buttonStyle.border.bottom = 5;
  76. buttonStyle.margins.left = 4;
  77. buttonStyle.margins.right = 4;
  78. buttonStyle.margins.top = 4;
  79. buttonStyle.margins.bottom = 4;
  80. buttonStyle.contentOffset.left = 2;
  81. buttonStyle.contentOffset.right = 2;
  82. buttonStyle.fixedHeight = true;
  83. buttonStyle.height = 21;
  84. buttonStyle.minWidth = 10;
  85. buttonStyle.font = font;
  86. buttonStyle.fontSize = DefaultFontSize;
  87. buttonStyle.textHorzAlign = THA_Center;
  88. buttonStyle.textVertAlign = TVA_Center;
  89. mSkin.setStyle(GUIButton::getGUITypeName(), buttonStyle);
  90. // Window background texture
  91. HTexture windowBgTexture = static_resource_cast<Texture>(Importer::instance().import(WindowBackgroundTexture));
  92. GUIElementStyle windowBgStyle;
  93. windowBgStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(windowBgTexture));
  94. mSkin.setStyle("WindowBackground", windowBgStyle);
  95. // Window title bar background
  96. HTexture windowTitleBarBg = static_resource_cast<Texture>(Importer::instance().import(WindowTitleBarBg));
  97. GUIElementStyle titleBarBgStyle;
  98. titleBarBgStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(windowTitleBarBg));
  99. titleBarBgStyle.fixedHeight = true;
  100. titleBarBgStyle.height = 13;
  101. mSkin.setStyle("TitleBarBackground", titleBarBgStyle);
  102. // Tabbed title bar tab button
  103. HTexture tabbedBarBtnNormal = static_resource_cast<Texture>(Importer::instance().import(TabbedBarBtnNormal));
  104. HTexture tabbedBarBtnActive = static_resource_cast<Texture>(Importer::instance().import(TabbedBarBtnActive));
  105. GUIElementStyle tabbedBarButton;
  106. tabbedBarButton.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(tabbedBarBtnNormal));
  107. tabbedBarButton.hover.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(tabbedBarBtnActive));
  108. tabbedBarButton.active.texture = tabbedBarButton.hover.texture;
  109. tabbedBarButton.normalOn.texture = tabbedBarButton.hover.texture;
  110. tabbedBarButton.hoverOn.texture = tabbedBarButton.hover.texture;
  111. tabbedBarButton.activeOn.texture = tabbedBarButton.hover.texture;
  112. tabbedBarButton.fixedHeight = true;
  113. tabbedBarButton.height = 13;
  114. tabbedBarButton.minWidth = 10;
  115. tabbedBarButton.maxWidth = 110;
  116. tabbedBarButton.font = font;
  117. tabbedBarButton.fontSize = DefaultFontSize;
  118. tabbedBarButton.textHorzAlign = THA_Center;
  119. tabbedBarButton.textVertAlign = TVA_Center;
  120. mSkin.setStyle("TabbedBarBtn", tabbedBarButton);
  121. // Tabbed title bar drag/drop button
  122. GUIElementStyle tabbedBarDropButton;
  123. tabbedBarDropButton.fixedHeight = true;
  124. tabbedBarDropButton.fixedWidth = true;
  125. tabbedBarDropButton.height = 13;
  126. tabbedBarDropButton.width = 6;
  127. mSkin.setStyle("TabbedBarDropArea", tabbedBarDropButton);
  128. // Window minimize button
  129. HTexture winMinBtnNormal = static_resource_cast<Texture>(Importer::instance().import(WindowMinButtonNormal));
  130. HTexture winMinBtnHover = static_resource_cast<Texture>(Importer::instance().import(WindowMinButtonHover));
  131. GUIElementStyle winMinButtonStyle;
  132. winMinButtonStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(winMinBtnNormal));
  133. winMinButtonStyle.hover.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(winMinBtnHover));
  134. winMinButtonStyle.active.texture = winMinButtonStyle.hover.texture;
  135. winMinButtonStyle.fixedHeight = true;
  136. winMinButtonStyle.fixedWidth = true;
  137. winMinButtonStyle.height = 7;
  138. winMinButtonStyle.width = 8;
  139. mSkin.setStyle("WinMinimizeBtn", winMinButtonStyle);
  140. // Window close button
  141. HTexture winCloseBtnNormal = static_resource_cast<Texture>(Importer::instance().import(WindowCloseButtonNormal));
  142. HTexture winCloseBtnHover = static_resource_cast<Texture>(Importer::instance().import(WindowCloseButtonHover));
  143. GUIElementStyle winCloseButtonStyle;
  144. winCloseButtonStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(winCloseBtnNormal));
  145. winCloseButtonStyle.hover.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(winCloseBtnHover));
  146. winCloseButtonStyle.active.texture = winCloseButtonStyle.active.texture;
  147. winCloseButtonStyle.fixedHeight = true;
  148. winCloseButtonStyle.fixedWidth = true;
  149. winCloseButtonStyle.height = 7;
  150. winCloseButtonStyle.width = 8;
  151. mSkin.setStyle("WinCloseBtn", winCloseButtonStyle);
  152. }
  153. }