Window Sizing

Size Changed vs Resized Events

What is the difference between SDL_WINDOWEVENT_SIZE_CHANGED and SDL_WINDOWEVENT_RESIZED?

Abstract art representing computer programming

Both SDL_WINDOWEVENT_SIZE_CHANGED and SDL_WINDOWEVENT_RESIZED are window events related to size changes, but they differ in when and how they are triggered.

SDL_WINDOWEVENT_SIZE_CHANGED

This event occurs when the window size changes and rendering must be updated. It’s typically triggered after the user completes a resize action or when the window is resized programmatically using functions like SDL_SetWindowSize().

Here’s how you might handle it:

if (event.type == SDL_WINDOWEVENT &&
    event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
  int width = event.window.data1;
  int height = event.window.data2;
  std::cout << "Size changed to: "
    << width << "x" << height << "\n";
}

SDL_WINDOWEVENT_RESIZED

This event is sent more broadly and includes platform-specific behavior. It’s triggered whenever a resize operation occurs, including intermediate steps while the user is actively resizing the window.

To handle this:

if (event.type == SDL_WINDOWEVENT &&
    event.window.event == SDL_WINDOWEVENT_RESIZED) {
  int width = event.window.data1;
  int height = event.window.data2;
  std::cout << "Resizing in progress: "
    << width << "x" << height << "\n";
}

Key Differences

  • Frequency: SDL_WINDOWEVENT_RESIZED fires multiple times during a resize operation, while SDL_WINDOWEVENT_SIZE_CHANGED fires once after the size stabilizes.
  • Purpose: Use SDL_WINDOWEVENT_RESIZED for tasks like logging or real-time feedback, and SDL_WINDOWEVENT_SIZE_CHANGED for updating rendering or layouts after resizing.

By distinguishing between these events, you can optimize your application’s response to resizing and avoid unnecessary recalculations or redraws.

Answers to questions are automatically generated and may not have been reviewed.

sdl2-promo.jpg
Part of the course:

Game Dev with SDL2

Learn C++ and SDL development by creating hands on, practical projects inspired by classic retro games

Free, unlimited access

This course includes:

  • 62 Lessons
  • 100+ Code Samples
  • 91% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Free, Unlimited Access

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects.

Screenshot from Warhammer: Total War
Screenshot from Tomb Raider
Screenshot from Jedi: Fallen Order
Contact|Privacy Policy|Terms of Use
Copyright © 2024 - All Rights Reserved