Removing dependencies on MainWindow.
This commit is contained in:
@@ -42,21 +42,22 @@ enum Commands {
|
||||
const std::wstring kBaseTitle = L"xenia";
|
||||
|
||||
MainWindow::MainWindow(Emulator* emulator)
|
||||
: PlatformWindow(kBaseTitle),
|
||||
: PlatformWindow(&loop_, kBaseTitle),
|
||||
emulator_(emulator),
|
||||
main_menu_(MenuItem::Type::kNormal),
|
||||
fullscreen_(false) {}
|
||||
main_menu_(MenuItem::Type::kNormal) {}
|
||||
|
||||
MainWindow::~MainWindow() = default;
|
||||
|
||||
void MainWindow::Start() {
|
||||
std::unique_ptr<PlatformWindow> MainWindow::Create(Emulator* emulator) {
|
||||
std::unique_ptr<MainWindow> main_window(new MainWindow(emulator));
|
||||
|
||||
xe::threading::Fence fence;
|
||||
|
||||
loop_.Post([&]() {
|
||||
main_window->loop()->Post([&main_window, &fence]() {
|
||||
xe::threading::set_name("Win32 Loop");
|
||||
xe::Profiler::ThreadEnter("Win32 Loop");
|
||||
|
||||
if (!Initialize()) {
|
||||
if (!main_window->Initialize()) {
|
||||
XEFATAL("Failed to initialize main window");
|
||||
exit(1);
|
||||
}
|
||||
@@ -65,6 +66,8 @@ void MainWindow::Start() {
|
||||
});
|
||||
|
||||
fence.Wait();
|
||||
|
||||
return std::unique_ptr<PlatformWindow>(main_window.release());
|
||||
}
|
||||
|
||||
bool MainWindow::Initialize() {
|
||||
@@ -98,8 +101,8 @@ bool MainWindow::Initialize() {
|
||||
} break;
|
||||
case 0x1B: { // VK_ESCAPE
|
||||
// Allow users to escape fullscreen (but not enter it).
|
||||
if (fullscreen_) {
|
||||
ToggleFullscreen();
|
||||
if (is_fullscreen()) {
|
||||
ToggleFullscreen(false);
|
||||
}
|
||||
} break;
|
||||
|
||||
@@ -187,7 +190,7 @@ bool MainWindow::Initialize() {
|
||||
}
|
||||
main_menu_.AddChild(std::move(help_menu));
|
||||
|
||||
SetMenu(&main_menu_);
|
||||
set_menu(&main_menu_);
|
||||
|
||||
Resize(1280, 720);
|
||||
|
||||
@@ -204,11 +207,6 @@ void MainWindow::UpdateTitle() {
|
||||
set_title(title);
|
||||
}
|
||||
|
||||
void MainWindow::ToggleFullscreen() {
|
||||
fullscreen_ = !fullscreen_;
|
||||
SetFullscreen(fullscreen_);
|
||||
}
|
||||
|
||||
void MainWindow::OnClose() {
|
||||
loop_.Quit();
|
||||
|
||||
@@ -250,7 +248,7 @@ void MainWindow::OnCommand(int id) {
|
||||
} break;
|
||||
|
||||
case IDC_WINDOW_FULLSCREEN: {
|
||||
ToggleFullscreen();
|
||||
ToggleFullscreen(!is_fullscreen());
|
||||
} break;
|
||||
|
||||
case IDC_HELP_WEBSITE: {
|
||||
|
||||
@@ -10,15 +10,10 @@
|
||||
#ifndef XENIA_UI_MAIN_WINDOW_H_
|
||||
#define XENIA_UI_MAIN_WINDOW_H_
|
||||
|
||||
#include "xenia/ui/platform.h"
|
||||
#include "xenia/ui/window.h"
|
||||
#include "xenia/xbox.h"
|
||||
|
||||
// TODO(benvanik): only on windows.
|
||||
#include "xenia/ui/win32/win32_file_picker.h"
|
||||
#include "xenia/ui/win32/win32_loop.h"
|
||||
#include "xenia/ui/win32/win32_menu_item.h"
|
||||
#include "xenia/ui/win32/win32_window.h"
|
||||
|
||||
namespace xe {
|
||||
class Emulator;
|
||||
} // namespace xe
|
||||
@@ -26,26 +21,20 @@ class Emulator;
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
|
||||
using PlatformLoop = xe::ui::win32::Win32Loop;
|
||||
using PlatformWindow = xe::ui::win32::Win32Window;
|
||||
using PlatformMenu = xe::ui::win32::Win32MenuItem;
|
||||
using PlatformFilePicker = xe::ui::win32::Win32FilePicker;
|
||||
|
||||
class MainWindow : public PlatformWindow {
|
||||
public:
|
||||
explicit MainWindow(Emulator* emulator);
|
||||
~MainWindow() override;
|
||||
|
||||
Emulator* emulator() const { return emulator_; }
|
||||
PlatformLoop* loop() { return &loop_; }
|
||||
static std::unique_ptr<PlatformWindow> Create(Emulator* emulator);
|
||||
|
||||
void Start();
|
||||
Emulator* emulator() const { return emulator_; }
|
||||
|
||||
private:
|
||||
explicit MainWindow(Emulator* emulator);
|
||||
|
||||
bool Initialize();
|
||||
|
||||
void UpdateTitle();
|
||||
void ToggleFullscreen();
|
||||
|
||||
void OnClose() override;
|
||||
void OnCommand(int id) override;
|
||||
@@ -53,7 +42,6 @@ class MainWindow : public PlatformWindow {
|
||||
Emulator* emulator_;
|
||||
PlatformLoop loop_;
|
||||
PlatformMenu main_menu_;
|
||||
bool fullscreen_;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
||||
31
src/xenia/ui/platform.h
Normal file
31
src/xenia/ui/platform.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2014 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef XENIA_UI_PLATFORM_H_
|
||||
#define XENIA_UI_PLATFORM_H_
|
||||
|
||||
// TODO(benvanik): only on windows.
|
||||
#include "xenia/ui/win32/win32_file_picker.h"
|
||||
#include "xenia/ui/win32/win32_loop.h"
|
||||
#include "xenia/ui/win32/win32_menu_item.h"
|
||||
#include "xenia/ui/win32/win32_window.h"
|
||||
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
|
||||
using PlatformFilePicker = xe::ui::win32::Win32FilePicker;
|
||||
using PlatformLoop = xe::ui::win32::Win32Loop;
|
||||
using PlatformMenu = xe::ui::win32::Win32MenuItem;
|
||||
using PlatformWindow = xe::ui::win32::Win32Window;
|
||||
|
||||
} // namespace ui
|
||||
} // namespace xe
|
||||
|
||||
#endif // XENIA_UI_PLATFORM_H_
|
||||
@@ -20,12 +20,10 @@ namespace xe {
|
||||
namespace ui {
|
||||
namespace win32 {
|
||||
|
||||
Win32Window::Win32Window(const std::wstring& title)
|
||||
: Window(title), closing_(false), fullscreen_(false) {
|
||||
menu_ = nullptr;
|
||||
}
|
||||
Win32Window::Win32Window(Loop* loop, const std::wstring& title)
|
||||
: Window(loop, title) {}
|
||||
|
||||
Win32Window::~Win32Window() {}
|
||||
Win32Window::~Win32Window() = default;
|
||||
|
||||
bool Win32Window::Initialize() {
|
||||
Create();
|
||||
@@ -160,8 +158,15 @@ void Win32Window::ResizeToFill(int32_t pad_left, int32_t pad_top,
|
||||
// TODO(benvanik): fullscreen.
|
||||
}
|
||||
|
||||
void Win32Window::SetFullscreen(bool fullscreen) {
|
||||
fullscreen_ = fullscreen;
|
||||
bool Win32Window::is_fullscreen() const {
|
||||
DWORD style = GetWindowLong(hwnd_, GWL_STYLE);
|
||||
return (style & WS_OVERLAPPEDWINDOW) != WS_OVERLAPPEDWINDOW;
|
||||
}
|
||||
|
||||
void Win32Window::ToggleFullscreen(bool fullscreen) {
|
||||
if (fullscreen == is_fullscreen()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD style = GetWindowLong(hwnd_, GWL_STYLE);
|
||||
if (fullscreen) {
|
||||
@@ -200,7 +205,7 @@ void Win32Window::OnClose() {
|
||||
void Win32Window::OnSetMenu(MenuItem* menu) {
|
||||
Win32MenuItem* win_menu = reinterpret_cast<Win32MenuItem*>(menu);
|
||||
// Don't actually set the menu if we're fullscreen. We'll do that later.
|
||||
if (win_menu && !fullscreen_) {
|
||||
if (win_menu && !is_fullscreen()) {
|
||||
::SetMenu(hwnd_, win_menu->handle());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace win32 {
|
||||
|
||||
class Win32Window : public Window<Win32Control> {
|
||||
public:
|
||||
Win32Window(const std::wstring& title);
|
||||
Win32Window(Loop* loop, const std::wstring& title);
|
||||
~Win32Window() override;
|
||||
|
||||
bool Initialize() override;
|
||||
@@ -35,7 +35,8 @@ class Win32Window : public Window<Win32Control> {
|
||||
void ResizeToFill(int32_t pad_left, int32_t pad_top, int32_t pad_right,
|
||||
int32_t pad_bottom) override;
|
||||
|
||||
void SetFullscreen(bool fullscreen) override;
|
||||
bool is_fullscreen() const override;
|
||||
void ToggleFullscreen(bool fullscreen) override;
|
||||
|
||||
protected:
|
||||
bool Create() override;
|
||||
@@ -49,9 +50,8 @@ class Win32Window : public Window<Win32Control> {
|
||||
private:
|
||||
void EnableMMCSS();
|
||||
|
||||
bool closing_;
|
||||
bool closing_ = false;
|
||||
|
||||
bool fullscreen_;
|
||||
WINDOWPLACEMENT windowed_pos_;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "xenia/base/delegate.h"
|
||||
#include "xenia/ui/control.h"
|
||||
#include "xenia/ui/loop.h"
|
||||
#include "xenia/ui/menu_item.h"
|
||||
#include "xenia/ui/ui_event.h"
|
||||
|
||||
@@ -27,6 +28,8 @@ class Window : public T {
|
||||
|
||||
virtual bool Initialize() { return true; }
|
||||
|
||||
Loop* loop() const { return loop_; }
|
||||
|
||||
const std::wstring& title() const { return title_; }
|
||||
virtual bool set_title(const std::wstring& title) {
|
||||
if (title == title_) {
|
||||
@@ -36,6 +39,15 @@ class Window : public T {
|
||||
return true;
|
||||
}
|
||||
|
||||
MenuItem* menu() const { return menu_; }
|
||||
void set_menu(MenuItem* menu) {
|
||||
if (menu == menu_) {
|
||||
return;
|
||||
}
|
||||
menu_ = menu;
|
||||
OnSetMenu(menu);
|
||||
}
|
||||
|
||||
void Close() {
|
||||
auto e = UIEvent(this);
|
||||
on_closing(e);
|
||||
@@ -46,13 +58,8 @@ class Window : public T {
|
||||
on_closed(e);
|
||||
}
|
||||
|
||||
virtual void SetMenu(MenuItem* menu) {
|
||||
menu_ = menu;
|
||||
|
||||
OnSetMenu(menu);
|
||||
}
|
||||
|
||||
virtual void SetFullscreen(bool fullscreen) {}
|
||||
virtual bool is_fullscreen() const { return false; }
|
||||
virtual void ToggleFullscreen(bool fullscreen) {}
|
||||
|
||||
public:
|
||||
Delegate<UIEvent> on_shown;
|
||||
@@ -61,7 +68,8 @@ class Window : public T {
|
||||
Delegate<UIEvent> on_closed;
|
||||
|
||||
protected:
|
||||
Window(const std::wstring& title) : T(0), title_(title) {}
|
||||
Window(Loop* loop, const std::wstring& title)
|
||||
: T(0), loop_(loop), title_(title) {}
|
||||
|
||||
void OnShow() {
|
||||
if (is_visible_) {
|
||||
@@ -87,8 +95,9 @@ class Window : public T {
|
||||
|
||||
virtual void OnCommand(int id) {}
|
||||
|
||||
MenuItem* menu_;
|
||||
Loop* loop_ = nullptr;
|
||||
std::wstring title_;
|
||||
MenuItem* menu_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
||||
Reference in New Issue
Block a user