Пример #1
0
/* GfxConvDialog::sliderAlphaThresholdChanged
 * Called when the alpha threshold slider is changed
 *******************************************************************/
void GfxConvDialog::onAlphaThresholdChanged(wxCommandEvent& e)
{
	// Ignore while slider is being dragged
	if (e.GetEventType() == wxEVT_SCROLL_THUMBTRACK)
	{
		e.Skip();
		return;
	}

	updatePreviewGfx();
}
Пример #2
0
/* GfxConvDialog::onPreviewCurrentMouseDown
 * Called when the 'current' gfx preview is clicked
 *******************************************************************/
void GfxConvDialog::onPreviewCurrentMouseDown(wxMouseEvent& e)
{
	// Get image coordinates of the point clicked
	point2_t imgcoord = gfx_current->imageCoords(e.GetX(), e.GetY());
	if (imgcoord.x < 0)
		return;

	// Get the colour at that point
	rgba_t col = gfx_current->getImage()->getPixel(imgcoord.x, imgcoord.y, gfx_current->getPalette());

	// Set the background colour
	colbox_transparent->setColour(col);
	updatePreviewGfx();
}
Пример #3
0
// -----------------------------------------------------------------------------
// Called when the 'current' gfx preview is clicked
// -----------------------------------------------------------------------------
void GfxConvDialog::onPreviewCurrentMouseDown(wxMouseEvent& e)
{
	// Get image coordinates of the point clicked
	auto imgcoord = gfx_current_->imageCoords(e.GetX(), e.GetY());
	if (imgcoord.x < 0)
		return;

	// Get the colour at that point
	auto col = gfx_current_->image().pixelAt(imgcoord.x, imgcoord.y, &gfx_current_->palette());

	// Set the background colour
	colbox_transparent_->setColour(col);
	updatePreviewGfx();
}
Пример #4
0
/* GfxConvDialog::nextItem
 * Opens the next item to be converted. Returns true if the selected
 * format was valid for the next image, false otherwise
 *******************************************************************/
bool GfxConvDialog::nextItem()
{
	// Go to next image
	current_item++;
	if (current_item >= items.size())
	{
		this->Close(true);
		return false;
	}

	// Load image if needed
	if (!items[current_item].image.isValid())
	{
		// If loading images from entries
		if (items[current_item].entry != NULL)
		{
			if (!Misc::loadImageFromEntry(&(items[current_item].image), items[current_item].entry))
				return nextItem();	// Skip if not a valid image entry
		}
		// If loading images from textures
		else if (items[current_item].texture != NULL)
		{
			if (items[current_item].force_rgba)
				items[current_item].image.convertRGBA(items[current_item].palette);
			if (!items[current_item].texture->toImage(items[current_item].image, items[current_item].archive, items[current_item].palette, items[current_item].force_rgba))
				return nextItem();	// Skip if not a valid image entry
		}
		else return nextItem();	// Skip if not a valid image entry
	}

	// Update valid formats
	combo_target_format->Clear();
	conv_formats.clear();
	vector<SIFormat*> all_formats;
	SIFormat::getAllFormats(all_formats);
	int current_index = -1;
	int default_index = -1;
	for (unsigned a = 0; a < all_formats.size(); a++)
	{
		// Check if the image can be written to this format
		if (all_formats[a]->canWrite(items[current_item].image))
		{
			// Add conversion formats depending on what colour types this image format can handle
			if (all_formats[a]->canWriteType(PALMASK))
			{
				// Add format
				conv_formats.push_back(conv_format_t(all_formats[a], PALMASK));
				combo_target_format->Append(all_formats[a]->getName() + " (Paletted)");

				// Check for match with current format
				if (current_format.format == all_formats[a] && current_format.coltype == PALMASK)
					current_index = conv_formats.size() - 1;

				// Default format is 'doom gfx'
				if (all_formats[a]->getId() == "doom")
					default_index = conv_formats.size() - 1;
			}

			if (all_formats[a]->canWriteType(RGBA))
			{
				// Add format
				conv_formats.push_back(conv_format_t(all_formats[a], RGBA));
				combo_target_format->Append(all_formats[a]->getName() + " (Truecolour)");

				// Check for match with current format
				if (current_format.format == all_formats[a] && current_format.coltype == RGBA)
					current_index = conv_formats.size() - 1;
			}

			if (all_formats[a]->canWriteType(ALPHAMAP))
			{
				// Add format
				conv_formats.push_back(conv_format_t(all_formats[a], ALPHAMAP));
				combo_target_format->Append(all_formats[a]->getName() + " (Alpha Map)");

				// Check for match with current format
				if (current_format.format == all_formats[a] && current_format.coltype == ALPHAMAP)
					current_index = conv_formats.size() - 1;
			}
		}
	}

	// If the image cannot be converted to the selected format
	bool ok = true;
	if (current_index < 0)
	{
		// Default to Doom Gfx
		current_index = default_index;
		ok = false;
	}

	// Set current format
	combo_target_format->SetSelection(current_index);
	current_format = conv_formats[current_index];

	// Setup current format string
	string fmt_string = "Current Format: ";
	if (items[current_item].texture == NULL)
	{
		if (items[current_item].image.getFormat())
			fmt_string += items[current_item].image.getFormat()->getName();
		else fmt_string += "Font";
	}
	else
		fmt_string += "Texture";
	if (items[current_item].image.getType() == RGBA)
		fmt_string += " (Truecolour)";
	else if (items[current_item].image.getType() == PALMASK)
	{
		fmt_string += " (Paletted - ";
		if (items[current_item].image.hasPalette())
			fmt_string += "Internally)";
		else fmt_string += "Externally)";
	}
	else if (items[current_item].image.getType() == ALPHAMAP)
		fmt_string += " (Alpha Map)";
	label_current_format->SetLabel(fmt_string);

	// Update UI
	updatePreviewGfx();
	theSplashWindow->setProgressMessage(S_FMT("%d of %lu", current_item, items.size()));
	theSplashWindow->setProgress((float)current_item / (float)items.size());

	return ok;
}
Пример #5
0
/* GfxConvDialog::onBtnColorimetrySettings
 * Called when the 'Adjust Colorimetry Settings' button is clicked
 *******************************************************************/
void GfxConvDialog::onBtnColorimetrySettings(wxCommandEvent& e)
{
	PreferencesDialog::openPreferences(this, "Colorimetry");
	updatePreviewGfx();
}
Пример #6
0
/* GfxConvDialog::transColourChanged
 * Called when the transparent colour box is changed
 *******************************************************************/
void GfxConvDialog::onTransColourChanged(wxEvent& e)
{
	updatePreviewGfx();
}
Пример #7
0
/* GfxConvDialog::transTypeChanged
 * Called when the 'existing' and 'colour' radio buttons are toggled
 *******************************************************************/
void GfxConvDialog::onTransTypeChanged(wxCommandEvent& e)
{
	updatePreviewGfx();
}
Пример #8
0
/* GfxConvDialog::cbEnableTransparencyChanged
 * Called when the 'enable transparency' checkbox is changed
 *******************************************************************/
void GfxConvDialog::onEnableTransparencyChanged(wxCommandEvent& e)
{
	updatePreviewGfx();
}
Пример #9
0
/* GfxConvDialog::paletteTargetChanged
 * Called when the target image palette chooser is changed
 *******************************************************************/
void GfxConvDialog::onTargetPaletteChanged(wxCommandEvent& e)
{
	updatePreviewGfx();
}
Пример #10
0
/* GfxConvDialog::comboTargetFormatChanged
 * Called when the 'Convert To' combo box is changed
 *******************************************************************/
void GfxConvDialog::onTargetFormatChanged(wxCommandEvent& e)
{
	current_format = conv_formats[combo_target_format->GetSelection()];
	updatePreviewGfx();
}
Пример #11
0
// -----------------------------------------------------------------------------
// Opens the next item to be converted.
// Returns true if the selected format was valid for the next image
// -----------------------------------------------------------------------------
bool GfxConvDialog::nextItem()
{
	// Go to next image
	current_item_++;
	if (current_item_ >= items_.size())
	{
		this->Close(true);
		return false;
	}

	// Load image if needed
	if (!items_[current_item_].image.isValid())
	{
		// If loading images from entries
		if (items_[current_item_].entry != nullptr)
		{
			if (!Misc::loadImageFromEntry(&(items_[current_item_].image), items_[current_item_].entry))
				return nextItem(); // Skip if not a valid image entry
		}
		// If loading images from textures
		else if (items_[current_item_].texture != nullptr)
		{
			if (items_[current_item_].force_rgba)
				items_[current_item_].image.convertRGBA(items_[current_item_].palette);
			if (!items_[current_item_].texture->toImage(
					items_[current_item_].image,
					items_[current_item_].archive,
					items_[current_item_].palette,
					items_[current_item_].force_rgba))
				return nextItem(); // Skip if not a valid image entry
		}
		else
			return nextItem(); // Skip if not a valid image entry
	}

	// Update valid formats
	combo_target_format_->Clear();
	conv_formats_.clear();
	vector<SIFormat*> all_formats;
	SIFormat::putAllFormats(all_formats);
	int current_index = -1;
	int default_index = -1;
	for (auto& format : all_formats)
	{
		// Check if the image can be written to this format
		if (format->canWrite(items_[current_item_].image) != SIFormat::Writable::No)
		{
			// Add conversion formats depending on what colour types this image format can handle
			if (format->canWriteType(SImage::Type::PalMask))
			{
				// Add format
				conv_formats_.emplace_back(format, SImage::Type::PalMask);
				combo_target_format_->Append(format->name() + " (Paletted)");

				// Check for match with current format
				if (current_format_.format == format && current_format_.coltype == SImage::Type::PalMask)
					current_index = conv_formats_.size() - 1;

				// Default format is 'doom gfx'
				if (format->id() == "doom")
					default_index = conv_formats_.size() - 1;
			}

			if (format->canWriteType(SImage::Type::RGBA))
			{
				// Add format
				conv_formats_.emplace_back(format, SImage::Type::RGBA);
				combo_target_format_->Append(format->name() + " (Truecolour)");

				// Check for match with current format
				if (current_format_.format == format && current_format_.coltype == SImage::Type::RGBA)
					current_index = conv_formats_.size() - 1;
			}

			if (format->canWriteType(SImage::Type::AlphaMap))
			{
				// Add format
				conv_formats_.emplace_back(format, SImage::Type::AlphaMap);
				combo_target_format_->Append(format->name() + " (Alpha Map)");

				// Check for match with current format
				if (current_format_.format == format && current_format_.coltype == SImage::Type::AlphaMap)
					current_index = conv_formats_.size() - 1;
			}
		}
	}

	// If the image cannot be converted to the selected format
	bool ok = true;
	if (current_index < 0)
	{
		// Default to Doom Gfx
		current_index = default_index;
		ok            = false;
	}

	// Set current format
	combo_target_format_->SetSelection(current_index);
	current_format_ = conv_formats_[current_index];

	// Setup current format string
	string fmt_string = "Current Format: ";
	if (items_[current_item_].texture == nullptr)
	{
		if (items_[current_item_].image.format())
			fmt_string += items_[current_item_].image.format()->name();
		else
			fmt_string += "Font";
	}
	else
		fmt_string += "Texture";
	if (items_[current_item_].image.type() == SImage::Type::RGBA)
		fmt_string += " (Truecolour)";
	else if (items_[current_item_].image.type() == SImage::Type::PalMask)
	{
		fmt_string += " (Paletted - ";
		if (items_[current_item_].image.hasPalette())
			fmt_string += "Internally)";
		else
			fmt_string += "Externally)";
	}
	else if (items_[current_item_].image.type() == SImage::Type::AlphaMap)
		fmt_string += " (Alpha Map)";
	label_current_format_->SetLabel(fmt_string);

	// Update UI
	updatePreviewGfx();
	UI::setSplashProgressMessage(S_FMT("%d of %lu", current_item_, items_.size()));
	UI::setSplashProgress((float)current_item_ / (float)items_.size());

	return ok;
}