summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/sdl/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/sdl/window.cpp')
-rw-r--r--src/osd/sdl/window.cpp141
1 files changed, 25 insertions, 116 deletions
diff --git a/src/osd/sdl/window.cpp b/src/osd/sdl/window.cpp
index 1ca6e9605a6..c2d86858bf9 100644
--- a/src/osd/sdl/window.cpp
+++ b/src/osd/sdl/window.cpp
@@ -389,94 +389,6 @@ void sdl_osd_interface::window_exit()
//============================================================
-// sdlwindow_blit_surface_size
-//============================================================
-
-static inline int better_mode(int width0, int height0, int width1, int height1, float desired_aspect)
-{
- float aspect0 = (float)width0 / (float)height0;
- float aspect1 = (float)width1 / (float)height1;
- return (fabs(desired_aspect - aspect0) < fabs(desired_aspect - aspect1)) ? 0 : 1;
-}
-
-osd_dim sdl_window_info::blit_surface_size()
-{
- osd_dim window_dim = get_size();
-
- int newwidth, newheight;
- int xscale = 1, yscale = 1;
- float desired_aspect = 1.0f;
- INT32 target_width = window_dim.width();
- INT32 target_height = window_dim.height();
-
- // start with the minimum size
- m_target->compute_minimum_size(newwidth, newheight);
-
- // compute the appropriate visible area if we're trying to keepaspect
- if (video_config.keepaspect)
- {
- // make sure the monitor is up-to-date
- m_target->compute_visible_area(target_width, target_height, m_monitor->aspect(), m_target->orientation(), target_width, target_height);
- desired_aspect = (float)target_width / (float)target_height;
- }
-
- // non-integer scaling - often gives more pleasing results in full screen
- if (!video_config.fullstretch)
- {
- // compute maximum integral scaling to fit the window
- xscale = (target_width + 2) / newwidth;
- yscale = (target_height + 2) / newheight;
-
- // try a little harder to keep the aspect ratio if desired
- if (video_config.keepaspect)
- {
- // if we could stretch more in the X direction, and that makes a better fit, bump the xscale
- while (newwidth * (xscale + 1) <= window_dim.width() &&
- better_mode(newwidth * xscale, newheight * yscale, newwidth * (xscale + 1), newheight * yscale, desired_aspect))
- xscale++;
-
- // if we could stretch more in the Y direction, and that makes a better fit, bump the yscale
- while (newheight * (yscale + 1) <= window_dim.height() &&
- better_mode(newwidth * xscale, newheight * yscale, newwidth * xscale, newheight * (yscale + 1), desired_aspect))
- yscale++;
-
- // now that we've maxed out, see if backing off the maximally stretched one makes a better fit
- if (window_dim.width() - newwidth * xscale < window_dim.height() - newheight * yscale)
- {
- while (better_mode(newwidth * xscale, newheight * yscale, newwidth * (xscale - 1), newheight * yscale, desired_aspect) && (xscale >= 0))
- xscale--;
- }
- else
- {
- while (better_mode(newwidth * xscale, newheight * yscale, newwidth * xscale, newheight * (yscale - 1), desired_aspect) && (yscale >= 0))
- yscale--;
- }
- }
-
- // ensure at least a scale factor of 1
- if (xscale <= 0) xscale = 1;
- if (yscale <= 0) yscale = 1;
-
- // apply the final scale
- newwidth *= xscale;
- newheight *= yscale;
- }
- else
- {
- newwidth = target_width;
- newheight = target_height;
- }
-
- //FIXME: really necessary to distinguish for yuv_modes ?
- if (m_target->zoom_to_screen()
- && (video_config.scale_mode == VIDEO_SCALE_MODE_NONE ))
- newwidth = window_dim.width();
-
- return osd_dim(newwidth, newheight);
-}
-
-
-//============================================================
// sdlwindow_resize
// (main thread)
//============================================================
@@ -1007,27 +919,10 @@ OSDWORK_CALLBACK( sdl_window_info::complete_create_wt )
// if we have a remembered size force the new window size to it
temp = window->m_windowed_dim;
}
+ else if (window->m_startmaximized)
+ temp = window->get_max_bounds(video_config.keepaspect );
else
- {
- if (window->m_startmaximized)
- {
- temp = window->get_max_bounds(video_config.keepaspect );
- }
- else
- {
-#if 0
- // Couriersud: This code never has worked with the last version of get_min_bounds
- /* Create the window directly with the correct aspect
- instead of letting sdlwindow_blit_surface_size() resize it
- this stops the window from "flashing" from the wrong aspect
- size to the right one at startup. */
- tempwidth = (window->m_win_config.width != 0) ? window->m_win_config.width : 640;
- tempheight = (window->m_win_config.height != 0) ? window->m_win_config.height : 480;
-#endif
- temp = window->get_min_bounds(video_config.keepaspect );
- }
- }
-
+ temp = window->get_min_bounds(video_config.keepaspect );
// create the window .....
@@ -1069,9 +964,14 @@ OSDWORK_CALLBACK( sdl_window_info::complete_create_wt )
#if defined(SDLMAME_WIN32)
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
#endif
+
+ // get monitor work area for centering
+ osd_rect work = window->monitor()->usuable_position_size();
+
// create the SDL window
window->m_sdl_window = SDL_CreateWindow(window->m_title,
- window->monitor()->position_size().left(), window->monitor()->position_size().top(),
+ work.left() + (work.width() - temp.width()) / 2,
+ work.top() + (work.height() - temp.height()) / 2,
temp.width(), temp.height(), window->m_extra_flags);
//window().sdl_window() = SDL_CreateWindow(window().m_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
// width, height, m_extra_flags);
@@ -1134,7 +1034,12 @@ OSDWORK_CALLBACK( sdl_window_info::complete_create_wt )
}
}
}
+
+ // update monitor resolution after mode change to ensure proper pixel aspect
window->monitor()->refresh();
+ if (window->fullscreen() && video_config.switchres)
+ window->monitor()->update_resolution(temp.width(), temp.height());
+
// initialize the drawing backend
if (window->renderer().create())
return (void *) &result[1];
@@ -1286,8 +1191,12 @@ osd_rect sdl_window_info::constrain_to_aspect_ratio(const osd_rect &rect, int ad
float pixel_aspect;
osd_monitor_info *monitor = m_monitor;
+ // do not constrain aspect ratio for integer scaled views
+ if (m_target->current_view()->bounds().scale_type != RENDER_SCALE_FRACTIONAL)
+ return rect;
+
// get the pixel aspect ratio for the target monitor
- pixel_aspect = monitor->aspect();
+ pixel_aspect = monitor->pixel_aspect();
// determine the proposed width/height
propwidth = rect.width() - extrawidth;
@@ -1407,7 +1316,7 @@ osd_dim sdl_window_info::get_min_bounds(int constrain)
minheight += wnd_extra_height();
// if we want it constrained, figure out which one is larger
- if (constrain)
+ if (constrain && m_target->current_view()->bounds().scale_type == RENDER_SCALE_FRACTIONAL)
{
// first constrain with no height limit
osd_rect test1(0,0,minwidth,10000);
@@ -1471,11 +1380,11 @@ osd_dim sdl_window_info::get_max_bounds(int constrain)
maximum = maximum.resize(tempw, temph);
// constrain to fit
- if (constrain)
+ if (constrain && m_target->current_view()->bounds().scale_type == RENDER_SCALE_FRACTIONAL)
maximum = constrain_to_aspect_ratio(maximum, WMSZ_BOTTOMRIGHT);
- else
- {
- maximum = maximum.resize(maximum.width() - wnd_extra_width(), maximum.height() - wnd_extra_height());
- }
+
+ // remove extra window stuff
+ maximum = maximum.resize(maximum.width() - wnd_extra_width(), maximum.height() - wnd_extra_height());
+
return maximum.dim();
}