diff options
| author | 2019-02-18 18:03:39 +1100 | |
|---|---|---|
| committer | 2019-02-18 18:03:39 +1100 | |
| commit | f17f6c9d5cfc3a2aff3d4afd39d59e1189385fea (patch) | |
| tree | 95a81da8ce9fbd93c72e3a0c8002385f40562595 /src/osd | |
| parent | 176ba64b260e32e792f7a6381e8bcd112f1ea415 (diff) | |
misc fixes
testkeys:
* Clean up and modernise code
* Use std::endl to end lines for its implicit flush
* Centre window (less likely to hide behind taskbar, etc.)
osdwin:
* Ensure new windows are positioned within the work area of a monitor
Diffstat (limited to 'src/osd')
| -rw-r--r-- | src/osd/modules/osdhelper.h | 61 | ||||
| -rw-r--r-- | src/osd/windows/video.h | 22 | ||||
| -rw-r--r-- | src/osd/windows/window.cpp | 29 |
3 files changed, 68 insertions, 44 deletions
diff --git a/src/osd/modules/osdhelper.h b/src/osd/modules/osdhelper.h index 463d8cdfb48..093c392e249 100644 --- a/src/osd/modules/osdhelper.h +++ b/src/osd/modules/osdhelper.h @@ -6,23 +6,23 @@ // //============================================================ -#pragma once +#ifndef MAME_OSD_MODULES_OSDHELPER_H +#define MAME_OSD_MODULES_OSDHELPER_H -#ifndef __OSDHELPER__ -#define __OSDHELPER__ +#pragma once class osd_dim { public: - osd_dim(const int &w, const int &h) - : m_w(w), m_h(h) - { - } - int width() const { return m_w; } - int height() const { return m_h; } + constexpr osd_dim() : m_w(0), m_h(0) { } + constexpr osd_dim(int w, int h) : m_w(w), m_h(h) { } + + constexpr int width() const { return m_w; } + constexpr int height() const { return m_h; } + + constexpr bool operator!=(const osd_dim &other) { return (m_w != other.width()) || (m_h != other.height()); } + constexpr bool operator==(const osd_dim &other) { return (m_w == other.width()) && (m_h == other.height()); } - bool operator!=(const osd_dim &other) { return (m_w != other.width()) || (m_h != other.height()); } - bool operator==(const osd_dim &other) { return (m_w == other.width()) && (m_h == other.height()); } private: int m_w; int m_h; @@ -31,30 +31,25 @@ private: class osd_rect { public: - osd_rect() - : m_x(0), m_y(0), m_d(0,0) - { - } - osd_rect(const int x, const int y, const int &w, const int &h) - : m_x(x), m_y(y), m_d(w,h) - { - } - osd_rect(const int x, const int y, const osd_dim &d) - : m_x(x), m_y(y), m_d(d) - { - } - int top() const { return m_y; } - int left() const { return m_x; } - int width() const { return m_d.width(); } - int height() const { return m_d.height(); } + constexpr osd_rect() : m_x(0), m_y(0), m_d(0, 0) { } + constexpr osd_rect(int x, int y, int w, int h) : m_x(x), m_y(y), m_d(w, h) { } + constexpr osd_rect(int x, int y, const osd_dim &d) : m_x(x), m_y(y), m_d(d) { } + + constexpr int left() const { return m_x; } + constexpr int top() const { return m_y; } + constexpr int width() const { return m_d.width(); } + constexpr int height() const { return m_d.height(); } + + constexpr osd_dim dim() const { return m_d; } - osd_dim dim() const { return m_d; } + constexpr int right() const { return m_x + m_d.width(); } + constexpr int bottom() const { return m_y + m_d.height(); } - int bottom() const { return m_y + m_d.height(); } - int right() const { return m_x + m_d.width(); } + constexpr osd_rect move_by(int dx, int dy) const { return osd_rect(m_x + dx, m_y + dy, m_d); } + constexpr osd_rect resize(int w, int h) const { return osd_rect(m_x, m_y, w, h); } - osd_rect move_by(int dx, int dy) const { return osd_rect(m_x + dx, m_y + dy, m_d); } - osd_rect resize(int w, int h) const { return osd_rect(m_x, m_y, w, h); } + constexpr bool operator!=(const osd_rect &other) { return (m_x != other.left()) || (m_y != other.top()) || (m_d != other.dim()); } + constexpr bool operator==(const osd_rect &other) { return (m_x == other.left()) && (m_y == other.top()) && (m_d == other.dim()); } private: int m_x; @@ -62,4 +57,4 @@ private: osd_dim m_d; }; -#endif // __OSDHELPER__ +#endif // MAME_OSD_MODULES_OSDHELPER_H diff --git a/src/osd/windows/video.h b/src/osd/windows/video.h index 3f4b49efbe4..c012e42af9d 100644 --- a/src/osd/windows/video.h +++ b/src/osd/windows/video.h @@ -1,19 +1,29 @@ // license:BSD-3-Clause -// copyright-holders:Aaron Giles +// copyright-holders:Aaron Giles, Vas Crabb //============================================================ // -// video.h - Win32 implementation of MAME video routines +// video.h - Win32 video helpers // //============================================================ +#ifndef MAME_OSD_WINDOWS_VIDEO_H +#define MAME_OSD_WINDOWS_VIDEO_H -#ifndef __WIN_VIDEO__ -#define __WIN_VIDEO__ +#pragma once #include "modules/osdhelper.h" -inline osd_rect RECT_to_osd_rect(const RECT &r) +#include <windows.h> + + +constexpr osd_rect RECT_to_osd_rect(RECT const &r) { return osd_rect(r.left, r.top, r.right - r.left, r.bottom - r.top); } -#endif +inline RECT osd_rect_to_RECT(osd_rect const &r) +{ + RECT const result{ r.left(), r.top(), r.right(), r.bottom() }; + return result; +} + +#endif // MAME_OSD_WINDOWS_VIDEO_H diff --git a/src/osd/windows/window.cpp b/src/osd/windows/window.cpp index c3376b2fb0c..d331ec3f4d8 100644 --- a/src/osd/windows/window.cpp +++ b/src/osd/windows/window.cpp @@ -15,6 +15,7 @@ #include <process.h> #include <atomic> +#include <cstring> #include <chrono> #include <list> #include <memory> @@ -1663,7 +1664,7 @@ void win_window_info::minimize_window() RECT bounds; GetWindowRect(platform_window(), &bounds); - osd_rect newrect(bounds.left, bounds.top, newsize ); + osd_rect newrect(bounds.left, bounds.top, newsize); SetWindowPos(platform_window(), nullptr, newrect.left(), newrect.top(), newrect.width(), newrect.height(), SWP_NOZORDER); @@ -1715,17 +1716,35 @@ void win_window_info::adjust_window_position_after_major_change() if (video_config.keepaspect) newrect = constrain_to_aspect_ratio(newrect, WMSZ_BOTTOMRIGHT); } - - // in full screen, make sure it covers the primary display else { + // in full screen, make sure it covers the primary display std::shared_ptr<osd_monitor_info> monitor = monitor_from_rect(nullptr); newrect = monitor->position_size(); } + // restrict the window to one monitor and avoid toolbars if possible + HMONITOR const nearest_monitor = MonitorFromWindow(platform_window(), MONITOR_DEFAULTTONEAREST); + if (NULL != nearest_monitor) + { + MONITORINFO info; + std::memset(&info, 0, sizeof(info)); + info.cbSize = sizeof(info); + if (GetMonitorInfo(nearest_monitor, &info)) + { + if (newrect.right() > info.rcWork.right) + newrect = newrect.move_by(info.rcWork.right - newrect.right(), 0); + if (newrect.bottom() > info.rcWork.bottom) + newrect = newrect.move_by(0, info.rcWork.bottom - newrect.bottom()); + if (newrect.left() < info.rcWork.left) + newrect = newrect.move_by(info.rcWork.left - newrect.left(), 0); + if (newrect.top() < info.rcWork.top) + newrect = newrect.move_by(0, info.rcWork.top - newrect.top()); + } + } + // adjust the position if different - if (oldrect.left != newrect.left() || oldrect.top != newrect.top() || - oldrect.right != newrect.right() || oldrect.bottom != newrect.bottom()) + if (RECT_to_osd_rect(oldrect) != newrect) SetWindowPos(platform_window(), fullscreen() ? HWND_TOPMOST : HWND_TOP, newrect.left(), newrect.top(), newrect.width(), newrect.height(), 0); |
