Previous 199869 Revisions Next

r45184 Wednesday 24th February, 2016 at 00:12:22 UTC by Ryan Holtz
Maybe fix nounevenstretch on windows osd
[src/osd/windows]window.cpp

trunk/src/osd/windows/window.cpp
r253695r253696
16131613}
16141614
16151615
1616static inline int better_mode(int width0, int height0, int width1, int height1, float desired_aspect)
1617{
1618   float aspect0 = (float)width0 / (float)height0;
1619   float aspect1 = (float)width1 / (float)height1;
1620   return (fabs(desired_aspect - aspect0) < fabs(desired_aspect - aspect1)) ? 0 : 1;
1621}
16161622
16171623//============================================================
16181624//  constrain_to_aspect_ratio
r253695r253696
16261632   INT32 propwidth, propheight;
16271633   INT32 minwidth, minheight;
16281634   INT32 maxwidth, maxheight;
1629   INT32 viswidth, visheight;
16301635   INT32 adjwidth, adjheight;
1631   float pixel_aspect;
1636   float desired_aspect = 1.0f;
1637   osd_dim window_dim = get_size();
1638   INT32 target_width = window_dim.width();
1639   INT32 target_height = window_dim.height();
1640   INT32 xscale = 1, yscale = 1;
1641   int newwidth, newheight;
16321642   osd_monitor_info *monitor = winwindow_video_window_monitor(&rect);
16331643
16341644   assert(GetCurrentThreadId() == window_threadid);
16351645
16361646   // get the pixel aspect ratio for the target monitor
1637   pixel_aspect = monitor->aspect();
1647   float pixel_aspect = monitor->aspect();
16381648
16391649   // determine the proposed width/height
16401650   propwidth = rect.width() - extrawidth;
r253695r253696
16621672   // get the minimum width/height for the current layout
16631673   m_target->compute_minimum_size(minwidth, minheight);
16641674
1675   // compute the appropriate visible area if we're trying to keepaspect
1676   if (video_config.keepaspect)
1677   {
1678      // make sure the monitor is up-to-date
1679      m_target->compute_visible_area(target_width, target_height, m_monitor->aspect(), m_target->orientation(), target_width, target_height);
1680      desired_aspect = (float)target_width / (float)target_height;
1681   }
1682
1683   // non-integer scaling - often gives more pleasing results in full screen
1684   if (!video_config.fullstretch)
1685   {
1686      // compute maximum integral scaling to fit the window
1687      xscale = (target_width + 2) / newwidth;
1688      yscale = (target_height + 2) / newheight;
1689
1690      // try a little harder to keep the aspect ratio if desired
1691      if (video_config.keepaspect)
1692      {
1693         // if we could stretch more in the X direction, and that makes a better fit, bump the xscale
1694         while (newwidth * (xscale + 1) <= window_dim.width() &&
1695            better_mode(newwidth * xscale, newheight * yscale, newwidth * (xscale + 1), newheight * yscale, desired_aspect))
1696            xscale++;
1697
1698         // if we could stretch more in the Y direction, and that makes a better fit, bump the yscale
1699         while (newheight * (yscale + 1) <= window_dim.height() &&
1700            better_mode(newwidth * xscale, newheight * yscale, newwidth * xscale, newheight * (yscale + 1), desired_aspect))
1701            yscale++;
1702
1703         // now that we've maxed out, see if backing off the maximally stretched one makes a better fit
1704         if (window_dim.width() - newwidth * xscale < window_dim.height() - newheight * yscale)
1705         {
1706            while (better_mode(newwidth * xscale, newheight * yscale, newwidth * (xscale - 1), newheight * yscale, desired_aspect) && (xscale >= 0))
1707               xscale--;
1708         }
1709         else
1710         {
1711            while (better_mode(newwidth * xscale, newheight * yscale, newwidth * xscale, newheight * (yscale - 1), desired_aspect) && (yscale >= 0))
1712               yscale--;
1713         }
1714      }
1715
1716      // ensure at least a scale factor of 1
1717      if (xscale <= 0) xscale = 1;
1718      if (yscale <= 0) yscale = 1;
1719
1720      // apply the final scale
1721      newwidth *= xscale;
1722      newheight *= yscale;
1723   }
1724   else
1725   {
1726      newwidth = target_width;
1727      newheight = target_height;
1728   }
1729
16651730   // clamp against the absolute minimum
16661731   propwidth = MAX(propwidth, MIN_WINDOW_DIM);
16671732   propheight = MAX(propheight, MIN_WINDOW_DIM);
r253695r253696
16921757   propwidth = MIN(propwidth, maxwidth);
16931758   propheight = MIN(propheight, maxheight);
16941759
1695   // compute the visible area based on the proposed rectangle
1696   m_target->compute_visible_area(propwidth, propheight, pixel_aspect, m_target->orientation(), viswidth, visheight);
1697
16981760   // compute the adjustments we need to make
1699   adjwidth = (viswidth + extrawidth) - rect.width();
1700   adjheight = (visheight + extraheight) - rect.height();
1761   adjwidth = (propwidth + extrawidth) - rect.width();
1762   adjheight = (propheight + extraheight) - rect.height();
17011763
17021764   // based on which corner we're adjusting, constrain in different ways
17031765   osd_rect ret(rect);
r253695r253696
17241786         ret = rect.move_by(0, -adjheight).resize(rect.width() + adjwidth, rect.height() + adjheight);
17251787         break;
17261788   }
1789
17271790   return ret;
17281791}
17291792


Previous 199869 Revisions Next


© 1997-2024 The MAME Team