UI: Hide the cursor after 3 seconds in fullscreen-mode.

This commit is contained in:
Dr. Chat 2016-08-06 17:00:12 -05:00
parent 1a5d4b99fc
commit 1de47e0d17
4 changed files with 44 additions and 4 deletions

View File

@ -141,6 +141,20 @@ bool EmulatorWindow::Initialize() {
e->set_handled(handled); e->set_handled(handled);
}); });
window_->on_mouse_move.AddListener([this](MouseEvent* e) {
if (window_->is_fullscreen() && (e->dx() > 2 || e->dy() > 2)) {
if (!window_->is_cursor_visible()) {
window_->set_cursor_visible(true);
}
cursor_hide_time_ = Clock::QueryHostSystemTime() + 30000000;
}
e->set_handled(false);
});
window_->on_paint.AddListener([this](UIEvent* e) { CheckHideCursor(); });
// Main menu. // Main menu.
// FIXME: This code is really messy. // FIXME: This code is really messy.
auto main_menu = MenuItem::Create(MenuItem::Type::kNormal); auto main_menu = MenuItem::Create(MenuItem::Type::kNormal);
@ -277,6 +291,17 @@ void EmulatorWindow::FileOpen() {
} }
} }
void EmulatorWindow::CheckHideCursor() {
if (!window_->is_fullscreen()) {
// Only hide when fullscreen.
return;
}
if (Clock::QueryHostSystemTime() > cursor_hide_time_) {
window_->set_cursor_visible(false);
}
}
void EmulatorWindow::CpuTimeScalarReset() { void EmulatorWindow::CpuTimeScalarReset() {
Clock::set_guest_time_scalar(1.0); Clock::set_guest_time_scalar(1.0);
UpdateTitle(); UpdateTitle();
@ -320,6 +345,12 @@ void EmulatorWindow::GpuClearCaches() {
void EmulatorWindow::ToggleFullscreen() { void EmulatorWindow::ToggleFullscreen() {
window_->ToggleFullscreen(!window_->is_fullscreen()); window_->ToggleFullscreen(!window_->is_fullscreen());
// Hide the cursor after a second if we're going fullscreen
cursor_hide_time_ = Clock::QueryHostSystemTime() + 30000000;
if (!window_->is_fullscreen()) {
window_->set_cursor_visible(true);
}
} }
void EmulatorWindow::ShowHelpWebsite() { LaunchBrowser("http://xenia.jp"); } void EmulatorWindow::ShowHelpWebsite() { LaunchBrowser("http://xenia.jp"); }

View File

@ -43,6 +43,7 @@ class EmulatorWindow {
bool Initialize(); bool Initialize();
void FileOpen(); void FileOpen();
void CheckHideCursor();
void CpuTimeScalarReset(); void CpuTimeScalarReset();
void CpuTimeScalarSetHalf(); void CpuTimeScalarSetHalf();
void CpuTimeScalarSetDouble(); void CpuTimeScalarSetDouble();
@ -56,6 +57,7 @@ class EmulatorWindow {
std::unique_ptr<ui::Loop> loop_; std::unique_ptr<ui::Loop> loop_;
std::unique_ptr<ui::Window> window_; std::unique_ptr<ui::Window> window_;
std::wstring base_title_; std::wstring base_title_;
uint64_t cursor_hide_time_ = 0;
}; };
} // namespace app } // namespace app

View File

@ -57,7 +57,7 @@ bool Win32Window::OnCreate() {
wcex.hInstance = hInstance; wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, L"MAINICON"); wcex.hIcon = LoadIcon(hInstance, L"MAINICON");
wcex.hIconSm = LoadIcon(hInstance, L"MAINICON"); wcex.hIconSm = LoadIcon(hInstance, L"MAINICON");
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); wcex.hCursor = nullptr;
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = nullptr; wcex.lpszMenuName = nullptr;
wcex.lpszClassName = L"XeniaWindowClass"; wcex.lpszClassName = L"XeniaWindowClass";
@ -105,6 +105,8 @@ bool Win32Window::OnCreate() {
ShowWindow(hwnd_, SW_SHOWNORMAL); ShowWindow(hwnd_, SW_SHOWNORMAL);
UpdateWindow(hwnd_); UpdateWindow(hwnd_);
arrow_cursor_ = LoadCursor(nullptr, IDC_ARROW);
// Initial state. // Initial state.
if (!is_cursor_visible_) { if (!is_cursor_visible_) {
ShowCursor(FALSE); ShowCursor(FALSE);
@ -254,9 +256,10 @@ void Win32Window::set_cursor_visible(bool value) {
if (is_cursor_visible_ == value) { if (is_cursor_visible_ == value) {
return; return;
} }
is_cursor_visible_ = value;
if (value) { if (value) {
ShowCursor(TRUE); ShowCursor(TRUE);
SetCursor(nullptr);
} else { } else {
ShowCursor(FALSE); ShowCursor(FALSE);
} }
@ -483,8 +486,8 @@ bool Win32Window::HandleMouse(UINT message, WPARAM wParam, LPARAM lParam) {
} }
MouseEvent::Button button = MouseEvent::Button::kNone; MouseEvent::Button button = MouseEvent::Button::kNone;
int32_t dx = 0; int32_t dx = x - last_mouse_pos_.x;
int32_t dy = 0; int32_t dy = y - last_mouse_pos_.y;
switch (message) { switch (message) {
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
case WM_LBUTTONUP: case WM_LBUTTONUP:
@ -524,6 +527,8 @@ bool Win32Window::HandleMouse(UINT message, WPARAM wParam, LPARAM lParam) {
return true; return true;
} }
last_mouse_pos_ = {x, y};
auto e = MouseEvent(this, button, x, y, dx, dy); auto e = MouseEvent(this, button, x, y, dx, dy);
switch (message) { switch (message) {
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:

View File

@ -73,8 +73,10 @@ class Win32Window : public Window {
HICON icon_ = nullptr; HICON icon_ = nullptr;
bool closing_ = false; bool closing_ = false;
bool fullscreen_ = false; bool fullscreen_ = false;
HCURSOR arrow_cursor_ = nullptr;
WINDOWPLACEMENT windowed_pos_ = {0}; WINDOWPLACEMENT windowed_pos_ = {0};
POINT last_mouse_pos_ = {0};
}; };
class Win32MenuItem : public MenuItem { class Win32MenuItem : public MenuItem {