mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementa Sprite
This commit is contained in:
parent
f36f67f401
commit
d35b564ddd
@ -24,8 +24,8 @@ add_executable (xna WIN32
|
|||||||
"platform/constbuffer-dx.cpp"
|
"platform/constbuffer-dx.cpp"
|
||||||
"platform/databuffer-dx.cpp"
|
"platform/databuffer-dx.cpp"
|
||||||
"platform/samplerstate-dx.cpp"
|
"platform/samplerstate-dx.cpp"
|
||||||
"platform/spritebatch-dx.cpp"
|
"platform/sprite-dx.cpp"
|
||||||
"platform/spritefont-dx.cpp"
|
|
||||||
"platform/depthstencilstate-dx.cpp"
|
"platform/depthstencilstate-dx.cpp"
|
||||||
"platform/keyboard-dx.cpp"
|
"platform/keyboard-dx.cpp"
|
||||||
"platform/mouse-dx.cpp"
|
"platform/mouse-dx.cpp"
|
||||||
|
@ -6,9 +6,8 @@
|
|||||||
#include "platform-dx/texture-dx.hpp"
|
#include "platform-dx/texture-dx.hpp"
|
||||||
#include "common/color.hpp"
|
#include "common/color.hpp"
|
||||||
#include "common/numerics.hpp"
|
#include "common/numerics.hpp"
|
||||||
#include "graphics/spritebatch.hpp"
|
#include "graphics/sprite.hpp"
|
||||||
#include "graphics/viewport.hpp"
|
#include "graphics/viewport.hpp"
|
||||||
#include "platform-dx/spritefont-dx.hpp"
|
|
||||||
|
|
||||||
using DxSpriteBatch = DirectX::SpriteBatch;
|
using DxSpriteBatch = DirectX::SpriteBatch;
|
||||||
using DxSpriteSortMode = DirectX::SpriteSortMode;
|
using DxSpriteSortMode = DirectX::SpriteSortMode;
|
||||||
@ -18,8 +17,35 @@ using DirectX::XMFLOAT2;
|
|||||||
using DirectX::FXMVECTOR;
|
using DirectX::FXMVECTOR;
|
||||||
using DirectX::XMVECTORF32;
|
using DirectX::XMVECTORF32;
|
||||||
using DirectX::GXMVECTOR;
|
using DirectX::GXMVECTOR;
|
||||||
|
using DxSpriteFont = DirectX::SpriteFont;
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
|
struct SpriteFont::PlatformImplementation {
|
||||||
|
sptr<DirectX::SpriteFont> _dxSpriteFont = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
SpriteFont::SpriteFont(GraphicsDevice& device, String const& fontFileName)
|
||||||
|
{
|
||||||
|
const auto wString = XnaHToWString(fontFileName);
|
||||||
|
implementation = uNew<PlatformImplementation>();
|
||||||
|
implementation->_dxSpriteFont = New<DxSpriteFont>(device._device, wString.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
SpriteFont::~SpriteFont() {}
|
||||||
|
|
||||||
|
Vector2 SpriteFont::MeasureString(String const& text, bool ignoreWhiteSpace)
|
||||||
|
{
|
||||||
|
if (!implementation->_dxSpriteFont)
|
||||||
|
return Vector2();
|
||||||
|
|
||||||
|
const auto size = implementation->_dxSpriteFont->MeasureString(text.c_str(), ignoreWhiteSpace);
|
||||||
|
Vector2 vec2{};
|
||||||
|
vec2.X = size.m128_f32[0];
|
||||||
|
vec2.Y = size.m128_f32[1];
|
||||||
|
|
||||||
|
return vec2;
|
||||||
|
}
|
||||||
|
|
||||||
struct SpriteBatch::PlatformImplementation {
|
struct SpriteBatch::PlatformImplementation {
|
||||||
sptr<DirectX::SpriteBatch> _dxspriteBatch = nullptr;
|
sptr<DirectX::SpriteBatch> _dxspriteBatch = nullptr;
|
||||||
};
|
};
|
||||||
@ -290,17 +316,17 @@ namespace xna {
|
|||||||
_view.MaxDepth = value.MaxDepth;
|
_view.MaxDepth = value.MaxDepth;
|
||||||
|
|
||||||
implementation->_dxspriteBatch->SetViewport(_view);
|
implementation->_dxspriteBatch->SetViewport(_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteBatch::DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position, Color const& color) {
|
void SpriteBatch::DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position, Color const& color) {
|
||||||
if (!implementation->_dxspriteBatch || !spriteFont._dxSpriteFont)
|
if (!implementation->_dxspriteBatch || !spriteFont.implementation->_dxSpriteFont)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto _position = XMFLOAT2(position.X, position.Y);
|
const auto _position = XMFLOAT2(position.X, position.Y);
|
||||||
const auto v4 = color.ToVector4();
|
const auto v4 = color.ToVector4();
|
||||||
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
|
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
|
||||||
|
|
||||||
spriteFont._dxSpriteFont->DrawString(
|
spriteFont.implementation->_dxSpriteFont->DrawString(
|
||||||
implementation->_dxspriteBatch.get(),
|
implementation->_dxspriteBatch.get(),
|
||||||
text.c_str(),
|
text.c_str(),
|
||||||
_position,
|
_position,
|
||||||
@ -310,7 +336,7 @@ namespace xna {
|
|||||||
|
|
||||||
void SpriteBatch::DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position,
|
void SpriteBatch::DrawString(SpriteFont& spriteFont, String const& text, Vector2 const& position,
|
||||||
Color const& color, float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth) {
|
Color const& color, float rotation, Vector2 const& origin, float scale, SpriteEffects effects, float layerDepth) {
|
||||||
if (!implementation->_dxspriteBatch || !spriteFont._dxSpriteFont)
|
if (!implementation->_dxspriteBatch || !spriteFont.implementation->_dxSpriteFont)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto _position = XMFLOAT2(position.X, position.Y);
|
const auto _position = XMFLOAT2(position.X, position.Y);
|
||||||
@ -319,7 +345,7 @@ namespace xna {
|
|||||||
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
|
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
|
||||||
const auto _effects = static_cast<DxSpriteEffects>(effects);
|
const auto _effects = static_cast<DxSpriteEffects>(effects);
|
||||||
|
|
||||||
spriteFont._dxSpriteFont->DrawString(
|
spriteFont.implementation->_dxSpriteFont->DrawString(
|
||||||
implementation->_dxspriteBatch.get(),
|
implementation->_dxspriteBatch.get(),
|
||||||
text.c_str(),
|
text.c_str(),
|
||||||
_position,
|
_position,
|
@ -1,24 +0,0 @@
|
|||||||
#include "platform-dx/spritefont-dx.hpp"
|
|
||||||
|
|
||||||
using DxSpriteFont = DirectX::SpriteFont;
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
SpriteFont::SpriteFont(GraphicsDevice& device, String const& fontFileName)
|
|
||||||
{
|
|
||||||
const auto wString = XnaHToWString(fontFileName);
|
|
||||||
_dxSpriteFont = New<DxSpriteFont>(device._device, wString.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 SpriteFont::MeasureString(String const& text, bool ignoreWhiteSpace)
|
|
||||||
{
|
|
||||||
if (!_dxSpriteFont)
|
|
||||||
return Vector2();
|
|
||||||
|
|
||||||
const auto size = _dxSpriteFont->MeasureString(text.c_str(), ignoreWhiteSpace);
|
|
||||||
Vector2 vec2{};
|
|
||||||
vec2.X = size.m128_f32[0];
|
|
||||||
vec2.Y = size.m128_f32[1];
|
|
||||||
|
|
||||||
return vec2;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,9 @@
|
|||||||
#ifndef XNA_GRAPHICS_SPRITEBATCH_HPP
|
#ifndef XNA_GRAPHICS_SPRITE_HPP
|
||||||
#define XNA_GRAPHICS_SPRITEBATCH_HPP
|
#define XNA_GRAPHICS_SPRITE_HPP
|
||||||
|
|
||||||
#include "../default.hpp"
|
#include "../default.hpp"
|
||||||
#include "../common/numerics.hpp"
|
#include "../common/numerics.hpp"
|
||||||
|
#include "common/color.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
class SpriteBatch {
|
class SpriteBatch {
|
||||||
@ -38,6 +39,17 @@ namespace xna {
|
|||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
uptr<PlatformImplementation> implementation = nullptr;
|
uptr<PlatformImplementation> implementation = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SpriteFont {
|
||||||
|
public:
|
||||||
|
SpriteFont(GraphicsDevice& device, String const& fontFileName);
|
||||||
|
~SpriteFont();
|
||||||
|
Vector2 MeasureString(String const& text, bool ignoreWhiteSpace = true);
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct PlatformImplementation;
|
||||||
|
uptr<PlatformImplementation> implementation = nullptr;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,15 +0,0 @@
|
|||||||
#ifndef XNA_GRAPHICS_SPRITEFONT_HPP
|
|
||||||
#define XNA_GRAPHICS_SPRITEFONT_HPP
|
|
||||||
|
|
||||||
#include "../default.hpp"
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
class ISpriteFont {
|
|
||||||
public:
|
|
||||||
virtual ~ISpriteFont(){}
|
|
||||||
|
|
||||||
virtual Vector2 MeasureString(String const& text, bool ignoreWhiteSpace = true) = 0;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,23 +0,0 @@
|
|||||||
#ifndef XNA_PLATFORM_SPRITEFONT_DX_HPP
|
|
||||||
#define XNA_PLATFORM_SPRITEFONT_DX_HPP
|
|
||||||
|
|
||||||
#include "../graphics/spritefont.hpp"
|
|
||||||
#include "../common/numerics.hpp"
|
|
||||||
#include "SpriteFont.h"
|
|
||||||
#include "device-dx.hpp"
|
|
||||||
|
|
||||||
namespace xna {
|
|
||||||
class SpriteFont : public ISpriteFont {
|
|
||||||
public:
|
|
||||||
SpriteFont(GraphicsDevice& device, String const& fontFileName);
|
|
||||||
|
|
||||||
virtual ~SpriteFont() override {}
|
|
||||||
|
|
||||||
Vector2 MeasureString(String const& text, bool ignoreWhiteSpace = true) override;
|
|
||||||
|
|
||||||
public:
|
|
||||||
sptr<DirectX::SpriteFont> _dxSpriteFont = nullptr;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -22,7 +22,6 @@
|
|||||||
#include "samplerstate-dx.hpp"
|
#include "samplerstate-dx.hpp"
|
||||||
#include "shader-dx.hpp"
|
#include "shader-dx.hpp"
|
||||||
#include "soundeffect-dx.hpp"
|
#include "soundeffect-dx.hpp"
|
||||||
#include "spritefont-dx.hpp"
|
|
||||||
#include "swapchain-dx.hpp"
|
#include "swapchain-dx.hpp"
|
||||||
#include "texture-dx.hpp"
|
#include "texture-dx.hpp"
|
||||||
#include "vertexbuffer-dx.hpp"
|
#include "vertexbuffer-dx.hpp"
|
||||||
|
@ -46,8 +46,7 @@
|
|||||||
#include "graphics/rendertarget.hpp"
|
#include "graphics/rendertarget.hpp"
|
||||||
#include "graphics/samplerstate.hpp"
|
#include "graphics/samplerstate.hpp"
|
||||||
#include "graphics/shader.hpp"
|
#include "graphics/shader.hpp"
|
||||||
#include "graphics/spritebatch.hpp"
|
#include "graphics/sprite.hpp"
|
||||||
#include "graphics/spritefont.hpp"
|
|
||||||
#include "graphics/swapchain.hpp"
|
#include "graphics/swapchain.hpp"
|
||||||
#include "graphics/texture.hpp"
|
#include "graphics/texture.hpp"
|
||||||
#include "graphics/vertexbuffer.hpp"
|
#include "graphics/vertexbuffer.hpp"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user