MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / runEventLoop

Function runEventLoop

apps/tools/Tools/SDLPreview.cpp:18–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16{
17
18static void runEventLoop(SDL_Window* window, SDL_Renderer* renderer, SDL_Texture*& tex, int& imgW, int& imgH,
19 SDL_PixelFormat pixelFormat, int bytesPerPixel, std::vector<uint8_t>& pixelsCopy,
20 ResizeCallback onResize)
21{
22 SDL_Event e;
23 bool running = true;
24 while (running)
25 {
26 while (SDL_PollEvent(&e))
27 {
28 if (e.type == SDL_EVENT_QUIT)
29 running = false;
30 if (e.type == SDL_EVENT_KEY_DOWN && e.key.scancode == SDL_SCANCODE_ESCAPE)
31 running = false;
32 if (e.type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED && onResize)
33 {
34 imgW = e.window.data1;
35 imgH = e.window.data2;
36 auto resized = onResize(imgW, imgH);
37 if (!resized.empty())
38 pixelsCopy = std::move(resized);
39 SDL_DestroyTexture(tex);
40 tex = SDL_CreateTexture(renderer, pixelFormat, SDL_TEXTUREACCESS_STATIC, imgW, imgH);
41 SDL_UpdateTexture(tex, nullptr, pixelsCopy.data(), imgW * bytesPerPixel);
42 }
43 }
44 SDL_SetRenderDrawColor(renderer, 40, 40, 40, 255);
45 SDL_RenderClear(renderer);
46 SDL_RenderTexture(renderer, tex, nullptr, nullptr);
47 SDL_RenderPresent(renderer);
48 SDL_Delay(16);
49 }
50}
51
52static void displayWindow(const std::string& title, int imgW, int imgH, const uint8_t* pixels,
53 SDL_PixelFormat pixelFormat, int bytesPerPixel, int minWinSize, ResizeCallback onResize)

Callers 1

displayWindowFunction · 0.85

Calls 1

emptyMethod · 0.45

Tested by

no test coverage detected