Skip to content

Commit

Permalink
#5537: Since the ParticlePreview isn't a wxWindow itself, add a GetPr…
Browse files Browse the repository at this point in the history
…eviewWidget method to the IDeclarationPreview interface.
  • Loading branch information
codereader committed Sep 17, 2022
1 parent e21d25e commit 264995a
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 29 deletions.
5 changes: 5 additions & 0 deletions include/ui/ideclpreview.h
Expand Up @@ -2,6 +2,8 @@

#include <string>

class wxWindow;

namespace ui
{

Expand All @@ -15,6 +17,9 @@ class IDeclarationPreview
public:
virtual ~IDeclarationPreview() {}

// Returns the widget that can be packed into the selector container
virtual wxWindow* GetPreviewWidget() = 0;

// Clear the preview
virtual void ClearPreview() = 0;

Expand Down
5 changes: 5 additions & 0 deletions libs/wxutil/preview/ParticlePreview.cpp
Expand Up @@ -78,6 +78,11 @@ ParticlePreview::~ParticlePreview()
ev->disconnectToolItem(_reloadButton);
}

wxWindow* ParticlePreview::GetPreviewWidget()
{
return _mainPanel;
}

void ParticlePreview::ClearPreview()
{
SetPreviewDeclName({});
Expand Down
2 changes: 2 additions & 0 deletions libs/wxutil/preview/ParticlePreview.h
Expand Up @@ -42,6 +42,8 @@ class ParticlePreview :

~ParticlePreview();

wxWindow* GetPreviewWidget() override;

void ClearPreview() override;

/**
Expand Down
26 changes: 12 additions & 14 deletions radiant/ui/common/DeclarationSelector.cpp
Expand Up @@ -37,32 +37,30 @@ DeclarationSelector::DeclarationSelector(wxWindow* parent, decl::Type declType,
// a preview widget can be appended to the vertical sizer => AddPreviewToBottom
}

void DeclarationSelector::AddPreviewToRightPane(wxWindow* preview, int sizerProportion)
void DeclarationSelector::AddPreviewToRightPane(IDeclarationPreview* preview, int sizerProportion)
{
auto widget = preview->GetPreviewWidget();

// Tree view no longer takes full proportion after a full-size preview has been added
if (sizerProportion == 1)
{
_treeViewSizerItem->SetProportion(0);
}

preview->Reparent(this);
_horizontalSizer->Add(preview, sizerProportion, wxEXPAND | wxLEFT, 6);
widget->Reparent(this);
_horizontalSizer->Add(widget, sizerProportion, wxEXPAND | wxLEFT, 6);

if (auto declPreview = dynamic_cast<IDeclarationPreview*>(preview); declPreview)
{
_previews.push_back(declPreview);
}
_previews.push_back(preview);
}

void DeclarationSelector::AddPreviewToBottom(wxWindow* preview, int sizerProportion)
void DeclarationSelector::AddPreviewToBottom(IDeclarationPreview* preview, int sizerProportion)
{
preview->Reparent(this);
GetSizer()->Add(preview, sizerProportion, wxEXPAND | wxTOP, 3);
auto widget = preview->GetPreviewWidget();

if (auto declPreview = dynamic_cast<IDeclarationPreview*>(preview); declPreview)
{
_previews.push_back(declPreview);
}
widget->Reparent(this);
GetSizer()->Add(widget, sizerProportion, wxEXPAND | wxTOP, 3);

_previews.push_back(preview);
}

void DeclarationSelector::createTreeView()
Expand Down
4 changes: 2 additions & 2 deletions radiant/ui/common/DeclarationSelector.h
Expand Up @@ -57,8 +57,8 @@ class DeclarationSelector :
wxutil::DeclarationTreeView* GetTreeView() const;

// Adds a preview widget to the right of the tree view
void AddPreviewToRightPane(wxWindow* preview, int sizerProportion = 1);
void AddPreviewToBottom(wxWindow* preview, int sizerProportion = 0);
void AddPreviewToRightPane(IDeclarationPreview* preview, int sizerProportion = 1);
void AddPreviewToBottom(IDeclarationPreview* preview, int sizerProportion = 0);

const wxutil::DeclarationTreeView::Columns& GetColumns() const;

Expand Down
5 changes: 5 additions & 0 deletions radiant/ui/common/SoundShaderPreview.h
Expand Up @@ -74,6 +74,11 @@ class SoundShaderPreview :

~SoundShaderPreview() override;

wxWindow* GetPreviewWidget() override
{
return this;
}

void ClearPreview() override;

/**
Expand Down
5 changes: 5 additions & 0 deletions radiant/ui/common/TexturePreviewCombo.h
Expand Up @@ -45,6 +45,11 @@ class TexturePreviewCombo :
*/
TexturePreviewCombo(wxWindow* parent);

wxWindow* GetPreviewWidget() override
{
return this;
}

void ClearPreview() override;

/** Set the texture to preview.
Expand Down
12 changes: 1 addition & 11 deletions radiant/ui/particles/ParticleSelector.cpp
Expand Up @@ -10,7 +10,7 @@ ParticleSelector::ParticleSelector(wxWindow* parent) :
DeclarationSelector(parent, decl::Type::Particle),
_preview(new wxutil::ParticlePreview(this))
{
AddPreviewToRightPane(_preview->getWidget());
AddPreviewToRightPane(_preview.get());

GlobalParticlesManager().signal_particlesReloaded().connect(
sigc::mem_fun(this, &ParticleSelector::reloadParticles)
Expand Down Expand Up @@ -39,14 +39,4 @@ void ParticleSelector::SetSelectedParticle(const std::string& particleName)
GetTreeView()->SetSelectedFullname(particleName);
}

void ParticleSelector::onTreeViewSelectionChanged()
{
auto selectedParticle = GetSelectedParticle();

if (!selectedParticle.empty())
{
_preview->SetPreviewDeclName(selectedParticle);
}
}

}
2 changes: 0 additions & 2 deletions radiant/ui/particles/ParticleSelector.h
Expand Up @@ -28,8 +28,6 @@ class ParticleSelector :
std::string GetSelectedParticle();
void SetSelectedParticle(const std::string& particleName);

void onTreeViewSelectionChanged() override;

private:
// Populate the list of particles
void populateParticleList();
Expand Down

0 comments on commit 264995a

Please sign in to comment.