@@ -538,7 +538,7 @@ bool Display::detect_fullscreen_like_state() const {
538538}
539539
540540std::array<int , 2 > Display::compute_mode_switch_target_window_size () const {
541- const float target_aspect_ratio = std::max (compute_content_aspect_ratio (), 0 .001F );
541+ const float target_aspect_ratio = std::max (compute_active_content_aspect_ratio (), 0 .001F );
542542 const double current_area = static_cast <double >(std::max (window_width_, MIN_WINDOW_WIDTH)) * static_cast <double >(std::max (window_height_, MIN_WINDOW_HEIGHT));
543543
544544 int target_w = std::max (MIN_WINDOW_WIDTH, static_cast <int >(std::round (std::sqrt (current_area * target_aspect_ratio))));
@@ -573,7 +573,7 @@ void Display::resize_window_for_mode_switch() {
573573 const auto target_size = compute_mode_switch_target_window_size ();
574574 const int target_w = target_size[0 ];
575575 const int target_h = target_size[1 ];
576- const float target_aspect_ratio = std::max (compute_content_aspect_ratio (), 0 .001F );
576+ const float target_aspect_ratio = std::max (compute_active_content_aspect_ratio (), 0 .001F );
577577
578578 // Keep WINDOW aspect lock consistent with the newly selected display mode.
579579 if (aspect_lock_mode_ == AspectLockMode::Window) {
@@ -635,7 +635,7 @@ void Display::print_verbose_info() {
635635 std::cout << " Main program version: " << VersionInfo::version << std::endl;
636636 std::cout << " Video size: " << video_width_ << " x" << video_height_ << std::endl;
637637 std::cout << " Video duration: " << format_duration (duration_) << std::endl;
638- std::cout << " Display mode: " << modeToString (mode_) << std::endl;
638+ std::cout << " Display mode: " << mode_to_string (mode_) << std::endl;
639639 std::cout << " Fit to usable bounds: " << std::boolalpha << fit_window_to_usable_bounds_ << std::endl;
640640 std::cout << " High-DPI allowed: " << std::boolalpha << high_dpi_allowed_ << std::endl;
641641 std::string aspect_lock_mode = " off" ;
@@ -805,14 +805,42 @@ float Display::compute_content_aspect_ratio() const {
805805 return content_w / std::max (content_h, 1 .0F );
806806}
807807
808+ float Display::compute_active_content_aspect_ratio () const {
809+ auto apply_mode_layout_multiplier = [&](const float single_frame_ratio) {
810+ if (mode_ == Mode::HStack) {
811+ return single_frame_ratio * 2 .0F ;
812+ }
813+ if (mode_ == Mode::VStack) {
814+ return single_frame_ratio * 0 .5F ;
815+ }
816+ return single_frame_ratio;
817+ };
818+
819+ switch (aspect_view_mode_) {
820+ case AspectViewMode::Stretch:
821+ return static_cast <float >(std::max (window_width_, 1 )) / static_cast <float >(std::max (window_height_, 1 ));
822+ case AspectViewMode::Preset16x9:
823+ return apply_mode_layout_multiplier (16 .0F / 9 .0F );
824+ case AspectViewMode::Preset4x3:
825+ return apply_mode_layout_multiplier (4 .0F / 3 .0F );
826+ case AspectViewMode::Preset1x1:
827+ return apply_mode_layout_multiplier (1 .0F );
828+ case AspectViewMode::Original:
829+ default :
830+ break ;
831+ }
832+
833+ return compute_content_aspect_ratio ();
834+ }
835+
808836void Display::update_content_window_layout () {
809837 const int safe_window_w = std::max (1 , window_width_);
810838 const int safe_window_h = std::max (1 , window_height_);
811839
812840 content_window_ = SDL_Rect{0 , 0 , safe_window_w, safe_window_h};
813841
814- if (is_fullscreen_ ) {
815- const float content_aspect_ratio = std::max (compute_content_aspect_ratio (), 0 .001F );
842+ if (aspect_view_mode_ != AspectViewMode::Stretch ) {
843+ const float content_aspect_ratio = std::max (compute_active_content_aspect_ratio (), 0 .001F );
816844 const float window_aspect_ratio = static_cast <float >(safe_window_w) / static_cast <float >(safe_window_h);
817845
818846 if (window_aspect_ratio > content_aspect_ratio) {
@@ -864,7 +892,7 @@ void Display::handle_window_resize(const bool reset_forced_size_guard, const boo
864892
865893 // If aspect-ratio locking is enabled, snap the resize to the selected ratio.
866894 if (!skip_forced_size && !is_fullscreen_ && aspect_lock_mode_ != AspectLockMode::Off) {
867- const float target_aspect_ratio = (aspect_lock_mode_ == AspectLockMode::Window) ? window_aspect_ratio_ : compute_content_aspect_ratio ();
895+ const float target_aspect_ratio = (aspect_lock_mode_ == AspectLockMode::Window) ? window_aspect_ratio_ : compute_active_content_aspect_ratio ();
868896 const float safe_target_aspect_ratio = std::max (target_aspect_ratio, 0 .001F );
869897 const float current_ratio = static_cast <float >(new_window_w) / static_cast <float >(new_window_h);
870898 if (std::abs (current_ratio - safe_target_aspect_ratio) > 0 .001F ) {
@@ -3307,8 +3335,23 @@ void Display::handle_event(const SDL_Event& event) {
33073335 notify_user (string_sprintf (" Video texture filter set to '%s'" , bilinear_texture_filtering_ ? " BILINEAR" : " NEAREST NEIGHBOR" ));
33083336 break ;
33093337 case SDLK_s: {
3310- swap_left_right_ = !swap_left_right_;
3311- refresh_display_side_mapping ();
3338+ if (is_shift_down) {
3339+ constexpr int kModeCount = 5 ;
3340+ const int delta = is_ctrl_down ? -1 : 1 ;
3341+ aspect_view_mode_ = static_cast <AspectViewMode>((static_cast <int >(aspect_view_mode_) + delta + kModeCount ) % kModeCount );
3342+
3343+ if (is_fullscreen_) {
3344+ handle_window_resize (true , true );
3345+ } else {
3346+ const auto target_size = compute_mode_switch_target_window_size ();
3347+ apply_window_size_and_relayout (target_size[0 ], target_size[1 ], true );
3348+ }
3349+
3350+ notify_user (string_sprintf (" Aspect view mode set to '%s'" , to_upper_case (aspect_view_mode_to_string (aspect_view_mode_)).c_str ()));
3351+ } else {
3352+ swap_left_right_ = !swap_left_right_;
3353+ refresh_display_side_mapping ();
3354+ }
33123355 break ;
33133356 }
33143357 case SDLK_f:
@@ -3345,7 +3388,7 @@ void Display::handle_event(const SDL_Event& event) {
33453388 recreate_video_textures_for_current_mode ();
33463389 resize_window_for_mode_switch ();
33473390
3348- const std::string mode_name = modeToString (mode_);
3391+ const std::string mode_name = mode_to_string (mode_);
33493392 notify_user (string_sprintf (" Display mode set to '%s'" , to_upper_case (mode_name).c_str ()));
33503393 } else {
33513394 print_image_similarity_metrics_ = true ;
@@ -3430,7 +3473,11 @@ void Display::handle_event(const SDL_Event& event) {
34303473 }
34313474 break ;
34323475 case SDLK_x:
3433- show_fps_ = true ;
3476+ if (is_shift_down) {
3477+ notify_user (string_sprintf (" Display state: window=%dx%d aspect=%s" , window_width_, window_height_, aspect_view_mode_to_string (aspect_view_mode_).c_str ()));
3478+ } else {
3479+ show_fps_ = true ;
3480+ }
34343481 break ;
34353482 case SDLK_PLUS:
34363483 case SDLK_KP_PLUS:
0 commit comments