You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __GUI_SDL_HEADER__
  2. #define __GUI_SDL_HEADER__
  3. #include <stdio.h>
  4. #include <vector>
  5. #include "../components/base/basicMutex.h"
  6. #include "../components/base/basicThread.h"
  7. #include "../components/base/basicLogCollection.h"
  8. #include "../components/base/basicSettingsProvider.h"
  9. #include <SDL.h>
  10. #include <SDL_image.h>
  11. #include <SDL_ttf.h>
  12. #include "core/coreElement.h"
  13. #include "core/coreLayout.h"
  14. extern "C" {
  15. FILE* __cdecl __iob_func(void);
  16. }
  17. class sdlJoystickWrapper;
  18. #define SCREEN_WIDTH 800
  19. #define SCREEN_HEIGHT 600
  20. typedef struct {
  21. SDL_Renderer* renderer;
  22. SDL_Window* window;
  23. int up;
  24. int down;
  25. int left;
  26. int right;
  27. int fire;
  28. } App;
  29. typedef struct {
  30. int x;
  31. int y;
  32. int dx;
  33. int dy;
  34. SDL_Texture* texture;
  35. int health;
  36. } Entity;
  37. class classGUI_SDL: public basicThread{
  38. private:
  39. bool m_bInitOk;
  40. bool m_bWindowSystemOk;
  41. bool m_bUseAltBackground;
  42. config_setting_t * m_pSettings;
  43. basicLogCollection * m_pLog;
  44. SDL_Color m_sBackgroundSolidColor;
  45. uint32_t m_aBackgroundGradientColor[4];
  46. char m_pBackgroundFileName[256];
  47. SDL_Texture * m_pBackgroundTexture;
  48. uint32_t m_nBackgroundTextureWidth;
  49. uint32_t m_nBackgroundTextureHeight;
  50. SDL_Color m_sAltBackgroundSolidColor;
  51. uint32_t m_aAltBackgroundGradientColor[4];
  52. char m_pAltBackgroundFileName[256];
  53. SDL_Texture * m_pAltBackgroundTexture;
  54. uint32_t m_nAltBackgroundTextureWidth;
  55. uint32_t m_nAltBackgroundTextureHeight;
  56. SDL_Window * m_pWindow;
  57. SDL_Renderer * m_pRenderer;
  58. sdlJoystickWrapper * m_pJoystickWraper;
  59. sdlCoreLayout * m_pMainLayout;
  60. int m_nWindowMode;
  61. int m_nBackgroundMode;
  62. int m_nWidth;
  63. int m_nHeight;
  64. int m_iCursorPosX;
  65. int m_iCursorPosY;
  66. basicMutex * m_pProtector;
  67. vectorGEL m_vGraphicElements;
  68. TEXTURE_HEAP m_vTextureHeap;
  69. //App app;
  70. void doKeyUp(SDL_KeyboardEvent* event);
  71. void doKeyDown(SDL_KeyboardEvent* event);
  72. public:
  73. static classGUI_SDL * getInstance();
  74. SDL_Renderer * getRenderer(void) { return m_pRenderer; };
  75. virtual void m_fThreadProc(void);
  76. void registerGEL( sdlGraphicElement* tPtr);
  77. void removeGEL( sdlGraphicElement* tPtr);
  78. void registerJoystickWraper(sdlJoystickWrapper* Ptr);
  79. bool setFullScreen( bool status );
  80. void alterateBackground(bool b) { m_bUseAltBackground = b; };
  81. void setLayout(sdlCoreLayout* ll);
  82. TEXTURE_HEAP_ITEM * loadTexture(char* filename);
  83. TEXTURE_HEAP_ITEM * createTexture(int width, int height);
  84. TEXTURE_HEAP_ITEM * createYUV420PTexture(int width, int height, bool streaming = true);
  85. SDL_Surface * loadSurface(CSTR path);
  86. protected:
  87. classGUI_SDL();
  88. ~classGUI_SDL();
  89. static classGUI_SDL * m_pInstance;
  90. };
  91. #endif