Skip to content

Commit

Permalink
#4764: Experimentally place a popup containing the thumbnails next to…
Browse files Browse the repository at this point in the history
… the media browser
  • Loading branch information
codereader committed Nov 6, 2022
1 parent 8b6c608 commit 7555819
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
33 changes: 33 additions & 0 deletions radiant/ui/mediabrowser/MediaBrowser.cpp
@@ -1,5 +1,7 @@
#include "MediaBrowser.h"

#include <wx/display.h>

#include "ideclmanager.h"
#include "imap.h"
#include "ishaders.h"
Expand All @@ -8,13 +10,15 @@
#include "wxutil/dataview/ResourceTreeViewToolbar.h"

#include <wx/sizer.h>
#include <wx/popupwin.h>

#include "util/ScopedBoolLock.h"
#include "ui/texturebrowser/TextureBrowserManager.h"
#include "ui/common/TexturePreviewCombo.h"

#include "FocusMaterialRequest.h"
#include "ui/UserInterfaceModule.h"
#include "ui/texturebrowser/TextureDirectoryBrowser.h"

namespace ui
{
Expand Down Expand Up @@ -190,6 +194,35 @@ void MediaBrowser::_onTreeViewSelectionChanged(wxDataViewEvent& ev)
else
{
_preview->ClearPreview();

// When a directory is selected, open the popup
auto popup = new wxPopupTransientWindow(this);

popup->SetSizer(new wxBoxSizer(wxVERTICAL));

auto browser = new TextureDirectoryBrowser(popup, _treeView->GetSelectedFullname());
//browser->SetMinSize(size);

wxPoint posScreen;
wxSize sizeScreen;

const int displayNum = wxDisplay::GetFromPoint(GetScreenPosition());
if ( displayNum != wxNOT_FOUND )
{
wxRect rectScreen = wxDisplay(displayNum).GetGeometry();
posScreen = rectScreen.GetPosition();
sizeScreen = rectScreen.GetSize();
}

// From the upper edge of the mediabrowser to the bottom of the screen (minus a few pixels)
wxSize size(600, (posScreen.y + sizeScreen.y) - GetScreenPosition().y - 40);

popup->GetSizer()->Add(browser, 1, wxEXPAND);
popup->SetPosition(this->GetScreenRect().GetRightTop());
popup->SetSize(size);
popup->Layout();
//popup->Position(this->GetScreenRect().GetRightTop(), size);
popup->Popup();
}

sendSelectionToShaderClipboard();
Expand Down
7 changes: 6 additions & 1 deletion radiant/ui/texturebrowser/TextureDirectoryBrowser.h
Expand Up @@ -2,6 +2,7 @@

#include "ishaders.h"
#include "TextureThumbnailBrowser.h"
#include "os/path.h"

namespace ui
{
Expand All @@ -18,7 +19,7 @@ class TextureDirectoryBrowser :
public:
TextureDirectoryBrowser(wxWindow* parent, const std::string& texturePath) :
TextureThumbnailBrowser(parent),
_texturePath(texturePath)
_texturePath(os::standardPathWithSlash(texturePath))
{}

protected:
Expand All @@ -29,6 +30,10 @@ class TextureDirectoryBrowser :
// Check if this material is matching the prefix
if (!string::istarts_with(name, _texturePath)) return;

// Ignore any subdirectories, just direct leafs
auto partAfterPrefix = name.substr(_texturePath.length());
if (partAfterPrefix.find('/') != std::string::npos) return;

createTileForMaterial(GlobalMaterialManager().getMaterial(name));
});
}
Expand Down

0 comments on commit 7555819

Please sign in to comment.