Example #1
0
void CGraphicsBank::contextMenuEvent(QContextMenuEvent* event, QTreeView* parent)
{
   const QString EXPORT_PNG_TEXT    = "Export as PNG";
   const QString DELETE_TEXT        = "&Delete";

   QMenu menu(parent);
   menu.addAction(EXPORT_PNG_TEXT);
   menu.addSeparator();
   menu.addAction(DELETE_TEXT);

   QAction* ret = menu.exec(event->globalPos());

   if (ret)
   {
      if (ret->text() == DELETE_TEXT)
      {
         if (QMessageBox::question(parent, "Delete Source", "Are you sure you want to delete " + caption(),
                                   QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes)
         {
            return;
         }

         if (m_editor)
         {
            QTabWidget* tabWidget = (QTabWidget*)this->m_editor->parentWidget()->parentWidget();
            tabWidget->removeTab(tabWidget->indexOf(m_editor));
         }

         // TODO: Fix this logic so the memory doesn't get lost.
         nesicideProject->getProject()->getGraphicsBanks()->removeChild(this);
         nesicideProject->getProject()->getGraphicsBanks()->getGraphicsBanks().removeAll(this);
         //((CProjectTreeViewModel*)parent->model())->layoutChangedEvent();
      }
      else if (ret->text() == EXPORT_PNG_TEXT)
      {
         exportAsPNG();
      }
   }
}
Example #2
0
/* TextureXPanel::extractTexture
 * Create standalone image entries of any selected textures
 *******************************************************************/
void TextureXPanel::extractTexture()
{
	// Get selected textures
	vector<long> selec_num = list_textures->getSelection();
	vector<CTexture*> selection;

	if (!tx_entry) return;

	//saveTEXTUREX();

	Archive* archive = tx_entry->getParent();
	bool force_rgba = texture_editor->getBlendRGBA();

	// Go through selection
	for (unsigned a = 0; a < selec_num.size(); ++a)
	{
		selection.push_back(texturex.getTexture(selec_num[a]));
	}


	// If we're just exporting one texture
	if (selection.size() == 1)
	{
		string name = Misc::lumpNameToFileName(selection[0]->getName());
		wxFileName fn(name);

		// Set extension
		fn.SetExt("png");

		// Run save file dialog
		SFileDialog::fd_info_t info;
		if (SFileDialog::saveFile(info, "Export Texture \"" + selection[0]->getName() + "\" as PNG", "PNG Files (*.png)|*.png", this, fn.GetFullName()))
		{
			// If a filename was selected, export it
			if (!exportAsPNG(selection[0], info.filenames[0], force_rgba))
			{
				wxMessageBox(S_FMT("Error: %s", Global::error), "Error", wxOK|wxICON_ERROR);
				return;
			}
		}

		return;
	}
	else
	{
		// Run save files dialog
		SFileDialog::fd_info_t info;
		if (SFileDialog::saveFiles(info, "Export Textures as PNG (Filename will be ignored)", "PNG Files (*.png)|*.png", this))
		{
			// Show splash window
			theSplashWindow->show("Saving converted image data...", true);

			// Go through the selection
			for (size_t a = 0; a < selection.size(); a++)
			{
				// Update splash window
				theSplashWindow->setProgressMessage(selection[a]->getName());
				theSplashWindow->setProgress((float)a / (float)selection.size());

				// Setup entry filename
				wxFileName fn(selection[a]->getName());
				fn.SetPath(info.path);
				fn.SetExt("png");

				// Do export
				exportAsPNG(selection[a], fn.GetFullPath(), force_rgba);
			}

			// Hide splash window
			theSplashWindow->hide();
		}
	}
}