/* GfxEntryPanel::handleAction * Handles the action [id]. Returns true if the action was handled, * false otherwise *******************************************************************/ bool GfxEntryPanel::handleAction(string id) { // Don't handle actions if hidden if (!isActivePanel()) return false; // We're only interested in "pgfx_" actions if (!id.StartsWith("pgfx_")) return false; // Mirror if (id == "pgfx_mirror") { // Mirror X getImage()->mirror(false); // Update UI gfx_canvas->updateImageTexture(); gfx_canvas->Refresh(); // Update variables image_data_modified = true; setModified(); } // Flip else if (id == "pgfx_flip") { // Mirror Y getImage()->mirror(true); // Update UI gfx_canvas->updateImageTexture(); gfx_canvas->Refresh(); // Update variables image_data_modified = true; setModified(); } // Rotate else if (id == "pgfx_rotate") { // Prompt for rotation angle string angles[] = { "90", "180", "270" }; int choice = wxGetSingleChoiceIndex("Select rotation angle", "Rotate", 3, angles, 0); // Rotate image switch (choice) { case 0: getImage()->rotate(90); break; case 1: getImage()->rotate(180); break; case 2: getImage()->rotate(270); break; default: break; } // Update UI gfx_canvas->updateImageTexture(); gfx_canvas->Refresh(); // Update variables image_data_modified = true; setModified(); } // Translate else if (id == "pgfx_translate") { // Create translation editor dialog Palette8bit* pal = theMainWindow->getPaletteChooser()->getSelectedPalette(); TranslationEditorDialog ted(theMainWindow, pal, " Colour Remap", gfx_canvas->getImage()); // Create translation to edit ted.openTranslation(prev_translation); // Show the dialog if (ted.ShowModal() == wxID_OK) { // Apply translation to image getImage()->applyTranslation(&ted.getTranslation(), pal); // Update UI gfx_canvas->updateImageTexture(); gfx_canvas->Refresh(); // Update variables image_data_modified = true; gfx_canvas->updateImageTexture(); setModified(); prev_translation.copy(ted.getTranslation()); } } // Colourise else if (id == "pgfx_colourise") { Palette8bit* pal = theMainWindow->getPaletteChooser()->getSelectedPalette(); GfxColouriseDialog gcd(theMainWindow, entry, pal); gcd.setColour(last_colour); // Show colourise dialog if (gcd.ShowModal() == wxID_OK) { // Colourise image getImage()->colourise(gcd.getColour(), pal); // Update UI gfx_canvas->updateImageTexture(); gfx_canvas->Refresh(); // Update variables image_data_modified = true; Refresh(); setModified(); } rgba_t gcdcol = gcd.getColour(); last_colour = S_FMT("RGB(%d, %d, %d)", gcdcol.r, gcdcol.g, gcdcol.b); } // Tint else if (id == "pgfx_tint") { Palette8bit* pal = theMainWindow->getPaletteChooser()->getSelectedPalette(); GfxTintDialog gtd(theMainWindow, entry, pal); gtd.setValues(last_tint_colour, last_tint_amount); // Show tint dialog if (gtd.ShowModal() == wxID_OK) { // Tint image getImage()->tint(gtd.getColour(), gtd.getAmount(), pal); // Update UI gfx_canvas->updateImageTexture(); gfx_canvas->Refresh(); // Update variables image_data_modified = true; Refresh(); setModified(); } rgba_t gtdcol = gtd.getColour(); last_tint_colour = S_FMT("RGB(%d, %d, %d)", gtdcol.r, gtdcol.g, gtdcol.b); last_tint_amount = (int)(gtd.getAmount() * 100.0); } // Crop else if (id == "pgfx_crop") { Palette8bit* pal = theMainWindow->getPaletteChooser()->getSelectedPalette(); GfxCropDialog gcd(theMainWindow, entry, pal); // Show crop dialog if (gcd.ShowModal() == wxID_OK) { // stuff } } // alPh/tRNS else if (id == "pgfx_alph" || id == "pgfx_trns") { setModified(); Refresh(); } // Optimize PNG else if (id == "pgfx_pngopt") { // This is a special case. If we set the entry as modified, SLADE will prompt // to save it, rewriting the entry and cancelling the optimization done... if (EntryOperations::optimizePNG(entry)) setModified(false); else wxMessageBox("Warning: Couldn't optimize this image, check console log for info", "Warning", wxOK|wxCENTRE|wxICON_WARNING); Refresh(); } // Extract all else if (id == "pgfx_extract") { extractAll(); } // Convert else if (id == "pgfx_convert") { GfxConvDialog gcd(theMainWindow); gcd.CenterOnParent(); gcd.openEntry(entry); gcd.ShowModal(); if (gcd.itemModified(0)) { // Get image and conversion info SImage* image = gcd.getItemImage(0); SIFormat* format = gcd.getItemFormat(0); // Write converted image back to entry format->saveImage(*image, entry_data, gcd.getItemPalette(0)); // This makes the "save" button (and the setModified stuff) redundant and confusing! // The alternative is to save to entry effectively (uncomment the importMemChunk line) // but remove the setModified and image_data_modified lines, and add a call to refresh // to get the PNG tRNS status back in sync. //entry->importMemChunk(entry_data); image_data_modified = true; setModified(); // Fix tRNS status if we converted to paletted PNG int MENU_GFXEP_PNGOPT = theApp->getAction("pgfx_pngopt")->getWxId(); int MENU_GFXEP_ALPH = theApp->getAction("pgfx_alph")->getWxId(); int MENU_GFXEP_TRNS = theApp->getAction("pgfx_trns")->getWxId(); int MENU_ARCHGFX_EXPORTPNG = theApp->getAction("arch_gfx_exportpng")->getWxId(); if (format->getName() == "PNG") { ArchiveEntry temp; temp.importMemChunk(entry_data); temp.setType(EntryType::getType("png")); menu_custom->Enable(MENU_GFXEP_ALPH, true); menu_custom->Enable(MENU_GFXEP_TRNS, true); menu_custom->Check(MENU_GFXEP_TRNS, EntryOperations::gettRNSChunk(&temp)); menu_custom->Enable(MENU_ARCHGFX_EXPORTPNG, false); menu_custom->Enable(MENU_GFXEP_PNGOPT, true); toolbar->enableGroup("PNG", true); } else { menu_custom->Enable(MENU_GFXEP_ALPH, false); menu_custom->Enable(MENU_GFXEP_TRNS, false); menu_custom->Enable(MENU_ARCHGFX_EXPORTPNG, true); menu_custom->Enable(MENU_GFXEP_PNGOPT, false); toolbar->enableGroup("PNG", false); } // Refresh getImage()->open(entry_data, 0, format->getId()); gfx_canvas->Refresh(); } } // Unknown action else return false; // Action handled return true; }