Code: Select all
IconBrowser::IconBrowser(Mainframe* parent)
: wxFrame(parent, wxID_ANY, _("Select the icon to insert..."), wxDefaultPosition, wxSize(300,400)),
m_selected_icon(-1), m_notebook(NULL), m_mainframe(parent)
{
wxArrayString all_dirs;
// Prevent the warnings about the not proper png
wxLogNull noLog;
// Create Notebook
m_notebook = new wxNotebook(this, wxID_ANY);
// Get all directories
MyDirTraverser traverser(all_dirs);
wxDir dir("icons");
if ( dir.IsOpened() )
{
dir.Traverse(traverser);
for ( size_t i = 0; i < all_dirs.GetCount(); i++ )
//for ( size_t i = 0; i < 1; i++ )
{
// Create new ListControl
wxListView* lstCtrl = new wxListView(m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, ASS_LIST_CTRL_STYLE);
wxFileName fn(all_dirs[i]);
m_notebook->AddPage(lstCtrl, fn.GetName());
// Show Progress
wxProgressDialog * progress = new wxProgressDialog (_("Please wait..."), _("Searching for Images.."), 1, this);
// Get Files
wxArrayString files;
wxDir::GetAllFiles(all_dirs[i], &files, "*.png", wxDIR_FILES);
// Create ImageList
wxSize size = wxStringToSize(fn.GetName());
wxImageList* images = new wxImageList(size.x, size.y, false, files.GetCount());
// Update Progress
progress->Update(1, _("Found all files.."));
wxDELETE(progress);
// New Dialog
progress = new wxProgressDialog (_("Please wait..."), _("Adding Images.."), files.GetCount(), this);
// Traversing files
for ( size_t i = 0; i < files.GetCount(); i++ )
{
// Getting the file
wxFileName f_source(files.Item(i));
f_source.MakeAbsolute();
// Updating progress
wxString msg;
msg << _("Processing: ") << i << "/" << files.GetCount() << ": " << f_source.GetFullName();
progress->Update(i, msg);
// Add into lists
wxString s_display = files.Item(i);
s_display.Replace("\\\", "/");
lstCtrl->InsertItem(i, s_display, i);
images->Add(wxBitmap(f_source.GetFullPath(), wxBITMAP_TYPE_PNG));
}
lstCtrl->AssignImageList(images, wxIMAGE_LIST_SMALL);
wxDELETE(progress);
}
}
else
{
wxMessageBox(_("Icons have not been imported yet!"), wxMessageBoxCaptionStr, wxICON_ERROR|wxOK, this);
}
}
Sorry for the wall of Source, but this is how I load my Images. Setting the initial size of wxImageList already helps a lot in loading my 7000 Icons into my IconBrowser, but I am not yet happy with the speed and time it takes to load it.
I hope anyone can help me in improving this.
I load all those icons into a browser, so the user is able to view them and select some to use it in the scripteditor for Anarchy Online. The Icons come from Anarchy Onlines database.
I appreciate any input .
regards