/* TextureXPanel::newTextureFromPatch * Creates a new texture called [name] from [patch]. The new texture * will be set to the dimensions of the patch, with the patch added * at 0,0 *******************************************************************/ CTexture* TextureXPanel::newTextureFromPatch(string name, string patch) { // Create new texture CTexture* tex = new CTexture(); tex->setName(name); tex->setState(2); // Setup texture scale if (texturex.getFormat() == TXF_TEXTURES) { tex->setScale(1, 1); tex->setExtended(true); } else tex->setScale(0, 0); // Add patch tex->addPatch(patch, 0, 0); // Load patch image (to determine dimensions) SImage image; tex->loadPatchImage(0, image); // Set dimensions tex->setWidth(image.getWidth()); tex->setHeight(image.getHeight()); // Update variables modified = true; // Return the new texture return tex; }
TextureModificationUS(TextureXPanel* tx_panel, CTexture* texture) : tx_panel(tx_panel) { tex_copy = new CTexture(); tex_copy->copyTexture(texture); tex_copy->setState(texture->getState()); index = tx_panel->txList().textureIndex(tex_copy->getName()); }
// ----------------------------------------------------------------------------- // Creates a new, empty texture // ----------------------------------------------------------------------------- void TextureXPanel::newTexture() { // Prompt for new texture name string name = wxGetTextFromUser("Enter a texture name:", "New Texture"); // Do nothing if no name entered if (name.IsEmpty()) return; // Process name if (!TxListIsTextures(texturex_)) { name = name.Upper().Truncate(8); } // Create new texture CTexture* tex = new CTexture(); tex->setName(name); tex->setState(2); // Default size = 64x128 tex->setWidth(64); tex->setHeight(128); // Setup texture scale if (TxListIsTextures(texturex_)) { tex->setScale(1, 1); tex->setExtended(true); } else tex->setScale(0, 0); // Add it after the last selected item int selected = list_textures_->getItemIndex(list_textures_->getLastSelected()); if (selected == -1) selected = texturex_.nTextures() - 1; // Add to end of the list if nothing selected texturex_.addTexture(tex, selected + 1); // Record undo level undo_manager_->beginRecord("New Texture"); undo_manager_->recordUndoStep(new TextureCreateDeleteUS(this, tex, true)); undo_manager_->endRecord(true); // Update texture list list_textures_->updateList(); // Select the new texture list_textures_->clearSelection(); list_textures_->selectItem(selected + 1); list_textures_->EnsureVisible(selected + 1); // Update variables modified_ = true; }
// ----------------------------------------------------------------------------- // Changes the offsets for each selected texture. Only for ZDoom! // ----------------------------------------------------------------------------- bool TextureXPanel::modifyOffsets() { if (!tx_entry_) return false; // saveTEXTUREX(); // Create modify offsets dialog ModifyOffsetsDialog mod; mod.SetParent(this); mod.CenterOnParent(); // Run the dialog if (mod.ShowModal() == wxID_CANCEL) return false; // Go through selection vector<long> selec_num = list_textures_->getSelection(true); for (unsigned a = 0; a < selec_num.size(); ++a) { // Get texture bool current = false; CTexture* ctex = texturex_.getTexture(selec_num[a]); if (ctex == tex_current_) { // Texture is currently open in the editor ctex = texture_editor_->texture(); current = true; } // Calculate and apply new offsets point2_t offsets = mod.calculateOffsets(ctex->getOffsetX(), ctex->getOffsetY(), ctex->getWidth(), ctex->getHeight()); ctex->setOffsetX(offsets.x); ctex->setOffsetY(offsets.y); ctex->setState(1); modified_ = true; // If it was the current texture, update controls if (current) texture_editor_->updateTextureControls(); } return true; }
/* TextureXPanel::paste * Pastes any textures on the clipboard after the last selected * texture *******************************************************************/ void TextureXPanel::paste() { // Check there is anything on the clipboard if (theClipboard->nItems() == 0) return; // Get last selected index int selected = list_textures->getLastSelected(); if (selected == -1) selected = texturex.nTextures() - 1; // Add to end of the list if nothing selected // Begin recording undo level undo_manager->beginRecord("Paste Texture(s)"); // Go through clipboard items for (unsigned a = 0; a < theClipboard->nItems(); a++) { // Skip if not a texture clipboard item if (theClipboard->getItem(a)->getType() != CLIPBOARD_COMPOSITE_TEXTURE) continue; // Get texture item TextureClipboardItem* item = (TextureClipboardItem*)(theClipboard->getItem(a)); // Add new texture after last selected item CTexture* ntex = new CTexture((texturex.getFormat() == TXF_TEXTURES)); ntex->copyTexture(item->getTexture(), true); ntex->setState(2); texturex.addTexture(ntex, ++selected); // Record undo step undo_manager->recordUndoStep(new TextureCreateDeleteUS(this, ntex, true)); // Deal with patches for (unsigned p = 0; p < ntex->nPatches(); p++) { CTPatch* patch = ntex->getPatch(p); // Update patch table if necessary if (texturex.getFormat() != TXF_TEXTURES) tx_editor->patchTable().addPatch(patch->getName()); // Get the entry for this patch ArchiveEntry* entry = patch->getPatchEntry(tx_editor->getArchive()); // If the entry wasn't found in any open archive, try copying it from the clipboard // (the user may have closed the archive the original patch was in) if (!entry) { entry = item->getPatchEntry(patch->getName()); // Copy the copied patch entry over to this archive if (entry) tx_editor->getArchive()->addEntry(entry, "patches", true); } // If the entry exists in the base resource archive or this archive, do nothing else if (entry->getParent() == theArchiveManager->baseResourceArchive() || entry->getParent() == tx_editor->getArchive()) continue; // Otherwise, copy the entry over to this archive else tx_editor->getArchive()->addEntry(entry, "patches", true); } } // End recording undo level undo_manager->endRecord(true); // Refresh list_textures->updateList(); // Update variables modified = true; }