diff --git a/licence.txt b/licence.txt index ac201ce..d8591b9 100644 --- a/licence.txt +++ b/licence.txt @@ -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 diff --git a/readme.md b/readme.md index ddb1e79..cb00a89 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/src/SelbaWard.hpp b/src/SelbaWard.hpp index f6e7102..9cf96cd 100644 --- a/src/SelbaWard.hpp +++ b/src/SelbaWard.hpp @@ -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 diff --git a/src/SelbaWard/BitmapFont.cpp b/src/SelbaWard/BitmapFont.cpp index 7f00de6..eaf38dc 100644 --- a/src/SelbaWard/BitmapFont.cpp +++ b/src/SelbaWard/BitmapFont.cpp @@ -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 @@ -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; } @@ -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; diff --git a/src/SelbaWard/BitmapFont.hpp b/src/SelbaWard/BitmapFont.hpp index 1b5b4a8..c4348d6 100644 --- a/src/SelbaWard/BitmapFont.hpp +++ b/src/SelbaWard/BitmapFont.hpp @@ -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 @@ -41,7 +41,7 @@ namespace selbaward { -// SW Bitmap Font v1.1.1 +// SW Bitmap Font v1.1.2 class BitmapFont { public: diff --git a/src/SelbaWard/BitmapText.cpp b/src/SelbaWard/BitmapText.cpp index 783c0db..ed6100b 100644 --- a/src/SelbaWard/BitmapText.cpp +++ b/src/SelbaWard/BitmapText.cpp @@ -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 @@ -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(scaleX), static_cast(scaleY)); + setScale({ scaleX, scaleY }); } sf::FloatRect BitmapText::getGlobalBounds() const @@ -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); @@ -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(glyph.textureRect.height) }; - m_vertices[(character * 6u) + 2u].position = glyphPosition + sf::Vector2f{ static_cast(glyph.textureRect.width), 0.f }; - m_vertices[(character * 6u) + 3u].position = glyphPosition + sf::Vector2f{ static_cast(glyph.textureRect.width), static_cast(glyph.textureRect.height) }; - - m_vertices[(character * 6u) + 0u].texCoords = sf::Vector2f{ - static_cast(glyph.textureRect.left), - static_cast(glyph.textureRect.top) }; - m_vertices[(character * 6u) + 1u].texCoords = sf::Vector2f{ - static_cast(glyph.textureRect.left), - static_cast(glyph.textureRect.top + glyph.textureRect.height) }; - m_vertices[(character * 6u) + 2u].texCoords = sf::Vector2f{ - static_cast(glyph.textureRect.left + glyph.textureRect.width), - static_cast(glyph.textureRect.top) }; - m_vertices[(character * 6u) + 3u].texCoords = sf::Vector2f{ - static_cast(glyph.textureRect.left + glyph.textureRect.width), - static_cast(glyph.textureRect.top + glyph.textureRect.height) }; + m_vertices[(character * 6u) + 1u].position = glyphPosition + sf::Vector2f(0, static_cast(glyph.textureRect.size.y)); + m_vertices[(character * 6u) + 2u].position = glyphPosition + sf::Vector2f(static_cast(glyph.textureRect.size.x), 0); + m_vertices[(character * 6u) + 3u].position = glyphPosition + sf::Vector2f(static_cast(glyph.textureRect.size.x), static_cast(glyph.textureRect.size.y)); + + m_vertices[(character * 6u) + 0u].texCoords = sf::Vector2f( + static_cast(glyph.textureRect.position.x), + static_cast(glyph.textureRect.position.y)); + m_vertices[(character * 6u) + 1u].texCoords = sf::Vector2f( + static_cast(glyph.textureRect.position.x), + static_cast(glyph.textureRect.position.y + glyph.textureRect.size.y)); + m_vertices[(character * 6u) + 2u].texCoords = sf::Vector2f( + static_cast(glyph.textureRect.position.x + glyph.textureRect.size.x), + static_cast(glyph.textureRect.position.y)); + m_vertices[(character * 6u) + 3u].texCoords = sf::Vector2f( + static_cast(glyph.textureRect.position.x + glyph.textureRect.size.x), + static_cast(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); @@ -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() diff --git a/src/SelbaWard/BitmapText.hpp b/src/SelbaWard/BitmapText.hpp index 490dbb7..3ed9ba5 100644 --- a/src/SelbaWard/BitmapText.hpp +++ b/src/SelbaWard/BitmapText.hpp @@ -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 @@ -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: @@ -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(); }; diff --git a/src/SelbaWard/Common.hpp b/src/SelbaWard/Common.hpp index f38125e..ba59521 100644 --- a/src/SelbaWard/Common.hpp +++ b/src/SelbaWard/Common.hpp @@ -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 @@ -33,12 +33,6 @@ #include #include -#if defined(_MSC_VER) && (_MSC_VER < 1900) -#define SELBAWARD_NOEXCEPT -#else -#define SELBAWARD_NOEXCEPT noexcept -#endif - namespace selbaward { @@ -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(); } @@ -73,10 +67,4 @@ namespace sw = selbaward; // create shortcut namespace #include #include -#if (SFML_VERSION_MAJOR == 2) - #if (SFML_VERSION_MINOR < 4) - #define USE_SFML_PRE_2_4 - #endif -#endif - #endif // SELBAWARD_COMMON_HPP diff --git a/src/SelbaWard/ConsoleScreen.cpp b/src/SelbaWard/ConsoleScreen.cpp index a774386..d59f055 100644 --- a/src/SelbaWard/ConsoleScreen.cpp +++ b/src/SelbaWard/ConsoleScreen.cpp @@ -5,7 +5,7 @@ // // Console Screen v2 // -// 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 @@ -93,7 +93,7 @@ inline sf::Color sepiaColor(const float alpha) const unsigned int r{ static_cast(linearInterpolation(0.f, 344.505f, alpha)) }; const unsigned int g{ static_cast(linearInterpolation(0.f, 306.765f, alpha)) }; const unsigned int b{ static_cast(linearInterpolation(0.f, 238.935f, alpha)) }; - return sf::Color((r > 255 ? 255u : static_cast(r)), (g > 255 ? 255u : static_cast(g)), (b > 255 ? 255u : static_cast(b))); + return sf::Color((r > 255 ? 255u : static_cast(r)), (g > 255 ? 255u : static_cast(g)), (b > 255 ? 255u : static_cast(b))); } inline float relativeLuminance(const sf::Color& color) @@ -170,21 +170,21 @@ void addPalette8ColorRgb(std::vector& palette) void addPalette16ColorGreenscale(std::vector& palette) { - for (sf::Uint8 i{ 0u }; i < 16u; ++i) - addColorToPalette(palette, sf::Color(0, i * 17u, 0)); + for (uint8_t i{ 0u }; i < 16u; ++i) + addColorToPalette(palette, sf::Color(0u, i * 17u, 0u)); } void addPalette16ColorGrayscale(std::vector& palette) { - for (sf::Uint8 i{ 0u }; i < 16u; ++i) + for (uint8_t i{ 0u }; i < 16u; ++i) addColorToPalette(palette, sf::Color(i * 17u, i * 17u, i * 17u)); } void addPalette16ColorSepia(std::vector& palette) { - const unsigned int numberOfColors{ 16 }; - for (unsigned int i{ 0 }; i < numberOfColors; ++i) - addColorToPalette(palette, sepiaColor(static_cast(i) / (numberOfColors - 1))); + constexpr unsigned int numberOfColors{ 16u }; + for (unsigned int i{ 0u }; i < numberOfColors; ++i) + addColorToPalette(palette, sepiaColor(static_cast(i) / (numberOfColors - 1u))); } void addPalette16ColorCga(std::vector& palette) @@ -294,11 +294,11 @@ void addPalette16Color16Html(std::vector& palette) void addPalette216ColorWebSafe(std::vector& palette) { - for (sf::Uint8 r{ 0u }; r < 6; ++r) + for (uint8_t r{ 0u }; r < 6; ++r) { - for (sf::Uint8 g{ 0u }; g < 6; ++g) + for (uint8_t g{ 0u }; g < 6; ++g) { - for (sf::Uint8 b{ 0u }; b < 6; ++b) + for (uint8_t b{ 0u }; b < 6; ++b) addColorToPalette(palette, sf::Color(r * 51u, g * 51u, b * 51u)); } } @@ -306,21 +306,21 @@ void addPalette216ColorWebSafe(std::vector& palette) void addPalette256ColorGreenscale(std::vector& palette) { - for (unsigned int i{ 0u }; i < 256; ++i) - addColorToPalette(palette, sf::Color(0, static_cast(i), 0)); + for (unsigned int i{ 0u }; i < 256u; ++i) + addColorToPalette(palette, sf::Color(0, static_cast(i), 0)); } void addPalette256ColorGrayscale(std::vector& palette) { - for (unsigned int i{ 0 }; i < 256; ++i) - addColorToPalette(palette, sf::Color(static_cast(i), static_cast(i), static_cast(i))); + for (unsigned int i{ 0u }; i < 256u; ++i) + addColorToPalette(palette, sf::Color(static_cast(i), static_cast(i), static_cast(i))); } void addPalette256ColorSepia(std::vector& palette) { - const unsigned int numberOfColors{ 256 }; - for (unsigned int i{ 0 }; i < numberOfColors; ++i) - addColorToPalette(palette, sepiaColor(static_cast(i) / (numberOfColors - 1))); + constexpr unsigned int numberOfColors{ 256u }; + for (unsigned int i{ 0u }; i < numberOfColors; ++i) + addColorToPalette(palette, sepiaColor(static_cast(i) / (numberOfColors - 1u))); } } // namespace @@ -1617,21 +1617,21 @@ void ConsoleScreen::scrollUp(unsigned int amount, sf::IntRect selectionRectangle return; } - std::vector topRow(selectionRectangle.width); + std::vector topRow(selectionRectangle.size.x); for (unsigned int repeat{ 0 }; repeat < amount; ++repeat) // lazy way of scrolling multiple times - loop scrolling (entirely by 1 each time) { - for (unsigned int y{ 0 }; y < static_cast(selectionRectangle.height); ++y) + for (unsigned int y{ 0 }; y < static_cast(selectionRectangle.size.y); ++y) { - for (unsigned int x{ 0 }; x < static_cast(selectionRectangle.width); ++x) + for (unsigned int x{ 0 }; x < static_cast(selectionRectangle.size.x); ++x) { if (m_do.wrapOnManualScroll && y == 0) - topRow[x] = m_cells[priv_cellIndex({ selectionRectangle.left + x, selectionRectangle.top + y })]; - if (y < static_cast(selectionRectangle.height) - 1) - m_cells[priv_cellIndex({ selectionRectangle.left + x, selectionRectangle.top + y })] = m_cells[priv_cellIndex({ selectionRectangle.left + x, selectionRectangle.top + y + 1 })]; + topRow[x] = m_cells[priv_cellIndex({ selectionRectangle.position.x + x, selectionRectangle.position.y + y })]; + if (y < static_cast(selectionRectangle.size.y) - 1) + m_cells[priv_cellIndex({ selectionRectangle.position.x + x, selectionRectangle.position.y + y })] = m_cells[priv_cellIndex({ selectionRectangle.position.x + x, selectionRectangle.position.y + y + 1 })]; else if (m_do.wrapOnManualScroll) - m_cells[priv_cellIndex({ selectionRectangle.left + x, selectionRectangle.top + y })] = topRow[x]; + m_cells[priv_cellIndex({ selectionRectangle.position.x + x, selectionRectangle.position.y + y })] = topRow[x]; else - priv_clearCell(priv_cellIndex({ selectionRectangle.left + x, selectionRectangle.top + y }), true, true); + priv_clearCell(priv_cellIndex({ selectionRectangle.position.x + x, selectionRectangle.position.y + y }), true, true); } } } @@ -1652,22 +1652,22 @@ void ConsoleScreen::scrollDown(unsigned int amount, sf::IntRect selectionRectang return; } - std::vector bottomRow(selectionRectangle.width); + std::vector bottomRow(selectionRectangle.size.x); for (unsigned int repeat{ 0 }; repeat < amount; ++repeat) // lazy way of scrolling multiple times - loop scrolling (entirely by 1 each time) { - for (unsigned int y{ 0 }; y < static_cast(selectionRectangle.height); ++y) + for (unsigned int y{ 0 }; y < static_cast(selectionRectangle.size.y); ++y) { - for (unsigned int x{ 0 }; x < static_cast(selectionRectangle.width); ++x) + for (unsigned int x{ 0 }; x < static_cast(selectionRectangle.size.x); ++x) { - const unsigned cellY{ selectionRectangle.top + selectionRectangle.height - y - 1 }; + const unsigned cellY{ selectionRectangle.position.x + selectionRectangle.size.y - y - 1 }; if (m_do.wrapOnManualScroll && y == 0) - bottomRow[x] = m_cells[priv_cellIndex({ selectionRectangle.left + x, cellY })]; - if (cellY > static_cast(selectionRectangle.top)) - m_cells[priv_cellIndex({ selectionRectangle.left + x, cellY })] = m_cells[priv_cellIndex({ selectionRectangle.left + x, cellY - 1 })]; + bottomRow[x] = m_cells[priv_cellIndex({ selectionRectangle.position.x + x, cellY })]; + if (cellY > static_cast(selectionRectangle.position.y)) + m_cells[priv_cellIndex({ selectionRectangle.position.x + x, cellY })] = m_cells[priv_cellIndex({ selectionRectangle.position.x + x, cellY - 1 })]; else if (m_do.wrapOnManualScroll) - m_cells[priv_cellIndex({ selectionRectangle.left + x, cellY })] = bottomRow[x]; + m_cells[priv_cellIndex({ selectionRectangle.position.x + x, cellY })] = bottomRow[x]; else - priv_clearCell(priv_cellIndex({ selectionRectangle.left + x, cellY }), true, true); + priv_clearCell(priv_cellIndex({ selectionRectangle.position.x + x, cellY }), true, true); } } } @@ -1688,21 +1688,21 @@ void ConsoleScreen::scrollLeft(unsigned int amount, sf::IntRect selectionRectang return; } - std::vector leftColumn(selectionRectangle.height); + std::vector leftColumn(selectionRectangle.size.y); for (unsigned int repeat{ 0 }; repeat < amount; ++repeat) // lazy way of scrolling multiple times - loop scrolling (entirely by 1 each time) { - for (unsigned int x{ 0 }; x < static_cast(selectionRectangle.width); ++x) + for (unsigned int x{ 0 }; x < static_cast(selectionRectangle.size.x); ++x) { - for (unsigned int y{ 0 }; y < static_cast(selectionRectangle.height); ++y) + for (unsigned int y{ 0 }; y < static_cast(selectionRectangle.size.y); ++y) { if (m_do.wrapOnManualScroll && x == 0) - leftColumn[y] = m_cells[priv_cellIndex({ selectionRectangle.left + x, selectionRectangle.top + y })]; - if (x < static_cast(selectionRectangle.width) - 1) - m_cells[priv_cellIndex({ selectionRectangle.left + x, selectionRectangle.top + y })] = m_cells[priv_cellIndex({ selectionRectangle.left + x + 1, selectionRectangle.top + y })]; + leftColumn[y] = m_cells[priv_cellIndex({ selectionRectangle.position.x + x, selectionRectangle.position.y + y })]; + if (x < static_cast(selectionRectangle.size.x) - 1) + m_cells[priv_cellIndex({ selectionRectangle.position.x + x, selectionRectangle.position.y + y })] = m_cells[priv_cellIndex({ selectionRectangle.position.x + x + 1, selectionRectangle.position.y + y })]; else if (m_do.wrapOnManualScroll) - m_cells[priv_cellIndex({ selectionRectangle.left + x, selectionRectangle.top + y })] = leftColumn[y]; + m_cells[priv_cellIndex({ selectionRectangle.position.x + x, selectionRectangle.position.y + y})] = leftColumn[y]; else - priv_clearCell(priv_cellIndex({ selectionRectangle.left + x, selectionRectangle.top + y }), true, true); + priv_clearCell(priv_cellIndex({ selectionRectangle.position.x + x, selectionRectangle.position.y + y }), true, true); } } } @@ -1723,22 +1723,22 @@ void ConsoleScreen::scrollRight(unsigned int amount, sf::IntRect selectionRectan return; } - std::vector rightColumn(selectionRectangle.height); + std::vector rightColumn(selectionRectangle.size.y); for (unsigned int repeat{ 0 }; repeat < amount; ++repeat) // lazy way of scrolling multiple times - loop scrolling (entirely by 1 each time) { - for (unsigned int y{ 0 }; y < static_cast(selectionRectangle.height); ++y) + for (unsigned int y{ 0 }; y < static_cast(selectionRectangle.size.y); ++y) { - for (unsigned int x{ 0 }; x < static_cast(selectionRectangle.width); ++x) + for (unsigned int x{ 0 }; x < static_cast(selectionRectangle.size.x); ++x) { - const unsigned cellX{ selectionRectangle.left + selectionRectangle.width - x - 1 }; + const unsigned cellX{ selectionRectangle.position.x + selectionRectangle.size.x - x - 1 }; if (m_do.wrapOnManualScroll && x == 0) - rightColumn[y] = m_cells[priv_cellIndex({ cellX, selectionRectangle.top + y, })]; - if (cellX > static_cast(selectionRectangle.left)) - m_cells[priv_cellIndex({ cellX, selectionRectangle.top + y })] = m_cells[priv_cellIndex({ cellX - 1, selectionRectangle.top + y })]; + rightColumn[y] = m_cells[priv_cellIndex({ cellX, selectionRectangle.position.y + y, })]; + if (cellX > static_cast(selectionRectangle.position.x)) + m_cells[priv_cellIndex({ cellX, selectionRectangle.position.y + y })] = m_cells[priv_cellIndex({ cellX - 1, selectionRectangle.position.y + y })]; else if (m_do.wrapOnManualScroll) - m_cells[priv_cellIndex({ cellX, selectionRectangle.top + y })] = rightColumn[y]; + m_cells[priv_cellIndex({ cellX, selectionRectangle.position.y + y })] = rightColumn[y]; else - priv_clearCell(priv_cellIndex({ cellX, selectionRectangle.top + y }), true, true); + priv_clearCell(priv_cellIndex({ cellX, selectionRectangle.position.y + y }), true, true); } } } @@ -1935,7 +1935,7 @@ sf::Color ConsoleScreen::getPaletteColor(const Color color) const return sf::Color::Transparent; } - return m_is.rgbMode ? sf::Color(static_cast(color.id / 65536), static_cast((color.id % 65536) / 256), static_cast(color.id % 256)) : m_palette[color.id]; + return m_is.rgbMode ? sf::Color(static_cast(color.id / 65536), static_cast((color.id % 65536) / 256), static_cast(color.id % 256)) : m_palette[color.id]; } void ConsoleScreen::setPaletteSize(const unsigned long int size) @@ -2780,12 +2780,12 @@ void ConsoleScreen::priv_scroll() void ConsoleScreen::priv_copyToBufferFromSelectionRectangle(Buffer& buffer, const sf::IntRect& selectionRectangle) { - if (selectionRectangle.left >= static_cast(m_mode.x) || - selectionRectangle.top >= static_cast(m_mode.y) || - selectionRectangle.width <= 0 || - selectionRectangle.height <= 0 || - (selectionRectangle.left + selectionRectangle.width) < 0 || - (selectionRectangle.top + selectionRectangle.height) < 0) + if (selectionRectangle.position.x >= static_cast(m_mode.x) || + selectionRectangle.position.y >= static_cast(m_mode.y) || + selectionRectangle.size.x <= 0 || + selectionRectangle.size.y <= 0 || + (selectionRectangle.position.x + selectionRectangle.size.x) < 0 || + (selectionRectangle.position.y + selectionRectangle.size.y) < 0) { if (m_do.throwExceptions) throw Exception(exceptionPrefix + "Cannot copy selection.\nSelection does not contain any cells."); @@ -2795,11 +2795,11 @@ void ConsoleScreen::priv_copyToBufferFromSelectionRectangle(Buffer& buffer, cons buffer.width = 0u; buffer.cells.clear(); - for (int y{ 0 }; y < selectionRectangle.height; ++y) + for (int y{ 0 }; y < selectionRectangle.size.y; ++y) { - for (int x{ 0 }; x < selectionRectangle.width; ++x) + for (int x{ 0 }; x < selectionRectangle.size.x; ++x) { - const sf::Vector2i location{ x + selectionRectangle.left, y + selectionRectangle.top }; + const sf::Vector2i location{ x + selectionRectangle.position.x, y + selectionRectangle.position.y }; if (location.x < 0 || location.y < 0) continue; const sf::Vector2u cellLocation{ static_cast(location.x), static_cast(location.y) }; @@ -2831,12 +2831,12 @@ void ConsoleScreen::priv_pasteOffsettedBuffer(Buffer& buffer, const sf::Vector2i bool ConsoleScreen::priv_isSelectionRectangleContainedInScreen(const sf::IntRect& selectionRectangle) { - return (selectionRectangle.left >= 0 && - selectionRectangle.top >= 0 && - selectionRectangle.width >= 0 && - selectionRectangle.height >= 0 && - static_cast(selectionRectangle.left + selectionRectangle.width) <= m_mode.x && - static_cast(selectionRectangle.top + selectionRectangle.height) <= m_mode.y); + return (selectionRectangle.position.x >= 0 && + selectionRectangle.position.y >= 0 && + selectionRectangle.size.x >= 0 && + selectionRectangle.size.y >= 0 && + static_cast(selectionRectangle.position.x + selectionRectangle.size.x) <= m_mode.x && + static_cast(selectionRectangle.position.y + selectionRectangle.size.y) <= m_mode.y); } unsigned int ConsoleScreen::priv_getPrintIndex(sf::Vector2u location) const @@ -3014,9 +3014,9 @@ void ConsoleScreen::priv_modifyCellUsingPrintProperties(const unsigned int index void ConsoleScreen::priv_makeColorDark(sf::Color& color) { - color.r = static_cast(m_darkAttributeMultiplier * color.r); - color.g = static_cast(m_darkAttributeMultiplier * color.g); - color.b = static_cast(m_darkAttributeMultiplier * color.b); + color.r = static_cast(m_darkAttributeMultiplier * color.r); + color.g = static_cast(m_darkAttributeMultiplier * color.g); + color.b = static_cast(m_darkAttributeMultiplier * color.b); } } // namespace selbaward diff --git a/src/SelbaWard/ConsoleScreen.hpp b/src/SelbaWard/ConsoleScreen.hpp index 0b52895..9aa6eaf 100644 --- a/src/SelbaWard/ConsoleScreen.hpp +++ b/src/SelbaWard/ConsoleScreen.hpp @@ -5,7 +5,7 @@ // // Console Screen v2 // -// 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 @@ -45,7 +45,7 @@ namespace sf namespace selbaward { -// SW Console Screen v2.4.5 +// SW Console Screen v2.4.6 class ConsoleScreen : public sf::Drawable, public sf::Transformable { public: @@ -531,7 +531,7 @@ class ConsoleScreen : public sf::Drawable, public sf::Transformable sf::Vector2u m_tileSize; unsigned int m_numberOfTilesPerRow; - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void priv_setVerticesFromCell(unsigned int index, int baseVertex = -1, bool overLayer = true); void priv_updateCell(unsigned int index); void priv_updateUnderCells(); diff --git a/src/SelbaWard/Crosshair.cpp b/src/SelbaWard/Crosshair.cpp index e24c9b2..eed1444 100644 --- a/src/SelbaWard/Crosshair.cpp +++ b/src/SelbaWard/Crosshair.cpp @@ -5,7 +5,7 @@ // // Crosshair // -// Copyright(c) 2016-2024 M.J.Silk +// Copyright(c) 2016-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 diff --git a/src/SelbaWard/Crosshair.hpp b/src/SelbaWard/Crosshair.hpp index c6872ff..d8d8b75 100644 --- a/src/SelbaWard/Crosshair.hpp +++ b/src/SelbaWard/Crosshair.hpp @@ -5,7 +5,7 @@ // // Crosshair // -// Copyright(c) 2016-2024 M.J.Silk +// Copyright(c) 2016-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 @@ -35,13 +35,15 @@ #include "Common.hpp" +#include #include #include +#include namespace selbaward { -// SW Crosshair v1.0.1 +// SW Crosshair v1.0.2 class Crosshair : public sf::Drawable { public: @@ -64,7 +66,7 @@ class Crosshair : public sf::Drawable sf::Color m_verticalColor; mutable sf::VertexArray m_vertices; - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; }; } // namespace selbaward diff --git a/src/SelbaWard/ElasticSprite.cpp b/src/SelbaWard/ElasticSprite.cpp index 90312e0..6fe92fc 100644 --- a/src/SelbaWard/ElasticSprite.cpp +++ b/src/SelbaWard/ElasticSprite.cpp @@ -5,7 +5,7 @@ // // Elastic Sprite // -// Copyright(c) 2017-2024 M.J.Silk +// Copyright(c) 2017-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 @@ -106,7 +106,7 @@ const std::string perspectiveFragmentShaderCode void loadShader() { if (!areShadersLoaded && - bilinearShader.loadFromMemory(bilinearFragmentShaderCode, sf::Shader::Fragment) && + bilinearShader.loadFromMemory(bilinearFragmentShaderCode, sf::Shader::Type::Fragment) && perspectiveShader.loadFromMemory(perspectiveVertexShaderCode, perspectiveFragmentShaderCode)) areShadersLoaded = true; } @@ -135,9 +135,9 @@ inline sf::Color encodeFloatAsColor(const float f) { return { - static_cast(static_cast(f / 256) & 0xFF), - static_cast(static_cast(f) & 0xFF), - static_cast(static_cast(f * 256) & 0xFF), + static_cast(static_cast(f / 256) & 0xFF), + static_cast(static_cast(f) & 0xFF), + static_cast(static_cast(f * 256) & 0xFF), 0u }; } @@ -305,7 +305,7 @@ sf::Color ElasticSprite::getColor() const const unsigned int totalG{ static_cast(m_vertices[0].color.g) + m_vertices[1].color.g + m_vertices[2].color.g + m_vertices[3].color.g }; const unsigned int totalB{ static_cast(m_vertices[0].color.b) + m_vertices[1].color.b + m_vertices[2].color.b + m_vertices[3].color.b }; const unsigned int totalA{ static_cast(m_vertices[0].color.a) + m_vertices[1].color.a + m_vertices[2].color.a + m_vertices[3].color.a }; - return{ static_cast(totalR / 4), static_cast(totalG / 4), static_cast(totalB / 4), static_cast(totalA / 4) }; + return{ static_cast(totalR / 4), static_cast(totalG / 4), static_cast(totalB / 4), static_cast(totalA / 4) }; } sf::Color ElasticSprite::getVertexColor(const unsigned int vertexIndex) const @@ -459,10 +459,10 @@ void ElasticSprite::draw(sf::RenderTarget& target, sf::RenderStates states) cons { bilinearShader.setUniform("texture", *m_pTexture); const sf::Vector2f textureSize(m_pTexture->getSize()); - bilinearShader.setUniform("textureRectLeftRatio", m_actualTextureRect.left / textureSize.x); - bilinearShader.setUniform("textureRectTopRatio", m_actualTextureRect.top / textureSize.y); - bilinearShader.setUniform("textureRectWidthRatio", m_actualTextureRect.width / textureSize.x); - bilinearShader.setUniform("textureRectHeightRatio", m_actualTextureRect.height / textureSize.y); + bilinearShader.setUniform("textureRectLeftRatio", m_actualTextureRect.position.x / textureSize.x); + bilinearShader.setUniform("textureRectTopRatio", m_actualTextureRect.position.y / textureSize.y); + bilinearShader.setUniform("textureRectWidthRatio", m_actualTextureRect.size.x / textureSize.x); + bilinearShader.setUniform("textureRectHeightRatio", m_actualTextureRect.size.y / textureSize.y); } bilinearShader.setUniform("renderTargetHeight", static_cast(target.getSize().y)); bilinearShader.setUniform("v0", sf::Glsl::Vec2(target.mapCoordsToPixel(m_vertices[0].position))); @@ -492,13 +492,13 @@ void ElasticSprite::priv_updateVertices(sf::Transform transform) const if (m_textureFlipX) { - m_actualTextureRect.left += m_actualTextureRect.width; - m_actualTextureRect.width = -m_actualTextureRect.width; + m_actualTextureRect.position.x += m_actualTextureRect.size.x; + m_actualTextureRect.size.x = -m_actualTextureRect.size.x; } if (m_textureFlipY) { - m_actualTextureRect.top += m_actualTextureRect.height; - m_actualTextureRect.height = -m_actualTextureRect.height; + m_actualTextureRect.position.y += m_actualTextureRect.size.y; + m_actualTextureRect.size.y = -m_actualTextureRect.size.y; } if (m_useShader && m_usePerspectiveInterpolation && m_pTexture != nullptr) @@ -514,15 +514,15 @@ void ElasticSprite::priv_updateVertices(sf::Transform transform) const m_weights[3] = (distanceToIntersection3 + distanceToIntersection1) / distanceToIntersection1; const sf::Vector2f textureSize(m_pTexture->getSize()); - m_vertices[0].texCoords = { m_weights[0] * (m_actualTextureRect.left / textureSize.x), m_weights[0] * (m_actualTextureRect.top / textureSize.y) }; - m_vertices[1].texCoords = { m_weights[1] * (m_actualTextureRect.left / textureSize.x), m_weights[1] * ((m_actualTextureRect.top + m_actualTextureRect.height) / textureSize.y) }; - m_vertices[2].texCoords = { m_weights[2] * ((m_actualTextureRect.left + m_actualTextureRect.width) / textureSize.x), m_weights[2] * ((m_actualTextureRect.top + m_actualTextureRect.height) / textureSize.y) }; - m_vertices[3].texCoords = { m_weights[3] * ((m_actualTextureRect.left + m_actualTextureRect.width) / textureSize.x), m_weights[3] * (m_actualTextureRect.top / textureSize.y) }; + m_vertices[0].texCoords = { m_weights[0] * (m_actualTextureRect.position.x / textureSize.x), m_weights[0] * (m_actualTextureRect.position.y / textureSize.y) }; + m_vertices[1].texCoords = { m_weights[1] * (m_actualTextureRect.position.x / textureSize.x), m_weights[1] * ((m_actualTextureRect.position.y + m_actualTextureRect.size.y) / textureSize.y) }; + m_vertices[2].texCoords = { m_weights[2] * ((m_actualTextureRect.position.x + m_actualTextureRect.size.x) / textureSize.x), m_weights[2] * ((m_actualTextureRect.position.y + m_actualTextureRect.size.y) / textureSize.y) }; + m_vertices[3].texCoords = { m_weights[3] * ((m_actualTextureRect.position.x + m_actualTextureRect.size.x) / textureSize.x), m_weights[3] * (m_actualTextureRect.position.y / textureSize.y) }; } else { - m_vertices[0].texCoords = { m_actualTextureRect.left, m_actualTextureRect.top }; - m_vertices[2].texCoords = { m_actualTextureRect.left + m_actualTextureRect.width, m_actualTextureRect.top + m_actualTextureRect.height }; + m_vertices[0].texCoords = { m_actualTextureRect.position.x, m_actualTextureRect.position.y }; + m_vertices[2].texCoords = { m_actualTextureRect.position.x + m_actualTextureRect.size.x, m_actualTextureRect.position.y + m_actualTextureRect.size.y }; m_vertices[1].texCoords = { m_vertices[0].texCoords.x, m_vertices[2].texCoords.y }; m_vertices[3].texCoords = { m_vertices[2].texCoords.x, m_vertices[0].texCoords.y }; } @@ -536,11 +536,11 @@ sf::Vector2f ElasticSprite::priv_getVertexBasePosition(const unsigned int vertex switch (vertexIndex) { case 1u: - return sf::Vector2f(0.f, m_baseTextureRect.height); + return sf::Vector2f(0.f, m_baseTextureRect.size.y); case 2u: - return sf::Vector2f(m_baseTextureRect.width, m_baseTextureRect.height); + return sf::Vector2f(m_baseTextureRect.size.x, m_baseTextureRect.size.y); case 3u: - return sf::Vector2f(m_baseTextureRect.width, 0.f); + return sf::Vector2f(m_baseTextureRect.size.x, 0.f); case 0u: default: return { 0.f, 0.f }; diff --git a/src/SelbaWard/ElasticSprite.hpp b/src/SelbaWard/ElasticSprite.hpp index 55ec10a..bf7fdff 100644 --- a/src/SelbaWard/ElasticSprite.hpp +++ b/src/SelbaWard/ElasticSprite.hpp @@ -5,7 +5,7 @@ // // Elastic Sprite // -// Copyright(c) 2017-2024 M.J.Silk +// Copyright(c) 2017-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 @@ -49,7 +49,7 @@ class Vector2; namespace selbaward { -// SW Elastic Sprite v1.3.1 +// SW Elastic Sprite v1.3.2 class ElasticSprite : public sf::Drawable, public sf::Transformable { public: @@ -110,7 +110,7 @@ class ElasticSprite : public sf::Drawable, public sf::Transformable bool m_textureFlipX; bool m_textureFlipY; - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void priv_updateVertices(sf::Transform Transform) const; sf::Vector2f priv_getVertexBasePosition(const unsigned int vertexIndex) const; }; diff --git a/src/SelbaWard/Exception.hpp b/src/SelbaWard/Exception.hpp deleted file mode 100644 index fd4b07c..0000000 --- a/src/SelbaWard/Exception.hpp +++ /dev/null @@ -1,35 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// Selba Ward (https://github.com/Hapaxia/SelbaWard) -// -// Copyright(c) 2015-2024 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 -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions : -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software.If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -// M.J.Silk -// MJSilk2@gmail.com -// -////////////////////////////////////////////////////////////////////////////// - -#ifndef SELBAWARD_EXCEPTION_HPP -#define SELBAWARD_EXCEPTION_HPP - -#include "Common.hpp" - -#endif // SELBAWARD_EXCEPTION_HPP diff --git a/src/SelbaWard/GallerySprite.cpp b/src/SelbaWard/GallerySprite.cpp index aebd7d4..7315f6f 100644 --- a/src/SelbaWard/GallerySprite.cpp +++ b/src/SelbaWard/GallerySprite.cpp @@ -5,7 +5,7 @@ // // Gallery Sprite // -// Copyright(c) 2016-2024 M.J.Silk +// Copyright(c) 2016-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 @@ -99,7 +99,7 @@ sf::Vector2f GallerySprite::getSize() const sf::Vector2f GallerySprite::getSize(const unsigned int exhibitNumber) const { const sf::FloatRect& exhibitRectangle{ priv_getExhibit(exhibitNumber).rectangle }; - return{ exhibitRectangle.width, exhibitRectangle.height }; + return{ exhibitRectangle.size.x, exhibitRectangle.size.y }; } void GallerySprite::setScaleFromTargetSize(const sf::Vector2f& targetSize) @@ -257,18 +257,18 @@ void GallerySprite::draw(sf::RenderTarget& target, sf::RenderStates states) cons void GallerySprite::priv_updateVertices() { const Exhibit exhibit{ priv_getCurrentExhibit() }; - m_vertices[0].position = { -exhibit.anchor.x, exhibit.rectangle.height - exhibit.anchor.y }; + m_vertices[0].position = { -exhibit.anchor.x, exhibit.rectangle.size.y - exhibit.anchor.y }; m_vertices[1].position = -exhibit.anchor; - m_vertices[2].position = { exhibit.rectangle.width - exhibit.anchor.x, exhibit.rectangle.height - exhibit.anchor.y }; - m_vertices[3].position = { exhibit.rectangle.width - exhibit.anchor.x, -exhibit.anchor.y }; + m_vertices[2].position = { exhibit.rectangle.size.x - exhibit.anchor.x, exhibit.rectangle.size.y - exhibit.anchor.y }; + m_vertices[3].position = { exhibit.rectangle.size.x - exhibit.anchor.x, -exhibit.anchor.y }; if (m_pTexture == nullptr) return; - m_vertices[0].texCoords = { exhibit.rectangle.left, exhibit.rectangle.top + exhibit.rectangle.height }; - m_vertices[1].texCoords = { exhibit.rectangle.left, exhibit.rectangle.top }; - m_vertices[2].texCoords = { exhibit.rectangle.left + exhibit.rectangle.width, exhibit.rectangle.top + exhibit.rectangle.height }; - m_vertices[3].texCoords = { exhibit.rectangle.left + exhibit.rectangle.width, exhibit.rectangle.top }; + m_vertices[0].texCoords = { exhibit.rectangle.position.x, exhibit.rectangle.position.y + exhibit.rectangle.size.y }; + m_vertices[1].texCoords = { exhibit.rectangle.position.x, exhibit.rectangle.position.y }; + m_vertices[2].texCoords = { exhibit.rectangle.position.x + exhibit.rectangle.size.x, exhibit.rectangle.position.y + exhibit.rectangle.size.y }; + m_vertices[3].texCoords = { exhibit.rectangle.position.x + exhibit.rectangle.size.x, exhibit.rectangle.position.y }; } GallerySprite::Exhibit GallerySprite::priv_getCurrentExhibit() const @@ -282,7 +282,7 @@ GallerySprite::Exhibit GallerySprite::priv_getExhibit(unsigned int exhibitNumber return Exhibit(); if (exhibitNumber == 0u) - return{ { 0.f, 0.f, static_cast(m_pTexture->getSize().x), static_cast(m_pTexture->getSize().y) }, { 0.f, 0.f } }; + return{ { { 0.f, 0.f }, { static_cast(m_pTexture->getSize().x), static_cast(m_pTexture->getSize().y) } }, { 0.f, 0.f } }; return m_exhibits[exhibitNumber - 1]; } diff --git a/src/SelbaWard/GallerySprite.hpp b/src/SelbaWard/GallerySprite.hpp index 9a0b527..e646e2b 100644 --- a/src/SelbaWard/GallerySprite.hpp +++ b/src/SelbaWard/GallerySprite.hpp @@ -5,7 +5,7 @@ // // Gallery Sprite // -// Copyright(c) 2016-2024 M.J.Silk +// Copyright(c) 2016-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 @@ -39,7 +39,7 @@ namespace selbaward { -// Gallery Sprite v1.1.2 +// Gallery Sprite v1.1.3 class GallerySprite : public sf::Drawable, public sf::Transformable { public: @@ -48,7 +48,7 @@ class GallerySprite : public sf::Drawable, public sf::Transformable sf::FloatRect rectangle; sf::Vector2f anchor; - Exhibit(const sf::FloatRect& newRectangle = { 0.f, 0.f, 0.f, 0.f }, const sf::Vector2f& newAnchor = { 0u, 0u }) : rectangle(newRectangle), anchor(newAnchor) { } + Exhibit(const sf::FloatRect& newRectangle = { { 0.f, 0.f }, { 0.f, 0.f } }, const sf::Vector2f& newAnchor = { 0u, 0u }) : rectangle(newRectangle), anchor(newAnchor) { } }; GallerySprite(); @@ -94,7 +94,7 @@ class GallerySprite : public sf::Drawable, public sf::Transformable unsigned int m_currentExhibit; std::vector m_exhibits; - virtual void draw(sf::RenderTarget&, sf::RenderStates) const; + void draw(sf::RenderTarget&, sf::RenderStates) const override; void priv_updateVertices(); Exhibit priv_getCurrentExhibit() const; Exhibit priv_getExhibit(unsigned int exhibitNumber) const; diff --git a/src/SelbaWard/Line.cpp b/src/SelbaWard/Line.cpp index 62c39be..f7f5e5d 100644 --- a/src/SelbaWard/Line.cpp +++ b/src/SelbaWard/Line.cpp @@ -5,7 +5,7 @@ // // Line // -// 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 @@ -104,17 +104,17 @@ sf::FloatRect Line::getLocalBounds() const minY = std::min(minY, m_quad[v].position.y); maxY = std::max(maxY, m_quad[v].position.y); } - box.left = minX; - box.top = minY; - box.width = maxX - minX; - box.height = maxY - minY; + box.position.x = minX; + box.position.y = minY; + box.size.x = maxX - minX; + box.size.y = maxY - minY; } else { - box.left = std::min(m_vertices[0].position.x, m_vertices[1].position.x); - box.top = std::min(m_vertices[0].position.y, m_vertices[1].position.y); - box.width = std::max(m_vertices[0].position.x, m_vertices[1].position.x) - box.left; - box.height = std::max(m_vertices[0].position.y, m_vertices[1].position.y) - box.top; + box.position.x = std::min(m_vertices[0].position.x, m_vertices[1].position.x); + box.position.y = std::min(m_vertices[0].position.y, m_vertices[1].position.y); + box.size.x = std::max(m_vertices[0].position.x, m_vertices[1].position.x) - box.position.x; + box.size.y = std::max(m_vertices[0].position.y, m_vertices[1].position.y) - box.position.y; } return box; } @@ -137,19 +137,19 @@ sf::FloatRect Line::getGlobalBounds() const minY = std::min(minY, transformedPosition.y); maxY = std::max(maxY, transformedPosition.y); } - box.left = minX; - box.top = minY; - box.width = maxX - minX; - box.height = maxY - minY; + box.position.x = minX; + box.position.y = minY; + box.size.x = maxX - minX; + box.size.y = maxY - minY; } else { const sf::Vector2f transformedStartPosition{ getTransform().transformPoint(m_vertices[0].position) }; const sf::Vector2f transformedEndPosition{ getTransform().transformPoint(m_vertices[1].position) }; - box.left = std::min(transformedStartPosition.x, transformedEndPosition.x); - box.top = std::min(transformedStartPosition.y, transformedEndPosition.y); - box.width = std::max(transformedStartPosition.x, transformedEndPosition.x) - box.left; - box.height = std::max(transformedStartPosition.y, transformedEndPosition.y) - box.top; + box.position.x = std::min(transformedStartPosition.x, transformedEndPosition.x); + box.position.y = std::min(transformedStartPosition.y, transformedEndPosition.y); + box.size.x = std::max(transformedStartPosition.x, transformedEndPosition.x) - box.position.x; + box.size.y = std::max(transformedStartPosition.y, transformedEndPosition.y) - box.position.y; } return box; } @@ -243,10 +243,10 @@ void Line::updateQuad() m_quad[2u].position = m_vertices[1u].position + normalVector; m_quad[3u].position = m_vertices[1u].position - normalVector; - m_quad[0u].texCoords = { m_textureRect.left, m_textureRect.top }; - m_quad[1u].texCoords = { m_textureRect.left, m_textureRect.top + m_textureRect.height }; - m_quad[2u].texCoords = { m_textureRect.left + m_textureRect.width, m_textureRect.top }; - m_quad[3u].texCoords = { m_textureRect.left + m_textureRect.width, m_textureRect.top + m_textureRect.height }; + m_quad[0u].texCoords = { m_textureRect.position.x, m_textureRect.position.y }; + m_quad[1u].texCoords = { m_textureRect.position.x, m_textureRect.position.y + m_textureRect.size.y }; + m_quad[2u].texCoords = { m_textureRect.position.x + m_textureRect.size.x, m_textureRect.position.x }; + m_quad[3u].texCoords = { m_textureRect.position.x + m_textureRect.size.x, m_textureRect.position.x + m_textureRect.size.y }; } } // selbaward diff --git a/src/SelbaWard/Line.hpp b/src/SelbaWard/Line.hpp index b724655..c454f4e 100644 --- a/src/SelbaWard/Line.hpp +++ b/src/SelbaWard/Line.hpp @@ -5,7 +5,7 @@ // // Line // -// 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 @@ -41,7 +41,7 @@ namespace selbaward { -// SW Line v1.2.3 +// SW Line v1.2.4 class Line : public sf::Drawable, public sf::Transformable { public: @@ -85,7 +85,7 @@ class Line : public sf::Drawable, public sf::Transformable const sf::Texture* m_texture; sf::FloatRect m_textureRect; - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; bool isThick() const; void updateQuad(); }; diff --git a/src/SelbaWard/NinePatch.cpp b/src/SelbaWard/NinePatch.cpp index 7c20e1f..f33ac24 100644 --- a/src/SelbaWard/NinePatch.cpp +++ b/src/SelbaWard/NinePatch.cpp @@ -5,7 +5,7 @@ // // NinePatch // -// 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 @@ -32,6 +32,8 @@ #include "NinePatch.hpp" +#include + namespace { @@ -43,13 +45,13 @@ void extractScalePositionsAndContentAreaFromTexture(const sf::Texture* const pTe // scale positions topLeft = { 0.f, 0.f }; - bottomRight = { textureRectangle.width - 2.f, textureRectangle.height - 2.f }; + bottomRight = { textureRectangle.size.x - 2.f, textureRectangle.size.y - 2.f }; bool foundStart{ false }, foundEnd{ false }; - for (unsigned int x{ 1u }; x < static_cast(textureRectangle.width); ++x) + for (unsigned int x{ 1u }; x < static_cast(textureRectangle.size.x); ++x) { if (!foundStart) { - if (image.getPixel(textureRectangle.left + x, textureRectangle.top) == sf::Color::Black) + if (image.getPixel(sf::Vector2u(textureRectangle.position.x + x, textureRectangle.position.y)) == sf::Color::Black) { foundStart = true; topLeft.x = x - 1.f; @@ -59,7 +61,7 @@ void extractScalePositionsAndContentAreaFromTexture(const sf::Texture* const pTe } if (foundStart) { - if (image.getPixel(textureRectangle.left + x, textureRectangle.top) == sf::Color::Black) + if (image.getPixel(sf::Vector2u(textureRectangle.position.x + x, textureRectangle.position.y)) == sf::Color::Black) bottomRight.x = x - 1.f; else break; @@ -67,11 +69,11 @@ void extractScalePositionsAndContentAreaFromTexture(const sf::Texture* const pTe } foundStart = false; foundEnd = false; - for (unsigned int y{ 1u }; y < static_cast(textureRectangle.height); ++y) + for (unsigned int y{ 1u }; y < static_cast(textureRectangle.size.y); ++y) { if (!foundStart) { - if (image.getPixel(textureRectangle.left, textureRectangle.top + y) == sf::Color::Black) + if (image.getPixel(sf::Vector2u(textureRectangle.position.x, textureRectangle.position.y + y)) == sf::Color::Black) { foundStart = true; topLeft.y = y - 1.f; @@ -81,7 +83,7 @@ void extractScalePositionsAndContentAreaFromTexture(const sf::Texture* const pTe } if (foundStart) { - if (image.getPixel(textureRectangle.left, textureRectangle.top + y) == sf::Color::Black) + if (image.getPixel(sf::Vector2u(textureRectangle.position.x, textureRectangle.position.y + y)) == sf::Color::Black) bottomRight.y = y - 1.f; else break; @@ -90,15 +92,15 @@ void extractScalePositionsAndContentAreaFromTexture(const sf::Texture* const pTe // content area contentTopLeft = { 0.f, 0.f }; - contentBottomRight = { textureRectangle.width - 2.f, textureRectangle.height - 2.f }; + contentBottomRight = { textureRectangle.size.x - 2.f, textureRectangle.size.y - 2.f }; foundStart = false; foundEnd = false; - const sf::Vector2u textureBottomRightPixel(textureRectangle.width - 1u, textureRectangle.height - 1u); - for (unsigned int x{ 1u }; x < static_cast(textureRectangle.width); ++x) + const sf::Vector2u textureBottomRightPixel(textureRectangle.size.x - 1u, textureRectangle.size.y - 1u); + for (unsigned int x{ 1u }; x < static_cast(textureRectangle.size.x); ++x) { if (!foundStart) { - if (image.getPixel(textureRectangle.left + x, textureRectangle.top + textureBottomRightPixel.y) == sf::Color::Black) + if (image.getPixel(sf::Vector2u(textureRectangle.position.x + x, textureRectangle.position.y + textureBottomRightPixel.y)) == sf::Color::Black) { foundStart = true; contentTopLeft.x = x - 1.f; @@ -108,7 +110,7 @@ void extractScalePositionsAndContentAreaFromTexture(const sf::Texture* const pTe } if (foundStart) { - if (image.getPixel(textureRectangle.left + x, textureRectangle.top + textureBottomRightPixel.y) == sf::Color::Black) + if (image.getPixel(sf::Vector2u(textureRectangle.position.x + x, textureRectangle.position.y + textureBottomRightPixel.y)) == sf::Color::Black) contentBottomRight.x = x - 1.f; else break; @@ -116,11 +118,11 @@ void extractScalePositionsAndContentAreaFromTexture(const sf::Texture* const pTe } foundStart = false; foundEnd = false; - for (unsigned int y{ 1u }; y < static_cast(textureRectangle.height); ++y) + for (unsigned int y{ 1u }; y < static_cast(textureRectangle.size.y); ++y) { if (!foundStart) { - if (image.getPixel(textureRectangle.left + textureBottomRightPixel.x, textureRectangle.top + y) == sf::Color::Black) + if (image.getPixel(sf::Vector2u(textureRectangle.position.x + textureBottomRightPixel.x, textureRectangle.position.y + y)) == sf::Color::Black) { foundStart = true; contentTopLeft.y = y - 1.f; @@ -130,7 +132,7 @@ void extractScalePositionsAndContentAreaFromTexture(const sf::Texture* const pTe } if (foundStart) { - if (image.getPixel(textureRectangle.left + textureBottomRightPixel.x, textureRectangle.top + y) == sf::Color::Black) + if (image.getPixel(sf::Vector2u(textureRectangle.position.x + textureBottomRightPixel.x, textureRectangle.position.y + y)) == sf::Color::Black) contentBottomRight.y = y - 1.f; else break; @@ -153,7 +155,7 @@ NinePatch::NinePatch() , m_scaleBottomRight({ 0.f, 0.f }) , m_contentTopLeft({ 0.f, 0.f }) , m_contentBottomRight({ 0.f, 0.f }) - , m_textureRectangle({ 0, 0, 3, 3 }) + , m_textureRectangle({ { 0, 0 }, { 3, 3 } }) { } @@ -163,7 +165,7 @@ void NinePatch::setTexture(const sf::Texture& texture, const bool resetSize, con if (resetRect) m_textureRectangle = { { 0, 0 }, sf::Vector2i(m_texture->getSize()) }; //m_trimmedSize = sf::Vector2f(m_texture->getSize()) - trimAmount * 2.f; - m_trimmedSize = sf::Vector2f{ static_cast(m_textureRectangle.width), static_cast(m_textureRectangle.height) } -trimAmount * 2.f; + m_trimmedSize = sf::Vector2f{ static_cast(m_textureRectangle.size.x), static_cast(m_textureRectangle.size.y) } -trimAmount * 2.f; if (resetSize) m_size = m_trimmedSize; extractScalePositionsAndContentAreaFromTexture(m_texture, m_textureRectangle, m_scaleTopLeft, m_scaleBottomRight, m_contentTopLeft, m_contentBottomRight); @@ -189,7 +191,7 @@ void NinePatch::resetSize() void NinePatch::setTextureRect(const sf::IntRect textureRectangle, const bool resetSize) { m_textureRectangle = textureRectangle; - m_trimmedSize = sf::Vector2f{ static_cast(m_textureRectangle.width), static_cast(m_textureRectangle.height) } -trimAmount * 2.f; + m_trimmedSize = sf::Vector2f{ static_cast(m_textureRectangle.size.x), static_cast(m_textureRectangle.size.y) } -trimAmount * 2.f; if (resetSize) m_size = m_trimmedSize; if (m_texture != nullptr) @@ -327,7 +329,7 @@ void NinePatch::priv_updateVerticesTexCoords() m_vertices[21u].texCoords = { x3, y3 }; // offset trim and texture rectangle - const sf::Vector2f textureRectangleOffset{ static_cast(m_textureRectangle.left), static_cast(m_textureRectangle.top) }; + const sf::Vector2f textureRectangleOffset{ static_cast(m_textureRectangle.position.x), static_cast(m_textureRectangle.position.y) }; for (auto& vertex : m_vertices) vertex.texCoords += textureRectangleOffset + trimAmount; } diff --git a/src/SelbaWard/NinePatch.hpp b/src/SelbaWard/NinePatch.hpp index 1a6f99d..e66024c 100644 --- a/src/SelbaWard/NinePatch.hpp +++ b/src/SelbaWard/NinePatch.hpp @@ -5,7 +5,7 @@ // // NinePatch // -// 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 @@ -40,7 +40,7 @@ namespace selbaward { -// SW Nine Patch v1.4.3 +// SW Nine Patch v1.4.4 class NinePatch : public sf::Drawable, public sf::Transformable { public: @@ -71,7 +71,7 @@ class NinePatch : public sf::Drawable, public sf::Transformable sf::Vector2f m_contentBottomRight; sf::IntRect m_textureRectangle; - 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_updateVerticesPositions(); void priv_updateVerticesTexCoords(); diff --git a/src/SelbaWard/PaletteEnums.hpp b/src/SelbaWard/PaletteEnums.hpp index 9db6a26..4ca0f9a 100644 --- a/src/SelbaWard/PaletteEnums.hpp +++ b/src/SelbaWard/PaletteEnums.hpp @@ -5,7 +5,7 @@ // // Palette Enums // -// Copyright(c) 2016-2024 M.J.Silk +// Copyright(c) 2016-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 diff --git a/src/SelbaWard/PieChart.cpp b/src/SelbaWard/PieChart.cpp index 132eb39..1ca56d9 100644 --- a/src/SelbaWard/PieChart.cpp +++ b/src/SelbaWard/PieChart.cpp @@ -5,7 +5,7 @@ // // Pie Chart // -// 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 diff --git a/src/SelbaWard/PieChart.hpp b/src/SelbaWard/PieChart.hpp index 04f737f..64c49cd 100644 --- a/src/SelbaWard/PieChart.hpp +++ b/src/SelbaWard/PieChart.hpp @@ -5,7 +5,7 @@ // // Pie Chart // -// 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 @@ -38,7 +38,7 @@ namespace selbaward { -// SW Pie Chart v1.0.3 +// SW Pie Chart v1.0.4 class PieChart : public sf::Drawable, public sf::Transformable { public: @@ -67,7 +67,7 @@ class PieChart : public sf::Drawable, public sf::Transformable std::vector m_vertices; sf::Vector2f m_size; - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; }; inline void PieChart::setSize(sf::Vector2f size) diff --git a/src/SelbaWard/PixelDisplay.cpp b/src/SelbaWard/PixelDisplay.cpp index 03b8d32..09ddb67 100644 --- a/src/SelbaWard/PixelDisplay.cpp +++ b/src/SelbaWard/PixelDisplay.cpp @@ -5,7 +5,7 @@ // // Pixel Display // -// Copyright(c) 2019-2024 M.J.Silk +// Copyright(c) 2019-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 @@ -203,19 +203,19 @@ void PixelDisplay::shiftRight(const unsigned int amount, const unsigned int star void PixelDisplay::scrollUp(const unsigned int color, const unsigned int amount, sf::IntRect selectionRectangle) { assert(color < m_palette.size()); - assert(selectionRectangle.left < static_cast(m_resolution.x)); - assert(selectionRectangle.top < static_cast(m_resolution.y)); - if (selectionRectangle.width == 0u) - selectionRectangle.width = m_resolution.x - selectionRectangle.left; - if (selectionRectangle.height == 0u) - selectionRectangle.height = m_resolution.y - selectionRectangle.top; + assert(selectionRectangle.position.x < static_cast(m_resolution.x)); + assert(selectionRectangle.position.y < static_cast(m_resolution.y)); + if (selectionRectangle.size.x == 0u) + selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + if (selectionRectangle.size.y == 0u) + selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; sf::Rect rectangle(selectionRectangle); - for (unsigned int y{ 0u }; y < rectangle.height; ++y) + for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) { - for (unsigned int x{ 0u }; x < rectangle.width; ++x) + for (unsigned int x{ 0u }; x < rectangle.size.x; ++x) { - const unsigned int index{ (rectangle.top + y) * m_resolution.x + rectangle.left + x }; - m_pixels[index] = (y == rectangle.height - 1u) ? color : m_pixels[index + m_resolution.x]; + const unsigned int index{ (rectangle.position.y + y) * m_resolution.x + rectangle.position.x + x }; + m_pixels[index] = (y == rectangle.size.y - 1u) ? color : m_pixels[index + m_resolution.x]; } } priv_updatePixels(); @@ -224,19 +224,19 @@ void PixelDisplay::scrollUp(const unsigned int color, const unsigned int amount, void PixelDisplay::scrollDown(const unsigned int color, const unsigned int amount, sf::IntRect selectionRectangle) { assert(color < m_palette.size()); - assert(selectionRectangle.left < static_cast(m_resolution.x)); - assert(selectionRectangle.top < static_cast(m_resolution.y)); - if (selectionRectangle.width == 0u) - selectionRectangle.width = m_resolution.x - selectionRectangle.left; - if (selectionRectangle.height == 0u) - selectionRectangle.height = m_resolution.y - selectionRectangle.top; + assert(selectionRectangle.position.x < static_cast(m_resolution.x)); + assert(selectionRectangle.position.y < static_cast(m_resolution.y)); + if (selectionRectangle.size.x == 0u) + selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + if (selectionRectangle.size.y == 0u) + selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; sf::Rect rectangle(selectionRectangle); - for (unsigned int y{ 0u }; y < rectangle.height; ++y) + for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) { - for (unsigned int x{ 0u }; x < rectangle.width; ++x) + for (unsigned int x{ 0u }; x < rectangle.size.x; ++x) { - const unsigned int index{ (rectangle.top + rectangle.height - y - 1u) * m_resolution.x + rectangle.left + x }; - m_pixels[index] = (y == rectangle.height - 1u) ? color : m_pixels[index - m_resolution.x]; + const unsigned int index{ (rectangle.position.y + rectangle.size.y - y - 1u) * m_resolution.x + rectangle.position.x + x }; + m_pixels[index] = (y == rectangle.size.y - 1u) ? color : m_pixels[index - m_resolution.x]; } } priv_updatePixels(); @@ -245,18 +245,18 @@ void PixelDisplay::scrollDown(const unsigned int color, const unsigned int amoun void PixelDisplay::scrollLeft(const unsigned int color, const unsigned int amount, sf::IntRect selectionRectangle) { assert(color < m_palette.size()); - assert(selectionRectangle.left < static_cast(m_resolution.x)); - assert(selectionRectangle.top < static_cast(m_resolution.y)); - if (selectionRectangle.width == 0u) - selectionRectangle.width = m_resolution.x - selectionRectangle.left; - if (selectionRectangle.height == 0u) - selectionRectangle.height = m_resolution.y - selectionRectangle.top; + assert(selectionRectangle.position.x < static_cast(m_resolution.x)); + assert(selectionRectangle.position.y < static_cast(m_resolution.y)); + if (selectionRectangle.size.x == 0u) + selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + if (selectionRectangle.size.y == 0u) + selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; sf::Rect rectangle(selectionRectangle); - for (unsigned int y{ 0u }; y < rectangle.height; ++y) + for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) { - const unsigned int firstPixelIndex{ (rectangle.top + y) * m_resolution.x + rectangle.left }; - shiftVectorDown(m_pixels, amount, firstPixelIndex, rectangle.width); - m_pixels[firstPixelIndex + rectangle.width - 1u] = color; + const unsigned int firstPixelIndex{ (rectangle.position.y + y) * m_resolution.x + rectangle.position.x }; + shiftVectorDown(m_pixels, amount, firstPixelIndex, rectangle.size.x); + m_pixels[firstPixelIndex + rectangle.size.x - 1u] = color; } priv_updatePixels(); } @@ -264,17 +264,17 @@ void PixelDisplay::scrollLeft(const unsigned int color, const unsigned int amoun void PixelDisplay::scrollRight(const unsigned int color, const unsigned int amount, sf::IntRect selectionRectangle) { assert(color < m_palette.size()); - assert(selectionRectangle.left < static_cast(m_resolution.x)); - assert(selectionRectangle.top < static_cast(m_resolution.y)); - if (selectionRectangle.width == 0u) - selectionRectangle.width = m_resolution.x - selectionRectangle.left; - if (selectionRectangle.height == 0u) - selectionRectangle.height = m_resolution.y - selectionRectangle.top; + assert(selectionRectangle.position.x < static_cast(m_resolution.x)); + assert(selectionRectangle.position.y < static_cast(m_resolution.y)); + if (selectionRectangle.size.x == 0u) + selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + if (selectionRectangle.size.y == 0u) + selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; sf::Rect rectangle(selectionRectangle); - for (unsigned int y{ 0u }; y < rectangle.height; ++y) + for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) { - const unsigned int firstPixelIndex{ (rectangle.top + y) * m_resolution.x + rectangle.left }; - shiftVectorUp(m_pixels, amount, firstPixelIndex, rectangle.width); + const unsigned int firstPixelIndex{ (rectangle.position.y + y) * m_resolution.x + rectangle.position.x }; + shiftVectorUp(m_pixels, amount, firstPixelIndex, rectangle.size.x); m_pixels[firstPixelIndex] = color; } priv_updatePixels(); @@ -282,22 +282,22 @@ void PixelDisplay::scrollRight(const unsigned int color, const unsigned int amou void PixelDisplay::scrollWrapUp(const unsigned int amount, sf::IntRect selectionRectangle) { - assert(selectionRectangle.left < static_cast(m_resolution.x)); - assert(selectionRectangle.top < static_cast(m_resolution.y)); - if (selectionRectangle.width == 0u) - selectionRectangle.width = m_resolution.x - selectionRectangle.left; - if (selectionRectangle.height == 0u) - selectionRectangle.height = m_resolution.y - selectionRectangle.top; + assert(selectionRectangle.position.x < static_cast(m_resolution.x)); + assert(selectionRectangle.position.y < static_cast(m_resolution.y)); + if (selectionRectangle.size.x == 0u) + selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + if (selectionRectangle.size.y == 0u) + selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; sf::Rect rectangle(selectionRectangle); - std::vector tempRow(rectangle.width); - for (unsigned int x{ 0u }; x < rectangle.width; ++x) - tempRow[x] = m_pixels[rectangle.top * m_resolution.x + rectangle.left + x]; - for (unsigned int y{ 0u }; y < rectangle.height; ++y) + std::vector tempRow(rectangle.size.x); + for (unsigned int x{ 0u }; x < rectangle.size.x; ++x) + tempRow[x] = m_pixels[rectangle.position.y * m_resolution.x + rectangle.position.x + x]; + for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) { - for (unsigned int x{ 0u }; x < rectangle.width; ++x) + for (unsigned int x{ 0u }; x < rectangle.size.x; ++x) { - const unsigned int index{ (rectangle.top + y) * m_resolution.x + rectangle.left + x }; - m_pixels[index] = (y == rectangle.height - 1u) ? tempRow[x] : m_pixels[index + m_resolution.x]; + const unsigned int index{ (rectangle.position.y + y) * m_resolution.x + rectangle.position.x + x }; + m_pixels[index] = (y == rectangle.size.y - 1u) ? tempRow[x] : m_pixels[index + m_resolution.x]; } } priv_updatePixels(); @@ -305,22 +305,22 @@ void PixelDisplay::scrollWrapUp(const unsigned int amount, sf::IntRect selection void PixelDisplay::scrollWrapDown(const unsigned int amount, sf::IntRect selectionRectangle) { - assert(selectionRectangle.left < static_cast(m_resolution.x)); - assert(selectionRectangle.top < static_cast(m_resolution.y)); - if (selectionRectangle.width == 0u) - selectionRectangle.width = m_resolution.x - selectionRectangle.left; - if (selectionRectangle.height == 0u) - selectionRectangle.height = m_resolution.y - selectionRectangle.top; + assert(selectionRectangle.position.x < static_cast(m_resolution.x)); + assert(selectionRectangle.position.y < static_cast(m_resolution.y)); + if (selectionRectangle.size.x == 0u) + selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + if (selectionRectangle.size.y == 0u) + selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; sf::Rect rectangle(selectionRectangle); - std::vector tempRow(rectangle.width); - for (unsigned int x{ 0u }; x < rectangle.width; ++x) - tempRow[x] = m_pixels[(rectangle.top + rectangle.height - 1u) * m_resolution.x + rectangle.left + x]; - for (unsigned int y{ 0u }; y < rectangle.height; ++y) + std::vector tempRow(rectangle.size.x); + for (unsigned int x{ 0u }; x < rectangle.size.x; ++x) + tempRow[x] = m_pixels[(rectangle.position.y + rectangle.size.y - 1u) * m_resolution.x + rectangle.position.x + x]; + for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) { - for (unsigned int x{ 0u }; x < rectangle.width; ++x) + for (unsigned int x{ 0u }; x < rectangle.size.x; ++x) { - const unsigned int index{ (rectangle.top + rectangle.height - y - 1u) * m_resolution.x + rectangle.left + x }; - m_pixels[index] = (y == rectangle.height - 1u) ? tempRow[x] : m_pixels[index - m_resolution.x]; + const unsigned int index{ (rectangle.position.y + rectangle.size.y - y - 1u) * m_resolution.x + rectangle.position.x + x }; + m_pixels[index] = (y == rectangle.size.y - 1u) ? tempRow[x] : m_pixels[index - m_resolution.x]; } } priv_updatePixels(); @@ -328,28 +328,28 @@ void PixelDisplay::scrollWrapDown(const unsigned int amount, sf::IntRect selecti void PixelDisplay::scrollWrapLeft(const unsigned int amount, sf::IntRect selectionRectangle) { - assert(selectionRectangle.left < static_cast(m_resolution.x)); - assert(selectionRectangle.top < static_cast(m_resolution.y)); - if (selectionRectangle.width == 0u) - selectionRectangle.width = m_resolution.x - selectionRectangle.left; - if (selectionRectangle.height == 0u) - selectionRectangle.height = m_resolution.y - selectionRectangle.top; + assert(selectionRectangle.position.x < static_cast(m_resolution.x)); + assert(selectionRectangle.position.y < static_cast(m_resolution.y)); + if (selectionRectangle.size.x == 0u) + selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + if (selectionRectangle.size.y == 0u) + selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; sf::Rect rectangle(selectionRectangle); - for (unsigned int y{ 0u }; y < rectangle.height; ++y) - shiftVectorWrapDown(m_pixels, amount, (rectangle.top + y) * m_resolution.x + rectangle.left, rectangle.width); + for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) + shiftVectorWrapDown(m_pixels, amount, (rectangle.position.y + y) * m_resolution.x + rectangle.position.x, rectangle.size.x); priv_updatePixels(); } void PixelDisplay::scrollWrapRight(const unsigned int amount, sf::IntRect selectionRectangle) { - assert(selectionRectangle.left < static_cast(m_resolution.x)); - assert(selectionRectangle.top < static_cast(m_resolution.y)); - if (selectionRectangle.width == 0u) - selectionRectangle.width = m_resolution.x - selectionRectangle.left; - if (selectionRectangle.height == 0u) - selectionRectangle.height = m_resolution.y - selectionRectangle.top; - for (unsigned int y{ 0u }; y < static_cast(selectionRectangle.height); ++y) - shiftVectorWrapUp(m_pixels, amount, (selectionRectangle.top + y) * m_resolution.x + selectionRectangle.left, selectionRectangle.width); + assert(selectionRectangle.position.x < static_cast(m_resolution.x)); + assert(selectionRectangle.position.y < static_cast(m_resolution.y)); + if (selectionRectangle.size.x == 0u) + selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + if (selectionRectangle.size.y == 0u) + selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; + for (unsigned int y{ 0u }; y < static_cast(selectionRectangle.size.y); ++y) + shiftVectorWrapUp(m_pixels, amount, (selectionRectangle.position.y + y) * m_resolution.x + selectionRectangle.position.x, selectionRectangle.size.x); priv_updatePixels(); } @@ -574,13 +574,13 @@ unsigned int PixelDisplay::priv_getRandomColor() const void PixelDisplay::priv_copyToBufferFromSelectionRectangle(Buffer& buffer, const sf::IntRect& selectionRectangle) { assert(priv_isSelectionRectangleFullyContained(selectionRectangle)); - buffer.width = selectionRectangle.width; - buffer.pixels.resize(selectionRectangle.width * selectionRectangle.height); + buffer.width = selectionRectangle.size.x; + buffer.pixels.resize(selectionRectangle.size.x * selectionRectangle.size.y); sf::Rect rectangle(selectionRectangle); - for (unsigned int y{ 0u }; y < rectangle.height; ++y) + for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) { for (unsigned int x{ 0u }; x < buffer.width; ++x) - buffer.pixels[y * buffer.width + x] = m_pixels[(y + rectangle.top) * buffer.width + (x + rectangle.left)]; + buffer.pixels[y * buffer.width + x] = m_pixels[(y + rectangle.position.y) * buffer.width + (x + rectangle.position.x)]; } } @@ -599,12 +599,12 @@ void PixelDisplay::priv_pasteOffsetBuffer(const Buffer& buffer, const sf::Vector bool PixelDisplay::priv_isSelectionRectangleFullyContained(const sf::IntRect& selectionRectangle) { - return (selectionRectangle.left >= 0 && - selectionRectangle.top >= 0 && - selectionRectangle.width >= 0 && - selectionRectangle.height >= 0 && - static_cast(selectionRectangle.left + selectionRectangle.width) <= m_resolution.x && - static_cast(selectionRectangle.top + selectionRectangle.height) <= m_resolution.y); + return (selectionRectangle.position.x >= 0 && + selectionRectangle.position.y >= 0 && + selectionRectangle.size.x >= 0 && + selectionRectangle.size.y >= 0 && + static_cast(selectionRectangle.position.x + selectionRectangle.size.x) <= m_resolution.x && + static_cast(selectionRectangle.position.y + selectionRectangle.size.y) <= m_resolution.y); } } // namespace selbaward diff --git a/src/SelbaWard/PixelDisplay.hpp b/src/SelbaWard/PixelDisplay.hpp index ce55eef..241bd26 100644 --- a/src/SelbaWard/PixelDisplay.hpp +++ b/src/SelbaWard/PixelDisplay.hpp @@ -5,7 +5,7 @@ // // Pixel Display // -// Copyright(c) 2019-2024 M.J.Silk +// Copyright(c) 2019-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 @@ -66,14 +66,14 @@ class PixelDisplay : public sf::Drawable, public sf::Transformable // manual shifting/scrolling void shiftLeft(unsigned int amount = 1u, unsigned int startIndex = 0u, unsigned int numberOfPixels = 0u); void shiftRight(unsigned int amount = 1u, unsigned int startIndex = 0u, unsigned int numberOfPixels = 0u); - void scrollUp(unsigned int color = 0u, unsigned int amount = 1u, sf::IntRect selectionRectangle = { 0, 0, 0, 0 }); - void scrollDown(unsigned int color = 0u, unsigned int amount = 1u, sf::IntRect selectionRectangle = { 0, 0, 0, 0 }); - void scrollLeft(unsigned int color = 0u, unsigned int amount = 1u, sf::IntRect selectionRectangle = { 0, 0, 0, 0 }); - void scrollRight(unsigned int color = 0u, unsigned int amount = 1u, sf::IntRect selectionRectangle = { 0, 0, 0, 0 }); - void scrollWrapUp(unsigned int amount = 1u, sf::IntRect selectionRectangle = { 0, 0, 0, 0 }); - void scrollWrapDown(unsigned int amount = 1u, sf::IntRect selectionRectangle = { 0, 0, 0, 0 }); - void scrollWrapLeft(unsigned int amount = 1u, sf::IntRect selectionRectangle = { 0, 0, 0, 0 }); - void scrollWrapRight(unsigned int amount = 1u, sf::IntRect selectionRectangle = { 0, 0, 0, 0 }); + void scrollUp(unsigned int color = 0u, unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollDown(unsigned int color = 0u, unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollLeft(unsigned int color = 0u, unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollRight(unsigned int color = 0u, unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollWrapUp(unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollWrapDown(unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollWrapLeft(unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollWrapRight(unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); // palette void setPalette(const std::vector& palette); @@ -117,7 +117,7 @@ class PixelDisplay : public sf::Drawable, public sf::Transformable }; std::vector m_buffers; - 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_updatePixels(); void priv_updatePixel(const unsigned int index); diff --git a/src/SelbaWard/Polygon.cpp b/src/SelbaWard/Polygon.cpp index 3434eed..c41ce70 100644 --- a/src/SelbaWard/Polygon.cpp +++ b/src/SelbaWard/Polygon.cpp @@ -5,7 +5,7 @@ // // Polygon // -// Copyright(c) 2022-2024 M.J.Silk +// Copyright(c) 2022-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 @@ -318,7 +318,7 @@ float Polygon::getPerimeter() const { const std::size_t numberOfVertices{ m_vertices.size() }; float perimeter{ 0.f }; - const bool hasHoles{ !m_holeStartIndices.empty()}; + const bool hasHoles{ !m_holeStartIndices.empty() }; for (std::size_t i{ 0u }; i < numberOfVertices; ++i) { std::size_t nextI{ i + 1u }; @@ -530,11 +530,11 @@ void Polygon::draw(sf::RenderTarget& target, sf::RenderStates states) const states.texture = m_texture; states.transform *= getTransform(); if (!m_outputVertices.empty()) - target.draw(m_outputVertices.data(), m_outputVertices.size(), sf::Triangles, states); + target.draw(m_outputVertices.data(), m_outputVertices.size(), sf::PrimitiveType::Triangles, states); if (m_showWireframe && !m_wireframeVertices.empty()) { states.texture = nullptr; - target.draw(m_wireframeVertices.data(), m_wireframeVertices.size(), sf::Lines, states); + target.draw(m_wireframeVertices.data(), m_wireframeVertices.size(), sf::PrimitiveType::Lines, states); } } @@ -883,7 +883,7 @@ void Polygon::priv_triangulateEarClip() else return; } - + std::size_t currentPoint{ ear.front() }; std::vector::iterator currentIt{ std::find(indices.begin(), indices.end(), currentPoint) }; diff --git a/src/SelbaWard/Polygon.hpp b/src/SelbaWard/Polygon.hpp index 8d024f2..e01719b 100644 --- a/src/SelbaWard/Polygon.hpp +++ b/src/SelbaWard/Polygon.hpp @@ -5,7 +5,7 @@ // // Polygon // -// Copyright(c) 2022-2024 M.J.Silk +// Copyright(c) 2022-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 diff --git a/src/SelbaWard/ProgressBar.cpp b/src/SelbaWard/ProgressBar.cpp index 5bb11d3..e0d67e0 100644 --- a/src/SelbaWard/ProgressBar.cpp +++ b/src/SelbaWard/ProgressBar.cpp @@ -5,7 +5,7 @@ // // Progress Bar // -// 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 @@ -110,8 +110,8 @@ void ProgressBar::setTexture(const sf::Texture& texture, const bool resetRect) m_texture = &texture; if (resetRect) { - m_textureRectangle.width = m_texture->getSize().x; - m_textureRectangle.height = m_texture->getSize().y; + m_textureRectangle.size.x = m_texture->getSize().x; + m_textureRectangle.size.y = m_texture->getSize().y; } priv_updateGraphics(); } @@ -133,8 +133,8 @@ void ProgressBar::setBackgroundTexture(const sf::Texture& backgroundTexture, con m_backgroundTexture = &backgroundTexture; if (resetRect) { - m_backgroundTextureRectangle.width = m_backgroundTexture->getSize().x; - m_backgroundTextureRectangle.height = m_backgroundTexture->getSize().y; + m_backgroundTextureRectangle.size.x = m_backgroundTexture->getSize().x; + m_backgroundTextureRectangle.size.y = m_backgroundTexture->getSize().y; } priv_updateGraphics(); } @@ -219,11 +219,11 @@ void ProgressBar::priv_updateGraphics() m_bar[2u].position = { width, 0.f }; m_bar[3u].position = { width, m_size.y }; sf::FloatRect textureRect{ m_textureRectangle }; - textureRect.width = textureRect.width * m_amount; - m_bar[0u].texCoords = { textureRect.left, textureRect.top }; - m_bar[1u].texCoords = { textureRect.left, textureRect.top + textureRect.height }; - m_bar[2u].texCoords = { textureRect.left + textureRect.width, textureRect.top }; - m_bar[3u].texCoords = { textureRect.left + textureRect.width, textureRect.top + textureRect.height }; + textureRect.size.x = textureRect.size.x * m_amount; + m_bar[0u].texCoords = { textureRect.position.x, textureRect.position.y }; + m_bar[1u].texCoords = { textureRect.position.x, textureRect.position.y + textureRect.size.y }; + m_bar[2u].texCoords = { textureRect.position.x + textureRect.size.x, textureRect.position.y }; + m_bar[3u].texCoords = { textureRect.position.x + textureRect.size.x, textureRect.position.y + textureRect.size.y }; for (auto& vertex : m_bar) vertex.color = m_color; } diff --git a/src/SelbaWard/ProgressBar.hpp b/src/SelbaWard/ProgressBar.hpp index a4ef624..92ef179 100644 --- a/src/SelbaWard/ProgressBar.hpp +++ b/src/SelbaWard/ProgressBar.hpp @@ -5,7 +5,7 @@ // // Progress Bar // -// 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 @@ -41,7 +41,7 @@ namespace selbaward { -// SW Progress Bar 1.1.2 +// SW Progress Bar 1.1.3 class ProgressBar : public sf::Drawable, public sf::Transformable { public: @@ -106,7 +106,7 @@ class ProgressBar : public sf::Drawable, public sf::Transformable sf::IntRect m_textureRectangle; sf::IntRect m_backgroundTextureRectangle; - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void priv_updateGraphics(); }; diff --git a/src/SelbaWard/Ring.cpp b/src/SelbaWard/Ring.cpp index b79ef7a..a21a36b 100644 --- a/src/SelbaWard/Ring.cpp +++ b/src/SelbaWard/Ring.cpp @@ -5,7 +5,7 @@ // // Ring // -// Copyright(c) 2016-2024 M.J.Silk +// Copyright(c) 2016-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 @@ -228,7 +228,7 @@ void Ring::priv_updateVertices() it->position = { m_radius + std::sin(angle) * m_radius * (isInnerPoint ? m_hole : 1.f), m_radius - std::cos(angle) * m_radius * (isInnerPoint ? m_hole : 1.f), }; it->color = m_color; const sf::Vector2f scaledPosition{ it->position / (m_radius * 2.f) }; - it->texCoords = { scaledPosition.x * m_textureRect.width + m_textureRect.left, scaledPosition.y * m_textureRect.height + m_textureRect.top };; + it->texCoords = { scaledPosition.x * m_textureRect.size.x + m_textureRect.position.x, scaledPosition.y * m_textureRect.size.y + m_textureRect.position.y };; } } diff --git a/src/SelbaWard/Ring.hpp b/src/SelbaWard/Ring.hpp index 75b67a4..b70d20f 100644 --- a/src/SelbaWard/Ring.hpp +++ b/src/SelbaWard/Ring.hpp @@ -5,7 +5,7 @@ // // Ring // -// Copyright(c) 2016-2024 M.J.Silk +// Copyright(c) 2016-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 @@ -38,7 +38,7 @@ namespace selbaward { -// SW Ring v1.1.3 +// SW Ring v1.1.4 class Ring : public sf::Drawable, public sf::Transformable { public: @@ -74,7 +74,7 @@ class Ring : public sf::Drawable, public sf::Transformable const sf::Texture* m_texture; sf::IntRect m_textureRect; - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void priv_updateVertices(); }; diff --git a/src/SelbaWard/SpinningCard.cpp b/src/SelbaWard/SpinningCard.cpp index 713db68..4d447a1 100644 --- a/src/SelbaWard/SpinningCard.cpp +++ b/src/SelbaWard/SpinningCard.cpp @@ -5,7 +5,7 @@ // // SpinningCard // -// 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 @@ -32,6 +32,8 @@ #include "SpinningCard.hpp" +#include + #include namespace selbaward @@ -64,18 +66,18 @@ SpinningCard::SpinningCard(const sf::Sprite& sprite) m_vertices[i].position = sprite.getPosition() - sprite.getOrigin(); // top-left // ...then, add offsets to individual vertices - m_vertices[0].position += sf::Vector2f(static_cast(m_initial.width) / 2, static_cast(m_initial.height) / 2); // centre - m_vertices[2].position += sf::Vector2f(m_initial.width, 0.f); // top-right - m_vertices[3].position += sf::Vector2f(m_initial.width, m_initial.height); // bottom-right - m_vertices[4].position += sf::Vector2f(0.f, m_initial.height); // bottom-left + m_vertices[0].position += sf::Vector2f(static_cast(m_initial.size.x) / 2, static_cast(m_initial.size.y) / 2); // centre + m_vertices[2].position += sf::Vector2f(m_initial.size.x, 0.f); // top-right + m_vertices[3].position += sf::Vector2f(m_initial.size.x, m_initial.size.y); // bottom-right + m_vertices[4].position += sf::Vector2f(0.f, m_initial.size.y); // bottom-left // set texture coordinates to the same as the sprite's (using the same method for texCoords as position above) for (unsigned int i{ 0 }; i < 5; ++i) - m_vertices[i].texCoords = sf::Vector2f(static_cast(sprite.getTextureRect().left), static_cast(sprite.getTextureRect().top)); // top-left - m_vertices[0].texCoords += sf::Vector2f(static_cast(sprite.getTextureRect().width) / 2, static_cast(sprite.getTextureRect().height) / 2); // centre - m_vertices[2].texCoords += sf::Vector2f(static_cast(sprite.getTextureRect().width), 0.f); // top-right - m_vertices[3].texCoords += sf::Vector2f(static_cast(sprite.getTextureRect().width), static_cast(sprite.getTextureRect().height)); // bottom-right - m_vertices[4].texCoords += sf::Vector2f(0.f, static_cast(sprite.getTextureRect().height)); // bottom-left + m_vertices[i].texCoords = sf::Vector2f(static_cast(sprite.getTextureRect().position.x), static_cast(sprite.getTextureRect().position.x)); // top-left + m_vertices[0].texCoords += sf::Vector2f(static_cast(sprite.getTextureRect().size.x) / 2, static_cast(sprite.getTextureRect().size.y) / 2); // centre + m_vertices[2].texCoords += sf::Vector2f(static_cast(sprite.getTextureRect().size.x), 0.f); // top-right + m_vertices[3].texCoords += sf::Vector2f(static_cast(sprite.getTextureRect().size.x), static_cast(sprite.getTextureRect().size.y)); // bottom-right + m_vertices[4].texCoords += sf::Vector2f(0.f, static_cast(sprite.getTextureRect().size.y)); // bottom-left // set colours of vertices to match sprite's colour for (unsigned int i{ 0 }; i < 5; ++i) @@ -85,7 +87,7 @@ SpinningCard::SpinningCard(const sf::Sprite& sprite) m_vertices[5] = m_vertices[1]; // store a pointer to the sprite's texture - m_pTexture = sprite.getTexture(); + m_pTexture = &sprite.getTexture(); } void SpinningCard::spin(float angleInDegrees) @@ -96,11 +98,11 @@ void SpinningCard::spin(float angleInDegrees) void SpinningCard::spinRadians(float angleInRadians) { angleInRadians -= m_pi / 2; - m_vertices[0].position = sf::Vector2f(m_initial.left + m_initial.width / 2, m_initial.top + m_initial.height / 2); - m_vertices[1].position = sf::Vector2f(m_initial.left + (std::sin(angleInRadians) + 1) * m_initial.width / 2, m_initial.top - std::cos(angleInRadians) * m_depth * m_initial.height / 2); - m_vertices[2].position = sf::Vector2f(m_initial.left + (std::sin(angleInRadians + m_pi) + 1) * m_initial.width / 2, m_initial.top - std::cos(angleInRadians + m_pi) * m_depth * m_initial.height / 2); - m_vertices[3].position = sf::Vector2f(m_initial.left + (std::sin(angleInRadians + m_pi) + 1) * m_initial.width / 2, m_initial.top + (std::cos(angleInRadians + m_pi) * m_depth + 2) * m_initial.height / 2); - m_vertices[4].position = sf::Vector2f(m_initial.left + (std::sin(angleInRadians) + 1) * m_initial.width / 2, m_initial.top + (std::cos(angleInRadians) * m_depth + 2) * m_initial.height / 2); + m_vertices[0].position = sf::Vector2f(m_initial.position.x + m_initial.size.x / 2, m_initial.position.y + m_initial.size.y / 2); + m_vertices[1].position = sf::Vector2f(m_initial.position.x + (std::sin(angleInRadians) + 1) * m_initial.size.x / 2, m_initial.position.y - std::cos(angleInRadians) * m_depth * m_initial.size.y / 2); + m_vertices[2].position = sf::Vector2f(m_initial.position.x + (std::sin(angleInRadians + m_pi) + 1) * m_initial.size.x / 2, m_initial.position.y - std::cos(angleInRadians + m_pi) * m_depth * m_initial.size.y / 2); + m_vertices[3].position = sf::Vector2f(m_initial.position.x + (std::sin(angleInRadians + m_pi) + 1) * m_initial.size.x / 2, m_initial.position.y + (std::cos(angleInRadians + m_pi) * m_depth + 2) * m_initial.size.y / 2); + m_vertices[4].position = sf::Vector2f(m_initial.position.x + (std::sin(angleInRadians) + 1) * m_initial.size.x / 2, m_initial.position.y + (std::cos(angleInRadians) * m_depth + 2) * m_initial.size.y / 2); // weld last vertex to second vertex (to complete the solid) m_vertices[5] = m_vertices[1]; @@ -114,11 +116,11 @@ void SpinningCard::spinVertically(float angleInDegrees) void SpinningCard::spinVerticallyRadians(float angleInRadians) { angleInRadians -= m_pi / 2; - m_vertices[0].position = sf::Vector2f(m_initial.left + m_initial.width / 2, m_initial.top + m_initial.height / 2); - m_vertices[1].position = sf::Vector2f(m_initial.left - std::cos(angleInRadians) * m_depth * m_initial.width / 2, m_initial.top + (std::sin(angleInRadians) + 1) * m_initial.height / 2); - m_vertices[4].position = sf::Vector2f(m_initial.left - std::cos(angleInRadians + m_pi) * m_depth * m_initial.width / 2, m_initial.top + (std::sin(angleInRadians + m_pi) + 1) * m_initial.height / 2); - m_vertices[3].position = sf::Vector2f(m_initial.left + (std::cos(angleInRadians + m_pi) * m_depth + 2) * m_initial.width / 2, m_initial.top + (std::sin(angleInRadians + m_pi) + 1) * m_initial.height / 2); - m_vertices[2].position = sf::Vector2f(m_initial.left + (std::cos(angleInRadians) * m_depth + 2) * m_initial.width / 2, m_initial.top + (std::sin(angleInRadians) + 1) * m_initial.height / 2); + m_vertices[0].position = sf::Vector2f(m_initial.position.x + m_initial.size.x / 2, m_initial.position.y + m_initial.size.y / 2); + m_vertices[1].position = sf::Vector2f(m_initial.position.x - std::cos(angleInRadians) * m_depth * m_initial.size.x / 2, m_initial.position.y + (std::sin(angleInRadians) + 1) * m_initial.size.y / 2); + m_vertices[4].position = sf::Vector2f(m_initial.position.x - std::cos(angleInRadians + m_pi) * m_depth * m_initial.size.x / 2, m_initial.position.y + (std::sin(angleInRadians + m_pi) + 1) * m_initial.size.y / 2); + m_vertices[3].position = sf::Vector2f(m_initial.position.x + (std::cos(angleInRadians + m_pi) * m_depth + 2) * m_initial.size.x / 2, m_initial.position.y + (std::sin(angleInRadians + m_pi) + 1) * m_initial.size.y / 2); + m_vertices[2].position = sf::Vector2f(m_initial.position.x + (std::cos(angleInRadians) * m_depth + 2) * m_initial.size.x / 2, m_initial.position.y + (std::sin(angleInRadians) + 1) * m_initial.size.y / 2); // weld last vertex to second vertex (to complete the solid) m_vertices[5] = m_vertices[1]; diff --git a/src/SelbaWard/SpinningCard.hpp b/src/SelbaWard/SpinningCard.hpp index fd8fffc..982568d 100644 --- a/src/SelbaWard/SpinningCard.hpp +++ b/src/SelbaWard/SpinningCard.hpp @@ -5,7 +5,7 @@ // // Spinning Card // -// 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 @@ -52,7 +52,7 @@ namespace selbaward { -// SpinningCard (v1.2.3) +// SpinningCard v1.2.4 class SpinningCard : public sf::Drawable, public sf::Transformable { public: @@ -75,7 +75,7 @@ class SpinningCard : public sf::Drawable, public sf::Transformable void setDepth(float depth); private: - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; sf::VertexArray m_vertices; const sf::Texture* m_pTexture; sf::FloatRect m_initial; diff --git a/src/SelbaWard/Spline.cpp b/src/SelbaWard/Spline.cpp index 13c5a2e..aad514b 100644 --- a/src/SelbaWard/Spline.cpp +++ b/src/SelbaWard/Spline.cpp @@ -5,7 +5,7 @@ // // Spline // -// 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 @@ -343,7 +343,7 @@ void Spline::update() } if (m_isClosed) { - + m_interpolatedVertices.back().position = m_vertices.front().position; m_interpolatedVertices.back().color = m_color; } @@ -951,7 +951,7 @@ void Spline::draw(sf::RenderTarget& target, sf::RenderStates states) const if (m_outputVertices.size() > 0) target.draw(m_outputVertices.data(), m_outputVertices.size(), (priv_isThick() ? thickPrimitiveType : m_primitiveType), states); if (m_showHandles && m_handlesVertices.size() > 1) - target.draw(&m_handlesVertices.front(), m_handlesVertices.size(), sf::PrimitiveType::Lines, states); + target.draw(m_handlesVertices.data(), m_handlesVertices.size(), sf::PrimitiveType::Lines, states); } bool Spline::priv_isValidVertexIndex(const std::size_t vertexIndex) const @@ -1157,7 +1157,7 @@ void Spline::priv_updateOutputVertices() capOffset = tangentUnit * halfWidth; } - const sf::Vector2f forwardLine{ ((it != last) ? (it + 1)->position - it->position : (m_isClosed ? (begin + 1)->position - begin->position : it->position - (it - 1)->position )) }; + const sf::Vector2f forwardLine{ ((it != last) ? (it + 1)->position - it->position : (m_isClosed ? (begin + 1)->position - begin->position : it->position - (it - 1)->position)) }; const sf::Vector2f forwardUnit{ forwardLine / vectorLength(forwardLine) }; const sf::Vector2f backwardLine{ ((it != begin) ? it->position - (it - 1)->position : (m_isClosed ? it->position - (last)->position : (it + 1)->position - it->position)) }; const sf::Vector2f backwardUnit{ backwardLine / vectorLength(backwardLine) }; @@ -1181,7 +1181,7 @@ void Spline::priv_updateOutputVertices() itThick->color = color; itThick++->position = isClockwise ? insidePoint : outsidePoint; } - break; + break; case ThickCornerType::PointClip: case ThickCornerType::PointLimit: case ThickCornerType::Bevel: @@ -1258,7 +1258,7 @@ void Spline::priv_updateOutputVertices() } } } - break; + break; case ThickCornerType::Round: { if (it == begin) @@ -1309,7 +1309,7 @@ void Spline::priv_updateOutputVertices() } } } - break; + break; } } if (m_isClosed) @@ -1318,7 +1318,7 @@ void Spline::priv_updateOutputVertices() m_outputVertices.begin()->position = (itThick - 2)->position; (m_outputVertices.begin() + 1)->position = (itThick - 1)->position; } - + if (!m_isClosed && (m_thickEndCapType == ThickCapType::Round)) { std::vector::iterator vertex{ m_vertices.end() - 1u }; @@ -1340,7 +1340,7 @@ void Spline::priv_updateOutputVertices() itThick++->position = vertex->position - vector; } } - + } } diff --git a/src/SelbaWard/Spline.hpp b/src/SelbaWard/Spline.hpp index add7fd3..39e6ab7 100644 --- a/src/SelbaWard/Spline.hpp +++ b/src/SelbaWard/Spline.hpp @@ -5,7 +5,7 @@ // // Spline // -// 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 @@ -38,7 +38,7 @@ namespace selbaward { -// SW Spline v1.7.1 +// SW Spline v1.7.0 class Spline : public sf::Drawable { public: @@ -135,7 +135,7 @@ class Spline : public sf::Drawable void removeVertex(std::size_t index); void removeVertices(std::size_t index, std::size_t numberOfVertices = 0u); // if numberOfVertices is zero (the default), removes all vertices from specified index until the end void reverseVertices(); - + void setPosition(std::size_t index, sf::Vector2f position = { 0.f, 0.f }); void setPositions(std::size_t index, std::size_t numberOfVertices = 0u, sf::Vector2f position = { 0.f, 0.f }); // if numberOfVertices is zero (the default), sets positions of all vertices from specified index until the end void setPositions(const std::vector& positions, std::size_t index = 0u); @@ -231,7 +231,7 @@ class Spline : public sf::Drawable bool m_lockHandleMirror; bool m_lockHandleAngle; - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; bool priv_isValidVertexIndex(std::size_t vertexIndex) const; bool priv_testVertexIndex(std::size_t vertexIndex, const std::string& exceptionMessage) const; bool priv_isThick() const; diff --git a/src/SelbaWard/Sprite3d.cpp b/src/SelbaWard/Sprite3d.cpp index d4cac99..482c1f2 100644 --- a/src/SelbaWard/Sprite3d.cpp +++ b/src/SelbaWard/Sprite3d.cpp @@ -5,7 +5,7 @@ // // Sprite3d // -// 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 @@ -142,12 +142,12 @@ Sprite3d::Sprite3d(const sf::Texture& texture, const sf::IntRect& textureRect, c Sprite3d::Sprite3d(const sf::Sprite& sprite) : Sprite3d() { - setTexture(*sprite.getTexture()); + setTexture(sprite.getTexture()); setTextureRect(sprite.getTextureRect()); this->setColor(sprite.getColor()); this->setOrigin(sprite.getOrigin()); this->setPosition(sprite.getPosition()); - this->setRotation(sprite.getRotation()); + this->setRotation(sprite.getRotation().asDegrees()); this->setScale(sprite.getScale()); } @@ -165,9 +165,9 @@ const sf::Sprite Sprite3d::getSprite() const void Sprite3d::setTextureRect(const sf::IntRect& textureRectangle) { - m_textureOffset = sf::Vector2i(textureRectangle.left, textureRectangle.top); + m_textureOffset = sf::Vector2i(textureRectangle.position.x, textureRectangle.position.y); m_backTextureOffset = m_textureOffset; - m_size = sf::Vector2i(textureRectangle.width, textureRectangle.height); + m_size = sf::Vector2i(textureRectangle.size.x, textureRectangle.size.y); createPointGrid(); updateTransformedPoints(); updateVertices(); @@ -263,12 +263,12 @@ float Sprite3d::getYaw() const float Sprite3d::getRoll() const { - return this->getRotation(); + return this->getRotation().asDegrees(); } sf::Vector3f Sprite3d::getRotation3d() const { - return{ m_pitch, m_yaw, this->Transformable::getRotation() }; + return{ m_pitch, m_yaw, this->Transformable::getRotation().asDegrees()}; } sf::Vector3f Sprite3d::getOrigin3d() const @@ -297,7 +297,7 @@ void Sprite3d::setYaw(const float yaw) void Sprite3d::setRoll(const float roll) { - this->Transformable::setRotation(roll); + this->Transformable::setRotation(sf::degrees(roll)); } void Sprite3d::setRotation(const float rotation) @@ -486,11 +486,7 @@ void Sprite3d::draw(sf::RenderTarget& target, sf::RenderStates states) const else states.texture = m_pTexture; -#ifdef USE_SFML_PRE_2_4 - target.draw(&m_vertices[0], m_vertices.size(), sf::PrimitiveType::TrianglesStrip, states); -#else // USE_SFML_PRE_2_4 - target.draw(&m_vertices[0], m_vertices.size(), sf::PrimitiveType::TriangleStrip, states); -#endif // USE_SFML_PRE_2_4 + target.draw(m_vertices.data(), m_vertices.size(), sf::PrimitiveType::TriangleStrip, states); } } diff --git a/src/SelbaWard/Sprite3d.hpp b/src/SelbaWard/Sprite3d.hpp index 9a70609..674f950 100644 --- a/src/SelbaWard/Sprite3d.hpp +++ b/src/SelbaWard/Sprite3d.hpp @@ -5,7 +5,7 @@ // // Sprite3d // -// 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 @@ -44,7 +44,7 @@ namespace selbaward { -// Sprite3d version 1.2.2 +// Sprite3d version 1.2.3 class Sprite3d : public sf::Drawable, public sf::Transformable { public: @@ -181,7 +181,7 @@ class Sprite3d : public sf::Drawable, public sf::Transformable void createPointGrid() const; // needs to be const to allow dynamic subdivision - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void updateTransformedPoints() const; void updateVertices() const; void updateGlobalCorners() const; diff --git a/src/SelbaWard/Starfield.cpp b/src/SelbaWard/Starfield.cpp index 5c64d68..a469c40 100644 --- a/src/SelbaWard/Starfield.cpp +++ b/src/SelbaWard/Starfield.cpp @@ -5,7 +5,7 @@ // // Starfield // -// Copyright(c) 2016-2024 M.J.Silk +// Copyright(c) 2016-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 @@ -94,7 +94,7 @@ void Starfield::regenerate() { vertex.position = { randomValue(0.f, m_size.x), randomValue(0.f, m_size.y) }; vertex.color = m_color; - vertex.color.a = static_cast(randomAlpha()); + vertex.color.a = static_cast(randomAlpha()); } } @@ -120,7 +120,7 @@ void Starfield::setColor(const sf::Color color) m_color = color; for (auto& vertex : m_vertices) { - const sf::Uint8 alphaDepth{ vertex.color.a }; + const uint8_t alphaDepth{ vertex.color.a }; vertex.color = m_color; vertex.color.a = alphaDepth; } diff --git a/src/SelbaWard/Starfield.hpp b/src/SelbaWard/Starfield.hpp index 6366486..d279776 100644 --- a/src/SelbaWard/Starfield.hpp +++ b/src/SelbaWard/Starfield.hpp @@ -5,7 +5,7 @@ // // Starfield // -// Copyright(c) 2016-2024 M.J.Silk +// Copyright(c) 2016-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 @@ -38,7 +38,7 @@ namespace selbaward { -// SW Starfield v1.1.1 +// SW Starfield v1.1.2 class Starfield : public sf::Drawable, public sf::Transformable { public: @@ -58,7 +58,7 @@ class Starfield : public sf::Drawable, public sf::Transformable sf::Vector2f m_size; sf::Color m_color; - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; }; } // namespace selbaward diff --git a/src/SelbaWard/TileMap.hpp b/src/SelbaWard/TileMap.hpp index f999379..f646622 100644 --- a/src/SelbaWard/TileMap.hpp +++ b/src/SelbaWard/TileMap.hpp @@ -5,7 +5,7 @@ // // Tile Map // -// Copyright(c) 2016-2024 M.J.Silk +// Copyright(c) 2016-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 @@ -40,11 +40,12 @@ #include #include +#include namespace selbaward { -// SW Tile Map v2.0.3 +// SW Tile Map v2.0.4 template class TileMap : public sf::Drawable, public sf::Transformable { @@ -120,8 +121,8 @@ class TileMap : public sf::Drawable, public sf::Transformable Deque, Raw } m_levelContainerType; - unsigned long int m_levelWidth; - unsigned long int m_levelSize; + std::size_t m_levelWidth; + std::size_t m_levelSize; const void* m_pLevel; // data @@ -150,7 +151,7 @@ class TileMap : public sf::Drawable, public sf::Transformable mutable sf::RenderTexture m_renderTexture; mutable std::vector m_render; - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void priv_updateVertices() const; void priv_updateRender() const; void priv_recreateRenderTexture(); diff --git a/src/SelbaWard/TileMap.inl b/src/SelbaWard/TileMap.inl index 38fdcd1..b4c56d5 100644 --- a/src/SelbaWard/TileMap.inl +++ b/src/SelbaWard/TileMap.inl @@ -5,7 +5,7 @@ // // Tile Map // -// Copyright(c) 2016-2024 M.J.Silk +// Copyright(c) 2016-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 @@ -76,14 +76,14 @@ void TileMap::update() const sf::Vector2f actualCamera{ priv_getActualCamera() }; const sf::Vector2i levelOffset{ static_cast(std::floor(actualCamera.x)), static_cast(std::floor(actualCamera.y)) }; - const unsigned int height{ m_levelWidth > 0u ? m_levelSize / m_levelWidth : 0u }; + const std::size_t height{ m_levelWidth > 0u ? m_levelSize / m_levelWidth : 0u }; - for (unsigned int y{ 0 }; y < m_gridSize.y; ++y) + for (std::size_t y{ 0 }; y < m_gridSize.y; ++y) { - for (unsigned int x{ 0 }; x < m_gridSize.x; ++x) + for (std::size_t x{ 0 }; x < m_gridSize.x; ++x) { - const unsigned int gridIndex{ y * m_gridSize.x + x }; - const unsigned int levelIndex{ (levelOffset.y + y) * m_levelWidth + levelOffset.x + x }; + const std::size_t gridIndex{ y * m_gridSize.x + x }; + const std::size_t levelIndex{ (levelOffset.y + y) * m_levelWidth + levelOffset.x + x }; if (levelOffset.x + x >= 0 && levelOffset.x + x < m_levelWidth && levelOffset.y + y >= 0 && levelOffset.y + y < height) { @@ -473,10 +473,11 @@ void TileMap::priv_updateRender() const template void TileMap::priv_recreateRenderTexture() { + bool createSucceeded{ false }; if (m_gridSize.x < 2 || m_gridSize.y < 2) - m_renderTexture.create(1, 1); + createSucceeded = m_renderTexture.resize({ 1u, 1u }); else - m_renderTexture.create((m_gridSize.x - 1) * m_textureTileSize.x, (m_gridSize.y - 1) * m_textureTileSize.y); + createSucceeded = m_renderTexture.resize({ (m_gridSize.x - 1) * m_textureTileSize.x, (m_gridSize.y - 1) * m_textureTileSize.y }); m_redrawRequired = true; }