This repository has been archived by the owner on Sep 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee74327
commit af1b5c0
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace craftersmine.EtherEngine.Content | ||
{ | ||
/// <summary> | ||
/// Represents multi-texture atlas. This class cannot be inherited | ||
/// </summary> | ||
public sealed class TextureAtlas | ||
{ | ||
/// <summary> | ||
/// Gets currently used texture | ||
/// </summary> | ||
public Texture Texture { get; private set; } | ||
|
||
/// <summary> | ||
/// Creates new instance of <see cref="TextureAtlas"/> from specified texture | ||
/// </summary> | ||
/// <param name="textureAtlas"></param> | ||
public TextureAtlas(Texture textureAtlas) | ||
{ | ||
Texture = textureAtlas; | ||
} | ||
|
||
/// <summary> | ||
/// Cuts and returns single texture with specified rectangle bounds from atlas | ||
/// </summary> | ||
/// <param name="cuttingBounds"><see cref="Rectangle"/> with specified cutting bounds</param> | ||
/// <returns></returns> | ||
public Texture CutFromAtlas(Rectangle cuttingBounds) | ||
{ | ||
Bitmap bmp = new Bitmap(cuttingBounds.Width, cuttingBounds.Height); | ||
var image = Graphics.FromImage(bmp); | ||
image.DrawImage(Texture.BaseBitmap, new Rectangle(0, 0, cuttingBounds.Width, cuttingBounds.Height), cuttingBounds, GraphicsUnit.Pixel); | ||
image.Dispose(); | ||
|
||
return new Texture(bmp); | ||
} | ||
|
||
/// <summary> | ||
/// Cuts and returns single texture with specified bounds from atlas | ||
/// </summary> | ||
/// <param name="x">X position of left-upper corner of cutting bounds</param> | ||
/// <param name="y">Y position of left-upper corner of cutting bounds</param> | ||
/// <param name="height">Height of cutting texture</param> | ||
/// <param name="width">Width of cutting texture</param> | ||
/// <returns></returns> | ||
public Texture CutFromAtlas(int x, int y, int width, int height) | ||
{ | ||
return CutFromAtlas(new Rectangle(x, y, width, height)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters