float winvideo_monitor_get_aspect(win_monitor_info *monitor) { // refresh the monitor information and compute the aspect if (video_config.keepaspect) { int width, height; winvideo_monitor_refresh(monitor); width = rect_width(&monitor->info.rcMonitor); height = rect_height(&monitor->info.rcMonitor); return monitor->aspect / ((float)width / (float)height); } return 0.0f; }
win_monitor_info *winwindow_video_window_monitor(win_window_info *window, const RECT *proposed) { win_monitor_info *monitor; // in window mode, find the nearest if (!window->fullscreen) { if (proposed != NULL) monitor = winvideo_monitor_from_handle(MonitorFromRect(proposed, MONITOR_DEFAULTTONEAREST)); else monitor = winvideo_monitor_from_handle(MonitorFromWindow(window->hwnd, MONITOR_DEFAULTTONEAREST)); } // in full screen, just use the configured monitor else monitor = window->monitor; // make sure we're up-to-date winvideo_monitor_refresh(monitor); return monitor; }
static void get_max_bounds(win_window_info *window, RECT *bounds, int constrain) { RECT maximum; assert(GetCurrentThreadId() == window_threadid); // compute the maximum client area winvideo_monitor_refresh(window->monitor); maximum = window->monitor->info.rcWork; // clamp to the window's max if (window->maxwidth != 0) { int temp = window->maxwidth + wnd_extra_width(window); if (temp < rect_width(&maximum)) maximum.right = maximum.left + temp; } if (window->maxheight != 0) { int temp = window->maxheight + wnd_extra_height(window); if (temp < rect_height(&maximum)) maximum.bottom = maximum.top + temp; } // constrain to fit if (constrain) constrain_to_aspect_ratio(window, &maximum, WMSZ_BOTTOMRIGHT); else { maximum.right -= wnd_extra_width(window); maximum.bottom -= wnd_extra_height(window); } // center within the work area bounds->left = window->monitor->info.rcWork.left + (rect_width(&window->monitor->info.rcWork) - rect_width(&maximum)) / 2; bounds->top = window->monitor->info.rcWork.top + (rect_height(&window->monitor->info.rcWork) - rect_height(&maximum)) / 2; bounds->right = bounds->left + rect_width(&maximum); bounds->bottom = bounds->top + rect_height(&maximum); }