#include "gui_sdl.h" #include "core/coreWidget.h" classGUI_SDL * classGUI_SDL::m_pInstance = NULL; classGUI_SDL * classGUI_SDL::getInstance(void){ if (m_pInstance == NULL){ m_pInstance = new classGUI_SDL(); }; return m_pInstance; }; classGUI_SDL::classGUI_SDL(): basicThread(){ m_pWindow = NULL; m_pScreenSurface = NULL; m_pTexture = NULL; m_pRenderer = NULL; m_bWindowSystemOk = false; m_bInitOk = false; m_pProtector = SDL_CreateMutex(); int display_count = 0, display_index = 0, mode_index = 0; SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; if ((display_count = SDL_GetNumVideoDisplays()) < 1) { SDL_Log("SDL_GetNumVideoDisplays returned: %i", display_count); }; SDL_Log("SDL_GetNumVideoDisplays returned: %i", display_count); if (SDL_GetDisplayMode(display_index, mode_index, &mode) != 0) { SDL_Log("SDL_GetDisplayMode failed: %s", SDL_GetError()); }; SDL_Log("SDL_GetDisplayMode(0, 0, &mode):\t\t%i bpp\t%i x %i", SDL_BITSPERPIXEL(mode.format), mode.w, mode.h ); m_bInitOk = basicThread::init(); while ( ( m_bWindowSystemOk == false ) && ( m_bThreadStatus < TH_ENDED ) ) SLEEP(1); }; classGUI_SDL::~classGUI_SDL(){ m_bWindowSystemOk = false; m_bInitOk = false; SDL_DestroyMutex( m_pProtector ); if (m_pRenderer!=NULL){ SDL_DestroyRenderer(m_pRenderer); }; if (m_pScreenSurface != NULL){ //Deallocate surface SDL_FreeSurface(m_pScreenSurface); m_pScreenSurface = NULL; }; if ( m_pWindow!= NULL ){ //Destroy window SDL_DestroyWindow(m_pWindow); m_pWindow = NULL; }; //Quit SDL subsystems SDL_Quit(); }; //https://www.facebook.com/missing.person.3158 //https://www.facebook.com/guga.wereteli.90 //https://www.facebook.com/mentul.ohmentul //https://www.facebook.com/profile.php?id=100001772172980 //https://www.facebook.com/egagua /* Collect Confirmation Codes Contact your friends and ask them for their help. 1. Call three of these friends or talk to them in person. Raphael LlamadoChantebis SamkaroMentul OhmentulEstrada Irish PotchEvgeny Gagua 2. Ask them to visit : https ://www.facebook.com/recover 3. Each friend will give you a code.Enter them below : */ void classGUI_SDL::m_fThreadProc(void){ if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ){ m_bInitOk = false; m_bThreadStatus = TH_ENDED; return; }; if (!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)){ //printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError()); m_bInitOk = false; m_bThreadStatus = TH_ENDED; return; }; //Initialize SDL_ttf if( TTF_Init() == -1 ){ //printf("SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError()); m_bInitOk = false; m_bThreadStatus = TH_ENDED; return; } else { m_bInitOk = true; if (SDL_CreateWindowAndRenderer(SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_RESIZABLE, &m_pWindow, &m_pRenderer)){ printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); m_bThreadStatus = TH_ENDED; m_bWindowSystemOk = false; return; } else { //SDL_SetWindowOpacity(m_pWindow, 0.5); //Get window surface //m_pScreenSurface = SDL_GetWindowSurface(m_pWindow); m_bThreadStatus = TH_WORKING; m_bWindowSystemOk = true; }; }; while( m_bThreadStatus < TH_ENDED ){ //Event handler SDL_Event mEvent; //Handle events on queue if( SDL_PollEvent(&mEvent) != 0 ){ //m_mProtector.lock(); SDL_LockMutex(m_pProtector); if (m_vWidgets.size()){ for (pWidgetVector::iterator index = m_vWidgets.begin(); index < m_vWidgets.end(); index++) (*index)->dispatch(&mEvent); }; //m_mProtector.unlock(); SDL_UnlockMutex(m_pProtector); // Global Window Event handler if( mEvent.type == SDL_QUIT ){ m_bThreadStatus = TH_ENDED; } else if (mEvent.type == SDL_KEYDOWN){ //User presses a key //Select surfaces based on key press switch( mEvent.key.keysym.sym ){ case SDLK_UP: //gCurrentSurface = gKeyPressSurfaces[KEY_PRESS_SURFACE_UP]; break; case SDLK_DOWN: //gCurrentSurface = gKeyPressSurfaces[KEY_PRESS_SURFACE_DOWN]; break; case SDLK_LEFT: //gCurrentSurface = gKeyPressSurfaces[KEY_PRESS_SURFACE_LEFT]; break; case SDLK_RIGHT: //gCurrentSurface = gKeyPressSurfaces[KEY_PRESS_SURFACE_RIGHT]; break; default: //gCurrentSurface = gKeyPressSurfaces[KEY_PRESS_SURFACE_DEFAULT]; break; }; }; }; //m_mProtector.lock(); SDL_LockMutex(m_pProtector); if (m_vWidgets.size()){ for (pWidgetVector::iterator index = m_vWidgets.begin(); index < m_vWidgets.end(); index++) (*index)->render(m_pRenderer); SDL_RenderPresent(m_pRenderer); }; //m_mProtector.unlock(); SDL_UnlockMutex(m_pProtector); //Apply the image //SDL_BlitSurface(gXOut, NULL, m_pScreenSurface, NULL); //Update the surface //SDL_UpdateWindowSurface(m_pWindow); //SLEEP(150); }; }; //FOXCONN PVB120G12H-P01 //AVC MD413 BA13733B12H void classGUI_SDL::registerWidget(sdlCoreWidget * tPtr){ while( !m_bWindowSystemOk ) SLEEP(1); if( tPtr != NULL ){ //m_mProtector.lock(); SDL_LockMutex(m_pProtector); m_vWidgets.push_back(tPtr); //m_mProtector.unlock(); SDL_UnlockMutex(m_pProtector); }; }; void classGUI_SDL::removeWidget(sdlCoreWidget * tPtr){ if (tPtr != NULL){ //m_mProtector.lock(); SDL_LockMutex(m_pProtector); for (pWidgetVector::iterator index = m_vWidgets.begin(); index < m_vWidgets.end(); index++){ if ((*index) == tPtr){ (*index)->hide(); m_vWidgets.erase(index); break; }; }; //m_mProtector.unlock(); SDL_UnlockMutex(m_pProtector); }; }; bool classGUI_SDL::setFullScreen( bool status ){ if (m_pWindow == NULL) return false; if (status){ SDL_SetWindowFullscreen(m_pWindow, SDL_WINDOW_FULLSCREEN ); } else { SDL_SetWindowFullscreen(m_pWindow, SDL_WINDOW_FULLSCREEN_DESKTOP); }; return true; };