Java Code Examples for com.badlogic.gdx.tools.texturepacker.TexturePacker#Settings

The following examples show how to use com.badlogic.gdx.tools.texturepacker.TexturePacker#Settings . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DesktopLauncher.java    From skin-composer with MIT License 6 votes vote down vote up
@Override
public void packFontImages(Array<FileHandle> files, FileHandle saveFile) {
    var settings = new TexturePacker.Settings();
    settings.pot = false;
    settings.duplicatePadding = true;
    settings.filterMin = Texture.TextureFilter.Linear;
    settings.filterMag = Texture.TextureFilter.Linear;
    settings.ignoreBlankImages = false;
    settings.useIndexes = false;
    settings.limitMemory = false;
    settings.maxWidth = 2048;
    settings.maxHeight = 2048;
    settings.flattenPaths = true;
    settings.silent = true;
    var texturePacker = new TexturePacker(settings);

    for (FileHandle file : files) {
        if (file.exists()) {
            texturePacker.addImage(file.file());
        }
    }

    texturePacker.pack(saveFile.parent().file(), saveFile.nameWithoutExtension());
}
 
Example 2
Source File: MainController.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@LmlAction("onSettingsCbChecked") void onSettingsCbChecked(VisCheckBox checkBox) {
    PackModel pack = getSelectedPack();
    if (pack == null) return;

    TexturePacker.Settings settings = pack.getSettings();
    switch (checkBox.getName()) {
        case "cbUseFastAlgorithm": settings.fast = checkBox.isChecked(); break;
        case "cbEdgePadding": settings.edgePadding = checkBox.isChecked(); break;
        case "cbStripWhitespaceX": settings.stripWhitespaceX = checkBox.isChecked(); break;
        case "cbStripWhitespaceY": settings.stripWhitespaceY = checkBox.isChecked(); break;
        case "cbAllowRotation": settings.rotation = checkBox.isChecked(); break;
        case "cbBleeding": settings.bleed = checkBox.isChecked(); break;
        case "cbDuplicatePadding": settings.duplicatePadding = checkBox.isChecked(); break;
        case "cbForcePot": settings.pot = checkBox.isChecked(); break;
        case "cbForceMof": settings.multipleOfFour = checkBox.isChecked(); break;
        case "cbUseAliases": settings.alias = checkBox.isChecked(); break;
        case "cbIgnoreBlankImages": settings.ignoreBlankImages = checkBox.isChecked(); break;
        case "cbDebug": settings.debug = checkBox.isChecked(); break;
        case "cbUseIndices": settings.useIndexes = checkBox.isChecked(); break;
        case "cbPremultiplyAlpha": settings.premultiplyAlpha = checkBox.isChecked(); break;
        case "cbGrid": settings.grid = checkBox.isChecked(); break;
        case "cbSquare": settings.square = checkBox.isChecked(); break;
        case "cbLimitMemory": settings.limitMemory = checkBox.isChecked(); break;
    }
}
 
Example 3
Source File: MainController.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@LmlAction("onSettingsIntSeekBarChanged") void onSettingsIntSeekBarChanged(SeekBar seekBar) {
    PackModel pack = getSelectedPack();
    if (pack == null) return;

    TexturePacker.Settings settings = pack.getSettings();
    IntSeekBarModel model = (IntSeekBarModel) seekBar.getModel();
    switch (seekBar.getName()) {
        case "skbMinPageWidth": settings.minWidth = model.getValue(); break;
        case "skbMinPageHeight": settings.minHeight = model.getValue(); break;
        case "skbMaxPageWidth": settings.maxWidth = model.getValue(); break;
        case "skbMaxPageHeight": settings.maxHeight = model.getValue(); break;
        case "skbAlphaThreshold": settings.alphaThreshold = model.getValue(); break;
        case "skbPaddingX": settings.paddingX = model.getValue(); break;
        case "skbPaddingY": settings.paddingY = model.getValue(); break;
    }
}
 
Example 4
Source File: MainController.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@LmlAction("onSettingsCboChanged") void onSettingsCboChanged(VisSelectBox selectBox) {
        if (!viewShown) return;

        PackModel pack = getSelectedPack();
        if (pack == null) return;

        TexturePacker.Settings settings = pack.getSettings();
        Object value = selectBox.getSelected();
        switch (selectBox.getName()) {
            case "cboEncodingFormat": settings.format = (Pixmap.Format) value; break;
            case "cboMinFilter": settings.filterMin = (Texture.TextureFilter) value; break;
            case "cboMagFilter": settings.filterMag = (Texture.TextureFilter) value; break;
            case "cboWrapX": settings.wrapX = (Texture.TextureWrap) value; break;
            case "cboWrapY": settings.wrapY = (Texture.TextureWrap) value; break;
//            case "cboOutputFormat": settings.outputFormat = (String) value; break;
        }
    }
 
Example 5
Source File: MainScreen.java    From gdx-skineditor with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
public void refreshResources() {
	
	TexturePacker.Settings settings = new TexturePacker.Settings();
	settings.combineSubdirectories = true;
	settings.maxWidth = 2048;
	settings.maxHeight = 2048;
	TexturePacker.process(settings, "projects/" + currentProject +"/assets/", "projects/" + currentProject, "uiskin");
	

	// Load project skin
	if (game.skinProject != null) {
		game.skinProject.dispose();
	}
	
	game.skinProject = new Skin();
	game.skinProject.addRegions(new TextureAtlas(Gdx.files.local("projects/" + currentProject +"/uiskin.atlas")));
	game.skinProject.load(Gdx.files.local("projects/" + currentProject +"/uiskin.json"));

	
}
 
Example 6
Source File: WelcomeScreen.java    From gdx-skineditor with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param projectName
 */
public void createProject(String projectName) {

	FileHandle projectFolder = Gdx.files.local("projects").child(projectName);
	if (projectFolder.exists() == true) {
		game.showNotice("Error", "Project name already in use!", stage);
		return;
	}

	projectFolder.mkdirs();
	projectFolder.child("assets").mkdirs();
	projectFolder.child("backups").mkdirs();
	game.skin.save(projectFolder.child("uiskin.json"));

	// Copy assets
	FileHandle assetsFolder = Gdx.files.local("resources/raw");
	assetsFolder.copyTo(projectFolder.child("assets"));
	// Rebuild from raw resources
	TexturePacker.Settings settings = new TexturePacker.Settings();
	settings.combineSubdirectories = true;
	TexturePacker.process(settings, "projects/" + projectName +"/assets/", "projects/" + projectName, "uiskin");

	game.showNotice("Operation completed", "New project successfully created.", stage);
	
	refreshProjects();
}
 
Example 7
Source File: DesktopLauncher.java    From FruitCatcher with Apache License 2.0 6 votes vote down vote up
public static void main (String[] arg) {
       // Create two run configurations
       // 1. For texture packing. Pass 'texturepacker' as argument and use desktop/src
       //    as working directory
       // 2. For playing game with android/assets as working directory
       if (arg.length == 1 && arg[0].equals("texturepacker")) {
           String outdir = "assets";
           TexturePacker.Settings settings = new TexturePacker.Settings();
           settings.maxWidth = 1024;
           settings.maxHeight = 1024;
           TexturePacker.process(settings, "images", outdir, "game");
           TexturePacker.process(settings, "text-images", outdir, "text_images");
           TexturePacker.process(settings, "text-images-de", outdir, "text_images_de");
       }
       else {
           LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
           config.title = "FruitCatcher";
           config.width = 800;
           config.height = 480;
           new LwjglApplication(new FruitCatcherGame(null, "en"), config);
       }
}
 
Example 8
Source File: GlobalActions.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
@LmlAction("copySettingsToAllPacks") public void copySettingsToAllPacks() {
    PackModel selectedPack = getSelectedPack();
    if (selectedPack == null) return;

    TexturePacker.Settings generalSettings = selectedPack.getSettings();
    Array<PackModel> packs = getProject().getPacks();
    for (PackModel pack : packs) {
        if (pack == selectedPack) continue;

        pack.setSettings(generalSettings);
    }

    eventDispatcher.postEvent(new ShowToastEvent()
            .message(getString("toastCopyAllSettings"))
            .duration(ShowToastEvent.DURATION_SHORT));
}
 
Example 9
Source File: PackDialogController.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
private Array<PackProcessingNode> prepareProcessingNodes(ProjectModel project, Array<PackModel> packs) {
    Array<PackProcessingNode> result = new Array<>();
    for (PackModel pack : packs) {
        for (ScaleFactorModel scaleFactor : pack.getScaleFactors()) {
            PackModel newPack = new PackModel(pack);
            newPack.setScaleFactors(Array.with(scaleFactor));
            TexturePacker.Settings settings = newPack.getSettings();
            settings.scaleSuffix[0] = "";
            settings.scale[0] = scaleFactor.getFactor();
            settings.scaleResampling[0] = scaleFactor.getResampling();

            PackProcessingNode processingNode = new PackProcessingNode(project, newPack);
            processingNode.setOrigPack(pack);

            result.add(processingNode);
        }
    }
    return result;
}
 
Example 10
Source File: SkinEditorGame.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
@Override
public void create() {
	
	opt = new OptionalChecker();
	
	fm = new SystemFonts();
	fm.refreshFonts();
	
	// Create projects folder if not already here
	FileHandle dirProjects = new FileHandle("projects");
	
	if (dirProjects.isDirectory() == false) {
		dirProjects.mkdirs();
	}
	
	// Rebuild from raw resources, kind of overkill, might disable it for production
	TexturePacker.Settings settings = new TexturePacker.Settings();
	settings.combineSubdirectories = true;
	TexturePacker.process(settings, "resources/raw/", ".", "resources/uiskin");

	batch = new SpriteBatch();
	skin = new Skin();
	atlas = new TextureAtlas(Gdx.files.internal("resources/uiskin.atlas"));
	
	
	skin.addRegions(new TextureAtlas(Gdx.files.local("resources/uiskin.atlas")));
	skin.load(Gdx.files.local("resources/uiskin.json"));
	
	screenMain = new MainScreen(this);
	screenWelcome = new WelcomeScreen(this);
	setScreen(screenWelcome);
	
}
 
Example 11
Source File: PackingProcessor.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
private static void deleteOldFiles(PackModel packModel) throws Exception {
    String filename = obtainFilename(packModel);

    TexturePacker.Settings settings = packModel.getSettings();
    String atlasExtension = settings.atlasExtension == null ? "" : settings.atlasExtension;
    atlasExtension = Pattern.quote(atlasExtension);

    for (int i = 0, n = settings.scale.length; i < n; i++) {
        FileProcessor deleteProcessor = new FileProcessor() {
            protected void processFile (Entry inputFile) throws Exception {
                Files.delete(inputFile.inputFile.toPath());
            }
        };
        deleteProcessor.setRecursive(false);

        String scaledPackFileName = settings.getScaledPackFileName(filename, i);
        File packFile = new File(scaledPackFileName);

        String prefix = filename;
        int dotIndex = prefix.lastIndexOf('.');
        if (dotIndex != -1) prefix = prefix.substring(0, dotIndex);
        deleteProcessor.addInputRegex("(?i)" + prefix + "\\d*\\.(png|jpg|jpeg|ktx|zktx)");
        deleteProcessor.addInputRegex("(?i)" + prefix + atlasExtension);

        File outputRoot = new File(packModel.getOutputDir());
        String dir = packFile.getParent();
        if (dir == null)
            deleteProcessor.process(outputRoot, null);
        else if (new File(outputRoot + "/" + dir).exists()) //
            deleteProcessor.process(outputRoot + "/" + dir, null);
    }
}
 
Example 12
Source File: KtxFileTypeProcessor.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public void saveToFile(TexturePacker.Settings settings, BufferedImage image, File file) throws IOException {
    FileHandle tmpPngFile = new FileHandle(File.createTempFile(file.getName(), null));
    FileHandle output = new FileHandle(file);

    super.saveToFile(settings, image, tmpPngFile.file());

    KtxEtc2Processor.process(tmpPngFile, output, pixelFormat);
    tmpPngFile.delete();

    if (zipping) {
        FileUtils.packGzip(output);
    }
}
 
Example 13
Source File: KtxFileTypeProcessor.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public void saveToFile(TexturePacker.Settings settings, BufferedImage image, File file) throws IOException {
    FileHandle tmpPngFile = new FileHandle(File.createTempFile(file.getName(), null));
    FileHandle output = new FileHandle(file);

    super.saveToFile(settings, image, tmpPngFile.file());

    KtxEtc1Processor.process(tmpPngFile, output, alphaChannel);
    tmpPngFile.delete();

    if (zipping) {
        FileUtils.packGzip(output);
    }
}
 
Example 14
Source File: Generator.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
        TexturePacker.Settings settings = new TexturePacker.Settings();
        settings.combineSubdirectories = true;
        TexturePacker.process(settings, "generator/gfx", "android/assets", "gfx");
        TexturePacker.process(settings, "generator/world-map", "android/assets", "world-map");
//        renamePrefixes("generator/gfx/ui/level-icon", "ui-level-icon-", "");
    }
 
Example 15
Source File: ProjectSerializer.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
private String serializePack(PackModel pack, FileHandle root) {
        StringBuilder sb = new StringBuilder();

        String filename = pack.getFilename();

        sb.append("name=").append(pack.getName()).append("\n");
        sb.append("filename=").append(filename).append("\n");
        sb.append("output=").append(PathUtils.relativize(pack.getOutputDir(), root.file().getPath())).append("\n");

        sb.append("\n");

        TexturePacker.Settings settings = pack.getSettings();
        sb.append("alias=").append(settings.alias).append("\n");
        sb.append("alphaThreshold=").append(settings.alphaThreshold).append("\n");
        sb.append("debug=").append(settings.debug).append("\n");
        sb.append("duplicatePadding=").append(settings.duplicatePadding).append("\n");
        sb.append("edgePadding=").append(settings.edgePadding).append("\n");
        sb.append("fast=").append(settings.fast).append("\n");
        sb.append("filterMag=").append(settings.filterMag).append("\n");
        sb.append("filterMin=").append(settings.filterMin).append("\n");
//        sb.append("format=").append(settings.format).append("\n");
        sb.append("ignoreBlankImages=").append(settings.ignoreBlankImages).append("\n");
//        sb.append("jpegQuality=").append(settings.jpegQuality).append("\n");
        sb.append("maxHeight=").append(settings.maxHeight).append("\n");
        sb.append("maxWidth=").append(settings.maxWidth).append("\n");
        sb.append("minHeight=").append(settings.minHeight).append("\n");
        sb.append("minWidth=").append(settings.minWidth).append("\n");
//        sb.append("outputFormat=").append(settings.outputFormat).append("\n");
        sb.append("paddingX=").append(settings.paddingX).append("\n");
        sb.append("paddingY=").append(settings.paddingY).append("\n");
        sb.append("pot=").append(settings.pot).append("\n");
        sb.append("mof=").append(settings.multipleOfFour).append("\n");
        sb.append("rotation=").append(settings.rotation).append("\n");
        sb.append("stripWhitespaceX=").append(settings.stripWhitespaceX).append("\n");
        sb.append("stripWhitespaceY=").append(settings.stripWhitespaceY).append("\n");
        sb.append("wrapX=").append(settings.wrapX).append("\n");
        sb.append("wrapY=").append(settings.wrapY).append("\n");
        sb.append("premultiplyAlpha=").append(settings.premultiplyAlpha).append("\n");
        sb.append("grid=").append(settings.grid).append("\n");
        sb.append("square=").append(settings.square).append("\n");
        sb.append("bleed=").append(settings.bleed).append("\n");
        sb.append("limitMemory=").append(settings.limitMemory).append("\n");
        sb.append("useIndexes=").append(settings.useIndexes).append("\n");

        sb.append("\n");

        sb.append("scaleFactors=").append(json.toJson(pack.getScaleFactors())).append("\n");

        inputFileSerializer.setRoot(root.file());
        sb.append("inputFiles=").append(json.toJson(pack.getInputFiles())).append("\n");

        return sb.toString();
    }
 
Example 16
Source File: TextureSetup.java    From SIFTrain with MIT License 4 votes vote down vote up
public static void main(String[] args) {
    TexturePacker.Settings config = new TexturePacker.Settings();
    config.maxWidth = 512;
    config.maxHeight = 512;
    TexturePacker.process(config, "images/", "textures/", "textures.pack");
}
 
Example 17
Source File: MainController.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
private void updateViewsFromPack(PackModel pack) {
    if (actorsPacks.packListAdapter.getSelected() != pack) {
        actorsPacks.packListAdapter.getSelectionManager().deselectAll();
        if (pack != null) {
            actorsPacks.packListAdapter.getSelectionManager().select(pack);
        }
    }

    // Update pack list item
    PackListAdapter.ViewHolder viewHolder = actorsPacks.packListAdapter.getViewHolder(pack);
    if (viewHolder != null) {
        viewHolder.updateViewData();
    }

    if (pack != null) {
        actorsPacks.edtOutputDir.setText(pack.getOutputDir());
        actorsPacks.edtFileName.setText(pack.getFilename());
        actorsPacks.edtFileName.setMessageText(pack.getName() + ".atlas");
    } else {
        actorsPacks.edtOutputDir.setText(null);
        actorsPacks.edtFileName.setText(null);
    }

    if (pack != null) {
        TexturePacker.Settings settings = pack.getSettings();

        actorsPackSettings.cbUseFastAlgorithm.setChecked(settings.fast);
        actorsPackSettings.cbEdgePadding.setChecked(settings.edgePadding);
        actorsPackSettings.cbStripWhitespaceX.setChecked(settings.stripWhitespaceX);
        actorsPackSettings.cbStripWhitespaceY.setChecked(settings.stripWhitespaceY);
        actorsPackSettings.cbAllowRotation.setChecked(settings.rotation);
        actorsPackSettings.cbBleeding.setChecked(settings.bleed);
        actorsPackSettings.cbDuplicatePadding.setChecked(settings.duplicatePadding);
        actorsPackSettings.cbForcePot.setChecked(settings.pot);
        actorsPackSettings.cbForceMof.setChecked(settings.multipleOfFour);
        actorsPackSettings.cbUseAliases.setChecked(settings.alias);
        actorsPackSettings.cbIgnoreBlankImages.setChecked(settings.ignoreBlankImages);
        actorsPackSettings.cbDebug.setChecked(settings.debug);
        actorsPackSettings.cbUseIndices.setChecked(settings.useIndexes);
        actorsPackSettings.cbPremultiplyAlpha.setChecked(settings.premultiplyAlpha);
        actorsPackSettings.cbGrid.setChecked(settings.grid);
        actorsPackSettings.cbSquare.setChecked(settings.square);
        actorsPackSettings.cbLimitMemory.setChecked(settings.limitMemory);

        ((IntSeekBarModel) actorsPackSettings.skbMinPageWidth.getModel()).setValue(settings.minWidth, false);
        ((IntSeekBarModel) actorsPackSettings.skbMinPageHeight.getModel()).setValue(settings.minHeight, false);
        ((IntSeekBarModel) actorsPackSettings.skbMaxPageWidth.getModel()).setValue(settings.maxWidth, false);
        ((IntSeekBarModel) actorsPackSettings.skbMaxPageHeight.getModel()).setValue(settings.maxHeight, false);
        ((IntSeekBarModel) actorsPackSettings.skbAlphaThreshold.getModel()).setValue(settings.alphaThreshold, false);
        ((IntSeekBarModel) actorsPackSettings.skbPaddingX.getModel()).setValue(settings.paddingX, false);
        ((IntSeekBarModel) actorsPackSettings.skbPaddingY.getModel()).setValue(settings.paddingY, false);

        actorsPackSettings.cboMinFilter.setSelected(settings.filterMin);
        actorsPackSettings.cboMagFilter.setSelected(settings.filterMag);
        actorsPackSettings.cboWrapX.setSelected(settings.wrapX);
        actorsPackSettings.cboWrapY.setSelected(settings.wrapY);

        // Scale factors
        {
            StringBuilder sb = new StringBuilder();
            Array<ScaleFactorModel> scaleFactors = pack.getScaleFactors();
            for (int i = 0; i < scaleFactors.size; i++) {
                ScaleFactorModel scaleFactor = scaleFactors.get(i);
                sb.append(String.format(Locale.US, "%.2f", scaleFactor.getFactor()));
                if (i < scaleFactors.size-1) { sb.append(", "); }
            }
            actorsPackSettings.eetbScaleFactors.setText(sb.toString());
        }
    }

    // Update pane lockers
    for (Actor locker : packPaneLockers) {
        locker.setVisible(pack == null);
    }
}
 
Example 18
Source File: NinePatchEditorDialog.java    From gdx-skineditor with Apache License 2.0 2 votes vote down vote up
public void refreshPreview() {

		Gdx.app.log("NinePatchEditorDialog","refresh preview.");

		Pixmap pixmapImage = new Pixmap(Gdx.files.internal(textSourceImage.getText()));
		
		Pixmap pixmap = new Pixmap((int) (pixmapImage.getWidth()+2), (int) (pixmapImage.getHeight()+2), Pixmap.Format.RGBA8888);
		pixmap.drawPixmap(pixmapImage,1,1);

		pixmap.setColor(Color.BLACK);
		
		// Range left
		int h = pixmapImage.getHeight()+1;
		pixmap.drawLine(0, (int) (h * rangeLeft.rangeStart),0, (int) (h * rangeLeft.rangeStop));
		

		// Range top
		int w = pixmapImage.getWidth()+1;
		pixmap.drawLine((int) (w * rangeTop.rangeStart), 0,(int) (w * rangeTop.rangeStop), 0);

		// Range right
		h = pixmapImage.getHeight()+1;
		pixmap.drawLine(pixmapImage.getWidth()+1, (int) (h * rangeRight.rangeStart),pixmapImage.getWidth()+1, (int) (h * rangeRight.rangeStop));

		// Range bottom
		w = pixmapImage.getWidth()+1;
		pixmap.drawLine((int) (w * rangeBottom.rangeStart), pixmap.getHeight()-1,(int) (w * rangeBottom.rangeStop), pixmap.getHeight()-1);
		
		
		PixmapIO.writePNG(tmpFile, pixmap);
		
		pixmapImage.dispose();
		pixmap.dispose();

		FileHandle fh = new FileHandle(System.getProperty("java.io.tmpdir")).child("skin_ninepatch");
		TexturePacker.Settings settings = new TexturePacker.Settings();
		TexturePacker.process(settings, fh.path(), fh.path(), "pack");

		TextureAtlas ta = new TextureAtlas(fh.child("pack.atlas"));
		NinePatch np = ta.createPatch("button");
		NinePatchDrawable drawable = new NinePatchDrawable(np);
		reviewTablePreview();	
		buttonPreview1.getStyle().up = drawable;
		

	}