bool SdlApp::createWindow(const char *title, int x, int y, int w, int h, Uint32 flags) { SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2 mWindowWidth = w; mWindowHeight = h; // Create an application window with the following settings: mWindow = SDL_CreateWindow(title, x, y, w, h, flags); // Check that the window was successfully made if (mWindow == NULL) { // In the event that the window could not be made... printf("Could not create window: %s\n", SDL_GetError()); setExitFlag(); return false; } // We must call SDL_CreateRenderer in order for draw calls to affect this window. mRenderer = SDL_CreateRenderer(mWindow, -1, 0); // Select the color for drawing. It is set to red here. SDL_SetRenderDrawColor(mRenderer, 0, 0, 0, 255); // Clear the entire screen to our selected color. SDL_RenderClear(mRenderer); // Up until now everything was drawn behind the scenes. // This will show the new, red contents of the window. SDL_RenderPresent(mRenderer); return true; }
void SdlApp::handleInput() { SDL_Event sdlEvent; while (SDL_PollEvent(&sdlEvent) != 0) { if (sdlEvent.type == SDL_QUIT) setExitFlag(); else if (sdlEvent.type == SDL_KEYDOWN) onKeyDown(sdlEvent.key.keysym.sym); else if (sdlEvent.type == SDL_WINDOWEVENT) { switch (sdlEvent.window.event) { case SDL_WINDOWEVENT_RESIZED: // Handle resize mWindowWidth = sdlEvent.window.data1; mWindowHeight = sdlEvent.window.data2; onResize(mWindowWidth, mWindowHeight); break; case SDL_WINDOWEVENT_EXPOSED: draw(); } } } }
//------------------------------------------------------------------------------ void AgentThread::start() //------------------------------------------------------------------------------ { if( !isConfigured() ) { throw AgentException(0, "[AgentThread::start] : Attempted to start without configuring"); } setExitFlag(false); QThread::start(); if( !QThread::isRunning() ) { throw AgentException(0, "[AgentThread::start] : Error starting thread"); } }
void EventLoop::stop() { setExitFlag(); }
//------------------------------------------------------------------------------ void AgentThread::stop() throw() //------------------------------------------------------------------------------ { setExitFlag(true); QThread::wait(); }
void SdlApp::onKeyDown(SDL_Keycode key) { if (key == SDLK_ESCAPE || key == SDLK_q) setExitFlag(); }