User:Johnz

From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
Jump to: navigation, search

How to use Imageset exporter script

Prenote

License, I guess, Public Domain.

How-to

Installation
    $HOME/.gimp-2.8/plug-ins




Usage
  1. Make sure that every GUI element is on its own layer, and that layer is cropped.
  2. Arrange layers around canvas the way you see fit. Crop the canvas to murder the whitespace.
  3. Click File->CEGUI->Export TGA Imageset

The progressbar on the bottom of the Gimp should show that TGA exporter did some work. Go into the directory where you saved your .xcf file and doublecheck that .imageset file and .tga files are there.

Voila!

Code

Yeah, about that. Copy this into file with whichever name you'd like, just make sure it has .py extension.

#!/usr/bin/env python
 
from gimpfu import *
 
def jz_export_imageset(image, imagePath, imageName):
	imagesetFile = open(imagePath + imageName + ".imageset", "w")
	imagesetFile.write("<?xml version=\"1.0\" ?>\n");
	imagesetFile.write("<Imageset Name=\"" + imageName \
		+ "\" Imagefile=\"" + imageName \
		+ ".tga\" NativeHorzRes=\"" + str(image.width) \
		+ "\" NativeVertRes=\"" + str(image.height) \
		+ "\" AutoScaled=\"true\">\n")
	
	for layer in image.layers:
		imagesetFile.write("\t<Image Name=\"" + layer.name \
		+ "\" XPos=\"" + str(layer.offsets[0]) \
		+ "\" YPos=\"" + str(layer.offsets[1]) \
		+ "\" Width=\"" + str(layer.width) \
		+ "\" Height=\"" + str(layer.height) \
		+ "\" />\n")
	
	imagesetFile.write("</Imageset>")
	imagesetFile.close()
	return

def jz_export_cegui_imageset_tga(image, drawable):
	imagePath = image.filename[: image.filename.rfind('/') + 1]
	imageName = image.filename[image.filename.rfind('/') + 1: ].replace('.xcf', '')
	jz_export_imageset(image, imagePath, imageName)
	
	tgaImageFilename = imagePath + imageName + ".tga"
	flattenedImage = image.duplicate()
	drawableToSave = flattenedImage.flatten()
	pdb.file_tga_save(flattenedImage, drawableToSave, tgaImageFilename, tgaImageFilename, 1, 1)
	pdb.gimp_image_delete(flattenedImage)
	return

register(
    "jz_export_cegui_imageset_tga",
    "CEGUI Imageset exporter (TGA)",
    """It assumes you arranged your UI elements in the separate layers and then exports fancily formatted Imageset file that describes that.
    Also gets you out TGA flattened image of your original XCF.""",
    "John Zezelic",
    "Copyright, LoL!",
    "August 2012",
    "<Image>/File/CEGUI/Export TGA Imageset",
    "*",
    [],
    [],
    jz_export_cegui_imageset_tga,
    )


main()