Skip to content

Commit

Permalink
#5527: Handle art provider (de-)registration in the LocalBitmapArtPro…
Browse files Browse the repository at this point in the history
…vider class itself
  • Loading branch information
codereader committed Feb 7, 2021
1 parent 4021f23 commit 751d8f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
17 changes: 13 additions & 4 deletions radiant/uimanager/LocalBitmapArtProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@ namespace ui
* bitmaps used in toolbars and other controls. The schema for these custom ArtIDs
* is "darkradiant:filename.png" where filename.png is a file in DR's bitmap folder.
*/
class LocalBitmapArtProvider :
class LocalBitmapArtProvider final :
public wxArtProvider
{
public:
LocalBitmapArtProvider()
{
wxArtProvider::Push(this);
}

~LocalBitmapArtProvider()
{
wxArtProvider::Remove(this);
}

wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size)
{
std::string filename(id.begin(), id.end()); // convert wxString to std::string

const std::string& prefix = ArtIdPrefix();
auto filename = id.ToStdString();
const auto& prefix = ArtIdPrefix();

if (string::starts_with(filename, prefix))
{
Expand Down
6 changes: 2 additions & 4 deletions radiant/uimanager/UIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ void UIManager::clear()
_dialogManager.reset();

wxFileSystem::CleanUpHandlers();
wxArtProvider::Delete(_bitmapArtProvider);
_bitmapArtProvider = nullptr;
_bitmapArtProvider.reset();
}

const std::string& UIManager::ArtIdPrefix() const
Expand Down Expand Up @@ -68,8 +67,7 @@ void UIManager::initialiseModule(const IApplicationContext& ctx)
{
rMessage() << getName() << "::initialiseModule called" << std::endl;

_bitmapArtProvider = new LocalBitmapArtProvider();
wxArtProvider::Push(_bitmapArtProvider);
_bitmapArtProvider.reset(new LocalBitmapArtProvider());

_dialogManager = std::make_shared<DialogManager>();

Expand Down
6 changes: 1 addition & 5 deletions radiant/uimanager/UIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ class UIManager :
// called before the main window is ready.
DialogManagerPtr _dialogManager;

LocalBitmapArtProvider* _bitmapArtProvider;
std::unique_ptr<LocalBitmapArtProvider> _bitmapArtProvider;

public:
UIManager() :
_bitmapArtProvider(nullptr)
{}

IGroupDialog& getGroupDialog() override;

IDialogManager& getDialogManager() override;
Expand Down

0 comments on commit 751d8f9

Please sign in to comment.