示例#1
0
bool RecurseDirectory(HZIP hz, QString sDir, QString prevDir = "") 
{
       QDir dir(sDir);
       QFileInfoList list = dir.entryInfoList();
       for (int iList=0;iList<list.count();iList++)
       {
           QFileInfo info = list[iList];

           QString sFilePath = info.filePath();
           if (info.isDir())
           {
               // recursive
               if (info.fileName()!=".." && info.fileName()!=".")
               {
                    ZRESULT zr;
                   return RecurseDirectory(hz, sFilePath);
               }
           }
           else
           {
               // Do something with the file here
               
               if(ZipAdd(hz, (/*sDir.right(sDir.size() - sDir.lastIndexOf("/") -1) + "/" + */info.fileName()).toLatin1().data(), info.absoluteFilePath().toLatin1().data()) != ZR_OK)
                   return false;
           }
       }

       return true;
};
void RecurseDirectory(const QString dir, bool recursion)
{
    QDir dirEnt(dir);
    QFileInfoList list = dirEnt.entryInfoList();
    for(int i = 0; i < list.count(); i++)
    {
        QFileInfo info = list[i];

        QString filePath = info.filePath();
        QString fileExt = info.suffix().toLower();
        QString name = dir + QDir::separator();
        if(recursion && info.isDir())
        {
            // recursive
            if(info.fileName() != ".." && info.fileName() != ".")
            {
                RecurseDirectory(filePath, recursion);
            }
        }
        else
            if(imageExtensions.contains(fileExt))
            {
                if(!QFile::exists(name + info.completeBaseName() + QString(".atlas")))
                {
                    packerData *data = new packerData;
                    data->path = info.absoluteFilePath();
                    data->file = filePath.replace(topImageDir, "");
                    //                qDebug() << "Packing " << data->path << "...";
                    mainPacker->addItem(data->path, data);
                }
            }
    }
}
示例#3
0
void CTerrainTextureManager::RecurseDirectory(const CTerrainPropertiesPtr& parentProps, const VfsPath& path)
{
	//LOGMESSAGE("CTextureManager::RecurseDirectory(%s)", path.string8());

	CTerrainPropertiesPtr props;

	// Load terrains.xml first, if it exists
	VfsPath pathname = path / "terrains.xml";
	if (VfsFileExists(pathname))
		props = GetPropertiesFromFile(parentProps, pathname);
	
	// No terrains.xml, or read failures -> use parent props (i.e. 
	if (!props)
	{
		LOGMESSAGE("CTerrainTextureManager::RecurseDirectory(%s): no terrains.xml (or errors while loading) - using parent properties", path.string8());
		props = parentProps;
	}

	// Recurse once for each subdirectory
	DirectoryNames subdirectoryNames;
	(void)g_VFS->GetDirectoryEntries(path, 0, &subdirectoryNames);
	for (size_t i=0;i<subdirectoryNames.size();i++)
	{
		VfsPath subdirectoryPath = path / subdirectoryNames[i] / "";
		RecurseDirectory(props, subdirectoryPath);
	}

	LoadTextures(props, path);
}
void MainWindow::RecurseDirectory(const QString &dir)
{
    QDir dirEnt(dir);
    QFileInfoList list = dirEnt.entryInfoList();
    for (int i = 0; i < list.count() && !recursiveLoaderDone;i++)
    {
        recursiveLoaderCounter++;
        QFileInfo info = list[i];

        QString filePath = info.filePath();
        QString fileExt = info.suffix().toLower();
        QString name = dir + QDir::separator();
        if (info.isDir())
        {
            // recursive
            if (info.fileName()!=".." && info.fileName()!=".")
                RecurseDirectory(filePath);
        }
        else if(imageExtensions.contains(fileExt))
        {
            if(!QFile::exists(name+info.completeBaseName()+QString(".atlas")))
            {
                ui->tilesList->addItem(filePath.replace(topImageDir, ""));
                packerData * data = new packerData;
                data->listItem = ui->tilesList->item(ui->tilesList->count() - 1);
                data->path = info.absoluteFilePath();
                packer.addItem(data->path, data);
            }
        }
        if(recursiveLoaderCounter == 500)
        {
            if(QMessageBox::No ==
                    QMessageBox::question(
                        this,
                        tr("Directory is too big"),
                        tr("It seems that directory <b>") + topImageDir +
                        tr("</b> is too big. "
                           "Loading may take HUGE amount of time and memory. "
                           "Please, check directory again. <br>"
                           "Do you want to continue?"),
                        QMessageBox::Yes,
                        QMessageBox::No))
            {
                recursiveLoaderDone = true;
                recursiveLoaderCounter++;
                continue;
            }
            ui->previewWithImages->setChecked(false);
        }
    }
}
void MainWindow::addDir(QString dir)
{
    //FIXME
    //this is messy hack due to difference between QFileDialog and QFileInfo dir separator in Windows
    if (QDir::separator() == '\\')
        topImageDir = dir.replace("\\","/") + "/";
    else
        topImageDir = dir + "/";
    ui->outDir->setText(dir);
    recursiveLoaderCounter = 0;
    recursiveLoaderDone = false;
    //packer.clear();
    RecurseDirectory(dir);
    QFileInfo info(dir);
    ui->outFile->setText(info.baseName());

}
示例#6
0
bool CZip::archive(const QString &filePath, const QDir &dir, const QString &comment)
{
   HZIP hz = CreateZip(filePath.toLatin1().data(), 0); 
   if (hz == 0) {
       qDebug() << "* Failed to create folders.zip";
   }

   ZRESULT zr;

   //zr = ZipAddFolder(hz, dir.dirName().toLatin1().data());

   if(!RecurseDirectory(hz, dir.absolutePath()))
   {
       zr = CloseZip(hz);
       return false;
   }
   zr = CloseZip(hz);

   return true;
 }
示例#7
0
// Ritorna FALSE se la esplora ed e' vuota oppure se non e' valida
BOOL Explorer::ExploreDirectory(WCHAR *wStartPath, DWORD dwDepth) {
	WIN32_FIND_DATAW wfd;
	HANDLE hFind = INVALID_HANDLE_VALUE;
	BOOL bFull = FALSE;
	FilesystemData fsData;
	WCHAR wFilePath[MAX_PATH], wRecursePath[MAX_PATH];
	WCHAR wHiddenPath[MAX_PATH];
	wstring strPath = L"\\*";

	if (wStartPath == NULL) {
		DBG_TRACE(L"Debug - Explorer.cpp - ExploreDirectory() [wStartPath == NULL] ", 5, TRUE);
		return FALSE;
	}

	if (dwDepth == 0)
		return TRUE;

	// Evita il browsing della dir nascosta
	_snwprintf(wHiddenPath, MAX_PATH, L"%s", LOG_DIR_NAME);		

	// Bisogna partire dalla lista dei drive
	if (!wcscmp(wStartPath, L"/")) {
		// Nel caso speciale impostiamo la depth a 2, il primo run
		// trova solo la root "\", il secondo i file nella root.
		dwDepth = 2;

		// Creiamo una root-entry artificiale
		ZeroMemory(&fsData, sizeof(FilesystemData));
		fsData.dwVersion = LOG_FILESYSTEM_VERSION;
		fsData.dwFlags = FILESYSTEM_IS_DIRECTORY;

		strPath = L"\\";

		DBG_TRACE_STR(L"Debug - Explorer.cpp - Logging path: ", strPath.c_str(), 4, FALSE);

		fsData.dwPathLen = strPath.size() * sizeof(WCHAR);

		log.WriteLog((BYTE *)&fsData, sizeof(fsData));
		log.WriteLog((BYTE *)strPath.c_str(), fsData.dwPathLen);

		// Iniziamo la ricerca reale
		ZeroMemory(&wfd, sizeof(wfd));
		hFind = FindFirstFileW(strPath.c_str(), &wfd);

		if (hFind == INVALID_HANDLE_VALUE) {
			DWORD dwErr = GetLastError();

			if (dwErr != ERROR_NO_MORE_FILES) {
				DBG_TRACE_INT(L"Debug - Explorer.cpp - ExploreDirectory() [FindFirstFileW() (1) Failed] Err: ", 5, FALSE, dwErr);
			}

			return FALSE;
		}

		do {
			if (wcsstr(wfd.cFileName, wHiddenPath))
				continue;

			ZeroMemory(&fsData, sizeof(FilesystemData));
			fsData.dwVersion = LOG_FILESYSTEM_VERSION;
			fsData.dwFileSizeHi = wfd.nFileSizeHigh;
			fsData.dwFileSizeLo = wfd.nFileSizeLow;
			fsData.ftTime = wfd.ftLastWriteTime;

			if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
				fsData.dwFlags |= FILESYSTEM_IS_DIRECTORY;

			strPath = L"\\";
			strPath += wfd.cFileName;

			DBG_TRACE_STR(L"Debug - Explorer.cpp - Logging path: ", strPath.c_str(), 4, FALSE);

			fsData.dwPathLen = strPath.size() * sizeof(WCHAR);

			log.WriteLog((BYTE *)&fsData, sizeof(fsData));
			log.WriteLog((BYTE *)strPath.c_str(), fsData.dwPathLen);

			if (!ExploreDirectory(RecurseDirectory(wfd.cFileName, wRecursePath), dwDepth - 1))
				fsData.dwFlags |= FILESYSTEM_IS_EMPTY;

		} while (FindNextFile(hFind, &wfd));

		FindClose(hFind);
		return TRUE;
	}

	ZeroMemory(&wfd, sizeof(wfd));
	hFind = FindFirstFileW(wStartPath, &wfd);

	if (hFind == INVALID_HANDLE_VALUE) {
		DWORD dwErr = GetLastError();

		if (dwErr != ERROR_NO_MORE_FILES) {
			DBG_TRACE_INT(L"Debug - Explorer.cpp - ExploreDirectory() [FindFirstFileW() (2) Failed] Err: ", 5, FALSE, dwErr);
		}
	}

	do {
		if (wcsstr(wfd.cFileName, wHiddenPath))
			continue;

		bFull = TRUE;
		ZeroMemory(&fsData, sizeof(FilesystemData));
		fsData.dwVersion = LOG_FILESYSTEM_VERSION;
		fsData.dwFileSizeHi = wfd.nFileSizeHigh;
		fsData.dwFileSizeLo = wfd.nFileSizeLow;
		fsData.ftTime = wfd.ftLastWriteTime;

		if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			fsData.dwFlags |= FILESYSTEM_IS_DIRECTORY;

		CompleteDirectoryPath(wStartPath, wfd.cFileName, wFilePath);

		fsData.dwPathLen = WideLen(wFilePath);

		if (fsData.dwFlags & FILESYSTEM_IS_DIRECTORY) 
			if (!ExploreDirectory(RecurseDirectory(wFilePath, wRecursePath), dwDepth - 1))
				fsData.dwFlags |= FILESYSTEM_IS_EMPTY;

		DBG_TRACE_STR(L"Debug - Explorer.cpp - Logging path: ", wFilePath, 4, FALSE);

		log.WriteLog((BYTE *)&fsData, sizeof(fsData));
		log.WriteLog((BYTE *)&wFilePath, fsData.dwPathLen);
	} while (FindNextFileW(hFind, &wfd));

	FindClose(hFind);
	return bFull;
}
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    imageExtensions << "bmp" << "png" << "jpg" << "jpeg";
    //command-line version
    if(argc > 1)
    {
        int textureWidth = 512;
        int textureHeight = 512;
        bool merge = true;
        bool crop = true;
        int border = 1;
        int extrude = 0;
        bool rotate = false;
        bool recursion = true;
        bool square = false;
        bool autosize = false;
        int cropThreshold = 1;
        int autosizeThreshold = 80;
        int minTextureSizeX = 32;
        int minTextureSizeY = 32;
        int sortorder = 4;
        ImagePacker packer;
        mainPacker = &packer;
        QString outDir = QDir::currentPath();
        QString outFile = "atlas";
        for(int i = 1; i < argc; ++i)
        {
            if(check_opt("--help") || check_opt("-h") || check_opt("-?"))
            {
                printHelp();
            }
            else
                if(check_opt("-s") || check_opt("--size"))
                {
                    ++i;
                    if(i >= argc)
                    {
                        printHelp("Argument needed for option -s");
                    }
                    if(sscanf(argv[i], "%10dx%10d", &textureWidth, &textureHeight) != 2)
                    {
                        if(sscanf(argv[i], "%10d", &textureWidth) != 1)
                        {
                            printHelp("Wrong texture size format");
                        }
                        else
                        {
                            textureHeight = textureWidth;
                        }
                    }
                    printf("Setting texture size: %dx%d\n", textureWidth, textureHeight);
                }
                else
                    if(check_opt("-o") || check_opt("--out-file"))
                    {
                        ++i;
                        if(i >= argc)
                        {
                            printHelp("Argument needed for option -o");
                        }
                        QFileInfo info(argv[i]);
                        outFile = info.baseName();
                        outDir = info.absolutePath();
                    }
                    else
                        if(check_opt("--disable-merge"))
                        {
                            merge = false;
                        }
                        else
                            if(check_opt("--disable-crop"))
                            {
                                crop = false;
                            }
                            else
                                if(check_opt("--disable-recursion"))
                                {
                                    recursion = false;
                                }
                                else
                                    if(check_opt("--square"))
                                    {
                                        square = true;
                                    }
                                    else
                                        if(check_opt("--autosize-threshold"))
                                        {
                                            autosize = true;
                                            ++i;
                                            if(i >= argc)
                                            {
                                                printHelp("Argument needed for option --autosize-threshold");
                                            }
                                            if((sscanf(argv[i], "%10d", &autosizeThreshold) != 1) ||
                                                    (autosizeThreshold < 0) ||
                                                    (autosizeThreshold > 100))
                                            {
                                                printHelp("Wrong autosize threshold");
                                            }
                                        }
                                        else
                                            if(check_opt("--extrude-size"))
                                            {
                                                ++i;
                                                if(i >= argc)
                                                {
                                                    printHelp("Argument needed for option --extrude-size");
                                                }
                                                if((sscanf(argv[i], "%10d", &extrude) != 1) || (extrude < 0))
                                                {
                                                    printHelp("Wrong extrude size");
                                                }
                                            }
                                            else
                                                if(check_opt("--border-size"))
                                                {
                                                    ++i;
                                                    if(i >= argc)
                                                    {
                                                        printHelp("Argument needed for option --border-size");
                                                    }
                                                    if((sscanf(argv[i], "%10d", &border) != 1) || (border < 0))
                                                    {
                                                        printHelp("Wrong border size");
                                                    }
                                                }
                                                else
                                                    if(check_opt("--min-texture-size"))
                                                    {
                                                        ++i;
                                                        if(i >= argc)
                                                        {
                                                            printHelp("Argument needed for option -min-texture-size");
                                                        }
                                                        if(sscanf(argv[i], "%10dx%10d", &minTextureSizeX, &minTextureSizeY) != 2)
                                                        {
                                                            if(sscanf(argv[i], "%10d", &minTextureSizeX) != 1)
                                                            {
                                                                printHelp("Wrong texture size format");
                                                            }
                                                            else
                                                            {
                                                                minTextureSizeY = minTextureSizeX;
                                                            }
                                                        }
                                                    }
                                                    else
                                                        if(check_opt("--crop-threshold"))
                                                        {
                                                            ++i;
                                                            if(i >= argc)
                                                            {
                                                                printHelp("Argument needed for option --crop-threshold");
                                                            }
                                                            if((sscanf(argv[i], "%10d", &cropThreshold) != 1) ||
                                                                    (cropThreshold < 0) ||
                                                                    (cropThreshold > 255))
                                                            {
                                                                printHelp("Wrong crop threshold");
                                                            }
                                                        }
                                                        else
                                                            if(check_opt("--sort-order"))
                                                            {
                                                                ++i;
                                                                if(i >= argc)
                                                                {
                                                                    printHelp("Argument needed for option --sort-order");
                                                                }
                                                                if((sscanf(argv[i], "%10d", &sortorder) != 1) ||
                                                                        (sortorder < 0) ||
                                                                        (sortorder > 4))
                                                                {
                                                                    printHelp("Wrong sortorder must be from 0 to 4");
                                                                }
                                                            }
                                                            else
                                                                if(check_opt("--disable-border"))
                                                                {
                                                                    border = 0;
                                                                }
                                                                else
                                                                    if(check_opt("--enable-rotate"))
                                                                    {
                                                                        rotate = true;
                                                                    }
                                                                    //dir or file
                                                                    else
                                                                    {
                                                                        QFileInfo file(argv[i]);
                                                                        if(file.isFile())
                                                                        {
                                                                            packerData *data = new packerData;
                                                                            data->path = file.absoluteFilePath();
                                                                            data->file = file.fileName();
                                                                            packer.addItem(data->path, data);
                                                                        }
                                                                        else
                                                                            if(file.isDir())
                                                                            {
                                                                                topImageDir = file.absoluteFilePath();
                                                                                RecurseDirectory(file.absoluteFilePath(), recursion);
                                                                            }
                                                                    }
        }

        qDebug() << "Saving to dir" << outDir << "and file" << outFile;
        packer.sortOrder = sortorder;
        packer.border.t = 0;
        packer.border.l = 0;
        packer.border.r = border;
        packer.border.b = border;
        packer.extrude = extrude;
        packer.cropThreshold = crop ? cropThreshold : 0;
        packer.minFillRate = autosize ? autosizeThreshold : 0;
        packer.minTextureSizeX = minTextureSizeX;
        packer.minTextureSizeY = minTextureSizeY;
        packer.merge = merge;
        packer.mergeBF = false;
        packer.rotate = rotate;
        packer.square = square;
        packer.autosize = autosize;
        int heuristic = 1;

        QString outFormat("PNG");

        if(packer.images.size() == 0)
        {
            fprintf(stderr, "No images found, exitting\n");
            exit(1);
        }

        packer.pack(heuristic, textureWidth, textureHeight);

        QList<QImage> textures;
        for(int i = 0; i < packer.bins.size(); i++)
        {
            QImage texture(packer.bins.at(i).width(), packer.bins.at(i).height(),
                           QImage::Format_ARGB32);
            texture.fill(Qt::transparent);
            textures << texture;
        }
        for(int j = 0; j < textures.count(); j++)
        {
            QString outputFile = outDir;
            outputFile += QDir::separator();
            outputFile += outFile;
            if(textures.count() > 1)
            {
                outputFile += QString("_") + QString::number(j + 1);
            }
            outputFile += ".atlas";
            QString imgFile = outFile;
            if(textures.count() > 1)
            {
                imgFile += QString("_") + QString::number(j + 1);
            }
            imgFile += ".";
            imgFile += outFormat.toLower();

            QFile positionsFile(outputFile);
            if(!positionsFile.open(QIODevice::WriteOnly | QIODevice::Text))
            {
                fprintf(stderr, "Cannot create file %s", qPrintable(outputFile));
            }
            else
            {
                QTextStream out(&positionsFile);
                out << "textures: " << imgFile << "\n";
                for(int i = 0; i < packer.images.size(); i++)
                {
                    if(packer.images.at(i).textureId != j)
                    {
                        continue;
                    }
                    QPoint pos(packer.images.at(i).pos.x() + packer.border.l + packer.extrude,
                               packer.images.at(i).pos.y() + packer.border.t + packer.extrude);
                    QSize size, sizeOrig;
                    QRect crop;
                    sizeOrig = packer.images.at(i).size;
                    if(!packer.cropThreshold)
                    {
                        size = packer.images.at(i).size;
                        crop = QRect(0, 0, size.width(), size.height());
                    }
                    else
                    {
                        size = packer.images.at(i).crop.size();
                        crop = packer.images.at(i).crop;
                    }
                    if(packer.images.at(i).rotated)
                    {
                        size.transpose();
                        crop = QRect(crop.y(), crop.x(), crop.height(), crop.width());
                    }
                    out << (static_cast<packerData *>(packer.images.at(i).id))->file <<
                        "\t" <<
                        pos.x() << "\t" <<
                        pos.y() << "\t" <<
                        crop.width() << "\t" <<
                        crop.height() << "\t" <<
                        crop.x() << "\t" <<
                        crop.y() << "\t" <<
                        sizeOrig.width() << "\t" <<
                        sizeOrig.height() << "\t" <<
                        (packer.images.at(i).rotated ? "r" : "") << "\n";
                }
            }
        }

        for(int i = 0; i < packer.images.size(); i++)
        {
            qDebug() << "Processing" << (static_cast<packerData *>(packer.images.at(
                                             i).id))->file;
            if(packer.images.at(i).duplicateId != NULL && packer.merge)
            {
                continue;
            }
            QPoint pos(packer.images.at(i).pos.x() + packer.border.l,
                       packer.images.at(i).pos.y() + packer.border.t);
            QSize size;
            QRect crop;
            if(!packer.cropThreshold)
            {
                size = packer.images.at(i).size;
                crop = QRect(0, 0, size.width(), size.height());
            }
            else
            {
                size = packer.images.at(i).crop.size();
                crop = packer.images.at(i).crop;
            }
            QImage img;
            img = QImage((static_cast<packerData *>(packer.images.at(i).id))->path);
            if(packer.images.at(i).rotated)
            {
                QTransform myTransform;
                myTransform.rotate(90);
                img = img.transformed(myTransform);
                size.transpose();
                crop = QRect(packer.images.at(i).size.height() - crop.y() - crop.height(),
                             crop.x(), crop.height(), crop.width());
            }
            if(packer.images.at(i).textureId < packer.bins.size())
            {
                QPainter p(&textures.operator [](packer.images.at(i).textureId));

                if(packer.extrude)
                {
                    QColor color1 = QColor::fromRgba(img.pixel(crop.x(), crop.y()));
                    p.setPen(color1);
                    p.setBrush(color1);
                    if(packer.extrude == 1)
                    {
                        p.drawPoint(QPoint(pos.x(), pos.y()));
                    }
                    else
                    {
                        p.drawRect(QRect(pos.x(), pos.y(), packer.extrude - 1, packer.extrude - 1));
                    }

                    QColor color2 = QColor::fromRgba(img.pixel(crop.x(),
                                                     crop.y() + crop.height() - 1));
                    p.setPen(color2);
                    p.setBrush(color2);
                    if(packer.extrude == 1)
                    {
                        p.drawPoint(QPoint(pos.x(), pos.y() + crop.height() + packer.extrude));
                    }
                    else
                    {
                        p.drawRect(QRect(pos.x(), pos.y() + crop.height() + packer.extrude,
                                         packer.extrude - 1, packer.extrude - 1));
                    }

                    QColor color3 = QColor::fromRgba(img.pixel(crop.x() + crop.width() - 1,
                                                     crop.y()));
                    p.setPen(color3);
                    p.setBrush(color3);
                    if(packer.extrude == 1)
                    {
                        p.drawPoint(QPoint(pos.x() + crop.width() + packer.extrude, pos.y()));
                    }
                    else
                    {
                        p.drawRect(QRect(pos.x() + crop.width() + packer.extrude, pos.y(),
                                         packer.extrude - 1, packer.extrude - 1));
                    }

                    QColor color4 = QColor::fromRgba(img.pixel(crop.x() + crop.width() - 1,
                                                     crop.y() + crop.height() - 1));
                    p.setPen(color4);
                    p.setBrush(color4);
                    if(packer.extrude == 1)
                    {
                        p.drawPoint(QPoint(pos.x() + crop.width() + packer.extrude,
                                           pos.y() + crop.height() + packer.extrude));
                    }
                    else
                    {
                        p.drawRect(QRect(pos.x() + crop.width() + packer.extrude,
                                         pos.y() + crop.height() + packer.extrude, packer.extrude - 1,
                                         packer.extrude - 1));
                    }

                    p.drawImage(QRect(pos.x(), pos.y() + packer.extrude, packer.extrude,
                                      crop.height()), img, QRect(crop.x(), crop.y(), 1, crop.height()));
                    p.drawImage(QRect(pos.x() + crop.width() + packer.extrude,
                                      pos.y() + packer.extrude, packer.extrude, crop.height()), img,
                                QRect(crop.x() + crop.width() - 1, crop.y(), 1, crop.height()));

                    p.drawImage(QRect(pos.x() + packer.extrude, pos.y(), crop.width(),
                                      packer.extrude), img, QRect(crop.x(), crop.y(), crop.width(), 1));
                    p.drawImage(QRect(pos.x() + packer.extrude,
                                      pos.y() + crop.height() + packer.extrude, crop.width(), packer.extrude), img,
                                QRect(crop.x(), crop.y() + crop.height() - 1, crop.width(), 1));

                    p.drawImage(pos.x() + packer.extrude, pos.y() + packer.extrude, img, crop.x(),
                                crop.y(), crop.width(), crop.height());
                }
                else
                {
                    p.drawImage(pos.x(), pos.y(), img, crop.x(), crop.y(), crop.width(),
                                crop.height());
                }
            }
        }
        qint64 area = 0;
        for(int i = 0; i < textures.count(); i++)
        {
            area += textures.at(i).width() * textures.at(i).height();
        }
        float percent = (((float)packer.area / (float)area) * 100.0f);
        //        float percent2 = (float)(((float)packer.neededArea / (float)area) * 100.0f );
        printf("Atlas generated. %f%% filled, %d images missed, %d merged, %d KB\n",
               percent, packer.missingImages, packer.mergedImages, (int)((area * 4) / 1024));

        //        const char * format = qPrintable(outFormat);
        for(int i = 0; i < textures.count(); i++)
        {
            QString imgdirFile;
            imgdirFile = outDir;
            imgdirFile += QDir::separator();
            imgdirFile += outFile;
            if(textures.count() > 1)
            {
                imgdirFile += QString("_") + QString::number(i + 1);
            }
            imgdirFile += ".";
            imgdirFile += outFormat.toLower();
            textures.at(i).save(imgdirFile);
        }

        return 0;
    }

    QTranslator myTranslator;
    myTranslator.load("tile_" + QLocale::system().name(), "qm");
    a.installTranslator(&myTranslator);
    MainWindow w;
    w.show();


    return a.exec();
}
示例#9
0
int CTerrainTextureManager::LoadTerrainTextures()
{
	CTerrainPropertiesPtr rootProps(new CTerrainProperties(CTerrainPropertiesPtr()));
	RecurseDirectory(rootProps, L"art/terrains/");
	return 0;
}