bsnes/hiro/windows/window.cpp

231 lines
6.0 KiB
C++
Raw Normal View History

#if defined(Hiro_Window)
namespace hiro {
vector<pWindow*> pWindow::modal;
Update to v088r11 release. byuu says: Changelog: - phoenix has added Window::setModal(bool modal = true); - file dialog is now modal. This allows emulation cores to request data and get it immediately before continuing the loading process - save data is hooked up for most systems, still need to handle subsystem slot saves (Sufami Turbo, basically.) - toggle fullscreen key binding added (Alt+Enter for now. I think F11 is probably better though, Enter is often mapped to game start button.) - video scaling is in (center, scale, stretch), works the same in windowed and fullscreen mode (stretch hides resize window option), all in the settings menu now - enough structure to map all saved paths for the browser and to load BS-X slotted carts, BS-X carts, single Sufami Turbo carts Caveats / Missing: - Super Game Boy input doesn't work yet (due to change in callback binding) - doesn't load secondary Sufami Turbo slot yet - BS-X BIOS isn't show the data pack games to load for some reason (ugh, I hate the shit out of debugging BS-X stuff ...) - need mute audio, sync audio+video toggle, save/load state menu and quick keys, XML mapping information window - need cheat editor and cheat database - need state manager - need to sort subsystems below main systems in load menu (basically just see if media.slot.size() > 0) - need video shaders (will probably leave off filters for the time being ... due to that 24/30-bit thing) - need video adjustments (contrast etc, overscan masks) - need audio adjustments (frequency, latency, resampler, volume, per-system frequency) - need driver selection and input focus policy (driver crash detection would be nice too) - need NSS DIP switch settings (that one will be really fun) - need to save and load window geometry settings - need to hook up controller selection (won't be fun), create a map to hide controllers with no inputs to reassign
2012-05-03 12:36:47 +00:00
static const unsigned FixedStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER;
static const unsigned ResizableStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME;
auto pWindow::construct() -> void {
hwnd = CreateWindow(L"hiroWindow", L"", ResizableStyle, 128, 128, 256, 256, 0, 0, GetModuleHandle(0), 0);
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&reference);
setDroppable(state().droppable);
setGeometry({128, 128, 256, 256});
}
auto pWindow::destruct() -> void {
if(hbrush) { DeleteObject(hbrush); hbrush = nullptr; }
DestroyWindow(hwnd);
}
auto pWindow::append(sLayout layout) -> void {
}
auto pWindow::append(sMenuBar menuBar) -> void {
}
auto pWindow::append(sStatusBar statusBar) -> void {
}
auto pWindow::focused() const -> bool override {
return (GetForegroundWindow() == hwnd);
}
auto pWindow::frameMargin() const -> Geometry {
unsigned style = state().resizable ? ResizableStyle : FixedStyle;
if(state().fullScreen) style = 0;
RECT rc{0, 0, 640, 480};
AdjustWindowRect(&rc, style, (bool)GetMenu(hwnd));
signed statusHeight = 0;
if(auto statusBar = state().statusBar) {
if(auto self = statusBar->self()) {
if(statusBar->visible()) {
RECT src;
GetClientRect(self->hwnd, &src);
statusHeight = src.bottom - src.top;
}
}
}
return {abs(rc.left), abs(rc.top), (rc.right - rc.left) - 640, (rc.bottom - rc.top) + statusHeight - 480};
}
auto pWindow::remove(sLayout layout) -> void {
}
auto pWindow::remove(sMenuBar menuBar) -> void {
}
auto pWindow::remove(sStatusBar statusBar) -> void {
}
auto pWindow::setBackgroundColor(Color color) -> void {
hbrushColor = CreateRGB(color);
if(hbrush) { DeleteObject(hbrush); hbrush = nullptr; }
if(color) hbrush = CreateSolidBrush(hbrushColor);
}
auto pWindow::setDroppable(bool droppable) -> void {
DragAcceptFiles(hwnd, droppable);
}
auto pWindow::setEnabled(bool enabled) -> void {
}
auto pWindow::setFocused() -> void {
if(!self().visible()) self().setVisible(true);
SetFocus(hwnd);
}
auto pWindow::setFullScreen(bool fullScreen) -> void {
lock();
if(fullScreen == false) {
SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | (state().resizable ? ResizableStyle : FixedStyle));
setGeometry(state().geometry);
} else {
HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
MONITORINFOEX info;
memset(&info, 0, sizeof(MONITORINFOEX));
info.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(monitor, &info);
RECT rc = info.rcMonitor;
Geometry geometry = {rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top};
SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | WS_POPUP);
Geometry margin = frameMargin();
setGeometry({
geometry.x() + margin.x(), geometry.y() + margin.y(),
geometry.width() - margin.width(), geometry.height() - margin.height()
});
}
unlock();
}
auto pWindow::setGeometry(Geometry geometry) -> void {
lock();
Geometry margin = frameMargin();
SetWindowPos(
hwnd, NULL,
geometry.x() - margin.x(), geometry.y() - margin.y(),
geometry.width() + margin.width(), geometry.height() + margin.height(),
SWP_NOZORDER | SWP_FRAMECHANGED
);
if(auto statusBar = state().statusBar) {
if(auto self = statusBar->self()) {
SetWindowPos(self->hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_FRAMECHANGED);
}
}
if(auto layout = state().layout) {
layout->setGeometry(geometry.setPosition(0, 0));
}
unlock();
}
auto pWindow::setModal(bool modality) -> void {
if(modality) {
modal.appendOnce(this);
while(state().modal) {
Application::processEvents();
if(Application::state.onMain) {
Application::doMain();
Update to v094r09 release. byuu says: This will easily be the biggest diff in the history of higan. And not in a good way. * target-higan and target-loki have been blown away completely * nall and ruby massively updated * phoenix replaced with hiro (pretty near a total rewrite) * target-higan restarted using hiro (just a window for now) * all emulation cores updated to compile again * installation changed to not require root privileges (installs locally) For the foreseeable future (maybe even permanently?), the new higan UI will only build under Linux/BSD with GTK+ 2.20+. Probably the most likely route for Windows/OS X will be to try and figure out how to build hiro/GTK on those platforms, as awful as that would be. The other alternative would be to produce new UIs for those platforms ... which would actually be a good opportunity to make something much more user friendly. Being that I just started on this a few hours ago, that means that for at least a few weeks, don't expect to be able to actually play any games. Right now, you can pretty much just compile the binary and that's it. It's quite possible that some nall changes didn't produce compilation errors, but will produce runtime errors. So until the UI can actually load games, we won't know if anything is broken. But we should mostly be okay. It was mostly just trim<1> -> trim changes, moving to Hash::SHA256 (much cleaner), and patching some reckless memory copy functions enough to compile. Progress isn't going to be like it was before: I'm now dividing my time much thinner between studying and other hobbies. My aim this time is not to produce a binary for everyone to play games on. Rather, it's to keep the emulator alive. I want to be able to apply critical patches again. And I would also like the base of the emulator to live on, for use in other emulator frontends that utilize higan.
2015-02-26 10:10:46 +00:00
} else {
usleep(20 * 1000);
}
}
if(auto position = modal.find(this)) modal.remove(position());
Update to v088r11 release. byuu says: Changelog: - phoenix has added Window::setModal(bool modal = true); - file dialog is now modal. This allows emulation cores to request data and get it immediately before continuing the loading process - save data is hooked up for most systems, still need to handle subsystem slot saves (Sufami Turbo, basically.) - toggle fullscreen key binding added (Alt+Enter for now. I think F11 is probably better though, Enter is often mapped to game start button.) - video scaling is in (center, scale, stretch), works the same in windowed and fullscreen mode (stretch hides resize window option), all in the settings menu now - enough structure to map all saved paths for the browser and to load BS-X slotted carts, BS-X carts, single Sufami Turbo carts Caveats / Missing: - Super Game Boy input doesn't work yet (due to change in callback binding) - doesn't load secondary Sufami Turbo slot yet - BS-X BIOS isn't show the data pack games to load for some reason (ugh, I hate the shit out of debugging BS-X stuff ...) - need mute audio, sync audio+video toggle, save/load state menu and quick keys, XML mapping information window - need cheat editor and cheat database - need state manager - need to sort subsystems below main systems in load menu (basically just see if media.slot.size() > 0) - need video shaders (will probably leave off filters for the time being ... due to that 24/30-bit thing) - need video adjustments (contrast etc, overscan masks) - need audio adjustments (frequency, latency, resampler, volume, per-system frequency) - need driver selection and input focus policy (driver crash detection would be nice too) - need NSS DIP switch settings (that one will be really fun) - need to save and load window geometry settings - need to hook up controller selection (won't be fun), create a map to hide controllers with no inputs to reassign
2012-05-03 12:36:47 +00:00
}
}
auto pWindow::setResizable(bool resizable) -> void {
SetWindowLongPtr(hwnd, GWL_STYLE, state().resizable ? ResizableStyle : FixedStyle);
setGeometry(state().geometry);
}
auto pWindow::setTitle(string text) -> void {
SetWindowText(hwnd, utf16_t(text));
}
auto pWindow::setVisible(bool visible) -> void {
ShowWindow(hwnd, visible ? SW_SHOWNORMAL : SW_HIDE);
if(!visible) setModal(false);
}
//
auto pWindow::onClose() -> void {
if(state().onClose) self().doClose();
else self().setVisible(false);
if(state().modal && !self().visible()) self().setModal(false);
}
auto pWindow::onDrop(WPARAM wparam) -> void {
lstring paths = DropPaths(wparam);
if(paths.empty()) return;
self().doDrop(paths);
}
auto pWindow::onEraseBackground() -> bool {
if(hbrush == 0) return false;
RECT rc;
GetClientRect(hwnd, &rc);
PAINTSTRUCT ps;
BeginPaint(hwnd, &ps);
FillRect(ps.hdc, &rc, hbrush);
EndPaint(hwnd, &ps);
return true;
}
auto pWindow::onModalBegin() -> void {
Application::Windows::doModalChange(true);
}
auto pWindow::onModalEnd() -> void {
Application::Windows::doModalChange(false);
}
auto pWindow::onMove() -> void {
if(locked()) return;
state().geometry.setPosition(_geometry().position());
self().doMove();
}
auto pWindow::onSize() -> void {
if(locked()) return;
if(auto statusBar = state().statusBar) {
if(auto self = statusBar->self()) {
SetWindowPos(self->hwnd, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_FRAMECHANGED);
}
}
state().geometry.setSize(_geometry().size());
if(auto layout = state().layout) {
layout->setGeometry(_geometry().setPosition(0, 0));
}
self().doSize();
}
//
auto pWindow::_geometry() -> Geometry {
Geometry margin = frameMargin();
RECT rc;
if(IsIconic(hwnd)) {
//GetWindowRect returns -32000(x),-32000(y) when window is minimized
WINDOWPLACEMENT wp;
GetWindowPlacement(hwnd, &wp);
rc = wp.rcNormalPosition;
} else {
GetWindowRect(hwnd, &rc);
}
signed x = rc.left + margin.x();
signed y = rc.top + margin.y();
signed width = (rc.right - rc.left) - margin.width();
signed height = (rc.bottom - rc.top) - margin.height();
return {x, y, width, height};
}
}
#endif