Skip to content

Commit

Permalink
Move DialogBase method bodies into a separate .cpp file
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mott committed Feb 25, 2020
1 parent ce08c7f commit a6c3540
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 50 deletions.
1 change: 1 addition & 0 deletions libs/wxutil/Makefile.am
Expand Up @@ -29,6 +29,7 @@ libwxutil_la_SOURCES = ConsoleView.cpp \
WindowPosition.cpp \
window/TransientWindow.cpp \
dialog/Dialog.cpp \
dialog/DialogBase.cpp \
dialog/MessageBox.cpp \
preview/ModelPreview.cpp \
preview/ParticlePreview.cpp \
Expand Down
46 changes: 46 additions & 0 deletions libs/wxutil/dialog/DialogBase.cpp
@@ -0,0 +1,46 @@
#include "DialogBase.h"

namespace wxutil
{

void DialogBase::_onDelete(wxCloseEvent& ev)
{
if (_onDeleteEvent())
{
ev.Veto();
}
else
{
EndModal(wxID_CANCEL);
}
}

DialogBase::DialogBase(const std::string& title, wxWindow* parent)
: wxDialog(parent ? parent : GlobalMainFrame().getWxTopLevelWindow(),
wxID_ANY, title, wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(DialogBase::_onDelete),
nullptr, this);
}

void DialogBase::FitToScreen(float xProp, float yProp)
{
int curDisplayIdx = 0;

if (GlobalMainFrame().getWxTopLevelWindow() != NULL)
{
curDisplayIdx = wxDisplay::GetFromWindow(GlobalMainFrame().getWxTopLevelWindow());
}

wxDisplay curDisplay(curDisplayIdx);

wxRect rect = curDisplay.GetGeometry();
int newWidth = static_cast<int>(rect.GetWidth() * xProp);
int newHeight = static_cast<int>(rect.GetHeight() * yProp);

SetSize(newWidth, newHeight);
CenterOnScreen();
}

}
70 changes: 20 additions & 50 deletions libs/wxutil/dialog/DialogBase.h
Expand Up @@ -11,65 +11,35 @@ namespace wxutil
{

/**
* \brief
* Base class for many DarkRadiant dialogs.
* It comes with a panel/sizer combination pre-populated, use
* the _mainPanel member to add more stuff.
*
* It comes with a panel/sizer combination pre-populated, use the _mainPanel
* member to add more stuff.
*/
class DialogBase :
public wxDialog
public wxDialog
{
private:
void _onDelete(wxCloseEvent& ev)
{
if (_onDeleteEvent())
{
ev.Veto();
}
else
{
EndModal(wxID_CANCEL);
}
}
void _onDelete(wxCloseEvent& ev);

public:
DialogBase(const std::string& title, wxWindow* parent = NULL) :
wxDialog(parent != NULL ? parent : GlobalMainFrame().getWxTopLevelWindow(),
wxID_ANY, title, wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(DialogBase::_onDelete), NULL, this);
}
/// Construct and initialise
DialogBase(const std::string& title, wxWindow* parent = NULL);

/**
* Adjust this window to fit the display DarkRadiant is currently (mainly) active on.
* Set the xProp and yProp factors to control how much space this window should use.
* The factors should be in the range (0.0..1.0], where 1.0 takes the entire space.
*/
void FitToScreen(float xProp, float yProp)
{
int curDisplayIdx = 0;

if (GlobalMainFrame().getWxTopLevelWindow() != NULL)
{
curDisplayIdx = wxDisplay::GetFromWindow(GlobalMainFrame().getWxTopLevelWindow());
}

wxDisplay curDisplay(curDisplayIdx);

wxRect rect = curDisplay.GetGeometry();
int newWidth = static_cast<int>(rect.GetWidth() * xProp);
int newHeight = static_cast<int>(rect.GetHeight() * yProp);

SetSize(newWidth, newHeight);
CenterOnScreen();
}
/**
* Adjust this window to fit the display DarkRadiant is currently (mainly)
* active on. Set the xProp and yProp factors to control how much space
* this window should use. The factors should be in the range (0.0..1.0],
* where 1.0 takes the entire space.
*/
void FitToScreen(float xProp, float yProp);

protected:
// Overrideable: return true to prevent the window from being deleted
virtual bool _onDeleteEvent()
{
return false;
}
// Overrideable: return true to prevent the window from being deleted
virtual bool _onDeleteEvent()
{
return false;
}
};

} // namespace

0 comments on commit a6c3540

Please sign in to comment.