mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementações em Sprite
This commit is contained in:
parent
c822f6d342
commit
d21d93eaf8
@ -28,26 +28,35 @@ namespace xna {
|
|||||||
Int lineSpacing,
|
Int lineSpacing,
|
||||||
float spacing,
|
float spacing,
|
||||||
std::vector<Vector3> const& kerning,
|
std::vector<Vector3> const& kerning,
|
||||||
std::optional<Char> defaultCharacter) :
|
std::optional<Char> const& defaultCharacter)
|
||||||
textureValue(texture), glyphData(glyphs), croppingData(cropping),
|
|
||||||
characterMap(charMap), lineSpacing(lineSpacing), spacing(spacing),
|
|
||||||
kerning(kerning), defaultCharacter(defaultCharacter)
|
|
||||||
{
|
{
|
||||||
if (!texture)
|
if (!texture || !texture->impl->dxShaderResource)
|
||||||
throw std::invalid_argument("SpriteFont: texture is null.");
|
throw std::invalid_argument("SpriteFont: texture is null.");
|
||||||
|
|
||||||
|
if(cropping.size() != glyphs.size() || charMap.size() != glyphs.size() || (!kerning.empty() && kerning.size() != glyphs.size()))
|
||||||
|
throw std::invalid_argument("SpriteFont: cropping, charmap and kerning (if not empty) must all be the same size.");
|
||||||
|
|
||||||
std::vector<DxGlyph> dxGlyps(glyphs.size());
|
std::vector<DxGlyph> dxGlyps(glyphs.size());
|
||||||
|
|
||||||
for (size_t i = 0; i < dxGlyps.size(); ++i) {
|
for (size_t i = 0; i < dxGlyps.size(); ++i) {
|
||||||
DxGlyph g;
|
DxGlyph g;
|
||||||
g.Subrect.left = glyphs[i].Left();
|
g.Subrect.left = static_cast<LONG>(glyphs[i].Left());
|
||||||
g.Subrect.right = glyphs[i].Right();
|
g.Subrect.right = static_cast<LONG>(glyphs[i].Right());
|
||||||
g.Subrect.top = glyphs[i].Top();
|
g.Subrect.top = static_cast<LONG>(glyphs[i].Top());
|
||||||
g.Subrect.bottom = glyphs[i].Bottom();
|
g.Subrect.bottom = static_cast<LONG>(glyphs[i].Bottom());
|
||||||
g.Character = static_cast<Uint>(charMap[i]);
|
g.Character = static_cast<Uint>(charMap[i]);
|
||||||
g.XOffset = kerning[i].X;
|
|
||||||
g.YOffset = cropping[i].Y;
|
if (!kerning.empty()) {
|
||||||
g.XAdvance = kerning[i].Z;
|
g.XOffset = kerning[i].X;
|
||||||
|
g.YOffset = static_cast<float>(cropping[i].Y);
|
||||||
|
g.XAdvance = kerning[i].Z + spacing;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g.XOffset = 0;
|
||||||
|
g.YOffset = 0;
|
||||||
|
g.XAdvance = spacing;
|
||||||
|
}
|
||||||
|
|
||||||
dxGlyps[i] = g;
|
dxGlyps[i] = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,14 +76,7 @@ namespace xna {
|
|||||||
const auto defChar = static_cast<wchar_t>(defaultCharacter.value());
|
const auto defChar = static_cast<wchar_t>(defaultCharacter.value());
|
||||||
impl->_dxSpriteFont->SetDefaultCharacter(defChar);
|
impl->_dxSpriteFont->SetDefaultCharacter(defChar);
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
impl->_dxSpriteFont->SetDefaultCharacter(charMap[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SpriteFont::~SpriteFont() {
|
|
||||||
impl = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 SpriteFont::MeasureString(String const& text, bool ignoreWhiteSpace)
|
Vector2 SpriteFont::MeasureString(String const& text, bool ignoreWhiteSpace)
|
||||||
{
|
{
|
||||||
@ -102,22 +104,37 @@ namespace xna {
|
|||||||
return vec2;
|
return vec2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr void ConvertSpriteSort(SpriteSortMode value, DirectX::SpriteSortMode& target) {
|
Char SpriteFont::DefaultCharacter() const {
|
||||||
target = static_cast<DirectX::SpriteSortMode>(static_cast<int>(value));
|
const auto defChar = impl->_dxSpriteFont->GetDefaultCharacter();
|
||||||
|
return static_cast<Char>(defChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpriteFont::DefaultCharacter(Char value) {
|
||||||
|
const auto defChar = static_cast<wchar_t>(value);
|
||||||
|
impl->_dxSpriteFont->SetDefaultCharacter(defChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Int SpriteFont::LineSpacing() const {
|
||||||
|
const auto space = impl->_dxSpriteFont->GetLineSpacing();
|
||||||
|
return static_cast<Int>(space);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpriteFont::LineSpacing(Int value) {
|
||||||
|
impl->_dxSpriteFont->SetLineSpacing(static_cast<float>(value));
|
||||||
|
}
|
||||||
|
|
||||||
SpriteBatch::SpriteBatch(GraphicsDevice& device) {
|
SpriteBatch::SpriteBatch(GraphicsDevice& device) {
|
||||||
if (!device.impl->_context)
|
if (!device.impl->_context)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
implementation = uNew<PlatformImplementation>();
|
implementation = uNew<PlatformImplementation>();
|
||||||
implementation->_dxspriteBatch = New<DxSpriteBatch>(device.impl->_context);
|
implementation->_dxspriteBatch = New<DxSpriteBatch>(
|
||||||
|
//ID3D11DeviceContext* deviceContext
|
||||||
|
device.impl->_context
|
||||||
|
);
|
||||||
|
|
||||||
Viewport(device.Viewport());
|
Viewport(device.Viewport());
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteBatch::~SpriteBatch() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpriteBatch::Begin(SpriteSortMode sortMode, BlendState* blendState, SamplerState* samplerState, DepthStencilState* depthStencil, RasterizerState* rasterizerState, Matrix const& transformMatrix) {
|
void SpriteBatch::Begin(SpriteSortMode sortMode, BlendState* blendState, SamplerState* samplerState, DepthStencilState* depthStencil, RasterizerState* rasterizerState, Matrix const& transformMatrix) {
|
||||||
|
|
||||||
@ -125,7 +142,7 @@ namespace xna {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
DxSpriteSortMode sort;
|
DxSpriteSortMode sort;
|
||||||
ConvertSpriteSort(sortMode, sort);
|
DxHelpers::ConvertSpriteSort(sortMode, sort);
|
||||||
|
|
||||||
const auto& t = transformMatrix;
|
const auto& t = transformMatrix;
|
||||||
DxMatrix matrix = DxMatrix(
|
DxMatrix matrix = DxMatrix(
|
||||||
@ -171,10 +188,10 @@ namespace xna {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteBatch::Draw(Texture2D& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color) {
|
void SpriteBatch::Draw(Texture2D& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color) {
|
||||||
if (!implementation->_dxspriteBatch)
|
if (!implementation->_dxspriteBatch)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!texture.impl->dxShaderResource)
|
if (!texture.impl->dxShaderResource)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -184,7 +201,7 @@ namespace xna {
|
|||||||
|
|
||||||
RECT _sourceRect{};
|
RECT _sourceRect{};
|
||||||
|
|
||||||
if (sourceRectangle) {
|
if (sourceRectangle.has_value()) {
|
||||||
_sourceRect.top = sourceRectangle->Y;
|
_sourceRect.top = sourceRectangle->Y;
|
||||||
_sourceRect.left = sourceRectangle->X;
|
_sourceRect.left = sourceRectangle->X;
|
||||||
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
||||||
@ -198,7 +215,7 @@ namespace xna {
|
|||||||
_color);
|
_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteBatch::Draw(Texture2D& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color, float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth) {
|
void SpriteBatch::Draw(Texture2D& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color, float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth) {
|
||||||
if (!implementation->_dxspriteBatch)
|
if (!implementation->_dxspriteBatch)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -212,7 +229,7 @@ namespace xna {
|
|||||||
|
|
||||||
RECT _sourceRect{};
|
RECT _sourceRect{};
|
||||||
|
|
||||||
if (sourceRectangle) {
|
if (sourceRectangle.has_value()) {
|
||||||
_sourceRect.top = sourceRectangle->Y;
|
_sourceRect.top = sourceRectangle->Y;
|
||||||
_sourceRect.left = sourceRectangle->X;
|
_sourceRect.left = sourceRectangle->X;
|
||||||
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
||||||
@ -233,7 +250,7 @@ namespace xna {
|
|||||||
layerDepth);
|
layerDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteBatch::Draw(Texture2D& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color, float rotation, Vector2 const& origin, Vector2 const& scale, SpriteEffects effects, float layerDepth) {
|
void SpriteBatch::Draw(Texture2D& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color, float rotation, Vector2 const& origin, Vector2 const& scale, SpriteEffects effects, float layerDepth) {
|
||||||
if (!implementation->_dxspriteBatch)
|
if (!implementation->_dxspriteBatch)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -247,7 +264,7 @@ namespace xna {
|
|||||||
|
|
||||||
RECT _sourceRect{};
|
RECT _sourceRect{};
|
||||||
|
|
||||||
if (sourceRectangle) {
|
if (sourceRectangle.has_value()) {
|
||||||
_sourceRect.top = sourceRectangle->Y;
|
_sourceRect.top = sourceRectangle->Y;
|
||||||
_sourceRect.left = sourceRectangle->X;
|
_sourceRect.left = sourceRectangle->X;
|
||||||
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
||||||
@ -288,7 +305,7 @@ namespace xna {
|
|||||||
implementation->_dxspriteBatch->Draw(texture.impl->dxShaderResource, _destinationRect, _color);
|
implementation->_dxspriteBatch->Draw(texture.impl->dxShaderResource, _destinationRect, _color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color) {
|
void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color) {
|
||||||
if (!implementation->_dxspriteBatch)
|
if (!implementation->_dxspriteBatch)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -306,7 +323,7 @@ namespace xna {
|
|||||||
|
|
||||||
RECT _sourceRect{};
|
RECT _sourceRect{};
|
||||||
|
|
||||||
if (sourceRectangle) {
|
if (sourceRectangle.has_value()) {
|
||||||
_sourceRect.top = sourceRectangle->Y;
|
_sourceRect.top = sourceRectangle->Y;
|
||||||
_sourceRect.left = sourceRectangle->X;
|
_sourceRect.left = sourceRectangle->X;
|
||||||
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
||||||
@ -316,7 +333,7 @@ namespace xna {
|
|||||||
implementation->_dxspriteBatch->Draw(texture.impl->dxShaderResource, _destinationRect, sourceRectangle ? &_sourceRect : nullptr, _color);
|
implementation->_dxspriteBatch->Draw(texture.impl->dxShaderResource, _destinationRect, sourceRectangle ? &_sourceRect : nullptr, _color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color, float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth) {
|
void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color, float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth) {
|
||||||
if (!implementation->_dxspriteBatch)
|
if (!implementation->_dxspriteBatch)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -334,7 +351,7 @@ namespace xna {
|
|||||||
|
|
||||||
RECT _sourceRect{};
|
RECT _sourceRect{};
|
||||||
|
|
||||||
if (sourceRectangle) {
|
if (sourceRectangle.has_value()) {
|
||||||
_sourceRect.top = sourceRectangle->Y;
|
_sourceRect.top = sourceRectangle->Y;
|
||||||
_sourceRect.left = sourceRectangle->X;
|
_sourceRect.left = sourceRectangle->X;
|
||||||
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
_sourceRect.right = sourceRectangle->X + sourceRectangle->Width;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "../default.hpp"
|
#include "../default.hpp"
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
struct Point {
|
struct Point {
|
||||||
@ -34,6 +35,10 @@ namespace xna {
|
|||||||
return Height == other.Height && Width == other.Width && X == other.X && Y == other.Y;
|
return Height == other.Height && Width == other.Width && X == other.X && Y == other.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr operator std::optional<Rectangle>() const {
|
||||||
|
return std::make_optional<Rectangle>(X, Y, Width, Height);
|
||||||
|
}
|
||||||
|
|
||||||
constexpr Int Left() const { return X; }
|
constexpr Int Left() const { return X; }
|
||||||
constexpr Int Right() const { return X + Width; }
|
constexpr Int Right() const { return X + Width; }
|
||||||
constexpr Int Top() const { return Y; }
|
constexpr Int Top() const { return Y; }
|
||||||
|
@ -10,7 +10,6 @@ namespace xna {
|
|||||||
class SpriteBatch {
|
class SpriteBatch {
|
||||||
public:
|
public:
|
||||||
SpriteBatch(GraphicsDevice& device);
|
SpriteBatch(GraphicsDevice& device);
|
||||||
~SpriteBatch();
|
|
||||||
void Begin(
|
void Begin(
|
||||||
SpriteSortMode sortMode = SpriteSortMode::Deferred,
|
SpriteSortMode sortMode = SpriteSortMode::Deferred,
|
||||||
BlendState* blendState = nullptr,
|
BlendState* blendState = nullptr,
|
||||||
@ -21,66 +20,63 @@ namespace xna {
|
|||||||
Matrix const& transformMatrix = Matrix::Identity()
|
Matrix const& transformMatrix = Matrix::Identity()
|
||||||
);
|
);
|
||||||
void End();
|
void End();
|
||||||
void Draw(sptr<Texture2D> const& texture, Vector2 const& position, Color const& color) {
|
|
||||||
Draw(*texture, position, color);
|
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); }
|
||||||
void Draw(Texture2D& texture, Vector2 const& position, Color const& color);
|
void Draw(Texture2D& texture, Vector2 const& position, Color const& color);
|
||||||
|
|
||||||
void Draw(sptr<Texture2D> const& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color) {
|
void Draw(uptr<Texture2D> const& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color) { Draw(*texture, position, sourceRectangle, 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);
|
||||||
void Draw(Texture2D& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color);
|
|
||||||
|
|
||||||
void Draw(sptr<Texture2D> const& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color,
|
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) {
|
float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth) { Draw(*texture, position, sourceRectangle, color, rotation, origin, scale, effects, 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, Rectangle const* sourceRectangle, Color const& color,
|
void Draw(Texture2D& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color,
|
||||||
float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth);
|
float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth);
|
||||||
|
|
||||||
void Draw(sptr<Texture2D> const& texture, Vector2 const& position, Rectangle const* sourceRectangle, Color const& color,
|
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) {
|
float rotation, Vector2 const& origin, Vector2 const& scale, SpriteEffects effects, float layerDepth) { Draw(*texture, position, sourceRectangle, color, rotation, origin, scale, effects, 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, Rectangle const* sourceRectangle, Color const& color,
|
void Draw(Texture2D& texture, Vector2 const& position, std::optional<Rectangle> const& sourceRectangle, Color const& color,
|
||||||
float rotation, Vector2 const& origin, Vector2 const& scale, SpriteEffects effects, float layerDepth);
|
float rotation, Vector2 const& origin, Vector2 const& scale, SpriteEffects effects, float layerDepth);
|
||||||
|
|
||||||
void Draw(sptr<Texture2D> const& texture, Rectangle const& destinationRectangle, Color const& color) {
|
void Draw(uptr<Texture2D> const& texture, Rectangle const& destinationRectangle, Color const& color) { Draw(*texture, destinationRectangle, color); }
|
||||||
Draw(*texture, destinationRectangle, color);
|
void Draw(sptr<Texture2D> const& texture, Rectangle const& destinationRectangle, Color const& color) { Draw(*texture, destinationRectangle, color); }
|
||||||
}
|
|
||||||
void Draw(Texture2D& texture, Rectangle const& destinationRectangle, Color const& color);
|
void Draw(Texture2D& texture, Rectangle const& destinationRectangle, Color const& color);
|
||||||
|
|
||||||
void Draw(sptr<Texture2D> const& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color) {
|
void Draw(uptr<Texture2D> const& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color) { Draw(*texture, destinationRectangle, sourceRectangle, 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);
|
||||||
void Draw(Texture2D& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color);
|
|
||||||
|
|
||||||
void Draw(sptr<Texture2D> const& texture, Rectangle const& destinationRectangle, Rectangle const* sourceRectangle, Color const& color,
|
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) {
|
float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth) { Draw(*texture, destinationRectangle, sourceRectangle, color, rotation, origin, effects, 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, Rectangle const* sourceRectangle, Color const& color,
|
void Draw(Texture2D& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color,
|
||||||
float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth);
|
float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth);
|
||||||
|
|
||||||
void Viewport(xna::Viewport const& value);
|
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); }
|
||||||
void DrawString(sptr<SpriteFont> const& spriteFont, String const& text, Vector2 const& position, Color const& color) {
|
|
||||||
DrawString(*spriteFont, text, position, color);
|
|
||||||
}
|
|
||||||
void DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position, Color const& color);
|
void DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position, Color const& color);
|
||||||
|
|
||||||
|
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); }
|
||||||
void DrawString(sptr<SpriteFont> const& spriteFont, String const& text, Vector2 const& position, Color const& color,
|
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) {
|
float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth) { DrawString(*spriteFont, text, position, color, rotation, origin, scale, effects, layerDepth); }
|
||||||
DrawString(*spriteFont, text, position, color, rotation, origin, scale, effects, layerDepth);
|
|
||||||
}
|
|
||||||
void DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position, Color const& color,
|
void DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position, Color const& color,
|
||||||
float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth);
|
float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth);
|
||||||
|
|
||||||
|
void Viewport(xna::Viewport const& value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
uptr<PlatformImplementation> implementation = nullptr;
|
uptr<PlatformImplementation> implementation = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Represents a font texture.
|
||||||
class SpriteFont {
|
class SpriteFont {
|
||||||
public:
|
public:
|
||||||
SpriteFont(
|
SpriteFont(
|
||||||
@ -91,20 +87,21 @@ namespace xna {
|
|||||||
Int lineSpacing,
|
Int lineSpacing,
|
||||||
float spacing,
|
float spacing,
|
||||||
std::vector<Vector3> const& kerning,
|
std::vector<Vector3> const& kerning,
|
||||||
std::optional<Char> defaultCharacter);
|
std::optional<Char> const& defaultCharacter);
|
||||||
~SpriteFont();
|
|
||||||
|
// Returns the width and height of a string.
|
||||||
Vector2 MeasureString(String const& text, bool ignoreWhiteSpace = true);
|
Vector2 MeasureString(String const& text, bool ignoreWhiteSpace = true);
|
||||||
Vector2 MeasureString(WString const& text, bool ignoreWhiteSpace = true);
|
// Returns the width and height of a string.
|
||||||
|
Vector2 MeasureString(WString const& text, bool ignoreWhiteSpace = true);
|
||||||
|
|
||||||
private:
|
//Gets or sets the default character for the font.
|
||||||
sptr<Texture2D> textureValue = nullptr;
|
Char DefaultCharacter() const;
|
||||||
std::vector<Rectangle> glyphData;
|
//Gets or sets the default character for the font.
|
||||||
std::vector<Rectangle> croppingData;
|
void DefaultCharacter(Char value);
|
||||||
std::vector<Char> characterMap;
|
//Gets or sets the vertical distance (in pixels) between the base lines of two consecutive lines of text
|
||||||
Int lineSpacing{0};
|
Int LineSpacing() const;
|
||||||
float spacing{0};
|
//Gets or sets the vertical distance (in pixels) between the base lines of two consecutive lines of text
|
||||||
std::vector<Vector3> kerning;
|
void LineSpacing(Int value);
|
||||||
std::optional<Char> defaultCharacter;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
|
@ -92,6 +92,10 @@ namespace xna {
|
|||||||
//==============================================//
|
//==============================================//
|
||||||
|
|
||||||
struct DxHelpers {
|
struct DxHelpers {
|
||||||
|
static constexpr void ConvertSpriteSort(SpriteSortMode value, DirectX::SpriteSortMode& target) {
|
||||||
|
target = static_cast<DirectX::SpriteSortMode>(static_cast<int>(value));
|
||||||
|
}
|
||||||
|
|
||||||
static constexpr DXGI_FORMAT ConvertSurfaceToDXGIFORMAT(SurfaceFormat format)
|
static constexpr DXGI_FORMAT ConvertSurfaceToDXGIFORMAT(SurfaceFormat format)
|
||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
@ -446,7 +450,7 @@ namespace xna {
|
|||||||
//==============================================//
|
//==============================================//
|
||||||
|
|
||||||
struct SpriteFont::PlatformImplementation {
|
struct SpriteFont::PlatformImplementation {
|
||||||
sptr<DirectX::SpriteFont> _dxSpriteFont = nullptr;
|
uptr<DirectX::SpriteFont> _dxSpriteFont{ nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SpriteBatch::PlatformImplementation {
|
struct SpriteBatch::PlatformImplementation {
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
using Sbyte = int8_t;
|
using Sbyte = int8_t;
|
||||||
@ -48,7 +49,7 @@ namespace xna {
|
|||||||
//
|
//
|
||||||
|
|
||||||
using String = std::string;
|
using String = std::string;
|
||||||
using WString = std::wstring;
|
using WString = std::wstring;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using sptr = std::shared_ptr<T>;
|
using sptr = std::shared_ptr<T>;
|
||||||
|
@ -34,6 +34,6 @@ namespace PlatformerStarterKit {
|
|||||||
const auto source = xna::Rectangle(frameIndex * animation->Texture()->Height(), 0, animation->Texture()->Height(), animation->Texture()->Height());
|
const auto source = xna::Rectangle(frameIndex * animation->Texture()->Height(), 0, animation->Texture()->Height(), animation->Texture()->Height());
|
||||||
|
|
||||||
// Draw the current frame.
|
// Draw the current frame.
|
||||||
spriteBatch.Draw(animation->Texture(), position, &source, xna::Colors::White, 0.0f, Origin(), 1.0f, spriteEffects, 0.0f);
|
spriteBatch.Draw(animation->Texture(), position, source, xna::Colors::White, 0.0f, Origin(), 1.0f, spriteEffects, 0.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -34,6 +34,6 @@ namespace PlatformerStarterKit {
|
|||||||
|
|
||||||
void Gem::Draw(xna::GameTime const& gameTime, xna::SpriteBatch& spriteBatch)
|
void Gem::Draw(xna::GameTime const& gameTime, xna::SpriteBatch& spriteBatch)
|
||||||
{
|
{
|
||||||
spriteBatch.Draw(texture, Position(), nullptr, Color, 0.0f, origin, 1.0f, xna::SpriteEffects::None, 0.0f);
|
spriteBatch.Draw(texture, Position(), std::nullopt, Color, 0.0f, origin, 1.0f, xna::SpriteEffects::None, 0.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user