Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Texture Atlas Maker

, 1 Apr 2012 BSD
A utility to create texture atlases for 2D OpenGL games
AtlasExample_iphone_project.zip
AtlasExample
.DS_Store
__MACOSX
AtlasExample
._.DS_Store
AtlasExample
.DS_Store
AtlasExample
._.DS_Store
AtlasAppDelegate.mm
AtlasExample-Info.plist
AtlasExample-Prefix.pch
._AtlasExample-Prefix.pch
EAGLView.mm
en.lproj
InfoPlist.strings
en.lproj
._InfoPlist.strings
MainWindow.xib
ImagePNG.mm
._ImagePNG.mm
images0.tga
main.m
._main.m
Shaders
Shader.fsh
Shaders
._Shader.fsh
Shader.vsh
._Shader.vsh
AtlasExample.xcodeproj
project.pbxproj
project.xcworkspace
contents.xcworkspacedata
xcuserdata
lefty.xcuserdatad
UserInterfaceState.xcuserstate
xcuserdata
lefty.xcuserdatad
xcdebugger
Breakpoints.xcbkptlist
xcschemes
AtlasExample.xcscheme
xcschememanagement.plist
AtlasExampleTests
AtlasExampleTests-Info.plist
AtlasExampleTests-Prefix.pch
AtlasExampleTests
._AtlasExampleTests-Prefix.pch
AtlasExampleTests.m
._AtlasExampleTests.m
en.lproj
InfoPlist.strings
en.lproj
._InfoPlist.strings
AtlasExample_iPhone_project_2.1.zip
.DS_Store
._.DS_Store
.DS_Store
._.DS_Store
AtlasAppDelegate.mm
AtlasExample-Info.plist
AtlasExample-Prefix.pch
._AtlasExample-Prefix.pch
EAGLView.mm
InfoPlist.strings
._InfoPlist.strings
MainWindow.xib
ImagePNG.mm
._ImagePNG.mm
imagesNelly0.tga
main.m
._main.m
Shader.fsh
._Shader.fsh
Shader.vsh
._Shader.vsh
project.pbxproj
contents.xcworkspacedata
UserInterfaceState.xcuserstate
Breakpoints.xcbkptlist
AtlasExample.xcscheme
xcschememanagement.plist
AtlasExampleTests-Info.plist
AtlasExampleTests-Prefix.pch
._AtlasExampleTests-Prefix.pch
AtlasExampleTests.m
._AtlasExampleTests.m
InfoPlist.strings
._InfoPlist.strings
AtlasMaker.zip
AtlasMaker
.classpath
.project
bin
icon.png
images
icon.png
output.png
settings.png
output.png
settings.png
src
AtlasMaker_jar.zip
AtlasMaker.jar
AtlasMaker_jar_2.0.zip
AtlasMaker.jar
AtlasMaker_jar_2.1.zip
AtlasMaker.jar
AtlasMaker_jar_2.2.1.zip
AtlasMaker.jar
AtlasMaker_jar_2.2.zip
AtlasMaker.jar
AtlasMaker_source.2.2.1.zip
.classpath
.project
.settings
org.eclipse.jdt.core.prefs
atlasMaker.properties
icon.png
icon.png
settings.png
settings.png
AtlasMaker_source.zip
.classpath
.project
icon.png
icon.png
output.png
settings.png
output.png
settings.png
AtlasMaker_source_2.0.zip
.classpath
.project
atlasMaker.properties
icon.png
icon.png
settings.png
settings.png
AtlasMaker_source_2.1.zip
.classpath
.project
org.eclipse.jdt.core.prefs
atlasMaker.properties
icon.png
icon.png
settings.png
settings.png
AtlasMaker_source_2.2.zip
.classpath
.project
org.eclipse.jdt.core.prefs
icon.png
icon.png
settings.png
settings.png
import java.awt.Frame;
import java.awt.event.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;


public class OptionsDialog extends JDialog implements ActionListener, ItemListener
{
	private static final long serialVersionUID = 8668228916639817663L;
	private JTextField textTextToolDir;
    private JTextField textAlphaThresh;
    private JPanel panelMain, panelAlphaThresh;
    private JPanel panelPVRDir;
    private JPanel panelPVROptions;
    private JButton btnSelTextToolDir;
    private JButton btnClose;
    private JRadioButton btnPVR2bit, btnPVR4bit;
    private JCheckBox checkConvPVR;
    private ButtonGroup buttonGroupPVR; 
    private JFileChooser fc = null;
    private Properties properties;
    public OptionsDialog(Frame owner, Properties mainProperties)
	{
		super(owner, "Options");
		properties = mainProperties;
        panelAlphaThresh = new JPanel();
        panelPVRDir = new JPanel();
        panelPVROptions = new JPanel();
        
        //Add various widgets to the sub panels.
        addWidgets();
        checkPVR();

        fc = new JFileChooser(".");
		setContentPane(panelMain);
        pack();
        setVisible(false);
	}


    private void addWidgets()
    {
    	textTextToolDir = new JTextField(40);
    	textAlphaThresh = new JTextField(3);
    	btnSelTextToolDir = new JButton("...");
    	btnClose = new JButton("Close");
    	textTextToolDir.setEnabled(false);
    	textAlphaThresh.setEnabled(true);
    	textAlphaThresh.setToolTipText("Pixels below this threshold are considered transparent and will be trimmed");
    	btnSelTextToolDir.addActionListener(this);
    	btnClose.addActionListener(this);
    	btnPVR2bit = new JRadioButton("2 bit");
    	btnPVR4bit = new JRadioButton("4 Bit");
    	checkConvPVR = new JCheckBox("Convert PVRs");
    	checkConvPVR.addItemListener(this);
    	
    	String last = properties.getProperty("lastAlphaThresh");
        if (last != null)
        	textAlphaThresh.setText(last);
        else textAlphaThresh.setText("2");
              
        last = properties.getProperty("PVRType");
        if (last == null)
        	btnPVR2bit.setSelected(true);
        else 
        {
        	if (last.equals("2bit"))
        		btnPVR2bit.setSelected(true);
        	else if (last.equals("4bit"))
        		btnPVR4bit.setSelected(true);
        }

        last = properties.getProperty("TextToolDir");
        if (last != null)
        	textTextToolDir.setText(last);

        //Add a border around the select panel.
        panelAlphaThresh.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Alpha Threshold"),
            BorderFactory.createEmptyBorder(5,5,5,5)));
        
        panelPVRDir.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder("Location of PVRTexTool"),
                BorderFactory.createEmptyBorder(5,5,5,5)));

        panelPVROptions.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder("PVR Options"),
                BorderFactory.createEmptyBorder(5,5,5,5)));
        
        panelAlphaThresh.add(textAlphaThresh);
        panelPVRDir.add(textTextToolDir);
        panelPVRDir.add(btnSelTextToolDir);
        panelPVROptions.add(checkConvPVR);
        panelPVROptions.add(btnPVR2bit);
        panelPVROptions.add(btnPVR4bit);

        buttonGroupPVR = new ButtonGroup();
        buttonGroupPVR.add(btnPVR2bit);
        buttonGroupPVR.add(btnPVR4bit);
        
        panelMain = new JPanel();
        panelMain.setLayout(new BoxLayout(panelMain, BoxLayout.PAGE_AXIS));
        panelMain.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));

        //Add the select and display panels to the main panel.
        panelMain.add(panelAlphaThresh);
        panelMain.add(panelPVRDir);
        panelMain.add(panelPVROptions);
        panelMain.add(btnClose);
    }
    
    public void actionPerformed(ActionEvent event)
	{
        if (event.getSource() == btnSelTextToolDir)
        {
            fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            fc.setDialogType(JFileChooser.SAVE_DIALOG);
            File file = new File(textTextToolDir.getText());
       
            if (file.isDirectory())
            	fc.setCurrentDirectory(file);
        	int returnVal = fc.showOpenDialog(null);
        	if (returnVal != JFileChooser.APPROVE_OPTION) return;
            file = fc.getSelectedFile();
            String strDir = file.getPath();
            if (file.isFile())
            {
	            int pos = strDir.lastIndexOf(File.separatorChar);
	            if (pos != -1)
	            {
	            	strDir = strDir.substring(0, pos+1);
	            }
            }
            if (!strDir.endsWith(File.separator)) strDir += File.separator;

            textTextToolDir.setText(strDir);
            properties.setProperty("TextToolDir", strDir);
        	try
        	{
				properties.store(new FileOutputStream(AtlasFrame.savePlace), null);
			} catch (IOException e)
			{
                System.out.println("error: "+e.toString());
			}
		}
        if (event.getSource() == btnClose)
        {
        	setVisible(false);
            properties.setProperty("lastAlphaThresh", textAlphaThresh.getText());

            if (btnPVR2bit.isSelected())
                properties.setProperty("PVRType", "2bit");
            else 
                properties.setProperty("PVRType", "4bit");
            
        	try
        	{
    			properties.store(new FileOutputStream(AtlasFrame.savePlace), null);
    		} catch (IOException ex)
    		{
                System.out.println("error: "+ex.toString());
    		}
    		
        }
		
	}

	public String getTextToolDir()
	{
		return textTextToolDir.getText();
	}
	public boolean is4Bit()
	{
		return btnPVR4bit.isSelected();
	}
	public int getAlphaThresh()
	{
    	int alphaThresh = Integer.parseInt(textAlphaThresh.getText());
		return alphaThresh;
	}

	public boolean convPVR()
	{
		return checkConvPVR.isSelected();
	}
	
    private void checkPVR()
    {
    	btnPVR2bit.setEnabled(checkConvPVR.isSelected());
    	btnPVR4bit.setEnabled(checkConvPVR.isSelected());
    }
    public void itemStateChanged(ItemEvent ie) 
    {
    	checkPVR();
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License

Share

About the Author

ed welch
Software Developer Astronautz
Spain Spain
After working in the software industry for many years, I've started my own games company that specialises in strategy games for mobile platforms.

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 1 Apr 2012
Article Copyright 2012 by ed welch
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid