Пример #1
0
void TextureCache::setConverted(const DAVA::TextureDescriptor *descriptor, DAVA::eGPUFamily gpu, DAVA::Vector<QImage>& images)
{
	if( NULL != descriptor && 
		gpu > DAVA::GPU_UNKNOWN && gpu < DAVA::GPU_FAMILY_COUNT)
	{
		DAVA::Vector<QImage> tmpImages;
		for(int i = 0; i < (int)images.size(); ++i)
		{
			tmpImages.push_back(images[i]);
		}

		cacheConverted[gpu][descriptor] = CacheEntity(tmpImages, curConvertedWeight[gpu]++);

		// reached max count
		if(cacheConverted[gpu].size() > maxConvertedCount)
		{
			int weightToRemove = curConvertedWeight[gpu] - maxConvertedCount;

			QMapIterator<const DAVA::TextureDescriptor*, CacheEntity> iter(cacheConverted[gpu]);
			while(iter.hasNext())
			{
				iter.next();
				if(iter.value().weight < weightToRemove)
				{
					cacheConverted[gpu].remove(iter.key());
				}
			}
		}
	}
}
Пример #2
0
void TextureCache::setOriginal(const DAVA::TextureDescriptor *descriptor, DAVA::Vector<QImage>& images)
{
	if(NULL != descriptor)
	{
		DAVA::Vector<QImage> tmpImages;
		for(size_t i = 0; i < images.size(); ++i)
		{
			tmpImages.push_back(images[i]);
		}
		
		cacheOriginal[descriptor] = CacheEntity(tmpImages, curOriginalWeight++);

		// reached max count
		if(cacheOriginal.size() > maxOrigCount)
		{
			int weightToRemove = curOriginalWeight - maxOrigCount;
			
			QMapIterator<const DAVA::TextureDescriptor*, CacheEntity> iter(cacheOriginal);
			while(iter.hasNext())
			{
				iter.next();
				if(iter.value().weight < weightToRemove)
				{
					cacheOriginal.remove(iter.key());
				}
			}
		}
	}
}
Пример #3
0
void FMODSoundBrowser::SelectItemAndExpandTreeByEventName(const DAVA::String & eventName)
{
    DAVA::Vector<DAVA::String> tokens;
    DAVA::Split(eventName, "/", tokens);
    DAVA::int32 tokensCount = tokens.size();
    QTreeWidgetItem * currentItem = ui->treeWidget->invisibleRootItem();
    for(DAVA::int32 i = 0; i < tokensCount; i++)
    {
        QString currentToken = QString(tokens[i].c_str());
        DAVA::int32 childrenCount = currentItem->childCount();
        QTreeWidgetItem * findedItem = 0;
        for(DAVA::int32 k = 0; k < childrenCount; k++)
        {
            QTreeWidgetItem * currentChild = currentItem->child(k);
            if(currentChild->text(0) == currentToken)
            {
                findedItem = currentChild;
                findedItem->setExpanded(true);
                break;
            }
        }
        if(!findedItem)
            return;

        currentItem = findedItem;
    }
    currentItem->setSelected(true);
}
Пример #4
0
void HashMapTest::HashMapInsertRemoveGetTest(PerfFuncData * data)
{
	const int sz = 20000;
	DAVA::int32 i;
	DAVA::Vector<DAVA::uint32> vect;
	DAVA::HashMap<DAVA::int32, DAVA::uint32> map;
	
	vect.resize(sz);

	for(i = 0; i < sz; ++i)
	{
		DAVA::uint32 v = (i + 1); // any value
		vect[i] = v;
		map.Insert(i, v);
	}

	// Get test
	for(i = 0; i < sz; ++i)
	{
		TEST_VERIFY(vect[i] == map[i]);
	}

	// remove some items
	for (int i = 0; i < sz/10; i++)
	{
		int index = DAVA::Random::Instance()->Rand(sz);
		vect[i] = 0;
		map.Remove(i);
	}

	// check get after remove
	for (int i = 0; i < sz; i++)
	{
		if(0 != vect[i])
		{
			TEST_VERIFY(vect[i] == map[i]);
		}
	}

	// iterator test
	DAVA::HashMap<DAVA::int32, DAVA::uint32>::Iterator iter = map.Begin();
	for(; iter != map.End(); ++iter)
	{
		TEST_VERIFY(vect[iter.GetKey()] == iter.GetValue());
	}

	// 0-size hash map iterator test
	DAVA::HashMap<DAVA::int32, DAVA::uint32> map0;
	iter = map0.Begin();
	for (; iter != map0.End(); ++iter)
	{}
}
Пример #5
0
void FMODSoundBrowser::FillEventsTree(const DAVA::Vector<DAVA::String> & names)
{
    ui->treeWidget->clear();

    DAVA::int32 eventsCount = names.size();
    for(DAVA::int32 i = 0; i < eventsCount; i++)
    {
        const DAVA::String & eventPath = names[i];

        DAVA::Vector<DAVA::String> tokens;
        DAVA::Split(eventPath, "/", tokens);

        DAVA::int32 tokensCount = tokens.size();
        QTreeWidgetItem * currentItem = ui->treeWidget->invisibleRootItem();
        for(DAVA::int32 j = 0; j < tokensCount; j++)
        {
            QString currentToken = QString(tokens[j].c_str());
            DAVA::int32 childrenCount = currentItem->childCount();
            QTreeWidgetItem * findedItem = 0;
            for(DAVA::int32 k = 0; k < childrenCount; k++)
            {
                QTreeWidgetItem * currentChild = currentItem->child(k);
                if(currentChild->text(0) == currentToken)
                {
                    findedItem = currentChild;
                    break;
                }
            }

            bool isEvent = (j == tokensCount-1);

            if(findedItem == 0)
            {
                findedItem = new QTreeWidgetItem(currentItem);
                currentItem->addChild(findedItem);
                findedItem->setText(0, currentToken);

                if(isEvent)
                {
                    findedItem->setIcon(0, QIcon(":/QtIcons/sound.png"));
                    findedItem->setData(0, Qt::UserRole, QString(eventPath.c_str()));
                }
                else
                {
                    findedItem->setIcon(0, QIcon(":/QtIcons/sound_group.png"));
                }
            }
            currentItem = findedItem;
        }
    }
}
Пример #6
0
DAVA::Vector<String> RecentFilesManager::GetRecentFiles()
{
	DAVA::Vector<String> retVector;
	VariantType recentFilesVariant = SettingsManager::GetValue(Settings::Internal_RecentFiles);
	if(recentFilesVariant.GetType() == DAVA::VariantType::TYPE_KEYED_ARCHIVE)
	{
		KeyedArchive* archiveRecentFiles = recentFilesVariant.AsKeyedArchive();
		DAVA::uint32 size = archiveRecentFiles->Count();
		retVector.resize(size);
		for (DAVA::uint32 i = 0; i < size; ++i)
		{
			retVector[i] = archiveRecentFiles->GetString(Format("%d", i));
		}
		
	}
	return retVector;
}
bool CubeMapTextureBrowser::ValidateTextureAndFillThumbnails(DAVA::FilePath& fp,
									  DAVA::Vector<QImage*>& icons,
									  DAVA::Vector<QSize>& actualSize)
{
	bool result = true;
	
	int width = 0;
	int height = 0;
	DAVA::Vector<DAVA::String> faceNames;
	CubemapUtils::GenerateFaceNames(fp.GetAbsolutePathname(), faceNames);
	for(size_t i = 0; i < faceNames.size(); ++i)
	{
		QImage faceImage;
		if(!faceImage.load(faceNames[i].c_str())) //file must be present
		{
			result = false;
		}
	
		if(faceImage.width() != faceImage.height() || //file must be square and be power of 2
		   !IsPowerOf2(faceImage.width()))
		{
			result = false;
		}
				
		if(0 == i)
		{
			width = faceImage.width();
			height = faceImage.height();
		}
		else if(faceImage.width() != width || //all files should be the same size
				faceImage.height() != height)
		{
			result = false;
		}
		
		//scale image and put scaled version to an array
		QImage scaledFaceTemp = faceImage.scaled(FACE_IMAGE_SIZE, FACE_IMAGE_SIZE);
		QImage* scaledFace = new QImage(scaledFaceTemp);
		
		icons.push_back(scaledFace);
		actualSize.push_back(QSize(faceImage.width(), faceImage.height()));
	}
	
	return result;
}
Пример #8
0
int32 SceneHelper::EnumerateModifiedTextures(DAVA::Scene *forScene, DAVA::Map<DAVA::Texture *, DAVA::Vector< DAVA::eGPUFamily> > &textures)
{
	int32 retValue = 0;
	textures.clear();
	TexturesMap allTextures;
	EnumerateSceneTextures(forScene, allTextures, EXCLUDE_NULL);
	for(TexturesMap::iterator it = allTextures.begin(); it != allTextures.end(); ++it)
	{
		DAVA::Texture * texture = it->second;
		if(NULL == texture)
		{
			continue;
		}
		
		DAVA::TextureDescriptor *descriptor = texture->GetDescriptor();
		if(NULL == descriptor)
		{
			continue;
		}

		DVASSERT(descriptor->compression);

		DAVA::Vector< DAVA::eGPUFamily> markedGPUs;
		for(int i = 0; i < DAVA::GPU_DEVICE_COUNT; ++i)
		{
			eGPUFamily gpu = (eGPUFamily)i;
			if(GPUFamilyDescriptor::IsFormatSupported(gpu, (PixelFormat)descriptor->compression[gpu].format))
			{
				FilePath texPath = descriptor->GetSourceTexturePathname();
				if(texPath.Exists() && !descriptor->IsCompressedTextureActual(gpu))
				{
					markedGPUs.push_back(gpu);
					retValue++;
				}
			}
		}
		if(markedGPUs.size() > 0)
		{
			textures[texture] = markedGPUs;
		}
	}
	return retValue;
}
Пример #9
0
void TextureBrowser::updateInfoOriginal(const DAVA::Vector<QImage> &images)
{
	if(NULL != curTexture && NULL != curDescriptor)
	{
		char tmp[1024];

		const char *formatStr = DAVA::Texture::GetPixelFormatString(DAVA::FORMAT_RGBA8888);

		int datasize = 0;
		int filesize = 0;
		for(size_t i = 0; i < images.size(); ++i)
		{
			datasize += images[i].width() * images[i].height() * DAVA::Texture::GetPixelFormatSizeInBytes(DAVA::FORMAT_RGBA8888);
		}
		
		if(!curDescriptor->IsCubeMap())
		{
			filesize = QFileInfo(curDescriptor->GetSourceTexturePathname().GetAbsolutePathname().c_str()).size();
		}
		else
		{
			DAVA::Vector<DAVA::String> faceNames;
			CubemapUtils::GenerateFaceNames(curDescriptor->pathname.GetAbsolutePathname(), faceNames);
			for(size_t i = 0; i < faceNames.size(); ++i)
			{
				filesize += QFileInfo(faceNames[i].c_str()).size();
			}
		}
		
		sprintf(tmp, "Format\t: %s\nSize\t: %dx%d\nData size\t: %s\nFile size\t: %s", formatStr, images[0].width(), images[0].height(),
			 SizeInBytesToString(datasize).c_str(),
			 SizeInBytesToString(filesize).c_str());

		ui->labelOriginalFormat->setText(tmp);
	}
	else
	{
		ui->labelOriginalFormat->setText("");
	}
}
Пример #10
0
void SceneHelper::EnumerateMaterialInstances(DAVA::Entity *forNode, DAVA::Vector<DAVA::NMaterial *> &materials)
{
    uint32 childrenCount = forNode->GetChildrenCount();
    for(uint32 i = 0; i < childrenCount; ++i)
        EnumerateMaterialInstances(forNode->GetChild(i), materials);

    RenderObject * ro = GetRenderObject(forNode);
    if(!ro) return;
    
    uint32 batchCount = ro->GetRenderBatchCount();
    for(uint32 i = 0; i < batchCount; ++i)
        materials.push_back(ro->GetRenderBatch(i)->GetMaterial());

}
Пример #11
0
void RecentFilesManager::SetFileToRecent(const DAVA::String& file)
{
    DAVA::Vector<String> vectorToSave = GetRecentFiles();
    DAVA::FilePath filePath(file);
    DAVA::String stringToInsert = filePath.GetAbsolutePathname();
    //check present set to avoid duplicates
    vectorToSave.erase(std::remove(vectorToSave.begin(), vectorToSave.end(), stringToInsert), vectorToSave.end());
    
    vectorToSave.insert(vectorToSave.begin(), stringToInsert);

    uint32 recentFilesMaxCount = SettingsManager::GetValue(Settings::General_RecentFilesCount).AsInt32();

    DAVA::uint32 size = vectorToSave.size() > recentFilesMaxCount ? recentFilesMaxCount : vectorToSave.size();
    KeyedArchive* archive = new KeyedArchive();
    for (DAVA::uint32 i = 0; i < size; ++i)
    {
        archive->SetString(Format("%d",i), vectorToSave[i]);
    }
    SettingsManager::SetValue(Settings::Internal_RecentFiles, DAVA::VariantType(archive));
    SafeRelease( archive);
}
Пример #12
0
void SceneTreeItemEntity::DoSync(QStandardItem *rootItem, DAVA::Entity *entity)
{
	if(NULL != rootItem && NULL != entity)
	{
		DAVA::int32 i;
		QSet<DAVA::Entity *> entitiesSet;
		QSet<DAVA::ParticleLayer *> layersSet;

		DAVA::ParticleEmitter *emitter = DAVA::GetEmitter(entity);
		DAVA::Vector<DAVA::ParticleLayer*> *emitterLayers = NULL;

		// remember all entity childs
		for(i = 0; i < entity->GetChildrenCount(); ++i)
		{
			entitiesSet.insert(entity->GetChild(i));
		}

		// remember all particle layers
		if(NULL != emitter)
		{
			emitterLayers = &emitter->GetLayers();
			for(size_t i = 0; i < emitterLayers->size(); ++i)
			{
				layersSet.insert(emitterLayers->operator[](i));
			}
		}

		// remove items that are not in set
		for(int i = 0; i < rootItem->rowCount(); ++i)
		{
			bool doRemove = true;
			SceneTreeItem *childItem = (SceneTreeItem *) rootItem->child(i);

			if(childItem->ItemType() == SceneTreeItem::EIT_Entity)
			{
				SceneTreeItemEntity *entityItem = (SceneTreeItemEntity *) childItem;
				if(entitiesSet.contains(entityItem->entity))
				{
					doRemove = false;
				}
			}
			else if(childItem->ItemType() == SceneTreeItem::EIT_Layer)
			{
				SceneTreeItemParticleLayer *layerItem = (SceneTreeItemParticleLayer *) childItem;
				if(layersSet.contains(layerItem->layer))
				{
					doRemove = false;
				}
			}

			if(doRemove)
			{
				rootItem->removeRow(i);
				i--;
			}
		}

		entitiesSet.clear();
		layersSet.clear();

		// add entities
		int row = 0;

		for(int i = 0; i < entity->GetChildrenCount(); ++i)
		{
			bool repeatStep;
			DAVA::Entity *childEntity = entity->GetChild(i);

			do
			{
				SceneTreeItem *item = (SceneTreeItem *) rootItem->child(row);
				DAVA::Entity *itemEntity = SceneTreeItemEntity::GetEntity(item);

				repeatStep = false;

				// remove items that we already add
				while(entitiesSet.contains(itemEntity))
				{
					rootItem->removeRow(row);

					item = (SceneTreeItem *) rootItem->child(row);
					itemEntity = SceneTreeItemEntity::GetEntity(item);
				}

				// append entity that isn't in child items list
				if(NULL == item)
				{
					rootItem->appendRow(new SceneTreeItemEntity(childEntity));
				}
				else if(childEntity != itemEntity)
				{
					// now we should decide what to do: remove item or insert it

					// calc len until itemEntity will be found in real entity childs
					int lenUntilRealEntity = 0;
					for(int j = i; j < entity->GetChildrenCount(); ++j)
					{
						if(entity->GetChild(j) == itemEntity)
						{
							lenUntilRealEntity = j - i;
							break;
						}
					}

					// calc len until current real entity child will be found in current item childs
					int lenUntilItem = 0;
					for(int j = i; j < rootItem->rowCount(); ++j)
					{
						SceneTreeItem *itm = (SceneTreeItem *) rootItem->child(j);
						DAVA::Entity *itmEn = SceneTreeItemEntity::GetEntity(itm);

						if(childEntity == itmEn)
						{
							lenUntilItem = j - i;
							break;
						}
					}

					if(lenUntilRealEntity >= lenUntilItem)
					{
						rootItem->removeRow(row);
						repeatStep = true;
					}
					else
					{
						rootItem->insertRow(row, new SceneTreeItemEntity(childEntity));
					}
				}
				else
				{
					DoSync(item, itemEntity);
				}
			}
			while(repeatStep);

			// remember that we add that entity
			entitiesSet.insert(childEntity);

			row++;
		}

		// add layers
		if(NULL != emitterLayers)
		{
			for(size_t i = 0; i < emitterLayers->size(); ++i)
			{
				bool repeatStep;
				DAVA::ParticleLayer* childLayer = emitterLayers->operator[](i);

				do 
				{
					SceneTreeItem *item = (SceneTreeItem *) rootItem->child(row);
					DAVA::ParticleLayer *itemLayer = SceneTreeItemParticleLayer::GetLayer(item);

					repeatStep = false;

					// remove items that we already add
					while(layersSet.contains(itemLayer))
					{
						rootItem->removeRow(row);

						SceneTreeItem *item = (SceneTreeItem *) rootItem->child(row);
						DAVA::ParticleLayer *itemLayer = SceneTreeItemParticleLayer::GetLayer(item);
					}

					if(NULL == item)
					{
						rootItem->appendRow(new SceneTreeItemParticleLayer(emitter, childLayer));
					}
					else if(childLayer != itemLayer)
					{
						// now we should decide what to do: remove layer or insert it

						// calc len until itemEntity will be found in real
						int lenUntilRealLayer = 0;
						for(int j = i; j < (int) emitterLayers->size(); ++j)
						{
							if(emitterLayers->operator[](j) == itemLayer)
							{
								lenUntilRealLayer = j - i;
								break;
							}
						}

						// calc len until current real entity child will be found in current item childs
						int lenUntilItem = 0;
						for(int j = i; j < rootItem->rowCount(); ++j)
						{
							SceneTreeItem *itm = (SceneTreeItem *) rootItem->child(j);
							DAVA::ParticleLayer *itmLay = SceneTreeItemParticleLayer::GetLayer(itm);

							if(childLayer == itmLay)
							{
								lenUntilItem = j - i;
								break;
							}
						}

						if(lenUntilRealLayer >= lenUntilItem)
						{
							rootItem->removeRow(row);
							repeatStep = true;
						}
						else
						{
							rootItem->insertRow(row, new SceneTreeItemParticleLayer(emitter, childLayer));
						}
					}
					else
					{
						SceneTreeItemParticleLayer::DoSync(item, itemLayer);
					}
				} while (repeatStep);

				row++;
				layersSet.insert(childLayer);
			}
		}

		// remove all other rows
		if(row < rootItem->rowCount())
		{
			rootItem->removeRows(row, rootItem->rowCount() - row);
		}
	}
}
Пример #13
0
QWidget* ActionItemEditDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
					  const QModelIndex &index) const
{	
	QWidget* editor = NULL;
	switch(index.column())
	{
		case COLUMN_ACTION_TYPE:
		{
			QComboBox* combo = new QComboBox(parent);
			combo->setFrame(false);
			for(int i = 1; i < ACTION_NAME_COUNT - 1; ++i) //do not add sound aciton
			{
				combo->addItem(ACTION_TYPE_NAME[i]);
			}
			
			editor = combo;
			
			break;
		}
			
		case COLUMN_ENTITY_NAME:
		{
			DAVA::Entity* parentEntity = targetComponent->GetEntity();
			DAVA::Vector<DAVA::Entity*> allChildren;
			parentEntity->GetChildNodes(allChildren);

			DAVA::Vector<DAVA::String> childrenNames;
			childrenNames.push_back(parentEntity->GetName());
			for(int i = 0; i < allChildren.size(); ++i)
			{
				childrenNames.push_back(allChildren[i]->GetName());
			}
			
			std::sort(childrenNames.begin(), childrenNames.end());
			childrenNames.erase(std::unique(childrenNames.begin(), childrenNames.end()), childrenNames.end());
			
			QComboBox* combo = new QComboBox(parent);
			combo->setFrame(false);
			for(int i = 0; i < childrenNames.size(); ++i)
			{
				combo->addItem(childrenNames[i].c_str());
			}
			
			editor = combo;
			
			break;
		}
			
		case COLUMN_DELAY:
		{
			QDoubleSpinBox* spinBox = new QDoubleSpinBox(parent);
			spinBox->setMinimum(0.0f);
			spinBox->setMaximum(3600.f);
			spinBox->setSingleStep(0.01f);
			
			editor = spinBox;
			
			break;
		}
			
		case COLUMN_SWITCH_INDEX:
		{
			QSpinBox* spinBox = new QSpinBox(parent);
			spinBox->setMinimum(-1);
			spinBox->setMaximum(128);
			spinBox->setSingleStep(1);
			
			editor = spinBox;

			break;
		}
			
		case COLUMN_STOPAFTERNREPEATS_INDEX:
		{
			QSpinBox* spinBox = new QSpinBox(parent);
			spinBox->setMinimum(-1);
			spinBox->setMaximum(100000);
			spinBox->setSingleStep(1);
			
			editor = spinBox;
			
			break;
		}

		case COLUMN_STOPWHENEMPTY_INDEX:
		{
			QComboBox* combo = new QComboBox(parent);
			combo->setFrame(false);
			combo->addItem("Yes");
			combo->addItem("No");
			
			editor = combo;
			break;
		}
	}

	DVASSERT(editor);
	return editor;
}
Пример #14
0
void TextureBrowser::setTexture(DAVA::Texture *texture, DAVA::TextureDescriptor *descriptor)
{
	curTexture = texture;
	curDescriptor = descriptor;

	// color channels to default value
	ui->actionColorR->setChecked(true);
	ui->actionColorG->setChecked(true);
	ui->actionColorB->setChecked(true);
	ui->actionColorA->setChecked(true);
	ui->textureAreaOriginal->setColorChannel(TextureScrollArea::ChannelAll);
	ui->textureAreaConverted->setColorChannel(TextureScrollArea::ChannelAll);

	ui->textureAreaOriginal->resetTexturePosZoom();
	ui->textureAreaConverted->resetTexturePosZoom();
	toolbarZoomSlider->setValue(0);

	// disable texture views by default
	ui->textureAreaOriginal->setEnabled(false);
	ui->textureAreaConverted->setEnabled(false);
	ui->convertToolButton->setEnabled(false);

	// set texture to properties control.
	// this should be done as a first step
	ui->textureProperties->setTextureDescriptor(curDescriptor);
	ui->textureProperties->setTextureGPU(curTextureView);

	updatePropertiesWarning();

	// if texture is ok - set it and enable texture views
	if(NULL != curTexture)
	{
		// enable convert button
		ui->convertToolButton->setEnabled(true);

		// load original image
		// check if image is in cache
		DAVA::Vector<QImage> images = TextureCache::Instance()->getOriginal(curDescriptor);
		if(images.size() > 0 &&
		   !images[0].isNull())
		{
			// image is in cache, so set it immediately (by calling image-ready slot)
			textureReadyOriginal(curDescriptor, images);
		}
		else
		{
			// set empty info
			DAVA::Vector<QImage> emptyImages;
			emptyImages.push_back(QImage());
			updateInfoOriginal(emptyImages);

			// there is no image in cache - start loading it in different thread. image-ready slot will be called 
			ui->textureAreaOriginal->setImage(QImage());
			TextureConvertor::Instance()->GetOriginal(curDescriptor);

			// show loading bar
			ui->textureAreaOriginal->waitbarShow(true);
		}
	}
	else
	{
		// no texture - set empty images to original/PVR views
		ui->textureAreaOriginal->setImage(QImage());
		ui->textureAreaConverted->setImage(QImage());
	}
}
Пример #15
0
void CubeMapTextureBrowser::ReloadTextures(const DAVA::String& rootPath)
{	
	cubeListItemDelegate.ClearCache();
	ui->listTextures->clear();
	ui->listTextures->setVisible(false);
	ui->loadingWidget->setVisible(true);
	
	
	this->paintEvent(NULL);
	ui->loadingWidget->update();
	QApplication::processEvents();
	QApplication::flush();
	
	this->setUpdatesEnabled(false);

	QDir dir(rootPath.c_str());
	QStringList filesList = dir.entryList(QStringList("*.tex"));
	size_t cubemapTextures = 0;
	
	if(filesList.size() > 0)
	{
		DAVA::Vector<CubeListItemDelegate::ListItemInfo> cubemapList;
		FilePath fp = rootPath;
		for(int i = 0; i < filesList.size(); ++i)
		{
			QString str = filesList.at(i);
			fp.ReplaceFilename(str.toStdString());
			
			DAVA::TextureDescriptor* texDesc = DAVA::TextureDescriptor::CreateFromFile(fp);
			if(texDesc && texDesc->IsCubeMap())
			{
				CubeListItemDelegate::ListItemInfo itemInfo;
				itemInfo.path = fp;
				itemInfo.valid = ValidateTextureAndFillThumbnails(fp, itemInfo.icons, itemInfo.actualSize);
				
				if(itemInfo.valid)
				{
					cubemapList.push_back(itemInfo);
				}
				else
				{
					//non-valid items should be always at the beginning of the list
					cubemapList.insert(cubemapList.begin(), itemInfo);
				}
			}

			SafeDelete(texDesc);
		}
		
		cubeListItemDelegate.UpdateCache(cubemapList);
		
		for(size_t i = 0; i < cubemapList.size(); ++i)
		{
			CubeListItemDelegate::ListItemInfo& itemInfo = cubemapList[i];
			
			QListWidgetItem* listItem = new QListWidgetItem();
			listItem->setData(Qt::CheckStateRole, false);
			listItem->setData(CUBELIST_DELEGATE_ITEMFULLPATH, itemInfo.path.GetAbsolutePathname().c_str());
			listItem->setData(CUBELIST_DELEGATE_ITEMFILENAME, itemInfo.path.GetFilename().c_str());
			ui->listTextures->addItem(listItem);
		}
		
		cubemapTextures = cubemapList.size();
		ui->listTextures->setCurrentItem(ui->listTextures->item(0));
	}
	
	this->setUpdatesEnabled(true);
	
	ui->listTextures->setVisible(cubemapTextures > 0);
	ui->loadingWidget->setVisible(false);
	
	UpdateCheckedState();
}
Пример #16
0
void CubeMapTextureBrowser::OnDeleteSelectedItemsClicked()
{
	int checkedItemCount = GetCheckedItemsCount();
	int answer = MB_FLAG_NO;
	if(checkedItemCount > 0)
	{
		QString text = QString("%1 item(s) will be deleted. Continue?").arg(QString().setNum(checkedItemCount));
		answer = ShowQuestion("Confirmation",
							  text.toStdString(),
							  MB_FLAG_YES | MB_FLAG_NO,
							  MB_FLAG_NO);
	}
	
	if(MB_FLAG_YES == answer)
	{
		DAVA::Vector<DAVA::String> failedToRemove;
		int itemCount = ui->listTextures->count();
		for(int i = 0; i < itemCount; ++i)
		{
			QListWidgetItem* item = ui->listTextures->item(i);
			bool checkedState = item->data(Qt::CheckStateRole).toBool();
			
			if(checkedState)
			{
				FilePath fp = item->data(CUBELIST_DELEGATE_ITEMFULLPATH).toString().toStdString();
				if(fp.Exists())
				{
					DAVA::Vector<DAVA::String> faceNames;
					CubemapUtils::GenerateFaceNames(fp.GetAbsolutePathname(), faceNames);
					for(size_t faceIndex = 0; faceIndex < faceNames.size(); ++faceIndex)
					{
						FilePath hackTex = faceNames[faceIndex];
						hackTex.ReplaceExtension(".tex");
						
						QFile::remove(hackTex.GetAbsolutePathname().c_str());
						bool removeResult = QFile::remove(faceNames[faceIndex].c_str());
						if(!removeResult)
						{
							failedToRemove.push_back(faceNames[faceIndex]);
						}
					}
					
					bool removeResult = QFile::remove(fp.GetAbsolutePathname().c_str());
					if(!removeResult)
					{
						failedToRemove.push_back(fp.GetAbsolutePathname().c_str());
					}
				}
			}
		}
		
		if(failedToRemove.size() > 0)
		{
			DAVA::String fileList;
			int count = failedToRemove.size();
			for(int i = 0; i < count; ++i)
			{
				fileList += failedToRemove[i];
				fileList += "\n";
			}
			
			DAVA::String message = "Failed to remove the following files. Please delete them manually.\n";
			message += fileList;
			
			ShowErrorDialog(message);
		}

		QString path = ui->textRootPath->text();
		ReloadTexturesFromUI(path);
		UpdateCheckedState();
	}
}