1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00
xn65/inc/xna/graphics/sprite.hpp

167 lines
9.0 KiB
C++
Raw Normal View History

2024-05-18 21:14:56 -03:00
#ifndef XNA_GRAPHICS_SPRITE_HPP
#define XNA_GRAPHICS_SPRITE_HPP
2024-04-14 16:11:15 -03:00
2024-06-03 21:55:09 -03:00
#include "../common/color.hpp"
2024-07-08 09:40:48 -03:00
#include "../common/numerics.hpp"
#include "../default.hpp"
#include "../graphics/gresource.hpp"
2024-04-14 16:11:15 -03:00
namespace xna {
//Enables a group of sprites to be drawn using the same settings.
class SpriteBatch : public GraphicsResource {
2024-04-14 16:11:15 -03:00
public:
SpriteBatch(sptr<GraphicsDevice> const& device);
2024-07-08 09:40:48 -03:00
//Begins a sprite batch operation.
void Begin(
std::optional<SpriteSortMode> sortMode,
uptr<BlendState> blendState,
uptr<SamplerState> samplerState,
uptr<DepthStencilState> depthStencil,
uptr<RasterizerState> rasterizerState,
uptr<Effect> effect,
Matrix const& transformMatrix = Matrix::Identity()
) {
Begin(
!sortMode.has_value() ? SpriteSortMode::Deferred : sortMode.value(),
blendState.get(),
samplerState.get(),
depthStencil.get(),
rasterizerState.get(),
effect.get(),
transformMatrix
);
}
void Begin(
std::optional<SpriteSortMode> sortMode,
sptr<BlendState> blendState,
sptr<SamplerState> samplerState,
sptr<DepthStencilState> depthStencil,
sptr<RasterizerState> rasterizerState,
sptr<Effect> effect,
Matrix const& transformMatrix = Matrix::Identity()
) {
Begin(
!sortMode.has_value() ? SpriteSortMode::Deferred : sortMode.value(),
blendState.get(),
samplerState.get(),
depthStencil.get(),
rasterizerState.get(),
effect.get(),
transformMatrix
);
}
2024-05-18 19:58:38 -03:00
void Begin(
2024-04-14 16:11:15 -03:00
SpriteSortMode sortMode = SpriteSortMode::Deferred,
BlendState* blendState = nullptr,
SamplerState* samplerState = nullptr,
2024-05-18 19:58:38 -03:00
DepthStencilState* depthStencil = nullptr,
2024-04-14 16:11:15 -03:00
RasterizerState* rasterizerState = nullptr,
2024-06-25 22:04:09 -03:00
Effect* effect = nullptr,
Matrix const& transformMatrix = Matrix::Identity()
2024-05-18 19:58:38 -03:00
);
//Flushes the sprite batch and restores the device state to how it was before Begin was called.
2024-05-18 19:58:38 -03:00
void End();
2024-06-06 14:18:16 -03:00
//
// Draw - Adds a sprite to a batch of sprites to be rendered.
//
2024-06-06 14:18:16 -03:00
void Draw(uptr<Texture2D> const& texture, Vector2 const& position, Color const& color) { Draw(*texture, position, color); }
void Draw(sptr<Texture2D> const& texture, Vector2 const& position, Color const& color) { Draw(*texture, position, color); }
2024-05-18 19:58:38 -03:00
void Draw(Texture2D& texture, Vector2 const& position, Color const& color);
2024-05-27 16:44:01 -03:00
2024-06-06 14:18:16 -03:00
void Draw(uptr<Texture2D> const& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color) { Draw(*texture, position, sourceRectangle, color); }
void Draw(sptr<Texture2D> const& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color) { Draw(*texture, position, sourceRectangle, color); }
void Draw(Texture2D& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color);
2024-05-27 16:44:01 -03:00
2024-06-06 14:18:16 -03:00
void Draw(uptr<Texture2D> const& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color,
float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth) { Draw(*texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth); }
void Draw(sptr<Texture2D> const& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color,
float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth) { Draw(*texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth); }
void Draw(Texture2D& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color,
2024-05-18 19:58:38 -03:00
float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth);
2024-05-27 16:44:01 -03:00
2024-06-06 14:18:16 -03:00
void Draw(uptr<Texture2D> const& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color,
float rotation, Vector2 const& origin, Vector2 const& scale, SpriteEffects effects, float layerDepth) { Draw(*texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth); }
void Draw(sptr<Texture2D> const& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color,
float rotation, Vector2 const& origin, Vector2 const& scale, SpriteEffects effects, float layerDepth) { Draw(*texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth); }
void Draw(Texture2D& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color,
2024-05-18 19:58:38 -03:00
float rotation, Vector2 const& origin, Vector2 const& scale, SpriteEffects effects, float layerDepth);
2024-05-27 16:44:01 -03:00
2024-06-06 14:18:16 -03:00
void Draw(uptr<Texture2D> const& texture, Rectangle const& destinationRectangle, Color const& color) { Draw(*texture, destinationRectangle, color); }
void Draw(sptr<Texture2D> const& texture, Rectangle const& destinationRectangle, Color const& color) { Draw(*texture, destinationRectangle, color); }
2024-05-18 19:58:38 -03:00
void Draw(Texture2D& texture, Rectangle const& destinationRectangle, Color const& color);
2024-05-27 16:44:01 -03:00
2024-06-06 14:18:16 -03:00
void Draw(uptr<Texture2D> const& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color) { Draw(*texture, destinationRectangle, sourceRectangle, color); }
void Draw(sptr<Texture2D> const& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color) { Draw(*texture, destinationRectangle, sourceRectangle, color); }
void Draw(Texture2D& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color);
2024-05-30 17:37:40 -03:00
2024-06-06 14:18:16 -03:00
void Draw(uptr<Texture2D> const& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color,
float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth) { Draw(*texture, destinationRectangle, sourceRectangle, color, rotation, origin, effects, layerDepth); }
void Draw(sptr<Texture2D> const& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color,
float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth) { Draw(*texture, destinationRectangle, sourceRectangle, color, rotation, origin, effects, layerDepth); }
void Draw(Texture2D& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color,
float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth);
2024-05-27 16:44:01 -03:00
//
// DrawString - Adds a string to a batch of sprites to be rendered.
//
2024-06-06 14:18:16 -03:00
void DrawString(uptr<SpriteFont> const& spriteFont, String const& text, Vector2 const& position, Color const& color) { DrawString(*spriteFont, text, position, color); }
void DrawString(sptr<SpriteFont> const& spriteFont, String const& text, Vector2 const& position, Color const& color) { DrawString(*spriteFont, text, position, color); }
2024-05-18 19:58:38 -03:00
void DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position, Color const& color);
2024-05-30 17:37:40 -03:00
2024-06-06 14:18:16 -03:00
void DrawString(uptr<SpriteFont> const& spriteFont, String const& text, Vector2 const& position, Color const& color,
float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth) { DrawString(*spriteFont, text, position, color, rotation, origin, scale, effects, layerDepth); }
2024-05-27 16:44:01 -03:00
void DrawString(sptr<SpriteFont> const& spriteFont, String const& text, Vector2 const& position, Color const& color,
2024-06-06 14:18:16 -03:00
float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth) { DrawString(*spriteFont, text, position, color, rotation, origin, scale, effects, layerDepth); }
2024-05-18 19:58:38 -03:00
void DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position, Color const& color,
float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth);
2024-06-06 14:18:16 -03:00
void Viewport(xna::Viewport const& value);
2024-05-19 16:11:34 -03:00
public:
2024-05-18 19:58:38 -03:00
struct PlatformImplementation;
2024-06-27 16:08:42 -03:00
uptr<PlatformImplementation> impl = nullptr;
2024-04-14 16:11:15 -03:00
};
2024-05-18 21:14:56 -03:00
2024-06-06 14:18:16 -03:00
//Represents a font texture.
2024-05-18 21:14:56 -03:00
class SpriteFont {
public:
2024-05-30 17:37:40 -03:00
SpriteFont(
sptr<Texture2D> const& texture,
std::vector<Rectangle> const& glyphs,
std::vector<Rectangle> const& cropping,
2024-05-31 22:30:45 -03:00
std::vector<Char> const& charMap,
2024-05-30 17:37:40 -03:00
Int lineSpacing,
float spacing,
std::vector<Vector3> const& kerning,
2024-06-06 14:18:16 -03:00
std::optional<Char> const& defaultCharacter);
// Returns the width and height of a string.
2024-06-01 12:43:11 -03:00
Vector2 MeasureString(String const& text, bool ignoreWhiteSpace = true);
2024-06-06 14:18:16 -03:00
// Returns the width and height of a string.
Vector2 MeasureString(WString const& text, bool ignoreWhiteSpace = true);
//Gets or sets the default character for the font.
Char DefaultCharacter() const;
//Gets or sets the default character for the font.
void DefaultCharacter(Char value);
//Gets or sets the vertical distance (in pixels) between the base lines of two consecutive lines of text
Int LineSpacing() const;
//Gets or sets the vertical distance (in pixels) between the base lines of two consecutive lines of text
void LineSpacing(Int value);
2024-05-18 21:14:56 -03:00
2024-05-19 16:11:34 -03:00
public:
2024-05-18 21:14:56 -03:00
struct PlatformImplementation;
2024-05-30 17:37:40 -03:00
uptr<PlatformImplementation> impl = nullptr;
2024-05-18 21:14:56 -03:00
};
2024-05-30 17:37:40 -03:00
using PSpriteFont = sptr<SpriteFont>;
2024-04-14 16:11:15 -03:00
}
#endif