Changeset 6053b24 in opengl-game


Ignore:
Timestamp:
Feb 14, 2021, 6:53:53 PM (4 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
db1b548
Parents:
8d96e95
git-author:
Dmitry Portnoy <dportnoy@…> (02/14/21 18:53:48)
git-committer:
Dmitry Portnoy <dportnoy@…> (02/14/21 18:53:53)
Message:

Read events from GameGui in both VulkanGame and SDLGame and don't pass
events to the main application when IMGUI wants to capture them.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sdl-game.cpp

    r8d96e95 r6053b24  
    154154   done = false;
    155155   while (!done) {
    156       // Poll and handle events (inputs, window resize, etc.)
    157       // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
    158       // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
    159       // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
    160       // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
    161       SDL_Event event;
    162       while (SDL_PollEvent(&event)) {
    163          ImGui_ImplSDL2_ProcessEvent(&event);
    164          if (event.type == SDL_QUIT)
     156
     157      gui->processEvents();
     158
     159      UIEvent uiEvent;
     160      while (gui->pollEvent(&uiEvent)) {
     161         GameEvent& e = uiEvent.event;
     162         SDL_Event sdlEvent = uiEvent.rawEvent.sdl;
     163
     164         ImGui_ImplSDL2_ProcessEvent(&sdlEvent);
     165         if (io.WantCaptureMouse &&
     166               (e.type == UI_EVENT_MOUSEBUTTONDOWN || e.type == UI_EVENT_MOUSEBUTTONUP || e.type == UI_EVENT_UNKNOWN)) {
     167            if (sdlEvent.type == SDL_MOUSEWHEEL || sdlEvent.type == SDL_MOUSEBUTTONDOWN || sdlEvent.type == SDL_MOUSEBUTTONUP) {
     168               continue;
     169            }
     170         }
     171         if (io.WantCaptureKeyboard &&
     172               (e.type == UI_EVENT_KEYDOWN || e.type == UI_EVENT_KEYUP)) {
     173            if (sdlEvent.type == SDL_KEYDOWN || sdlEvent.type == SDL_KEYUP) {
     174               continue;
     175            }
     176         }
     177         if (io.WantTextInput) {
     178            // show onscreen keyboard if on mobile
     179         }
     180
     181         if (e.type == UI_EVENT_QUIT) {
    165182            done = true;
    166          if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
    167             done = true;
     183         }
    168184      }
    169185
  • vulkan-game.cpp

    r8d96e95 r6053b24  
    781781   lastSpawn_asteroid = curTime;
    782782
     783   ImGuiIO& io = ImGui::GetIO();
     784
    783785   done = false;
    784786   while (!done) {
     
    802804      while (gui->pollEvent(&uiEvent)) {
    803805         GameEvent& e = uiEvent.event;
     806         SDL_Event sdlEvent = uiEvent.rawEvent.sdl;
     807
     808         ImGui_ImplSDL2_ProcessEvent(&sdlEvent);
     809         if (io.WantCaptureMouse &&
     810               (e.type == UI_EVENT_MOUSEBUTTONDOWN || e.type == UI_EVENT_MOUSEBUTTONUP || e.type == UI_EVENT_UNKNOWN)) {
     811            if (sdlEvent.type == SDL_MOUSEWHEEL || sdlEvent.type == SDL_MOUSEBUTTONDOWN || sdlEvent.type == SDL_MOUSEBUTTONUP) {
     812               continue;
     813            }
     814         }
     815         if (io.WantCaptureKeyboard &&
     816               (e.type == UI_EVENT_KEYDOWN || e.type == UI_EVENT_KEYUP)) {
     817            if (sdlEvent.type == SDL_KEYDOWN || sdlEvent.type == SDL_KEYUP) {
     818               continue;
     819            }
     820         }
     821         if (io.WantTextInput) {
     822            // show onscreen keyboard if on mobile
     823         }
    804824
    805825         switch(e.type) {
Note: See TracChangeset for help on using the changeset viewer.