Wiki Page Content

Differences between revisions 9 and 10
Revision 9 as of 2011-03-11 16:35:53
Size: 1489
Editor: SheenaSmith
Comment: update content - 3/10 46bd121b04a2 (2/12 8e421890cdb8)
Revision 10 as of 2011-06-28 13:02:02
Size: 2819
Editor: KenBull
Comment: Added examples
Deletions are marked like this. Additions are marked like this.
Line 27: Line 27:
<<Include(<SDL_WindowEvent>, , , from="##Example1 Start", to="##End")>>
Line 28: Line 30:
You can add your code example here #include "SDL.h"

int main(int, char**) {
  int width = 640;
  int height = 480;
  
  if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    return 1;
  }
  atexit(SDL_Quit);
  
  SDL_Window* window = SDL_CreateWindow(
    "Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
    width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE
  );
  Uint32 windowID = SDL_GetWindowFromID(window);
  
  while (true) {
    SDL_Event event;
    while (SDL_PollEvent(&event)) {
      switch (event.type) {
        
        case SDL_WINDOWEVENT: {
          if (event.window.windowID == windowID) {
            switch (event.window.event) {
              
              case SDL_WINDOWEVENT_SIZE_CHANGED: {
                width = event.window.data1;
                height = event.window.data2;
                break;
              }
              
              case SDL_WINDOWEVENT_CLOSE: {
                event.type = SDL_QUIT;
                SDL_PushEvent(&event);
                break;
              }
              
            }
          }
          break;
        }
        
        case SDL_QUIT: {
          return 0;
        }
        
        /* ... */
        
      }
    }
    
    /* ... */
    
    SDL_Sleep(1);
  }
}

SDL_WindowEventID

An enumeration of window events.

Values

SDL_WINDOWEVENT_NONE

never used

SDL_WINDOWEVENT_SHOWN

window has been shown

SDL_WINDOWEVENT_HIDDEN

window has been hidden

SDL_WINDOWEVENT_EXPOSED

window has been exposed and should be redrawn

SDL_WINDOWEVENT_MOVED

window has been moved to data1, data2

SDL_WINDOWEVENT_RESIZED

window has been resized to data1xdata2

SDL_WINDOWEVENT_SIZE_CHANGED

window size has changed, either as a result of an API call or through the system or user changing the window size

SDL_WINDOWEVENT_MINIMIZED

window has been minimized

SDL_WINDOWEVENT_MAXIMIZED

window has been maximized

SDL_WINDOWEVENT_RESTORED

window has been restored to normal size and position

SDL_WINDOWEVENT_ENTER

window has gained mouse focus

SDL_WINDOWEVENT_LEAVE

window has lost mouse focus

SDL_WINDOWEVENT_FOCUS_GAINED

window has gained keyboard focus

SDL_WINDOWEVENT_FOCUS_LOST

window has lost keyboard focus

SDL_WINDOWEVENT_CLOSE

the window manager requests that the window be closed

Code Examples

#include "SDL.h"

int main(int, char**)  {
  int width = 640;
  int height = 480;
  
  if (SDL_Init(SDL_INIT_VIDEO) != 0)  {
    return 1;
  }
  atexit(SDL_Quit);
  
  SDL_Window* window = SDL_CreateWindow(
    "Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 
    width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE
  );
  Uint32 windowID = SDL_GetWindowFromID(window);
  
  while (true)  {
    SDL_Event event;
    while (SDL_PollEvent(&event))  {
      switch (event.type)  {
        
        case SDL_WINDOWEVENT:  {
          if (event.window.windowID == windowID)  {
            switch (event.window.event)  {
              
              case SDL_WINDOWEVENT_SIZE_CHANGED:  {
                width = event.window.data1;
                height = event.window.data2;
                break;
              }
              
              case SDL_WINDOWEVENT_CLOSE:  {
                event.type = SDL_QUIT;
                SDL_PushEvent(&event);
                break;
              }
              
            }
          }
          break;
        }
        
        case SDL_QUIT:  {
          return 0;
        }
        
        /* ... */
        
      }
    }
    
    /* ... */
    
    SDL_Sleep(1);
  }
}

Remarks

You can add useful comments here


CategoryEnum, CategoryVideo, CategoryEvents

None: SDL_WindowEventID (last edited 2017-02-19 20:54:31 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit