Gui.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright © 2011-2020 Frictional Games
  3. *
  4. * This file is part of Amnesia: A Machine For Pigs.
  5. *
  6. * Amnesia: A Machine For Pigs is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. * Amnesia: A Machine For Pigs is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Amnesia: A Machine For Pigs. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. #ifndef HPL_GUI_H
  19. #define HPL_GUI_H
  20. #include <map>
  21. #include "engine/Updateable.h"
  22. #include "gui/GuiTypes.h"
  23. #include "system/SystemTypes.h"
  24. namespace hpl {
  25. class cResources;
  26. class cGraphics;
  27. class cSound;
  28. class cScene;
  29. class cInput;
  30. class cGuiSet;
  31. class cGuiSkin;
  32. class cGuiGfxElement;
  33. class iGuiMaterial;
  34. class iTexture;
  35. //------------------------------------------------
  36. typedef std::map<tString, cGuiSkin*> tGuiSkinMap;
  37. typedef tGuiSkinMap::iterator tGuiSkinMapIt;
  38. //-------------------------------------
  39. typedef std::map<tString, eGuiSkinGfx> tGuiSkinGfxMap;
  40. typedef tGuiSkinGfxMap::iterator tGuiSkinGfxMapIt;
  41. typedef std::map<tString, eGuiSkinFont> tGuiSkinFontMap;
  42. typedef tGuiSkinFontMap::iterator tGuiSkinFontMapIt;
  43. typedef std::map<tString, eGuiSkinAttribute> tGuiSkinAttributeMap;
  44. typedef tGuiSkinAttributeMap::iterator tGuiSkinAttributeMapIt;
  45. //------------------------------------------------
  46. class cGui : public iUpdateable
  47. {
  48. public:
  49. cGui();
  50. ~cGui();
  51. ///////////////////////////////
  52. // General
  53. void Init( cResources *apResources, cGraphics* apGraphics,
  54. cSound *apSound, cScene *apScene, cInput *apInput);
  55. void Update(float afTimeStep);
  56. void OnDraw(float afFrameTime);
  57. void OnPostBufferSwap();
  58. iGuiMaterial* GetMaterial(eGuiMaterial aType);
  59. ///////////////////////////////
  60. // Skins
  61. cGuiSkin* CreateSkin(const tString& asFile);
  62. eGuiSkinGfx GetSkinGfxFromString(const tString& asType);
  63. eGuiSkinFont GetSkinFontFromString(const tString& asType);
  64. eGuiSkinAttribute GetSkinAttributeFromString(const tString& asType);
  65. tString GetSkinGfxString(eGuiSkinGfx aType);
  66. tString GetSkinFontString(eGuiSkinFont aType);
  67. tString GetSkinAttributeString(eGuiSkinAttribute aType);
  68. ///////////////////////////////
  69. // Sets
  70. cGuiSet* CreateSet(const tString& asName, cGuiSkin *apSkin);
  71. cGuiSet* GetSetFromName(const tString& asName);
  72. void SetFocus(cGuiSet* apSet);
  73. void SetFocusByName(const tString& asSetName);
  74. cGuiSet* GetFocusedSet(){return mpSetInFocus;}
  75. void DestroySet(cGuiSet *apSet);
  76. ///////////////////////////////
  77. // Graphics creation
  78. cGuiGfxElement* CreateGfxFilledRect(const cColor& aColor, eGuiMaterial aMaterial, bool abAddToList=true);
  79. cGuiGfxElement* CreateGfxImage( const tString &asFile,eGuiMaterial aMaterial,
  80. const cColor& aColor=cColor(1,1), bool abAddToList=true);
  81. cGuiGfxElement* CreateGfxTexture( const tString &asFile,eGuiMaterial aMaterial,
  82. eTextureType aTextureType = eTextureType_2D,
  83. const cColor& aColor=cColor(1,1),
  84. bool abMipMaps=false,
  85. bool abAddToList=true);
  86. cGuiGfxElement* CreateGfxTexture( iTexture *apTexture, bool abAutoDestroyTexture,
  87. eGuiMaterial aMaterial,
  88. const cColor& aColor=cColor(1,1),bool abAddToList=true,
  89. const cVector2f& avStartUV=0, const cVector2f& avEndUV=1);
  90. /**
  91. * Loads several images asFile+00, etc. Used for animations.Must have extension!
  92. */
  93. cGuiGfxElement* CreateGfxImageBuffer( const tString &asFile,eGuiMaterial aMaterial,
  94. bool abCreateAnimation=true,
  95. const cColor& aColor=cColor(1,1), bool abAddToList=true);
  96. void DestroyGfx(cGuiGfxElement* apGfx);
  97. ///////////////////////////////
  98. // Input sending TODO (need some other way to pass key modifiers, but this will do now)
  99. bool SendMousePos(const cVector2l &avPos, const cVector2l &avRel);
  100. bool SendMouseClickDown(eGuiMouseButton aButton, int alKeyModifiers=0);
  101. bool SendMouseClickUp(eGuiMouseButton aButton, int alKeyModifiers=0);
  102. bool SendMouseDoubleClick(eGuiMouseButton aButton, int alKeyModifiers=0);
  103. bool SendKeyPress(const cKeyPress& keyPress);
  104. bool SendKeyRelease(const cKeyPress& keyPress);
  105. bool SendGamepadInput(const cGamepadInputData& aInput);
  106. bool SendUIArrowPress(eUIArrow aX);
  107. bool SendUIArrowRelease(eUIArrow aX);
  108. bool SendUIButtonPress(eUIButton aX);
  109. bool SendUIButtonRelease(eUIButton aX);
  110. bool SendUIButtonDoublePress(eUIButton aX);
  111. eMouseButton TranslateGuiMouseToMouse(eGuiMouseButton aButton);
  112. eGuiMouseButton TranslateMouseToGuiMouse(eMouseButton aButton);
  113. ///////////////////////////////
  114. // Properties
  115. cResources* GetResources(){ return mpResources;}
  116. cInput* GetInput() { return mpInput; }
  117. static cGuiGfxElement* mpGfxRect;
  118. private:
  119. void GenerateSkinTypeStrings();
  120. cResources *mpResources;
  121. cGraphics *mpGraphics;
  122. cSound *mpSound;
  123. cScene *mpScene;
  124. cInput *mpInput;
  125. cGuiSet *mpSetInFocus;
  126. tGuiSetMap m_mapSets;
  127. tGuiSkinMap m_mapSkins;
  128. iGuiMaterial *mvMaterials[eGuiMaterial_LastEnum];
  129. tGuiGfxElementList mlstGfxElements;
  130. tGuiGfxElementList mlstToBeDestroyedGfxElements;
  131. tGuiSkinGfxMap m_mapSkinGfxStrings;
  132. tGuiSkinFontMap m_mapSkinFontStrings;
  133. tGuiSkinAttributeMap m_mapSkinAttributeStrings;
  134. unsigned long mlLastRenderTime;
  135. };
  136. };
  137. #endif // HPL_GUI_H