From 6a742b950e0c95dffda5fa50952e6b15364f38f1 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sun, 17 Mar 2019 15:23:23 -0700 Subject: [PATCH] Ensure old focus is cleared when showing an overlay. --- src/3rdparty/win32_include/curses.h | 3 ++- src/3rdparty/win32_src/pdcurses/pdcdisp.c | 9 +++++++++ src/musikcube/cursespp/App.cpp | 1 + src/musikcube/cursespp/DialogOverlay.cpp | 2 ++ src/musikcube/cursespp/ToastOverlay.cpp | 2 ++ src/musikcube/cursespp/cursespp/OverlayBase.h | 9 +++++++++ 6 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/3rdparty/win32_include/curses.h b/src/3rdparty/win32_include/curses.h index 94eb05458..e99585fa0 100755 --- a/src/3rdparty/win32_include/curses.h +++ b/src/3rdparty/win32_include/curses.h @@ -1789,7 +1789,8 @@ PDCEX int PDC_set_function_key( const unsigned function, const int new_key); PDCEX int PDC_set_preferred_fontface( const wchar_t* fontface); -PDCEX void PDC_set_default_menu_visibility(int visible); +PDCEX void PDC_set_default_menu_visibility( int visible); +PDCEX void PDC_set_color_intensify_enabled( bool enabled); PDCEX WINDOW *Xinitscr(int, char **); #ifdef XCURSES diff --git a/src/3rdparty/win32_src/pdcurses/pdcdisp.c b/src/3rdparty/win32_src/pdcurses/pdcdisp.c index 461d27b08..dba712385 100644 --- a/src/3rdparty/win32_src/pdcurses/pdcdisp.c +++ b/src/3rdparty/win32_src/pdcurses/pdcdisp.c @@ -356,8 +356,17 @@ int PDC_choose_a_new_font( void) /* This should lead to proper handling of bold text in legacy */ /* apps, where "bold" means "high intensity". */ +static bool enable_color_intensification = TRUE; +void PDC_set_color_intensify_enabled(bool enabled) { + enable_color_intensification = enabled; +} + static COLORREF intensified_color( COLORREF ival) { + if ( !enable_color_intensification) { + return ival; + } + int rgb, i; COLORREF oval = 0; diff --git a/src/musikcube/cursespp/App.cpp b/src/musikcube/cursespp/App.cpp index 13a8414c0..ac3e4ddbc 100755 --- a/src/musikcube/cursespp/App.cpp +++ b/src/musikcube/cursespp/App.cpp @@ -133,6 +133,7 @@ void App::InitCurses() { PDC_set_function_key(FUNCTION_KEY_SHUT_DOWN, 4); PDC_set_default_menu_visibility(0); PDC_set_title(this->appTitle.c_str()); + PDC_set_color_intensify_enabled(false); #endif initscr(); diff --git a/src/musikcube/cursespp/DialogOverlay.cpp b/src/musikcube/cursespp/DialogOverlay.cpp index 7952c4503..bb4b0c638 100644 --- a/src/musikcube/cursespp/DialogOverlay.cpp +++ b/src/musikcube/cursespp/DialogOverlay.cpp @@ -46,7 +46,9 @@ using namespace cursespp; DialogOverlay::DialogOverlay() { this->SetFrameVisible(true); this->SetFrameColor(Color::OverlayFrame); + this->SetFocusedFrameColor(Color::OverlayFrame); this->SetContentColor(Color::OverlayContent); + this->SetFocusedContentColor(Color::OverlayContent); this->width = this->height = 0; this->autoDismiss = true; diff --git a/src/musikcube/cursespp/ToastOverlay.cpp b/src/musikcube/cursespp/ToastOverlay.cpp index a199baaeb..429f5b588 100644 --- a/src/musikcube/cursespp/ToastOverlay.cpp +++ b/src/musikcube/cursespp/ToastOverlay.cpp @@ -56,7 +56,9 @@ ToastOverlay::ToastOverlay(const std::string& text, long durationMs) { this->ticking = false; this->SetFrameVisible(true); this->SetFrameColor(Color::OverlayFrame); + this->SetFocusedFrameColor(Color::OverlayFrame); this->SetContentColor(Color::OverlayContent); + this->SetFocusedContentColor(Color::OverlayContent); } ToastOverlay::~ToastOverlay() { diff --git a/src/musikcube/cursespp/cursespp/OverlayBase.h b/src/musikcube/cursespp/cursespp/OverlayBase.h index f1afac1bd..8f9a7c90b 100644 --- a/src/musikcube/cursespp/cursespp/OverlayBase.h +++ b/src/musikcube/cursespp/cursespp/OverlayBase.h @@ -74,6 +74,15 @@ namespace cursespp { return false; } + virtual IWindowPtr FocusFirst() override { + auto focus = LayoutBase::FocusFirst(); + if (!focus) { + focus = shared_from_this(); + this->Focus(); + } + return focus; + } + protected: static void style(TextLabel& label) { label.SetContentColor(Color::OverlayContent);