Skip to content

Commit

Permalink
Merge branch 'upstream-master' into close_dlg_dbl_click
Browse files Browse the repository at this point in the history
# Conflicts:
#	radiant/ui/common/ShaderChooser.cpp
  • Loading branch information
duzenko committed Sep 18, 2021
2 parents 9cfda49 + d23d882 commit ffdcf5f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 24 deletions.
25 changes: 22 additions & 3 deletions radiant/eventmanager/GlobalKeyEventFilter.cpp
Expand Up @@ -29,6 +29,27 @@ namespace ui

return view != nullptr ? view : dynamic_cast<wxutil::TreeView*>(window->GetParent());
}

// Checks if the key event refers to a well-knnown shortcut that
// needs to be propagated to input controls. Returns false if the shortcut should be propagated.
bool FilterInTextControls(wxKeyEvent& keyEvent)
{
if (keyEvent.ControlDown() && keyEvent.GetKeyCode() > 32 && keyEvent.GetKeyCode() < 127)
{
switch (keyEvent.GetKeyCode())
{
case 'C':case 'V':case 'X': // copy/paste
case 'Y':case 'Z': // redo/undo
case 'A': // select all
return false;
default:
return true;
}
}

// For tool windows we let the ESC key propagate, since it's used to de-select stuff.
return keyEvent.GetKeyCode() == WXK_ESCAPE;
}
}

GlobalKeyEventFilter::GlobalKeyEventFilter(EventManager& eventManager) :
Expand Down Expand Up @@ -103,9 +124,7 @@ GlobalKeyEventFilter::EventCheckResult GlobalKeyEventFilter::checkEvent(wxKeyEve
wxDynamicCast(eventObject, wxComboBox) || wxDynamicCast(eventObject, wxSpinCtrl) ||
wxDynamicCast(eventObject, wxSpinCtrlDouble))
{
// For tool windows we let the ESC key propagate, since it's used to
// de-select stuff.
return keyEvent.GetKeyCode() == WXK_ESCAPE ? EventShouldBeProcessed : EventShouldBeIgnored;
return FilterInTextControls(keyEvent) ? EventShouldBeProcessed : EventShouldBeIgnored;
}

// Special handling for our treeviews with type ahead search
Expand Down
4 changes: 2 additions & 2 deletions radiant/ui/common/ShaderChooser.cpp
Expand Up @@ -32,9 +32,9 @@ ShaderChooser::ShaderChooser(wxWindow* parent, wxTextCtrl* targetEntry) :

_selector = new ShaderSelector(mainPanel, this, SHADER_PREFIXES);

if (_targetEntry != NULL)
if (_targetEntry != nullptr)
{
_initialShader = targetEntry->GetValue();
_initialShader = _targetEntry->GetValue();

// Set the cursor of the tree view to the currently selected shader
_selector->setSelection(_initialShader);
Expand Down
51 changes: 32 additions & 19 deletions radiant/xyview/XYWnd.cpp
Expand Up @@ -1546,32 +1546,42 @@ void XYWnd::mouseToPoint(int x, int y, Vector3& point)
// NOTE: the zoom out factor is 4/5, we could think about customizing it
// we don't go below a zoom factor corresponding to 10% of the max world size
// (this has to be computed against the window size)
void XYWnd::zoomOut()
float XYWnd::getZoomedScale(int steps)
{
float min_scale = std::min(getWidth(),getHeight()) / ( 1.1f * (_maxWorldCoord - _minWorldCoord));
float scale = getScale() * 4.0f / 5.0f;
if (scale < min_scale) {
if (getScale() != min_scale) {
setScale(min_scale);
}
} else {
setScale(scale);
const float min_scale = std::min(getWidth(), getHeight()) / (1.1f * (_maxWorldCoord - _minWorldCoord));
const float max_scale = GlobalXYWnd().maxZoomFactor();
const float fZoom = pow(5.0f / 4.0f, steps);
const float scale = getScale() * fZoom;

if (scale > max_scale)
{
return max_scale;
}

if (scale < min_scale)
{
return min_scale;
}

return scale;
}

void XYWnd::zoomOut()
{
setScale( getZoomedScale( -1 ) );
}

void XYWnd::zoomIn()
{
float max_scale = GlobalXYWnd().maxZoomFactor();
float scale = getScale() * 5.0f / 4.0f;
setScale( getZoomedScale( 1 ) );
}

if (scale > max_scale) {
if (getScale() != max_scale) {
setScale(max_scale);
}
}
else {
setScale(scale);
}
void XYWnd::zoomInOn( wxPoint cursor, int zoom ) {
const float oldScale = _scale;
const float newScale = getZoomedScale( zoom );
scroll( cursor.x - _width/2, _height / 2 - cursor.y );
setScale( newScale );
scroll( ( _width / 2 - cursor.x ) * oldScale / newScale, ( cursor.y - _height / 2 ) * oldScale / newScale );
}

// ================ CALLBACKS ======================================
Expand Down Expand Up @@ -1621,6 +1631,9 @@ bool XYWnd::onRender()

void XYWnd::onGLWindowScroll(wxMouseEvent& ev)
{
if ( !ev.ShiftDown() ) {
zoomInOn( ev.GetPosition(), ev.GetWheelRotation() / ev.GetWheelDelta() );
}
if (ev.GetWheelRotation() > 0)
{
zoomIn();
Expand Down
2 changes: 2 additions & 0 deletions radiant/xyview/XYWnd.h
Expand Up @@ -135,6 +135,7 @@ class XYWnd :

void zoomIn() override;
void zoomOut() override;
void zoomInOn( wxPoint cursor, int zoom );

void setActive(bool b);
bool isActive() const;
Expand Down Expand Up @@ -177,6 +178,7 @@ class XYWnd :
void onContextMenu();
void drawSizeInfo(int nDim1, int nDim2, const Vector3& vMinBounds, const Vector3& vMaxBounds);
void drawCameraIcon();
float getZoomedScale(int steps);

// callbacks
bool checkChaseMouse(unsigned int state);
Expand Down

0 comments on commit ffdcf5f

Please sign in to comment.