Refactor Output() slightly and document more stuff
This is in preparation for a GUI.
This commit is contained in:
parent
28e3fcbfe5
commit
d30ab8d4ef
1 changed files with 38 additions and 7 deletions
|
@ -17,8 +17,16 @@ namespace SpritePacker
|
|||
/// </summary>
|
||||
private List<Sprite> sprites = new List<Sprite>();
|
||||
|
||||
/// <summary>
|
||||
/// Whether debug information should be outputted to the console.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if verbose; <c>false</c> otherwise.</value>
|
||||
public bool Verbose { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new SpritePacker.
|
||||
/// </summary>
|
||||
/// <param name="inVerbose">Whether to output debug information to the console.</param>
|
||||
public SpritePacker(bool inVerbose = false)
|
||||
{
|
||||
Verbose = inVerbose;
|
||||
|
@ -176,7 +184,12 @@ namespace SpritePacker
|
|||
// because Sprite is a class and classes are passed by _reference_.
|
||||
}
|
||||
|
||||
public void Output(string outputFilename)
|
||||
/// <summary>
|
||||
/// Generates an image that contains all the currently added sprites.
|
||||
/// You probably want to call Arrage() before calling this method.
|
||||
/// </summary>
|
||||
/// <returns>The generated image.</returns>
|
||||
public Bitmap GenerateImage()
|
||||
{
|
||||
// Calculate the size of the image we are about to output
|
||||
Point imageSize = new Point(0, 0);
|
||||
|
@ -190,17 +203,35 @@ namespace SpritePacker
|
|||
|
||||
Bitmap finalImage = new Bitmap(imageSize.X, imageSize.Y, PixelFormat.Format32bppArgb);
|
||||
finalImage.MakeTransparent();
|
||||
Graphics context = Graphics.FromImage(finalImage);
|
||||
foreach(Sprite spr in sprites)
|
||||
using (Graphics context = Graphics.FromImage(finalImage))
|
||||
{
|
||||
context.DrawImage(spr.Image, spr.Location);
|
||||
foreach(Sprite spr in sprites)
|
||||
{
|
||||
context.DrawImage(spr.Image, spr.Location);
|
||||
}
|
||||
}
|
||||
finalImage.Save(outputFilename);
|
||||
|
||||
context.Dispose();
|
||||
finalImage.Dispose();
|
||||
return finalImage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Output the packed sprite as an image to the specified filename.
|
||||
/// You probably want to call Arrage() before calling this method.
|
||||
/// </summary>
|
||||
/// <param name="outputFilename">The filename to save the generated image to.</param>
|
||||
public void Output(string outputFilename)
|
||||
{
|
||||
using (Bitmap finalImage = GenerateImage())
|
||||
{
|
||||
finalImage.Save(outputFilename);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a the details of the currently added sprites as a string of CSV.
|
||||
/// </summary>
|
||||
/// <returns>Details of the current sprites as a string of CSV.</returns>
|
||||
/// <param name="header">Whether to include a header in the generated CSV.</param>
|
||||
public string GetSpritePositionsCSV(bool header = true)
|
||||
{
|
||||
StringWriter result = new StringWriter();
|
||||
|
|
Loading…
Reference in a new issue