UI hacking.

This commit is contained in:
Ben Vanik
2014-12-20 13:54:55 -08:00
parent c1df273600
commit d839359b4a
28 changed files with 1235 additions and 714 deletions

View File

@@ -20,7 +20,7 @@
#include <xenia/kernel/modules.h>
#include <xenia/kernel/fs/filesystem.h>
#include <xenia/memory.h>
#include <xenia/ui/window.h>
#include <xenia/ui/main_window.h>
namespace xe {
@@ -33,7 +33,7 @@ using namespace xe::kernel::fs;
using namespace xe::ui;
Emulator::Emulator(const std::wstring& command_line)
: command_line_(command_line), main_window_(nullptr) {}
: command_line_(command_line) {}
Emulator::~Emulator() {
// Note that we delete things in the reverse order they were initialized.
@@ -43,10 +43,6 @@ Emulator::~Emulator() {
ev->type = xdb::protocol::EventType::PROCESS_EXIT;
}
if (main_window_) {
main_window_->Close();
}
debug_agent_.reset();
xam_.reset();
@@ -66,11 +62,20 @@ Emulator::~Emulator() {
processor_.reset();
export_resolver_.reset();
// Kill the window last, as until the graphics system/etc is dead it's needed.
main_window_.reset();
}
X_STATUS Emulator::Setup() {
X_STATUS result = X_STATUS_UNSUCCESSFUL;
// Create the main window. Other parts will hook into this.
main_window_ = std::make_unique<ui::MainWindow>();
if (!main_window_->Initialize()) {
return result;
}
debug_agent_.reset(new DebugAgent(this));
result = debug_agent_->Initialize();
if (result) {
@@ -141,16 +146,6 @@ X_STATUS Emulator::Setup() {
return result;
}
void Emulator::set_main_window(Window* window) {
assert_null(main_window_);
main_window_ = window;
window->closed.AddListener([](UIEvent& e) {
// TODO(benvanik): call module API to kill? this is a bad shutdown.
exit(1);
});
}
X_STATUS Emulator::LaunchXexFile(const std::wstring& path) {
// We create a virtual filesystem pointing to its directory and symlink
// that to the game filesystem.

View File

@@ -37,7 +37,7 @@ class XamModule;
class XboxkrnlModule;
} // namespace kernel
namespace ui {
class Window;
class MainWindow;
} // namespace ui
} // namespace xe
@@ -52,8 +52,7 @@ class Emulator {
const std::wstring& command_line() const { return command_line_; }
ui::Window* main_window() const { return main_window_; }
void set_main_window(ui::Window* window);
ui::MainWindow* main_window() const { return main_window_.get(); }
Memory* memory() const { return memory_.get(); }
@@ -85,8 +84,7 @@ class Emulator {
std::wstring command_line_;
// TODO(benvanik): remove from here?
ui::Window* main_window_;
std::unique_ptr<ui::MainWindow> main_window_;
std::unique_ptr<Memory> memory_;

View File

@@ -7,17 +7,32 @@
******************************************************************************
*/
#include <xenia/ui/menu_item.h>
#include <xenia/ui/main_window.h>
#include <poly/logging.h>
namespace xe {
namespace ui {
MenuItem::MenuItem(Window* window) : window_(window), parent_item_(nullptr) {}
MainWindow::MainWindow() : PlatformWindow(L"xenia") {}
MenuItem::~MenuItem() {}
MainWindow::~MainWindow() {}
void MenuItem::AddChild(std::unique_ptr<MenuItem> child_item) {
children_.emplace_back(std::move(child_item));
void MainWindow::Start() {
loop_.Post([this]() {
if (!Initialize()) {
PFATAL("Failed to initialize main window");
exit(1);
}
});
}
bool MainWindow::Initialize() {
if (!Window::Initialize()) {
return false;
}
//
return true;
}
} // namespace ui

View File

@@ -7,36 +7,37 @@
******************************************************************************
*/
#ifndef XENIA_UI_MENU_ITEM_H_
#define XENIA_UI_MENU_ITEM_H_
#ifndef XENIA_UI_MAIN_WINDOW_H_
#define XENIA_UI_MAIN_WINDOW_H_
#include <memory>
#include <vector>
#include <poly/ui/window.h>
#include <xenia/common.h>
// TODO(benvanik): only on windows.
#include <poly/ui/win32/win32_loop.h>
#include <poly/ui/win32/win32_window.h>
namespace xe {
namespace ui {
class Window;
using PlatformLoop = poly::ui::win32::Win32Loop;
using PlatformWindow = poly::ui::win32::Win32Window;
class MenuItem {
class MainWindow : public PlatformWindow {
public:
MenuItem(Window* window);
virtual ~MenuItem();
MainWindow();
~MainWindow();
Window* window() const { return window_; }
MenuItem* parent_item() const { return parent_item_; }
PlatformLoop* loop() { return &loop_; }
virtual void AddChild(std::unique_ptr<MenuItem> child_item);
void Start();
private:
Window* window_;
MenuItem* parent_item_;
std::vector<std::unique_ptr<MenuItem>> children_;
bool Initialize();
PlatformLoop loop_;
};
} // namespace ui
} // namespace xe
#endif // XENIA_UI_MENU_ITEM_H_
#endif // XENIA_UI_MAIN_WINDOW_H_

View File

@@ -1,18 +1,7 @@
# Copyright 2014 Ben Vanik. All Rights Reserved.
{
'sources': [
'menu_item.cc',
'menu_item.h',
'ui_event.h',
'window.cc',
'window.h',
],
'conditions': [
['OS == "win"', {
'includes': [
'win32/sources.gypi',
],
}],
'main_window.cc',
'main_window.h',
],
}

View File

@@ -1,78 +0,0 @@
/**
******************************************************************************
* 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_UI_EVENT_H_
#define XENIA_UI_UI_EVENT_H_
#include <xenia/common.h>
namespace xe {
namespace ui {
class App;
class Window;
class UIEvent {
public:
UIEvent(Window* window = NULL) : window_(window) {}
virtual ~UIEvent() = default;
Window* window() const { return window_; }
private:
Window* window_;
};
class KeyEvent : public UIEvent {
public:
KeyEvent(Window* window, int key_code)
: UIEvent(window), key_code_(key_code) {}
~KeyEvent() override = default;
int key_code() const { return key_code_; }
private:
int key_code_;
};
class MouseEvent : public UIEvent {
public:
enum Button {
MOUSE_BUTTON_NONE = 0,
MOUSE_BUTTON_LEFT,
MOUSE_BUTTON_RIGHT,
MOUSE_BUTTON_MIDDLE,
MOUSE_BUTTON_X1,
MOUSE_BUTTON_X2,
};
public:
MouseEvent(Window* window, Button button, int32_t x, int32_t y,
int32_t dx = 0, int32_t dy = 0)
: UIEvent(window), button_(button), x_(x), y_(y), dx_(dx), dy_(dy) {}
~MouseEvent() override = default;
Button button() const { return button_; }
int32_t x() const { return x_; }
int32_t y() const { return y_; }
int32_t dx() const { return dx_; }
int32_t dy() const { return dy_; }
private:
Button button_;
int32_t x_;
int32_t y_;
int32_t dx_;
int32_t dy_;
};
} // namespace ui
} // namespace xe
#endif // XENIA_UI_UI_EVENT_H_

View File

@@ -1,11 +0,0 @@
# Copyright 2014 Ben Vanik. All Rights Reserved.
{
'sources': [
'win32_loop.cc',
'win32_loop.h',
'win32_menu_item.cc',
'win32_menu_item.h',
'win32_window.cc',
'win32_window.h',
],
}

View File

@@ -1,44 +0,0 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include <xenia/ui/win32/win32_loop.h>
namespace xe {
namespace ui {
namespace win32 {
const DWORD kWmWin32LoopQuit = WM_APP + 0x100;
Win32Loop::Win32Loop() {}
Win32Loop::~Win32Loop() {}
bool Win32Loop::Run() {
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
switch (msg.message) {
case kWmWin32LoopQuit:
if (msg.wParam == reinterpret_cast<WPARAM>(this)) {
return true;
}
break;
}
}
return true;
}
void Win32Loop::Quit() {
PostMessage(nullptr, kWmWin32LoopQuit, reinterpret_cast<WPARAM>(this), 0);
}
} // namespace win32
} // namespace ui
} // namespace xe

View File

@@ -1,36 +0,0 @@
/**
******************************************************************************
* 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_WIN32_WIN32_LOOP_H_
#define XENIA_UI_WIN32_WIN32_LOOP_H_
#include <xenia/common.h>
#include <xenia/ui/menu_item.h>
namespace xe {
namespace ui {
namespace win32 {
class Win32Loop {
public:
Win32Loop();
~Win32Loop();
bool Run();
void Quit();
private:
};
} // namespace win32
} // namespace ui
} // namespace xe
#endif // XENIA_UI_WIN32_WIN32_LOOP_H_

View File

@@ -1,22 +0,0 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include <xenia/ui/win32/win32_menu_item.h>
namespace xe {
namespace ui {
namespace win32 {
Win32MenuItem::Win32MenuItem(Window* window) : MenuItem(window) {}
Win32MenuItem::~Win32MenuItem() {}
} // namespace win32
} // namespace ui
} // namespace xe

View File

@@ -1,32 +0,0 @@
/**
******************************************************************************
* 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_WIN32_WIN32_MENU_ITEM_H_
#define XENIA_UI_WIN32_WIN32_MENU_ITEM_H_
#include <xenia/common.h>
#include <xenia/ui/menu_item.h>
namespace xe {
namespace ui {
namespace win32 {
class Win32MenuItem : public MenuItem {
public:
Win32MenuItem(Window* window);
~Win32MenuItem() override;
private:
};
} // namespace win32
} // namespace ui
} // namespace xe
#endif // XENIA_UI_WIN32_WIN32_MENU_ITEM_H_

View File

@@ -1,352 +0,0 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include <xenia/ui/win32/win32_window.h>
#include <dwmapi.h>
#include <tpcshrd.h>
#include <windowsx.h>
namespace xe {
namespace ui {
namespace win32 {
static LRESULT CALLBACK
Win32WindowWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
Win32Window* window = 0;
if (message == WM_NCCREATE) {
LPCREATESTRUCT create_struct = (LPCREATESTRUCT)lParam;
window = (Win32Window*)create_struct->lpCreateParams;
SetWindowLongPtr(hWnd, GWLP_USERDATA, (__int3264)(LONG_PTR)window);
} else {
window = (Win32Window*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
}
if (window) {
return window->WndProc(hWnd, message, wParam, lParam);
} else {
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
Win32Window::Win32Window() : handle_(0), closing_(false) {}
Win32Window::~Win32Window() {
if (handle_) {
CloseWindow(handle_);
handle_ = nullptr;
}
}
int Win32Window::Initialize(const std::wstring& title, uint32_t width,
uint32_t height) {
int result = Window::Initialize(title, width, height);
if (result) {
return result;
}
HINSTANCE hInstance = GetModuleHandle(NULL);
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_OWNDC;
wcex.lpfnWndProc = Win32WindowWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL; // LoadIcon(hInstance, (LPCTSTR)IDI_TUTORIAL1);
wcex.hIconSm = NULL; // LoadIcon(hInstance, (LPCTSTR)IDI_TUTORIAL1);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = L"XeniaWindowClass";
if (!RegisterClassEx(&wcex)) {
XELOGE("RegisterClassEx failed");
return 1;
}
// Setup initial size.
DWORD window_style = WS_OVERLAPPEDWINDOW;
DWORD window_ex_style = WS_EX_APPWINDOW;
RECT rc = {0, 0, static_cast<LONG>(width), static_cast<LONG>(height)};
AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);
// Create window.
handle_ = CreateWindowEx(window_ex_style, L"XeniaWindowClass", L"Xenia",
window_style, CW_USEDEFAULT, CW_USEDEFAULT,
rc.right - rc.left, rc.bottom - rc.top, NULL, NULL,
hInstance, this);
if (!handle_) {
XELOGE("CreateWindow failed");
return 1;
}
// Disable flicks.
ATOM atom = GlobalAddAtom(L"MicrosoftTabletPenServiceProperty");
const DWORD_PTR dwHwndTabletProperty =
TABLET_DISABLE_PRESSANDHOLD | // disables press and hold (right-click)
// gesture
TABLET_DISABLE_PENTAPFEEDBACK | // disables UI feedback on pen up (waves)
TABLET_DISABLE_PENBARRELFEEDBACK | // disables UI feedback on pen button
// down (circle)
TABLET_DISABLE_FLICKS | // disables pen flicks (back, forward, drag down,
// drag up)
TABLET_DISABLE_TOUCHSWITCH | TABLET_DISABLE_SMOOTHSCROLLING |
TABLET_DISABLE_TOUCHUIFORCEON | TABLET_ENABLE_MULTITOUCHDATA;
SetProp(handle_, L"MicrosoftTabletPenServiceProperty",
reinterpret_cast<HANDLE>(dwHwndTabletProperty));
GlobalDeleteAtom(atom);
// Enable DWM elevation.
EnableMMCSS();
ShowWindow(handle_, SW_SHOWNORMAL);
UpdateWindow(handle_);
return 0;
}
void Win32Window::EnableMMCSS() {
HMODULE hLibrary = LoadLibrary(L"DWMAPI.DLL");
if (!hLibrary) {
return;
}
typedef HRESULT(__stdcall * PDwmEnableMMCSS)(BOOL);
PDwmEnableMMCSS pDwmEnableMMCSS =
(PDwmEnableMMCSS)GetProcAddress(hLibrary, "DwmEnableMMCSS");
if (pDwmEnableMMCSS) {
pDwmEnableMMCSS(TRUE);
}
typedef HRESULT(__stdcall * PDwmSetPresentParameters)(
HWND, DWM_PRESENT_PARAMETERS*);
PDwmSetPresentParameters pDwmSetPresentParameters =
(PDwmSetPresentParameters)GetProcAddress(hLibrary,
"DwmSetPresentParameters");
if (pDwmSetPresentParameters) {
DWM_PRESENT_PARAMETERS pp;
memset(&pp, 0, sizeof(DWM_PRESENT_PARAMETERS));
pp.cbSize = sizeof(DWM_PRESENT_PARAMETERS);
pp.fQueue = FALSE;
pp.cBuffer = 2;
pp.fUseSourceRate = FALSE;
pp.cRefreshesPerFrame = 1;
pp.eSampling = DWM_SOURCE_FRAME_SAMPLING_POINT;
pDwmSetPresentParameters(handle_, &pp);
}
FreeLibrary(hLibrary);
}
bool Win32Window::set_title(const std::wstring& title) {
if (!Window::set_title(title)) {
return false;
}
SetWindowText(handle_, title.c_str());
return true;
}
bool Win32Window::set_cursor_visible(bool value) {
if (!Window::set_cursor_visible(value)) {
return false;
}
if (value) {
ShowCursor(TRUE);
SetCursor(NULL);
} else {
ShowCursor(FALSE);
}
return true;
}
bool Win32Window::SetSize(uint32_t width, uint32_t height) {
RECT rc = {0, 0, static_cast<LONG>(width), static_cast<LONG>(height)};
AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);
// TODO(benvanik): center?
MoveWindow(handle_, 0, 0, rc.right - rc.left, rc.bottom - rc.top, TRUE);
return true;
}
void Win32Window::OnClose() {
if (!closing_ && handle_) {
closing_ = true;
CloseWindow(handle_);
handle_ = NULL;
}
}
bool Win32Window::HandleMouse(UINT message, WPARAM wParam, LPARAM lParam) {
int32_t x = GET_X_LPARAM(lParam);
int32_t y = GET_Y_LPARAM(lParam);
if (message == WM_MOUSEWHEEL) {
POINT pt = {x, y};
ScreenToClient(handle_, &pt);
x = pt.x;
y = pt.y;
}
MouseEvent::Button button = MouseEvent::MOUSE_BUTTON_NONE;
int32_t dx = 0;
int32_t dy = 0;
switch (message) {
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
button = MouseEvent::MOUSE_BUTTON_LEFT;
break;
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
button = MouseEvent::MOUSE_BUTTON_RIGHT;
break;
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
button = MouseEvent::MOUSE_BUTTON_MIDDLE;
break;
case WM_XBUTTONDOWN:
case WM_XBUTTONUP:
switch (GET_XBUTTON_WPARAM(wParam)) {
case XBUTTON1:
button = MouseEvent::MOUSE_BUTTON_X1;
break;
case XBUTTON2:
button = MouseEvent::MOUSE_BUTTON_X2;
break;
default:
return false;
}
break;
case WM_MOUSEMOVE:
button = MouseEvent::MOUSE_BUTTON_NONE;
break;
case WM_MOUSEWHEEL:
button = MouseEvent::MOUSE_BUTTON_NONE;
dx = 0; // ?
dy = GET_WHEEL_DELTA_WPARAM(wParam);
break;
default:
// Double click/etc?
return true;
}
auto e = MouseEvent(this, button, x, y, dx, dy);
switch (message) {
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_XBUTTONDOWN:
mouse_down(e);
break;
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_XBUTTONUP:
mouse_up(e);
break;
case WM_MOUSEMOVE:
mouse_move(e);
break;
case WM_MOUSEWHEEL:
mouse_wheel(e);
break;
}
return true;
}
bool Win32Window::HandleKeyboard(UINT message, WPARAM wParam, LPARAM lParam) {
auto e = KeyEvent(this, (int)wParam);
switch (message) {
case WM_KEYDOWN:
key_down(e);
return true;
case WM_KEYUP:
key_up(e);
return true;
default:
return false;
}
}
LRESULT Win32Window::WndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam) {
if (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST) {
if (HandleMouse(message, wParam, lParam)) {
return 0;
} else {
return DefWindowProc(hWnd, message, wParam, lParam);
}
} else if (message >= WM_KEYFIRST && message <= WM_KEYLAST) {
if (HandleKeyboard(message, wParam, lParam)) {
return 0;
} else {
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
switch (message) {
case WM_NCCREATE:
handle_ = hWnd;
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_ACTIVATEAPP:
if (wParam) {
// Made active.
OnShow();
} else {
// Made inactive.
OnHide();
}
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_CLOSE:
closing_ = true;
Close();
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_DESTROY:
return 0;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
}
return 0;
case WM_ERASEBKGND:
return 0; // ignore
case WM_DISPLAYCHANGE:
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_MOVE:
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_SIZING:
BeginResizing();
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_SIZE: {
RECT frame;
GetClientRect(handle_, &frame);
OnResize(frame.right - frame.left, frame.bottom - frame.top);
EndResizing();
}
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_TABLET_QUERYSYSTEMGESTURESTATUS:
return TABLET_DISABLE_PRESSANDHOLD | // disables press and hold
// (right-click) gesture
TABLET_DISABLE_PENTAPFEEDBACK | // disables UI feedback on pen up
// (waves)
TABLET_DISABLE_PENBARRELFEEDBACK | // disables UI feedback on pen
// button down (circle)
TABLET_DISABLE_FLICKS | // disables pen flicks (back, forward,
// drag down, drag up)
TABLET_DISABLE_TOUCHSWITCH | TABLET_DISABLE_SMOOTHSCROLLING |
TABLET_DISABLE_TOUCHUIFORCEON | TABLET_ENABLE_MULTITOUCHDATA;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
} // namespace win32
} // namespace ui
} // namespace xe

View File

@@ -1,53 +0,0 @@
/**
******************************************************************************
* 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_WIN32_WIN32_WINDOW_H_
#define XENIA_UI_WIN32_WIN32_WINDOW_H_
#include <string>
#include <xenia/common.h>
#include <xenia/ui/window.h>
namespace xe {
namespace ui {
namespace win32 {
class Win32Window : public Window {
public:
Win32Window();
~Win32Window() override;
int Initialize(const std::wstring& title, uint32_t width,
uint32_t height) override;
bool set_title(const std::wstring& title) override;
bool set_cursor_visible(bool value) override;
HWND handle() const { return handle_; }
LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
protected:
bool SetSize(uint32_t width, uint32_t height) override;
void OnClose() override;
private:
void EnableMMCSS();
bool HandleMouse(UINT message, WPARAM wParam, LPARAM lParam);
bool HandleKeyboard(UINT message, WPARAM wParam, LPARAM lParam);
HWND handle_;
bool closing_;
};
} // namespace win32
} // namespace ui
} // namespace xe
#endif // XENIA_UI_WIN32_WIN32_WINDOW_H_

View File

@@ -1,114 +0,0 @@
/**
******************************************************************************
* 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. *
******************************************************************************
*/
#include <xenia/ui/window.h>
namespace xe {
namespace ui {
Window::Window()
: title_(L"Window"),
is_visible_(true),
is_cursor_visible_(true),
width_(0),
height_(0) {}
Window::~Window() {}
int Window::Initialize(const std::wstring& title, uint32_t width,
uint32_t height) {
title_ = title;
width_ = width;
height_ = height;
return 0;
}
bool Window::set_title(const std::wstring& title) {
if (title == title_) {
return false;
}
title_ = title;
return true;
}
bool Window::set_cursor_visible(bool value) {
if (value == is_cursor_visible_) {
return false;
}
is_cursor_visible_ = value;
return true;
}
void Window::OnShow() {
if (is_visible_) {
return;
}
is_visible_ = true;
auto e = UIEvent(this);
shown(e);
}
void Window::OnHide() {
if (!is_visible_) {
return;
}
is_visible_ = false;
auto e = UIEvent(this);
hidden(e);
}
void Window::Resize(uint32_t width, uint32_t height) {
BeginResizing();
SetSize(width, height);
OnResize(width, height); // redundant?
EndResizing();
}
void Window::BeginResizing() {
if (resizing_) {
return;
}
resizing_ = true;
auto e = UIEvent(this);
resizing(e);
}
bool Window::OnResize(uint32_t width, uint32_t height) {
if (!resizing_) {
BeginResizing();
}
if (width == width_ && height == height_) {
return false;
}
width_ = width;
height_ = height;
return true;
}
void Window::EndResizing() {
assert_true(resizing_);
resizing_ = false;
auto e = UIEvent(this);
resized(e);
}
void Window::Close() {
auto e = UIEvent(this);
closing(e);
OnClose();
e = UIEvent(this);
closed(e);
}
void Window::OnClose() {}
} // namespace ui
} // namespace xe

View File

@@ -1,80 +0,0 @@
/**
******************************************************************************
* 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_WINDOW_H_
#define XENIA_UI_WINDOW_H_
#include <string>
#include <poly/delegate.h>
#include <xenia/common.h>
#include <xenia/ui/ui_event.h>
namespace xe {
namespace ui {
class Window {
public:
Window();
virtual ~Window();
virtual int Initialize(const std::wstring& title, uint32_t width,
uint32_t height);
const std::wstring& title() const { return title_; }
virtual bool set_title(const std::wstring& title);
bool is_visible() const { return is_visible_; }
bool is_cursor_visible() const { return is_cursor_visible_; }
virtual bool set_cursor_visible(bool value);
uint32_t width() const { return width_; }
uint32_t height() const { return height_; }
void Resize(uint32_t width, uint32_t height);
void Close();
public:
poly::Delegate<UIEvent> shown;
poly::Delegate<UIEvent> hidden;
poly::Delegate<UIEvent> resizing;
poly::Delegate<UIEvent> resized;
poly::Delegate<UIEvent> closing;
poly::Delegate<UIEvent> closed;
poly::Delegate<KeyEvent> key_down;
poly::Delegate<KeyEvent> key_up;
poly::Delegate<MouseEvent> mouse_down;
poly::Delegate<MouseEvent> mouse_move;
poly::Delegate<MouseEvent> mouse_up;
poly::Delegate<MouseEvent> mouse_wheel;
protected:
void OnShow();
void OnHide();
void BeginResizing();
virtual bool OnResize(uint32_t width, uint32_t height);
void EndResizing();
virtual bool SetSize(uint32_t width, uint32_t height) = 0;
virtual void OnClose();
private:
std::wstring title_;
bool is_visible_;
bool is_cursor_visible_;
bool resizing_;
uint32_t width_;
uint32_t height_;
};
} // namespace ui
} // namespace xe
#endif // XENIA_UI_WINDOW_H_