1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
|
/*!
@file
@author George Evmenov
@date 08/2009
*/
#include "DemoKeeper.h"
#include "Base/Main.h"
#include "BaseLayout/BaseLayout.h"
#include "TreeControl.h"
#include "TreeControlItem.h"
#include "FileSystemInfo/FileSystemInfo.h"
// рутовая папка всей медиа
static MyGUI::UString gMediaBase;
using PairFileInfo = std::pair<std::wstring, common::FileInfo>;
class SampleLayout : public wraps::BaseLayout
{
public:
SampleLayout();
void notifyTreeNodePrepare(MyGUI::TreeControl* pTreeControl, MyGUI::TreeControl::Node* pNode);
MyGUI::UString getPath(MyGUI::TreeControl::Node* pNode) const;
private:
MyGUI::TreeControl* mpResourcesTree;
};
static SampleLayout* mSampleLayout;
SampleLayout::SampleLayout() :
BaseLayout("SampleLayout.layout")
{
assignWidget(mpResourcesTree, "ResourcesTree");
mpResourcesTree->eventTreeNodePrepare += newDelegate(this, &SampleLayout::notifyTreeNodePrepare);
MyGUI::TreeControl::Node* pRoot = mpResourcesTree->getRoot();
/*#ifdef MYGUI_OGRE_PLATFORM
Ogre::ArchiveManager::ArchiveMapIterator ArchiveIterator = Ogre::ArchiveManager::getSingleton().getArchiveIterator();
while (ArchiveIterator.hasMoreElements())
{
Ogre::Archive* pArchive = ArchiveIterator.getNext();
MyGUI::TreeControl::Node* pNode = new MyGUI::TreeControl::Node(pArchive->getName(), "Data");
pNode->setData(pArchive);
pRoot->add(pNode);
}
#else*/
common::VectorFileInfo result;
common::getSystemFileList(result, gMediaBase, L"*.*");
for (auto& item : result)
{
if (item.name == L".." || item.name == L".")
continue;
MyGUI::TreeControl::Node* pNode = new MyGUI::TreeControl::Node(item.name, "Data");
pNode->setData(PairFileInfo(gMediaBase, item));
pRoot->add(pNode);
}
//#endif
}
void SampleLayout::notifyTreeNodePrepare(MyGUI::TreeControl* pTreeControl, MyGUI::TreeControl::Node* pNode)
{
if (pNode == pTreeControl->getRoot())
return;
pNode->removeAll();
/*#ifdef MYGUI_OGRE_PLATFORM
Ogre::Archive* pArchive = *(pNode->getData<Ogre::Archive*>());
MyGUI::UString strPath(getPath(pNode));
Ogre::StringVectorPtr Resources = pArchive->find(strPath + "*", false, true);
for (Ogre::StringVector::iterator Iterator = Resources->begin(); Iterator != Resources->end(); ++Iterator)
{
MyGUI::TreeControl::Node* pChild = new MyGUI::TreeControl::Node(*Iterator, "Folder");
pChild->setData(pArchive);
pNode->add(pChild);
}
Resources = pArchive->find(strPath + "*", false, false);
for (Ogre::StringVector::iterator Iterator = Resources->begin(); Iterator != Resources->end(); ++Iterator)
{
MyGUI::UString strName(*Iterator);
MyGUI::UString strExtension;
size_t nPosition = strName.rfind(".");
if (nPosition != MyGUI::UString::npos)
{
strExtension = strName.substr(nPosition + 1);
std::transform(strExtension.begin(), strExtension.end(), strExtension.begin(), tolower);
}
MyGUI::UString strImage;
if (strExtension == "png" || strExtension == "tif" || strExtension == "tiff" || strExtension == "jpg" || strExtension == "jpeg")
strImage = "Image";
else
if (strExtension == "mat" || strExtension == "material")
strImage = "Material";
else
if (strExtension == "layout")
strImage = "Layout";
else
if (strExtension == "ttf" || strExtension == "font" || strExtension == "fontdef")
strImage = "Font";
else
if (strExtension == "txt" || strExtension == "text")
strImage = "Text";
else
if (strExtension == "xml")
strImage = "XML";
else
if (strExtension == "mesh")
strImage = "Mesh";
else
if (strExtension == "htm" || strExtension == "html")
strImage = "HTML";
else
strImage = "Unknown";
MyGUI::TreeControl::Node* pChild = new MyGUI::TreeControl::Node(strName, strImage);
pChild->setPrepared(true);
pNode->add(pChild);
}
#else*/
PairFileInfo info = *(pNode->getData<PairFileInfo>());
// если папка, то добавляем детей
if (info.second.folder)
{
std::wstring path = info.first + L"/" + info.second.name;
common::VectorFileInfo result;
common::getSystemFileList(result, path, L"*.*");
for (auto& item : result)
{
if (item.name == L".." || item.name == L".")
continue;
if (item.folder)
{
MyGUI::TreeControl::Node* pChild = new MyGUI::TreeControl::Node(item.name, "Folder");
pChild->setData(PairFileInfo(path, item));
pNode->add(pChild);
}
else
{
MyGUI::UString strName(item.name);
std::string strExtension;
size_t nPosition = strName.rfind(".");
if (nPosition != MyGUI::UString::npos)
{
strExtension = strName.substr(nPosition + 1);
std::transform(
strExtension.begin(),
strExtension.end(),
strExtension.begin(),
[](unsigned char c) { return tolower(c); });
}
MyGUI::UString strImage;
if (strExtension == "png" || strExtension == "tif" || strExtension == "tiff" || strExtension == "jpg" ||
strExtension == "jpeg")
strImage = "Image";
else if (strExtension == "mat" || strExtension == "material")
strImage = "Material";
else if (strExtension == "layout")
strImage = "Layout";
else if (strExtension == "ttf" || strExtension == "font" || strExtension == "fontdef")
strImage = "Font";
else if (strExtension == "txt" || strExtension == "text")
strImage = "Text";
else if (strExtension == "xml")
strImage = "XML";
else if (strExtension == "mesh")
strImage = "Mesh";
else if (strExtension == "htm" || strExtension == "html")
strImage = "HTML";
else
strImage = "Unknown";
MyGUI::TreeControl::Node* pChild = new MyGUI::TreeControl::Node(item.name, strImage);
pChild->setPrepared(true);
pNode->add(pChild);
}
}
}
//#endif
}
MyGUI::UString SampleLayout::getPath(MyGUI::TreeControl::Node* pNode) const
{
if (!pNode || pNode == mpResourcesTree->getRoot())
return {};
MyGUI::UString strPath;
while (pNode->getParent() != mpResourcesTree->getRoot())
{
strPath = pNode->getText() + "/" + strPath;
pNode = pNode->getParent();
}
return strPath;
}
namespace demo
{
void DemoKeeper::setupResources()
{
base::BaseManager::setupResources();
addResourceLocation(getRootMedia() + "/UnitTests/UnitTest_TreeControl");
addResourceLocation(getRootMedia() + "/Common/Tools");
gMediaBase = getRootMedia();
}
void DemoKeeper::createScene()
{
base::BaseDemoManager::createScene();
MyGUI::FactoryManager& factory = MyGUI::FactoryManager::getInstance();
const std::string& widgetCategory = MyGUI::WidgetManager::getInstance().getCategoryName();
factory.registerFactory<MyGUI::TreeControl>(widgetCategory);
factory.registerFactory<MyGUI::TreeControlItem>(widgetCategory);
MyGUI::ResourceManager::getInstance().load("FrameworkFonts.xml");
MyGUI::ResourceManager::getInstance().load("TreeControlSkin.xml");
MyGUI::ResourceManager::getInstance().load("TreeControlTemplate.xml");
mSampleLayout = new SampleLayout();
}
void DemoKeeper::destroyScene()
{
delete mSampleLayout;
mSampleLayout = nullptr;
MyGUI::FactoryManager& factory = MyGUI::FactoryManager::getInstance();
const std::string& widgetCategory = MyGUI::WidgetManager::getInstance().getCategoryName();
factory.unregisterFactory<MyGUI::TreeControl>(widgetCategory);
factory.unregisterFactory<MyGUI::TreeControlItem>(widgetCategory);
}
} // namespace demo
MYGUI_APP(demo::DemoKeeper)
|