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.

192 lines
5.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "gui_sdl.h"
  2. #include "core/coreWidget.h"
  3. classGUI_SDL * classGUI_SDL::m_pInstance = NULL;
  4. classGUI_SDL * classGUI_SDL::getInstance(void){
  5. if (m_pInstance == NULL){
  6. m_pInstance = new classGUI_SDL();
  7. };
  8. return m_pInstance;
  9. };
  10. classGUI_SDL::classGUI_SDL(): basicThread(){
  11. m_pWindow = NULL;
  12. m_pScreenSurface = NULL;
  13. m_pTexture = NULL;
  14. m_pRenderer = NULL;
  15. m_bWindowSystemOk = false;
  16. m_bInitOk = false;
  17. m_pProtector = SDL_CreateMutex();
  18. int display_count = 0, display_index = 0, mode_index = 0;
  19. SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
  20. if ((display_count = SDL_GetNumVideoDisplays()) < 1) {
  21. SDL_Log("SDL_GetNumVideoDisplays returned: %i", display_count);
  22. };
  23. SDL_Log("SDL_GetNumVideoDisplays returned: %i", display_count);
  24. if (SDL_GetDisplayMode(display_index, mode_index, &mode) != 0) {
  25. SDL_Log("SDL_GetDisplayMode failed: %s", SDL_GetError());
  26. };
  27. SDL_Log("SDL_GetDisplayMode(0, 0, &mode):\t\t%i bpp\t%i x %i", SDL_BITSPERPIXEL(mode.format), mode.w, mode.h );
  28. m_bInitOk = basicThread::init();
  29. while ( ( m_bWindowSystemOk == false ) && ( m_bThreadStatus < TH_ENDED ) ) SLEEP(1);
  30. };
  31. classGUI_SDL::~classGUI_SDL(){
  32. m_bWindowSystemOk = false;
  33. m_bInitOk = false;
  34. SDL_DestroyMutex( m_pProtector );
  35. if (m_pRenderer!=NULL){
  36. SDL_DestroyRenderer(m_pRenderer);
  37. };
  38. if (m_pScreenSurface != NULL){
  39. //Deallocate surface
  40. SDL_FreeSurface(m_pScreenSurface);
  41. m_pScreenSurface = NULL;
  42. };
  43. if ( m_pWindow!= NULL ){
  44. //Destroy window
  45. SDL_DestroyWindow(m_pWindow);
  46. m_pWindow = NULL;
  47. };
  48. //Quit SDL subsystems
  49. SDL_Quit();
  50. };
  51. //https://www.facebook.com/missing.person.3158
  52. //https://www.facebook.com/guga.wereteli.90
  53. //https://www.facebook.com/mentul.ohmentul
  54. //https://www.facebook.com/profile.php?id=100001772172980
  55. //https://www.facebook.com/egagua
  56. /* Collect Confirmation Codes
  57. Contact your friends and ask them for their help.
  58. 1. Call three of these friends or talk to them in person.
  59. Raphael LlamadoChantebis SamkaroMentul OhmentulEstrada Irish PotchEvgeny Gagua
  60. 2. Ask them to visit :
  61. https ://www.facebook.com/recover
  62. 3. Each friend will give you a code.Enter them below :
  63. */
  64. void classGUI_SDL::m_fThreadProc(void){
  65. if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ){
  66. m_bInitOk = false;
  67. m_bThreadStatus = TH_ENDED;
  68. return;
  69. };
  70. if (!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)){
  71. //printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
  72. m_bInitOk = false;
  73. m_bThreadStatus = TH_ENDED;
  74. return;
  75. };
  76. //Initialize SDL_ttf
  77. if( TTF_Init() == -1 ){
  78. //printf("SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError());
  79. m_bInitOk = false;
  80. m_bThreadStatus = TH_ENDED;
  81. return;
  82. } else {
  83. m_bInitOk = true;
  84. if (SDL_CreateWindowAndRenderer(SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_RESIZABLE, &m_pWindow, &m_pRenderer)){
  85. printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
  86. m_bThreadStatus = TH_ENDED;
  87. m_bWindowSystemOk = false;
  88. return;
  89. } else {
  90. //SDL_SetWindowOpacity(m_pWindow, 0.5);
  91. //Get window surface
  92. //m_pScreenSurface = SDL_GetWindowSurface(m_pWindow);
  93. m_bThreadStatus = TH_WORKING;
  94. m_bWindowSystemOk = true;
  95. };
  96. };
  97. while( m_bThreadStatus < TH_ENDED ){
  98. //Event handler
  99. SDL_Event mEvent;
  100. //Handle events on queue
  101. if( SDL_PollEvent(&mEvent) != 0 ){
  102. //m_mProtector.lock();
  103. SDL_LockMutex(m_pProtector);
  104. if (m_vWidgets.size()){
  105. for (pWidgetVector::iterator index = m_vWidgets.begin(); index < m_vWidgets.end(); index++) (*index)->dispatch(&mEvent);
  106. };
  107. //m_mProtector.unlock();
  108. SDL_UnlockMutex(m_pProtector);
  109. // Global Window Event handler
  110. if( mEvent.type == SDL_QUIT ){
  111. m_bThreadStatus = TH_ENDED;
  112. } else if (mEvent.type == SDL_KEYDOWN){ //User presses a key
  113. //Select surfaces based on key press
  114. switch( mEvent.key.keysym.sym ){
  115. case SDLK_UP:
  116. //gCurrentSurface = gKeyPressSurfaces[KEY_PRESS_SURFACE_UP];
  117. break;
  118. case SDLK_DOWN:
  119. //gCurrentSurface = gKeyPressSurfaces[KEY_PRESS_SURFACE_DOWN];
  120. break;
  121. case SDLK_LEFT:
  122. //gCurrentSurface = gKeyPressSurfaces[KEY_PRESS_SURFACE_LEFT];
  123. break;
  124. case SDLK_RIGHT:
  125. //gCurrentSurface = gKeyPressSurfaces[KEY_PRESS_SURFACE_RIGHT];
  126. break;
  127. default:
  128. //gCurrentSurface = gKeyPressSurfaces[KEY_PRESS_SURFACE_DEFAULT];
  129. break;
  130. };
  131. };
  132. };
  133. //m_mProtector.lock();
  134. SDL_LockMutex(m_pProtector);
  135. if (m_vWidgets.size()){
  136. for (pWidgetVector::iterator index = m_vWidgets.begin(); index < m_vWidgets.end(); index++) (*index)->render(m_pRenderer);
  137. SDL_RenderPresent(m_pRenderer);
  138. };
  139. //m_mProtector.unlock();
  140. SDL_UnlockMutex(m_pProtector);
  141. //Apply the image
  142. //SDL_BlitSurface(gXOut, NULL, m_pScreenSurface, NULL);
  143. //Update the surface
  144. //SDL_UpdateWindowSurface(m_pWindow);
  145. //SLEEP(150);
  146. };
  147. };
  148. //FOXCONN PVB120G12H-P01
  149. //AVC MD413 BA13733B12H
  150. void classGUI_SDL::registerWidget(sdlCoreWidget * tPtr){
  151. while( !m_bWindowSystemOk ) SLEEP(1);
  152. if( tPtr != NULL ){
  153. //m_mProtector.lock();
  154. SDL_LockMutex(m_pProtector);
  155. m_vWidgets.push_back(tPtr);
  156. //m_mProtector.unlock();
  157. SDL_UnlockMutex(m_pProtector);
  158. };
  159. };
  160. void classGUI_SDL::removeWidget(sdlCoreWidget * tPtr){
  161. if (tPtr != NULL){
  162. //m_mProtector.lock();
  163. SDL_LockMutex(m_pProtector);
  164. for (pWidgetVector::iterator index = m_vWidgets.begin(); index < m_vWidgets.end(); index++){
  165. if ((*index) == tPtr){
  166. (*index)->hide();
  167. m_vWidgets.erase(index);
  168. break;
  169. };
  170. };
  171. //m_mProtector.unlock();
  172. SDL_UnlockMutex(m_pProtector);
  173. };
  174. };
  175. bool classGUI_SDL::setFullScreen( bool status ){
  176. if (m_pWindow == NULL) return false;
  177. if (status){
  178. SDL_SetWindowFullscreen(m_pWindow, SDL_WINDOW_FULLSCREEN );
  179. } else {
  180. SDL_SetWindowFullscreen(m_pWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
  181. };
  182. return true;
  183. };