Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions src/gui/wxgui/EmulatedUSBDevices/EmulatedUSBDeviceFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,55 @@ EmulatedUSBDeviceFrame::EmulatedUSBDeviceFrame(wxWindow* parent)
auto& config = GetConfig();

auto* sizer = new wxBoxSizer(wxVERTICAL);
auto* notebook = new wxNotebook(this, wxID_ANY);

notebook->AddPage(AddSkylanderPage(notebook), _("Skylanders Portal"));
notebook->AddPage(AddInfinityPage(notebook), _("Infinity Base"));
notebook->AddPage(AddDimensionsPage(notebook), _("Dimensions Toypad"));
m_notebook = new wxNotebook(this, wxID_ANY);

m_notebook->AddPage(AddSkylanderPage(m_notebook), _("Skylanders Portal"));
m_notebook->AddPage(AddInfinityPage(m_notebook), _("Infinity Base"));
m_notebook->AddPage(AddDimensionsPage(m_notebook), _("Dimensions Toypad"));
m_notebook->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, [this](wxBookCtrlEvent& event) {
UpdateWindowSizeForCurrentPage();
event.Skip();
});

sizer->Add(notebook, 1, wxEXPAND | wxALL, 2);
sizer->Add(m_notebook, 1, wxEXPAND | wxALL, 2);

SetSizerAndFit(sizer);
SetSizer(sizer);
sizer->Fit(this);
m_notebook->SetFitToCurrentPage(true);
UpdateWindowSizeForCurrentPage();
Layout();
Centre(wxBOTH);
}

EmulatedUSBDeviceFrame::~EmulatedUSBDeviceFrame() {}

void EmulatedUSBDeviceFrame::UpdateWindowSizeForCurrentPage()
{
if (!m_notebook || !GetSizer())
return;

m_notebook->InvalidateBestSize();

wxSize frameSize = GetSize();
const wxSize minSize = GetSizer()->ComputeFittingWindowSize(this);
SetMinSize(minSize);
bool shouldGrow = false;

if (frameSize.x < minSize.x)
{
frameSize.x = minSize.x;
shouldGrow = true;
}
if (frameSize.y < minSize.y)
{
frameSize.y = minSize.y;
shouldGrow = true;
}

if (shouldGrow)
SetSize(frameSize);
}

wxPanel* EmulatedUSBDeviceFrame::AddSkylanderPage(wxNotebook* notebook)
{
auto* panel = new wxPanel(notebook);
Expand Down Expand Up @@ -177,7 +211,6 @@ wxBoxSizer* EmulatedUSBDeviceFrame::AddSkylanderRow(uint8 rowNumber, wxStaticBox
m_skylanderSlots[rowNumber] =
new wxTextCtrl(box, wxID_ANY, _("None"), wxDefaultPosition, wxDefaultSize,
wxTE_READONLY);
m_skylanderSlots[rowNumber]->SetMinSize(wxSize(150, -1));
m_skylanderSlots[rowNumber]->Disable();
row->Add(m_skylanderSlots[rowNumber], 1, wxEXPAND | wxALL, 2);
auto* loadButton = new wxButton(box, wxID_ANY, _("Load"));
Expand Down Expand Up @@ -207,7 +240,6 @@ wxBoxSizer* EmulatedUSBDeviceFrame::AddInfinityRow(wxString name, uint8 rowNumbe
m_infinitySlots[rowNumber] =
new wxTextCtrl(box, wxID_ANY, _("None"), wxDefaultPosition, wxDefaultSize,
wxTE_READONLY);
m_infinitySlots[rowNumber]->SetMinSize(wxSize(150, -1));
m_infinitySlots[rowNumber]->Disable();
row->Add(m_infinitySlots[rowNumber], 1, wxALL | wxEXPAND, 5);
auto* loadButton = new wxButton(box, wxID_ANY, _("Load"));
Expand Down
4 changes: 3 additions & 1 deletion src/gui/wxgui/EmulatedUSBDevices/EmulatedUSBDeviceFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class EmulatedUSBDeviceFrame : public wxFrame
std::array<std::optional<uint32>, 7> GetCurrentMinifigs();

private:
wxNotebook* m_notebook = nullptr;
wxCheckBox* m_emulatePortal;
wxCheckBox* m_emulateBase;
wxCheckBox* m_emulateToypad;
Expand All @@ -40,6 +41,7 @@ class EmulatedUSBDeviceFrame : public wxFrame
wxBoxSizer* AddSkylanderRow(uint8 row_number, wxStaticBox* box);
wxBoxSizer* AddInfinityRow(wxString name, uint8 row_number, wxStaticBox* box);
wxBoxSizer* AddDimensionPanel(uint8 pad, uint8 index, wxStaticBox* box);
void UpdateWindowSizeForCurrentPage();
void LoadSkylander(uint8 slot);
void LoadSkylanderPath(uint8 slot, wxString path);
void CreateSkylander(uint8 slot);
Expand Down Expand Up @@ -99,4 +101,4 @@ class MoveDimensionFigureDialog : public wxDialog

private:
wxBoxSizer* AddMinifigSlot(uint8 pad, uint8 index, uint8 oldIndex, std::optional<uint32> currentId);
};
};