Removing old run loop/ref/core/etc.
This commit is contained in:
@@ -9,14 +9,16 @@
|
||||
|
||||
#include <xenia/ui/menu_item.h>
|
||||
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::ui;
|
||||
MenuItem::MenuItem(Window* window) : window_(window), parent_item_(nullptr) {}
|
||||
|
||||
MenuItem::~MenuItem() {}
|
||||
|
||||
MenuItem::MenuItem(Window* window, MenuItem* parent_item) :
|
||||
window_(window), parent_item_(parent_item) {
|
||||
void MenuItem::AddChild(std::unique_ptr<MenuItem> child_item) {
|
||||
children_.emplace_back(std::move(child_item));
|
||||
}
|
||||
|
||||
MenuItem::~MenuItem() {
|
||||
}
|
||||
} // namespace ui
|
||||
} // namespace xe
|
||||
|
||||
@@ -10,32 +10,33 @@
|
||||
#ifndef XENIA_UI_MENU_ITEM_H_
|
||||
#define XENIA_UI_MENU_ITEM_H_
|
||||
|
||||
#include <xenia/core.h>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <xenia/common.h>
|
||||
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
|
||||
class Window;
|
||||
|
||||
|
||||
class MenuItem {
|
||||
public:
|
||||
MenuItem(Window* window, MenuItem* parent_item = NULL);
|
||||
public:
|
||||
MenuItem(Window* window);
|
||||
virtual ~MenuItem();
|
||||
|
||||
Window* window() const { return window_; }
|
||||
MenuItem* parent_item() const { return parent_item_; }
|
||||
|
||||
private:
|
||||
Window* window_;
|
||||
MenuItem* parent_item_;
|
||||
// children
|
||||
};
|
||||
virtual void AddChild(std::unique_ptr<MenuItem> child_item);
|
||||
|
||||
private:
|
||||
Window* window_;
|
||||
MenuItem* parent_item_;
|
||||
std::vector<std::unique_ptr<MenuItem>> children_;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_UI_MENU_ITEM_H_
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#ifndef XENIA_UI_UI_EVENT_H_
|
||||
#define XENIA_UI_UI_EVENT_H_
|
||||
|
||||
#include <xenia/core.h>
|
||||
#include <xenia/common.h>
|
||||
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# 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',
|
||||
|
||||
44
src/xenia/ui/win32/win32_loop.cc
Normal file
44
src/xenia/ui/win32/win32_loop.cc
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* 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
|
||||
36
src/xenia/ui/win32/win32_loop.h
Normal file
36
src/xenia/ui/win32/win32_loop.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* 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_
|
||||
@@ -9,15 +9,14 @@
|
||||
|
||||
#include <xenia/ui/win32/win32_menu_item.h>
|
||||
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
namespace win32 {
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::ui;
|
||||
using namespace xe::ui::win32;
|
||||
Win32MenuItem::Win32MenuItem(Window* window) : MenuItem(window) {}
|
||||
|
||||
Win32MenuItem::~Win32MenuItem() {}
|
||||
|
||||
Win32MenuItem::Win32MenuItem(Window* window, MenuItem* parent_item) :
|
||||
MenuItem(window, parent_item) {
|
||||
}
|
||||
|
||||
Win32MenuItem::~Win32MenuItem() {
|
||||
}
|
||||
} // namespace win32
|
||||
} // namespace ui
|
||||
} // namespace xe
|
||||
|
||||
@@ -10,28 +10,23 @@
|
||||
#ifndef XENIA_UI_WIN32_WIN32_MENU_ITEM_H_
|
||||
#define XENIA_UI_WIN32_WIN32_MENU_ITEM_H_
|
||||
|
||||
#include <xenia/core.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, MenuItem* parent_item = NULL);
|
||||
virtual ~Win32MenuItem();
|
||||
public:
|
||||
Win32MenuItem(Window* window);
|
||||
~Win32MenuItem() override;
|
||||
|
||||
private:
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
} // namespace win32
|
||||
} // namespace ui
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_UI_WIN32_WIN32_MENU_ITEM_H_
|
||||
|
||||
@@ -13,16 +13,12 @@
|
||||
#include <tpcshrd.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
namespace win32 {
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::ui;
|
||||
using namespace xe::ui::win32;
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
static LRESULT CALLBACK Win32WindowWndProc(
|
||||
HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
static LRESULT CALLBACK
|
||||
Win32WindowWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
Win32Window* window = 0;
|
||||
if (message == WM_NCCREATE) {
|
||||
LPCREATESTRUCT create_struct = (LPCREATESTRUCT)lParam;
|
||||
@@ -38,18 +34,12 @@ static LRESULT CALLBACK Win32WindowWndProc(
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
Win32Window::Win32Window(xe_run_loop_ref run_loop) :
|
||||
handle_(0), closing_(false),
|
||||
Window(run_loop) {
|
||||
}
|
||||
Win32Window::Win32Window() : handle_(0), closing_(false) {}
|
||||
|
||||
Win32Window::~Win32Window() {
|
||||
if (handle_) {
|
||||
CloseWindow(handle_);
|
||||
handle_ = NULL;
|
||||
handle_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,44 +53,34 @@ int Win32Window::Initialize(const std::wstring& title, uint32_t width,
|
||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||
|
||||
WNDCLASSEX wcex;
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
wcex.style = 0;
|
||||
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";
|
||||
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_style = WS_OVERLAPPEDWINDOW;
|
||||
DWORD window_ex_style = WS_EX_APPWINDOW;
|
||||
RECT rc = {
|
||||
0, 0,
|
||||
static_cast<LONG>(width), static_cast<LONG>(height)
|
||||
};
|
||||
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);
|
||||
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;
|
||||
@@ -109,18 +89,17 @@ int Win32Window::Initialize(const std::wstring& title, uint32_t width,
|
||||
// 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));
|
||||
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.
|
||||
@@ -138,27 +117,27 @@ void Win32Window::EnableMMCSS() {
|
||||
return;
|
||||
}
|
||||
|
||||
typedef HRESULT (__stdcall *PDwmEnableMMCSS)(BOOL);
|
||||
typedef HRESULT(__stdcall * PDwmEnableMMCSS)(BOOL);
|
||||
PDwmEnableMMCSS pDwmEnableMMCSS =
|
||||
(PDwmEnableMMCSS)GetProcAddress(
|
||||
hLibrary, "DwmEnableMMCSS");
|
||||
(PDwmEnableMMCSS)GetProcAddress(hLibrary, "DwmEnableMMCSS");
|
||||
if (pDwmEnableMMCSS) {
|
||||
pDwmEnableMMCSS(TRUE);
|
||||
}
|
||||
|
||||
typedef HRESULT (__stdcall *PDwmSetPresentParameters)(HWND, DWM_PRESENT_PARAMETERS*);
|
||||
typedef HRESULT(__stdcall * PDwmSetPresentParameters)(
|
||||
HWND, DWM_PRESENT_PARAMETERS*);
|
||||
PDwmSetPresentParameters pDwmSetPresentParameters =
|
||||
(PDwmSetPresentParameters)GetProcAddress(
|
||||
hLibrary, "DwmSetPresentParameters");
|
||||
(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;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -187,10 +166,7 @@ bool Win32Window::set_cursor_visible(bool value) {
|
||||
}
|
||||
|
||||
bool Win32Window::SetSize(uint32_t width, uint32_t height) {
|
||||
RECT rc = {
|
||||
0, 0,
|
||||
static_cast<LONG>(width), static_cast<LONG>(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);
|
||||
@@ -209,7 +185,7 @@ 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 };
|
||||
POINT pt = {x, y};
|
||||
ScreenToClient(handle_, &pt);
|
||||
x = pt.x;
|
||||
y = pt.y;
|
||||
@@ -219,64 +195,64 @@ bool Win32Window::HandleMouse(UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
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;
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_LBUTTONUP:
|
||||
button = MouseEvent::MOUSE_BUTTON_LEFT;
|
||||
break;
|
||||
case XBUTTON2:
|
||||
button = MouseEvent::MOUSE_BUTTON_X2;
|
||||
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:
|
||||
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;
|
||||
// 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;
|
||||
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;
|
||||
}
|
||||
@@ -284,19 +260,19 @@ bool Win32Window::HandleMouse(UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
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;
|
||||
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) {
|
||||
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;
|
||||
@@ -312,62 +288,65 @@ LRESULT Win32Window::WndProc(HWND hWnd, UINT message,
|
||||
}
|
||||
|
||||
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_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:
|
||||
{
|
||||
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);
|
||||
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:
|
||||
{
|
||||
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);
|
||||
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);
|
||||
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
|
||||
|
||||
@@ -12,8 +12,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
#include <xenia/common.h>
|
||||
#include <xenia/ui/window.h>
|
||||
|
||||
namespace xe {
|
||||
@@ -22,7 +21,7 @@ namespace win32 {
|
||||
|
||||
class Win32Window : public Window {
|
||||
public:
|
||||
Win32Window(xe_run_loop_ref run_loop);
|
||||
Win32Window();
|
||||
~Win32Window() override;
|
||||
|
||||
int Initialize(const std::wstring& title, uint32_t width,
|
||||
|
||||
@@ -9,19 +9,17 @@
|
||||
|
||||
#include <xenia/ui/window.h>
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::ui;
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
|
||||
Window::Window(xe_run_loop_ref run_loop)
|
||||
Window::Window()
|
||||
: title_(L"Window"),
|
||||
is_visible_(true),
|
||||
is_cursor_visible_(true),
|
||||
width_(0),
|
||||
height_(0) {
|
||||
run_loop_ = xe_run_loop_retain(run_loop);
|
||||
}
|
||||
height_(0) {}
|
||||
|
||||
Window::~Window() { xe_run_loop_release(run_loop_); }
|
||||
Window::~Window() {}
|
||||
|
||||
int Window::Initialize(const std::wstring& title, uint32_t width,
|
||||
uint32_t height) {
|
||||
@@ -111,3 +109,6 @@ void Window::Close() {
|
||||
}
|
||||
|
||||
void Window::OnClose() {}
|
||||
|
||||
} // namespace ui
|
||||
} // namespace xe
|
||||
|
||||
@@ -12,9 +12,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <xenia/core.h>
|
||||
|
||||
#include <alloy/delegate.h>
|
||||
#include <xenia/common.h>
|
||||
#include <xenia/ui/ui_event.h>
|
||||
|
||||
namespace xe {
|
||||
@@ -22,14 +21,12 @@ namespace ui {
|
||||
|
||||
class Window {
|
||||
public:
|
||||
Window(xe_run_loop_ref run_loop);
|
||||
Window();
|
||||
virtual ~Window();
|
||||
|
||||
virtual int Initialize(const std::wstring& title, uint32_t width,
|
||||
uint32_t height);
|
||||
|
||||
xe_run_loop_ref run_loop() const { return run_loop_; }
|
||||
|
||||
const std::wstring& title() const { return title_; }
|
||||
virtual bool set_title(const std::wstring& title);
|
||||
bool is_visible() const { return is_visible_; }
|
||||
@@ -69,7 +66,6 @@ class Window {
|
||||
virtual void OnClose();
|
||||
|
||||
private:
|
||||
xe_run_loop_ref run_loop_;
|
||||
std::wstring title_;
|
||||
bool is_visible_;
|
||||
bool is_cursor_visible_;
|
||||
|
||||
Reference in New Issue
Block a user