Skip to content

Commit

Permalink
Merge pull request #48 from Hapaxia/sfml3
Browse files Browse the repository at this point in the history
Sfml3
  • Loading branch information
Hapaxia authored Jan 23, 2025
2 parents c539a5f + c982fe7 commit 19162ca
Show file tree
Hide file tree
Showing 42 changed files with 416 additions and 455 deletions.
2 changes: 1 addition & 1 deletion licence.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Selba Ward (https://github.com/Hapaxia/SelbaWard)

Copyright (c) 2014-2024 M. J. Silk
Copyright (c) 2014-2025 M. J. Silk

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Contents: **Bitmap Text**, **Console Screen**, **Crosshair**, **Elastic Sprite**

Feedback and suggestions for new objects always welcome...

---
**IMPORTANT NOTE: The main branch is now targetted for SFML 3. If you are still using SFML 2, you can use the sfml2 branch.**
---

[Selba Ward thread on the SFML forum][SFMLForumSelbaWard]

[Wiki]: https://github.com/Hapaxia/SelbaWard/wiki
Expand Down
2 changes: 1 addition & 1 deletion src/SelbaWard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Selba Ward (https://github.com/Hapaxia/SelbaWard)
//
// Copyright(c) 2015-2024 M.J.Silk
// Copyright(c) 2015-2025 M.J.Silk
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down
10 changes: 5 additions & 5 deletions src/SelbaWard/BitmapFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// BitmapFont
//
// Copyright(c) 2014-2024 M.J.Silk
// Copyright(c) 2014-2025 M.J.Silk
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -116,8 +116,8 @@ void BitmapFont::setTextureRect(const sf::IntRect& textureRect, const std::size_

m_glyphs[glyphIndex].useDefaultTextureRect = false;
m_glyphs[glyphIndex].textureRect = textureRect;
m_glyphs[glyphIndex].width = textureRect.width;
m_glyphs[glyphIndex].baseline = textureRect.height - 1;
m_glyphs[glyphIndex].width = textureRect.size.x;
m_glyphs[glyphIndex].baseline = textureRect.size.y - 1;
m_glyphs[glyphIndex].startX = 0;
}

Expand Down Expand Up @@ -379,8 +379,8 @@ const BitmapFont::Glyph BitmapFont::priv_getGlyphWithDefaultTextureRect(std::siz
Glyph defaultGlyph;
defaultGlyph.useDefaultTextureRect = false;
defaultGlyph.textureRect = m_defaultTextureRect;
defaultGlyph.textureRect.left = m_defaultTextureRect.width * (glyphIndex % m_numberOfTilesPerRow);
defaultGlyph.textureRect.top = m_defaultTextureRect.height * (glyphIndex / m_numberOfTilesPerRow);
defaultGlyph.textureRect.position.x = m_defaultTextureRect.size.x * (glyphIndex % m_numberOfTilesPerRow);
defaultGlyph.textureRect.position.y = m_defaultTextureRect.size.y * (glyphIndex / m_numberOfTilesPerRow);
defaultGlyph.width = m_glyphs[glyphIndex].width;
defaultGlyph.baseline = m_glyphs[glyphIndex].baseline;
defaultGlyph.startX = m_glyphs[glyphIndex].startX;
Expand Down
4 changes: 2 additions & 2 deletions src/SelbaWard/BitmapFont.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// BitmapFont
//
// Copyright(c) 2014-2024 M.J.Silk
// Copyright(c) 2014-2025 M.J.Silk
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -41,7 +41,7 @@
namespace selbaward
{

// SW Bitmap Font v1.1.1
// SW Bitmap Font v1.1.2
class BitmapFont
{
public:
Expand Down
52 changes: 26 additions & 26 deletions src/SelbaWard/BitmapText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// BitmapText
//
// Copyright(c) 2014-2024 M.J.Silk
// Copyright(c) 2014-2025 M.J.Silk
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -96,12 +96,12 @@ void BitmapText::setScale(const std::size_t scale)

void BitmapText::setScale(const sf::Vector2u scale)
{
setScale(scale.x, scale.y);
this->Transformable::setScale(sf::Vector2f(scale));
}

void BitmapText::setScale(const std::size_t scaleX, const std::size_t scaleY)
{
this->Transformable::setScale(static_cast<float>(scaleX), static_cast<float>(scaleY));
setScale({ scaleX, scaleY });
}

sf::FloatRect BitmapText::getGlobalBounds() const
Expand Down Expand Up @@ -133,7 +133,7 @@ void BitmapText::priv_updateVertices()
if (m_pBitmapFont == nullptr)
{
m_vertices.clear();
m_bounds = { 0.f, 0.f, 0.f, 0.f };
m_bounds = { { 0.f, 0.f }, { 0.f, 0.f } };
}

m_vertices.resize(m_string.length() * 6u);
Expand All @@ -151,31 +151,31 @@ void BitmapText::priv_updateVertices()

BitmapFont::Glyph glyph{ m_pBitmapFont->getGlyph(glyphNumber) };

const sf::Vector2f glyphOffset{ 0.f - glyph.startX, (glyph.baseline < 0) ? (0.f - glyph.baseline - glyph.textureRect.height) : (0.f - glyph.baseline) };
const sf::Vector2f glyphOffset{ 0.f - glyph.startX, (glyph.baseline < 0) ? (0.f - glyph.baseline - glyph.textureRect.size.y) : (0.f - glyph.baseline) };
const sf::Vector2f glyphPosition{ penPosition + glyphOffset };

m_vertices[(character * 6u) + 0u].position = glyphPosition;
m_vertices[(character * 6u) + 1u].position = glyphPosition + sf::Vector2f{ 0.f, static_cast<float>(glyph.textureRect.height) };
m_vertices[(character * 6u) + 2u].position = glyphPosition + sf::Vector2f{ static_cast<float>(glyph.textureRect.width), 0.f };
m_vertices[(character * 6u) + 3u].position = glyphPosition + sf::Vector2f{ static_cast<float>(glyph.textureRect.width), static_cast<float>(glyph.textureRect.height) };

m_vertices[(character * 6u) + 0u].texCoords = sf::Vector2f{
static_cast<float>(glyph.textureRect.left),
static_cast<float>(glyph.textureRect.top) };
m_vertices[(character * 6u) + 1u].texCoords = sf::Vector2f{
static_cast<float>(glyph.textureRect.left),
static_cast<float>(glyph.textureRect.top + glyph.textureRect.height) };
m_vertices[(character * 6u) + 2u].texCoords = sf::Vector2f{
static_cast<float>(glyph.textureRect.left + glyph.textureRect.width),
static_cast<float>(glyph.textureRect.top) };
m_vertices[(character * 6u) + 3u].texCoords = sf::Vector2f{
static_cast<float>(glyph.textureRect.left + glyph.textureRect.width),
static_cast<float>(glyph.textureRect.top + glyph.textureRect.height) };
m_vertices[(character * 6u) + 1u].position = glyphPosition + sf::Vector2f(0, static_cast<float>(glyph.textureRect.size.y));
m_vertices[(character * 6u) + 2u].position = glyphPosition + sf::Vector2f(static_cast<float>(glyph.textureRect.size.x), 0);
m_vertices[(character * 6u) + 3u].position = glyphPosition + sf::Vector2f(static_cast<float>(glyph.textureRect.size.x), static_cast<float>(glyph.textureRect.size.y));

m_vertices[(character * 6u) + 0u].texCoords = sf::Vector2f(
static_cast<float>(glyph.textureRect.position.x),
static_cast<float>(glyph.textureRect.position.y));
m_vertices[(character * 6u) + 1u].texCoords = sf::Vector2f(
static_cast<float>(glyph.textureRect.position.x),
static_cast<float>(glyph.textureRect.position.y + glyph.textureRect.size.y));
m_vertices[(character * 6u) + 2u].texCoords = sf::Vector2f(
static_cast<float>(glyph.textureRect.position.x + glyph.textureRect.size.x),
static_cast<float>(glyph.textureRect.position.y));
m_vertices[(character * 6u) + 3u].texCoords = sf::Vector2f(
static_cast<float>(glyph.textureRect.position.x + glyph.textureRect.size.x),
static_cast<float>(glyph.textureRect.position.y + glyph.textureRect.size.y));

m_vertices[(character * 6u) + 4u] = m_vertices[(character * 6u) + 2u];
m_vertices[(character * 6u) + 5u] = m_vertices[(character * 6u) + 1u];

penPosition.x += (glyph.width > 0) ? (0.f + m_tracking + kerning + glyph.width) : (0.f + m_tracking + kerning + glyph.width + glyph.textureRect.width - glyph.startX);
penPosition.x += (glyph.width > 0) ? (0.f + m_tracking + kerning + glyph.width) : (0.f + m_tracking + kerning + glyph.width + glyph.textureRect.size.x - glyph.startX);

min.x = std::min(min.x, m_vertices[(character * 6u) + 0u].position.x);
max.x = std::max(max.x, m_vertices[(character * 6u) + 3u].position.x);
Expand All @@ -185,10 +185,10 @@ void BitmapText::priv_updateVertices()

priv_updateColor();

m_bounds.left = min.x;
m_bounds.top = min.y;
m_bounds.width = max.x - min.x;
m_bounds.height = max.y - min.y;
m_bounds.position.x = minX;
m_bounds.position.y = minY;
m_bounds.size.x = maxX - minX;
m_bounds.size.y = maxY - minY;
}

void BitmapText::priv_updateColor()
Expand Down
6 changes: 3 additions & 3 deletions src/SelbaWard/BitmapText.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// BitmapText
//
// Copyright(c) 2014-2024 M.J.Silk
// Copyright(c) 2014-2025 M.J.Silk
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -40,7 +40,7 @@
namespace selbaward
{

// SW Bitmap Text v1.1.3
// SW Bitmap Text v1.1.4
class BitmapText : public sf::Drawable, public sf::Transformable
{
public:
Expand All @@ -67,7 +67,7 @@ class BitmapText : public sf::Drawable, public sf::Transformable
int m_tracking;
sf::FloatRect m_bounds;

virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
void priv_updateVertices();
void priv_updateColor();
};
Expand Down
16 changes: 2 additions & 14 deletions src/SelbaWard/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Selba Ward (https://github.com/Hapaxia/SelbaWard)
//
// Copyright(c) 2015-2024 M.J.Silk
// Copyright(c) 2015-2025 M.J.Silk
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
Expand Down Expand Up @@ -33,12 +33,6 @@
#include <exception>
#include <string>

#if defined(_MSC_VER) && (_MSC_VER < 1900)
#define SELBAWARD_NOEXCEPT
#else
#define SELBAWARD_NOEXCEPT noexcept
#endif

namespace selbaward
{

Expand All @@ -49,7 +43,7 @@ class Exception : public std::exception
m_errorMessage("[Selba Ward] " + errorMessage)
{
}
virtual const char* what() const SELBAWARD_NOEXCEPT override
const char* what() const noexcept override
{
return m_errorMessage.c_str();
}
Expand All @@ -73,10 +67,4 @@ namespace sw = selbaward; // create shortcut namespace
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/RenderStates.hpp>

#if (SFML_VERSION_MAJOR == 2)
#if (SFML_VERSION_MINOR < 4)
#define USE_SFML_PRE_2_4
#endif
#endif

#endif // SELBAWARD_COMMON_HPP
Loading

0 comments on commit 19162ca

Please sign in to comment.