From 1bae2ef10b2c1bd73282866333c87301454c5a25 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Wed, 1 Jul 2015 08:13:22 -0700 Subject: [PATCH] Skeleton debugger window. --- src/xenia/debug/ui/main_window.cc | 145 ++++++++++++++++++ src/xenia/debug/ui/main_window.h | 46 ++++++ src/xenia/debug/ui/xe-debug-ui.cc | 31 ++++ src/xenia/debug/ui/xe-debug-ui.vcxproj | 13 +- .../debug/ui/xe-debug-ui.vcxproj.filters | 25 +++ 5 files changed, 255 insertions(+), 5 deletions(-) create mode 100644 src/xenia/debug/ui/main_window.cc create mode 100644 src/xenia/debug/ui/main_window.h create mode 100644 src/xenia/debug/ui/xe-debug-ui.cc diff --git a/src/xenia/debug/ui/main_window.cc b/src/xenia/debug/ui/main_window.cc new file mode 100644 index 000000000..4fc981294 --- /dev/null +++ b/src/xenia/debug/ui/main_window.cc @@ -0,0 +1,145 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2015 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#include "xenia/debug/ui/main_window.h" + +#include "xenia/base/clock.h" +#include "xenia/base/logging.h" +#include "xenia/base/platform.h" +#include "xenia/base/threading.h" +#include "xenia/profiling.h" + +namespace xe { +namespace debug { +namespace ui { + +using xe::ui::MenuItem; +using xe::ui::PlatformMenu; +using xe::ui::PlatformWindow; + +enum Commands { + IDC_FILE_EXIT, + + IDC_HELP_WEBSITE, + IDC_HELP_ABOUT, +}; + +const std::wstring kBaseTitle = L"xenia debugger"; + +MainWindow::MainWindow() + : PlatformWindow(&loop_, kBaseTitle), main_menu_(MenuItem::Type::kNormal) {} + +MainWindow::~MainWindow() = default; + +std::unique_ptr MainWindow::Create() { + std::unique_ptr main_window(new MainWindow()); + + xe::threading::Fence fence; + + main_window->loop()->Post([&main_window, &fence]() { + xe::threading::set_name("Win32 Loop"); + xe::Profiler::ThreadEnter("Win32 Loop"); + + if (!main_window->Initialize()) { + XEFATAL("Failed to initialize main window"); + exit(1); + } + + fence.Signal(); + }); + + fence.Wait(); + + return main_window; +} + +bool MainWindow::Initialize() { + if (!PlatformWindow::Initialize()) { + return false; + } + + on_key_down.AddListener([this](xe::ui::KeyEvent& e) { + bool handled = true; + switch (e.key_code()) { + case 0x1B: { // VK_ESCAPE + // Allow users to escape fullscreen (but not enter it). + if (is_fullscreen()) { + ToggleFullscreen(false); + } + } break; + + case 0x70: { // VK_F1 + OnCommand(Commands::IDC_HELP_WEBSITE); + } break; + + default: { handled = false; } break; + } + e.set_handled(handled); + }); + + // Main menu. + auto file_menu = + std::make_unique(MenuItem::Type::kPopup, L"&File"); + { + file_menu->AddChild(std::make_unique( + MenuItem::Type::kString, Commands::IDC_FILE_EXIT, L"E&xit", L"Alt+F4")); + } + main_menu_.AddChild(std::move(file_menu)); + + // Help menu. + auto help_menu = + std::make_unique(MenuItem::Type::kPopup, L"&Help"); + { + help_menu->AddChild(std::make_unique( + MenuItem::Type::kString, Commands::IDC_HELP_WEBSITE, L"&Website...", + L"F1")); + help_menu->AddChild(std::make_unique( + MenuItem::Type::kString, Commands::IDC_HELP_ABOUT, L"&About...")); + } + main_menu_.AddChild(std::move(help_menu)); + + set_menu(&main_menu_); + + // Setup the GL control that actually does the drawing. + // We run here in the loop and only touch it (and its context) on this + // thread. That means some sync-fu when we want to swap. + control_ = std::make_unique(loop()); + AddChild(control_.get()); + + Resize(1440, 1200); + + return true; +} + +void MainWindow::OnClose() { + loop_.Quit(); + + // TODO(benvanik): proper exit. + XELOGI("User-initiated death!"); + exit(1); +} + +void MainWindow::OnCommand(int id) { + switch (id) { + case IDC_FILE_EXIT: { + Close(); + } break; + + case IDC_HELP_WEBSITE: { + LaunchBrowser("http://xenia.jp"); + } break; + case IDC_HELP_ABOUT: { + LaunchBrowser("http://xenia.jp/about/"); + } break; + } +} + +} // namespace ui +} // namespace debug +} // namespace xe diff --git a/src/xenia/debug/ui/main_window.h b/src/xenia/debug/ui/main_window.h new file mode 100644 index 000000000..9e5cdaa76 --- /dev/null +++ b/src/xenia/debug/ui/main_window.h @@ -0,0 +1,46 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2015 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_DEBUG_UI_MAIN_WINDOW_H_ +#define XENIA_DEBUG_UI_MAIN_WINDOW_H_ + +#include + +#include "xenia/ui/gl/wgl_control.h" +#include "xenia/ui/platform.h" +#include "xenia/ui/window.h" + +namespace xe { +namespace debug { +namespace ui { + +class MainWindow : public xe::ui::PlatformWindow { + public: + ~MainWindow() override; + + static std::unique_ptr Create(); + + private: + explicit MainWindow(); + + bool Initialize(); + + void OnClose() override; + void OnCommand(int id) override; + + xe::ui::PlatformLoop loop_; + xe::ui::PlatformMenu main_menu_; + std::unique_ptr control_; +}; + +} // namespace ui +} // namespace debug +} // namespace xe + +#endif // XENIA_DEBUG_UI_MAIN_WINDOW_H_ diff --git a/src/xenia/debug/ui/xe-debug-ui.cc b/src/xenia/debug/ui/xe-debug-ui.cc new file mode 100644 index 000000000..e021cbc7d --- /dev/null +++ b/src/xenia/debug/ui/xe-debug-ui.cc @@ -0,0 +1,31 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2015 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#include + +#include + +#include "xenia/base/main.h" +#include "xenia/debug/ui/main_window.h" + +namespace xe { +namespace debug { +namespace ui { + +int main(std::vector& args) { + auto main_window = MainWindow::Create(); + main_window->loop()->AwaitQuit(); + return 0; +} + +} // namespace ui +} // namespace debug +} // namespace xe + +DEFINE_ENTRY_POINT(L"xe-debug-ui", L"xe-debug-ui ??", xe::debug::ui::main); diff --git a/src/xenia/debug/ui/xe-debug-ui.vcxproj b/src/xenia/debug/ui/xe-debug-ui.vcxproj index 1d3521a9a..cf409527c 100644 --- a/src/xenia/debug/ui/xe-debug-ui.vcxproj +++ b/src/xenia/debug/ui/xe-debug-ui.vcxproj @@ -52,8 +52,6 @@ Level3 - Disabled - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) Windows @@ -66,10 +64,8 @@ Level3 - MaxSpeed true true - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) Windows @@ -78,8 +74,15 @@ + + + + + + + - + \ No newline at end of file diff --git a/src/xenia/debug/ui/xe-debug-ui.vcxproj.filters b/src/xenia/debug/ui/xe-debug-ui.vcxproj.filters index ef1bec97d..affbf009b 100644 --- a/src/xenia/debug/ui/xe-debug-ui.vcxproj.filters +++ b/src/xenia/debug/ui/xe-debug-ui.vcxproj.filters @@ -10,5 +10,30 @@ {1b70e26e-0024-410f-b27f-ceaba190d5a9} + + {9b5a4bce-210a-4488-863a-9175f0543d00} + + + {9a5724c2-5473-4d53-93b4-26531201f38d} + + + + + src\xenia\base + + + src\xenia\debug\ui + + + + + src\xenia\base + + + src\xenia\debug\ui + + + src\xenia\debug\ui + \ No newline at end of file