Skip to content

Commit

Permalink
#5735: Conceptual work
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 9, 2021
1 parent 523da10 commit df9826b
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 3 deletions.
105 changes: 105 additions & 0 deletions radiant/eventmanager/ModifierHintPopup.h
@@ -0,0 +1,105 @@
#pragma once

#include <wx/popupwin.h>

namespace ui
{

class ModifierHintPopup :
public wxPopupWindow
{
private:
wxStaticText* _text;

public:
ModifierHintPopup(wxWindow* parent) :
wxPopupWindow(parent, wxBORDER_SIMPLE)
{
SetSizer(new wxBoxSizer(wxHORIZONTAL));

_text = new wxStaticText(this, wxID_ANY, _("Test"));
GetSizer()->Add(_text, 1, wxALL, 3);

Layout();
Fit();

Reposition();

#if 0
// Subscribe to the parent window's visibility and iconise events to avoid
// the popup from lingering around long after the tree is gone (#5095)
auto* parentWindow = wxGetTopLevelParent(parent);

if (parentWindow != nullptr)
{
parentWindow->Bind(wxEVT_SHOW, &SearchPopupWindow::_onParentVisibilityChanged, this);
parentWindow->Bind(wxEVT_ICONIZE, &SearchPopupWindow::_onParentMinimized, this);

// Detect when the parent window is losing focus (e.g. by alt-tabbing)
parentWindow->Bind(wxEVT_ACTIVATE, &SearchPopupWindow::_onParentActivate, this);

// Detect parent window movements to reposition ourselves
parentWindow->Bind(wxEVT_MOVE, &SearchPopupWindow::_onParentMoved, this);
}
#endif
}

virtual ~ModifierHintPopup()
{
}

void SetText(const wxString& text)
{
_text->SetLabelText(text);

Layout();
Fit();

Reposition();
}

private:
void Reposition()
{
// Position this control in the bottom left corner
wxPoint popupPos = GetParent()->GetScreenPosition() + wxSize(0, GetParent()->GetSize().y - GetSize().y);
Position(popupPos, wxSize(0, 0));
}
#if 0
void _onIdleClose(wxIdleEvent& ev)
{
_owner.Close();
ev.Skip();
}

void _onParentActivate(wxActivateEvent& ev)
{
if (!ev.GetActive())
{
_owner.Close();
}
}

void _onParentMoved(wxMoveEvent&)
{
Reposition();
}

void _onParentMinimized(wxIconizeEvent&)
{
// Close any searches when the parent window is minimized
_owner.Close();
}

void _onParentVisibilityChanged(wxShowEvent& ev)
{
if (!ev.IsShown())
{
// Close any searches when the parent window is hidden
_owner.Close();
}
}
#endif
};

}
51 changes: 48 additions & 3 deletions radiant/eventmanager/MouseToolManager.cpp
Expand Up @@ -21,8 +21,11 @@ namespace
}

MouseToolManager::MouseToolManager() :
_activeModifierState(0)
{}
_activeModifierState(0),
_hintCloseTimer(this)
{
Bind(wxEVT_TIMER, &MouseToolManager::onCloseTimerIntervalReached, this);
}

// RegisterableModule implementation
const std::string& MouseToolManager::getName() const
Expand Down Expand Up @@ -222,8 +225,50 @@ void MouseToolManager::updateStatusbar(unsigned int newState)
});
}

if (statusText.empty())
{
_hintCloseTimer.Stop();

if (_hintPopup)
{
_hintPopup->Close();
_hintPopup.reset();
}

return;
}

_hintCloseTimer.StartOnce(1000);

if (!_hintPopup)
{
_hintPopup.reset(new ModifierHintPopup(GlobalMainFrame().getWxTopLevelWindow()));
_hintPopup->Show();
}

_hintPopup->SetText(statusText);

// Pass the call
GlobalStatusBarManager().setText(STATUS_BAR_ELEMENT, statusText);
//GlobalStatusBarManager().setText(STATUS_BAR_ELEMENT, statusText);
}

void MouseToolManager::onCloseTimerIntervalReached(wxTimerEvent& ev)
{
// If no modifiers are held anymore, close the popup
bool modifierHeld = wxGetKeyState(WXK_SHIFT) || wxGetKeyState(WXK_CONTROL) || wxGetKeyState(WXK_ALT);

if (modifierHeld)
{
ev.GetTimer().StartOnce(1000);
return;
}

if (_hintPopup)
{
_hintPopup->Close();
_hintPopup.reset();
return;
}
}

module::StaticModule<MouseToolManager> mouseToolManagerModule;
Expand Down
9 changes: 9 additions & 0 deletions radiant/eventmanager/MouseToolManager.h
Expand Up @@ -5,6 +5,9 @@
#include "imousetoolmanager.h"
#include "xmlutil/Node.h"
#include "MouseToolGroup.h"
#include "ModifierHintPopup.h"
#include <wx/event.h>
#include <wx/timer.h>

namespace ui
{
Expand All @@ -14,6 +17,7 @@ namespace ui
* This is used by the GlobalXYWnd and GlobalCamera instances.
*/
class MouseToolManager :
public wxEvtHandler,
public IMouseToolManager
{
protected:
Expand All @@ -22,6 +26,9 @@ class MouseToolManager :

unsigned int _activeModifierState;

wxTimer _hintCloseTimer;
std::unique_ptr<ModifierHintPopup> _hintPopup;

public:
MouseToolManager();

Expand Down Expand Up @@ -51,6 +58,8 @@ class MouseToolManager :
void loadGroupMapping(MouseToolGroup::Type type, const xml::NodeList& userMappings, const xml::NodeList& defaultMappings);

void saveToolMappings();

void onCloseTimerIntervalReached(wxTimerEvent& ev);
};

} // namespace
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -399,6 +399,7 @@
<ClInclude Include="..\..\radiant\eventmanager\EventManager.h" />
<ClInclude Include="..\..\radiant\eventmanager\GlobalKeyEventFilter.h" />
<ClInclude Include="..\..\radiant\eventmanager\KeyEvent.h" />
<ClInclude Include="..\..\radiant\eventmanager\ModifierHintPopup.h" />
<ClInclude Include="..\..\radiant\eventmanager\MouseToolGroup.h" />
<ClInclude Include="..\..\radiant\eventmanager\MouseToolManager.h" />
<ClInclude Include="..\..\radiant\eventmanager\RegistryToggle.h" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -1407,6 +1407,9 @@
<ClInclude Include="..\..\radiant\map\AutoSaveTimer.h">
<Filter>src\map</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\eventmanager\ModifierHintPopup.h">
<Filter>src\eventmanager</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\radiant\darkradiant.rc" />
Expand Down

0 comments on commit df9826b

Please sign in to comment.