Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Contiunous Window Resize Event in SDL 2

Tags:

c++

sdl-2

I use the following structure to get new width and height of the resized SDL window. But with this structure I'm only able to get new data after the resizing is done that is when I finish dragging and release the mouse button. How can I get the new data continuously, that is while I'm dragging the window.

if (sdl_set->GetMainEvent()->type == SDL_WINDOWEVENT)
{
  if (sdl_set->GetMainEvent()->window.event == SDL_WINDOWEVENT_RESIZED)
  {
    ScreenWidth = sdl_set->GetMainEvent()->window.data1;
    ScreenHeight = sdl_set->GetMainEvent()->window.data2;
    cout << "Window Resized!" << endl;
  }
}
like image 204
bfkjohns Avatar asked Aug 30 '15 09:08

bfkjohns


People also ask

How do I resize a SDL window?

To resize a window in SDL, first set it with the flag SDL_WINDOW_RESIZABLE , then detect the resizing window event in a switch and finally call the following methods SDL_SetWindowSize(m_window, windowWidth, windowHeight) and glViewport(0, 0, windowWidth, windowHeight) .

How do you trigger a resize event?

In your modern browsers, you can trigger the event using: window. dispatchEvent(new Event('resize'));

How do I close SDL?

If you start a subsystem using a call to that subsystem's init function (for example SDL_VideoInit()) instead of SDL_Init() or SDL_InitSubSystem(), then you must use that subsystem's quit function (SDL_VideoQuit()) to shut it down before calling SDL_Quit().


1 Answers

static int resizingEventWatcher(void* data, SDL_Event* event) {
  if (event->type == SDL_WINDOWEVENT &&
      event->window.event == SDL_WINDOWEVENT_RESIZED) {
    SDL_Window* win = SDL_GetWindowFromID(event->window.windowID);
    if (win == (SDL_Window*)data) {
      printf("resizing.....\n");
    }
  }
  return 0;
}

int main() {
    SDL_Window* win = ...
    ...
    SDL_AddEventWatch(resizingEventWatcher, win);
    ...
}

use SDL's EventWatch can resolve it.

like image 51
ZhuYaDong Avatar answered Sep 18 '22 18:09

ZhuYaDong