Skip to content

Commit

Permalink
#5140: Fix ToggleFullscreenCamera in Regular and Regular Left layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Apr 23, 2020
1 parent bd5abee commit 92b8276
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 34 deletions.
53 changes: 22 additions & 31 deletions radiant/ui/mainframe/RegularLayout.cpp
Expand Up @@ -21,7 +21,6 @@ namespace ui
namespace
{
const std::string RKEY_REGULAR_ROOT = "user/ui/mainFrame/regular";
const std::string RKEY_REGULAR_TEMP_ROOT = RKEY_REGULAR_ROOT + "/temp";
}

RegularLayout::RegularLayout(bool regularLeft) :
Expand All @@ -30,7 +29,7 @@ RegularLayout::RegularLayout(bool regularLeft) :

std::string RegularLayout::getName()
{
return REGULAR_LAYOUT_NAME;
return _regularLeft ? REGULAR_LEFT_LAYOUT_NAME : REGULAR_LAYOUT_NAME;
}

void RegularLayout::activate()
Expand Down Expand Up @@ -132,31 +131,6 @@ void RegularLayout::deactivate()
_regular.texCamPane = nullptr;
}

void RegularLayout::maximiseCameraSize()
{
// Save the current state to the registry
saveStateToPath(RKEY_REGULAR_TEMP_ROOT);

// Maximise the camera
if (_regularLeft)
{
_regular.horizPane->SetSashPosition(0);
}
else
{
_regular.horizPane->SetSashPosition(2000000);
}
}

void RegularLayout::restorePanePositions()
{
// Restore state
restoreStateFromPath(RKEY_REGULAR_TEMP_ROOT);

// Remove all previously stored pane information
GlobalRegistry().deleteXPath(RKEY_REGULAR_TEMP_ROOT);
}

void RegularLayout::restoreStateFromPath(const std::string& path)
{
// Trigger a proper resize event before setting the sash position
Expand Down Expand Up @@ -191,14 +165,31 @@ void RegularLayout::saveStateToPath(const std::string& path)

void RegularLayout::toggleFullscreenCameraView()
{
if (GlobalRegistry().keyExists(RKEY_REGULAR_TEMP_ROOT))
if (_savedPositions)
{
restorePanePositions();
_regular.horizPane->SetSashPosition(_savedPositions->horizPanePosition);
_regular.texCamPane->SetSashPosition(_savedPositions->texCamPanePosition);

_savedPositions.reset();
}
else
{
// No saved info found in registry, maximise cam
maximiseCameraSize();
_savedPositions.reset(new SavedPositions{
_regular.horizPane->GetSashPosition(),
_regular.texCamPane->GetSashPosition()
});

// Maximise the camera
if (_regularLeft)
{
_regular.horizPane->SetSashPosition(2000000); // wx will cap this
_regular.texCamPane->SetSashPosition(2000000);
}
else
{
_regular.horizPane->SetSashPosition(1);
_regular.texCamPane->SetSashPosition(2000000);
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions radiant/ui/mainframe/RegularLayout.h
Expand Up @@ -33,6 +33,13 @@ class RegularLayout :
// Whether the cam is left or right
bool _regularLeft;

struct SavedPositions
{
int horizPanePosition;
int texCamPanePosition;
};
std::unique_ptr<SavedPositions> _savedPositions;

// Pass the exact type (left/right) to the constructor
RegularLayout(bool regularLeft);

Expand All @@ -49,9 +56,6 @@ class RegularLayout :
static RegularLayoutPtr CreateRegularInstance();

private:
void maximiseCameraSize();
void restorePanePositions();

// Saves the state of this window layout to the given XMLRegistry path (without trailing slash)
void restoreStateFromPath(const std::string& path);
void saveStateToPath(const std::string& path);
Expand Down

0 comments on commit 92b8276

Please sign in to comment.