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

117 lines
5.1 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
#include "../default.hpp"
2024-05-24 22:26:10 -03:00
#include "common/numerics.hpp"
2024-05-18 21:14:56 -03:00
#include "common/color.hpp"
2024-05-30 17:37:40 -03:00
#include <optional>
2024-04-14 16:11:15 -03:00
namespace xna {
2024-05-18 19:58:38 -03:00
class SpriteBatch {
2024-04-14 16:11:15 -03:00
public:
2024-05-18 19:58:38 -03:00
SpriteBatch(GraphicsDevice& device);
~SpriteBatch();
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-05-18 19:58:38 -03:00
//Effect
Matrix const& transformMatrix = Matrix::Identity()
2024-05-18 19:58:38 -03:00
);
void End();
2024-05-27 16:44:01 -03:00
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
void Draw(sptr<Texture2D> const& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color) {
Draw(*texture, position, sourceRectangle, color);
}
2024-05-18 19:58:38 -03:00
void Draw(Texture2D& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color);
2024-05-27 16:44:01 -03:00
void Draw(sptr<Texture2D> const& texture, Vector2 const& position, 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);
}
2024-05-18 19:58:38 -03:00
void Draw(Texture2D& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color,
float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth);
2024-05-27 16:44:01 -03:00
void Draw(sptr<Texture2D> const& texture, Vector2 const& position, 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);
}
2024-05-18 19:58:38 -03:00
void Draw(Texture2D& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color,
float rotation, Vector2 const& origin, Vector2 const& scale, SpriteEffects effects, float layerDepth);
2024-05-27 16:44:01 -03:00
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
void Draw(sptr<Texture2D> const& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color) {
Draw(*texture, destinationRectangle, sourceRectangle, color);
}
2024-05-18 19:58:38 -03:00
void Draw(Texture2D& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color);
2024-05-30 17:37:40 -03:00
2024-05-27 16:44:01 -03:00
void Draw(sptr<Texture2D> const& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color,
float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth) {
Draw(*texture, destinationRectangle, sourceRectangle, color, rotation, origin, effects, layerDepth);
}
2024-05-18 19:58:38 -03:00
void Draw(Texture2D& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color,
float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth);
2024-05-27 16:44:01 -03:00
2024-05-18 19:58:38 -03:00
void Viewport(xna::Viewport const& value);
2024-05-30 17:37:40 -03:00
2024-05-27 16:44:01 -03:00
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-05-27 16:44:01 -03:00
void DrawString(sptr<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-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-05-19 16:11:34 -03:00
public:
2024-05-18 19:58:38 -03:00
struct PlatformImplementation;
uptr<PlatformImplementation> implementation = nullptr;
2024-04-14 16:11:15 -03:00
};
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,
std::optional<Char> defaultCharacter);
2024-05-18 21:14:56 -03:00
~SpriteFont();
2024-05-30 17:37:40 -03:00
Vector2 MeasureString(String const& text, bool ignoreWhiteSpace = false);
Vector2 MeasureString(WString const& text, bool ignoreWhiteSpace = false);
private:
sptr<Texture2D> textureValue = nullptr;
std::vector<Rectangle> glyphData;
std::vector<Rectangle> croppingData;
2024-05-31 22:30:45 -03:00
std::vector<Char> characterMap;
2024-05-30 17:37:40 -03:00
Int lineSpacing{0};
float spacing{0};
std::vector<Vector3> kerning;
std::optional<Char> defaultCharacter;
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