Skip to content

Commit

Permalink
Merge pull request #49 from eXpl0it3r/feature/update-ci
Browse files Browse the repository at this point in the history
Update Remaining Code to SFML 3 & Update CI
  • Loading branch information
Hapaxia authored Feb 19, 2025
2 parents a1489e8 + ca4b484 commit 4140763
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 220 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- { name: Windows Clang, os: windows-2022, flags: -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ }
- { name: Linux GCC, os: ubuntu-22.04, flags: -GNinja }
- { name: Linux Clang, os: ubuntu-22.04, flags: -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ }
- { name: macOS, os: macos-12, flags: -GNinja }
- { name: macOS, os: macos-14, flags: -GNinja }
type:
- { name: Release }
- { name: Debug }
Expand All @@ -39,14 +39,14 @@ jobs:
if: runner.os == 'Linux'
run: |
sudo apt update
sudo apt install ninja-build llvm xorg-dev libxrandr-dev libxcursor-dev libudev-dev libgl1-mesa-dev libegl1-mesa-dev
sudo apt install ninja-build llvm xorg-dev libxrandr-dev libxcursor-dev libxi-dev libudev-dev libgl1-mesa-dev libegl1-mesa-dev
- name: Install macOS Tools
if: runner.os == 'macOS'
run: brew install ninja

- name: Checkout SFML
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: SFML/SFML
path: sfml
Expand All @@ -55,7 +55,8 @@ jobs:
- name: Configure SFML
run: |
cmake -S sfml -B sfml/build \
-DCMAKE_INSTALL_PREFIX=sfml/install \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/sfml/install \
-DCMAKE_BUILD_TYPE=${{matrix.type.name}} \
-DSFML_BUILD_AUDIO=OFF \
-DSFML_BUILD_NETWORK=OFF \
Expand All @@ -65,7 +66,7 @@ jobs:
run: cmake --build sfml/build --config ${{matrix.type.name}} --target install

- name: Checkout SelbaWard
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: SelbaWard

Expand Down
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
cmake_minimum_required(VERSION 3.16)
project(SelbaWard LANGUAGES CXX)

find_package(SFML 2.6 REQUIRED COMPONENTS graphics)
find_package(SFML 3 REQUIRED COMPONENTS Graphics)

add_library(SelbaWard
src/SelbaWard/BitmapFont.cpp
src/SelbaWard/BitmapText.cpp
src/SelbaWard/ConsoleScreen.cpp
src/SelbaWard/Crosshair.cpp
src/SelbaWard/ElasticSprite.cpp
src/SelbaWard/FrameTransition.cpp
src/SelbaWard/GallerySprite.cpp
src/SelbaWard/Line.cpp
src/SelbaWard/NinePatch.cpp
Expand All @@ -20,13 +21,14 @@ add_library(SelbaWard
src/SelbaWard/SpinningCard.cpp
src/SelbaWard/Spline.cpp
src/SelbaWard/Sprite3d.cpp
src/SelbaWard/SpriteBatch.cpp
src/SelbaWard/Starfield.cpp
src/SelbaWard/Starfield3d.cpp
)
add_library(SelbaWard::SelbaWard ALIAS SelbaWard)
target_include_directories(SelbaWard PUBLIC src)
target_link_libraries(SelbaWard PUBLIC sfml-graphics)
target_compile_features(SelbaWard PUBLIC cxx_std_11)
target_link_libraries(SelbaWard PUBLIC SFML::Graphics)
target_compile_features(SelbaWard PUBLIC cxx_std_17)

# Stop configuration if being consumed by a higher level project
if(NOT PROJECT_IS_TOP_LEVEL)
Expand Down
19 changes: 9 additions & 10 deletions examples/bitmapTextExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ int main()
// standard setup for a font
font.setExternalTexture(fontSheetTexture);
font.setNumberOfTilesPerRow(16);
font.setDefaultTextureRect({ 0, 0, 8, 8 });
font.setDefaultTextureRect({ { 0, 0 }, { 8, 8 } });

// customisation for the specific font ("Selba Ward Bitmap Font 0001.png")

// customise texture rects for 'j' and 'z' as the glyph for j spills into z
font.setTextureRect({ 80, 48, 8, 9 }, 'j');
font.setTextureRect({ 80, 57, 8, 7 }, 'z');
font.setTextureRect({ { 80, 48 }, { 8, 9 } }, 'j');
font.setTextureRect({ { 80, 57 }, { 8, 7 } }, 'z');
font.setBaseline(-1, 'z');

// starting values
Expand Down Expand Up @@ -94,23 +94,22 @@ int main()
const std::string defaultString = "012 Str;:zingy! qu,ic(k)jumps 57";
const std::string xxxyyyString = "xxxyyyiijiizzJJIIvvvwwyyxxzzz";
text.setString(prefixString + defaultString);
text.setPosition(20, 50);
text.setPosition({ 20, 50 });
text.setScale(2); // scale so we can see the pixels (only accepts unsigned integers - single unsigned int, two unsigned ints, sf::Vector2u)
//text.Transformable::setScale(3.5f, 9.75f); // it's still possible to scale by fractional amounts by explicitly calling the Transformable method
//text.setTracking(2); // base spacing between characters. default is 1

sf::RenderWindow window(sf::VideoMode(550, 100), "Bitmap Text example", sf::Style::Default);
sf::RenderWindow window(sf::VideoMode({ 550, 100 }), "Bitmap Text example", sf::Style::Default);
window.setFramerateLimit(20);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
while (const std::optional event = window.pollEvent())
{
if (event.type == sf::Event::Closed)
if (event->is<sf::Event::Closed>())
window.close();
else if (event.type == sf::Event::KeyPressed)
else if (const auto* keyPressed = event->getIf<sf::Event::KeyPressed>())
{
if (event.key.code == sf::Keyboard::Space)
if (keyPressed->code == sf::Keyboard::Key::Space)
{
if (text.getString() != prefixString + xxxyyyString)
text.setString(prefixString + xxxyyyString);
Expand Down
25 changes: 12 additions & 13 deletions examples/lineExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,35 @@ int main()
std::ios_base::iostate sfErrIoState = sf::err().rdstate(); // stores current state of SFML error stream
sf::err().clear(std::ios::failbit); // disables SFML error stream
sf::ContextSettings contextSettings;
contextSettings.antialiasingLevel = 8;
sf::RenderWindow window(sf::VideoMode(800, 600), "Line test", sf::Style::Default, contextSettings);
contextSettings.antiAliasingLevel = 8;
sf::RenderWindow window(sf::VideoMode({ 800, 600 }), "Line test", sf::Style::Default, sf::State::Windowed, contextSettings);
window.setFramerateLimit(60);
sf::err().clear(sfErrIoState); // re-enables SFML error stream (re-enstates the stored state)

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
while (const std::optional event = window.pollEvent())
{
if (event.type == sf::Event::Closed || event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
if (event->is<sf::Event::Closed>() || event->is<sf::Event::KeyPressed>() && event->getIf<sf::Event::KeyPressed>()->code == sf::Keyboard::Key::Escape)
window.close();
else if (event.type == sf::Event::MouseButtonPressed)
else if (const auto* mouseButton = event->getIf<sf::Event::MouseButtonPressed>())
{
if (event.mouseButton.button == sf::Mouse::Left)
if (mouseButton->button == sf::Mouse::Button::Left)
isButtonDown.left = true;
else if (event.mouseButton.button == sf::Mouse::Right)
else if (mouseButton->button == sf::Mouse::Button::Right)
isButtonDown.right = true;
}
else if (event.type == sf::Event::MouseButtonReleased)
else if (const auto* mouseButton = event->getIf<sf::Event::MouseButtonReleased>())
{
if (event.mouseButton.button == sf::Mouse::Left)
if (mouseButton->button == sf::Mouse::Button::Left)
isButtonDown.left = false;
else if (event.mouseButton.button == sf::Mouse::Right)
else if (mouseButton->button == sf::Mouse::Button::Right)
isButtonDown.right = false;
}
else if (event.type == sf::Event::MouseWheelMoved)
else if (const auto* mouseWheel = event->getIf<sf::Event::MouseWheelScrolled>())
{
const float lineThicknessOffset{ 2.f };
if (event.mouseWheel.delta > 0)
if (mouseWheel->delta > 0)
lineThickness += lineThicknessOffset;
else
lineThickness -= lineThicknessOffset;
Expand Down
23 changes: 11 additions & 12 deletions examples/progressBarExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int main()
return EXIT_FAILURE;
}

sf::RenderWindow window(sf::VideoMode(800, 600), "Progress Bar example");
sf::RenderWindow window(sf::VideoMode({ 800, 600 }), "Progress Bar example");

sw::ProgressBar progressBar({ 300.f, 40.f });

Expand All @@ -42,7 +42,7 @@ int main()
progressBar.setBackgroundColor(sf::Color(128, 128, 128));
progressBar.setFrameColor(sf::Color(128, 128, 255, 192));
progressBar.setFrameThickness(2.f);
progressBar.setRotation(-30);
progressBar.setRotation(sf::degrees(-30));

// set textures
progressBar.setTexture(texture);
Expand All @@ -56,7 +56,7 @@ int main()
// marker
std::vector<sf::CircleShape> markers(3, sf::CircleShape(3.f));
for (auto& marker : markers)
marker.setOrigin(marker.getRadius(), marker.getRadius());
marker.setOrigin({ marker.getRadius(), marker.getRadius() });
markers[0].setFillColor(sf::Color::Red);
markers[1].setFillColor(sf::Color::Yellow);
markers[2].setFillColor(sf::Color::Green);
Expand All @@ -65,10 +65,9 @@ int main()

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
while (const std::optional event = window.pollEvent())
{
if ((event.type == sf::Event::Closed) || (event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
if (event->is<sf::Event::Closed>() || event->is<sf::Event::KeyPressed>() && event->getIf<sf::Event::KeyPressed>()->code == sf::Keyboard::Key::Escape)
window.close();
}

Expand All @@ -78,14 +77,14 @@ int main()

float frameTime{ clock.restart().asSeconds() };

if (sf::Keyboard::isKeyPressed(sf::Keyboard::Add)) // [+] (number pad) increase progress
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Add)) // [+] (number pad) increase progress
progressBar.setRatio(progressBar.getRatio() + frameTime * 0.3f);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Subtract)) // [-] (number pad) decrease progress
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Subtract)) // [-] (number pad) decrease progress
progressBar.setRatio(progressBar.getRatio() - frameTime * 0.3f);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Period)) // [.]/[>] rotate left
progressBar.rotate(frameTime * 30.f);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Comma)) // [,]/[<] rotate right
progressBar.rotate(-frameTime * 30.f);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Period)) // [.]/[>] rotate left
progressBar.rotate(sf::degrees(frameTime * 30.f));
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Comma)) // [,]/[<] rotate right
progressBar.rotate(sf::degrees(-frameTime * 30.f));

window.clear();
window.draw(progressBar);
Expand Down
35 changes: 17 additions & 18 deletions examples/spinningCardExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

int main()
{
sf::RenderWindow window(sf::VideoMode(500, 500), "Spinning card effect");
sf::RenderWindow window(sf::VideoMode({ 500, 500 }), "Spinning card effect");
window.setFramerateLimit(60);

const std::string faceTextureFilename{ "resources/Card Face - SFML.png" };
Expand All @@ -40,12 +40,12 @@ int main()

// set up and position cards
const sf::Vector2f positionOfSpinningCard{ static_cast<float>(window.getSize().x) / 2, static_cast<float>(window.getSize().y) / 2 };
faceSprite.setOrigin(faceSprite.getLocalBounds().width / 2, faceSprite.getLocalBounds().height / 2);
backSprite.setOrigin(backSprite.getLocalBounds().width / 2, backSprite.getLocalBounds().height / 2);
faceSprite.setOrigin(faceSprite.getLocalBounds().size / 2.f);
backSprite.setOrigin(backSprite.getLocalBounds().size / 2.f);
faceSprite.setPosition(positionOfSpinningCard);
backSprite.setPosition(positionOfSpinningCard);
faceSprite.setRotation(10);
backSprite.setRotation(10);
faceSprite.setRotation(sf::degrees(10));
backSprite.setRotation(sf::degrees(10));
//faceSprite.setColor(sf::Color::Blue);
//backSprite.setColor(sf::Color::Green);

Expand All @@ -68,14 +68,13 @@ int main()

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
while (const std::optional event = window.pollEvent())
{
if ((event.type == sf::Event::Closed) || (event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
if (event->is<sf::Event::Closed>() || event->is<sf::Event::KeyPressed>() && event->getIf<sf::Event::KeyPressed>()->code == sf::Keyboard::Key::Escape)
window.close();
if (event.type == sf::Event::KeyPressed)
if (const auto* keyPressed = event->getIf<sf::Event::KeyPressed>())
{
if (event.key.code == sf::Keyboard::Space)
if (keyPressed->code == sf::Keyboard::Key::Space)
{
isSpinning = true;
clock.restart();
Expand Down Expand Up @@ -105,21 +104,21 @@ int main()

// smoothly move "out" when spinning
const float scale{ 1.f + (0.5f * std::sin(spinAngle * 3.14159f / 360)) };
cardFace.setScale(scale, scale);
cardBack.setScale(scale, scale);
cardFace.setScale({ scale, scale });
cardBack.setScale({ scale, scale });
}

window.clear();

// side cards (must return for the central card)
backSprite.move(-120, 0);
backSprite.rotate(-2);
backSprite.move({ -120, 0 });
backSprite.rotate(sf::degrees(-2));
window.draw(backSprite);
backSprite.move(240, 0);
backSprite.rotate(4);
backSprite.move({ 240, 0 });
backSprite.rotate(sf::degrees(4));
window.draw(backSprite);
backSprite.move(-120, 0);
backSprite.rotate(-2);
backSprite.move({ -120, 0 });
backSprite.rotate(sf::degrees(-2));

// central card
if (isSpinning)
Expand Down
23 changes: 11 additions & 12 deletions examples/splineExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Selba Ward - Spline example", sf::Style::Default);
sf::RenderWindow window(sf::VideoMode({ 800, 600 }), "Selba Ward - Spline example", sf::Style::Default);
window.setFramerateLimit(15);

const unsigned int numberOfVertices{ 50u }; // number of (control) vertices in spline (one vertex per frame)
Expand All @@ -40,28 +40,27 @@ int main()

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
while (const std::optional event = window.pollEvent())
{
if (event.type == sf::Event::Closed || event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
if (event->is<sf::Event::Closed>() || event->is<sf::Event::KeyPressed>() && event->getIf<sf::Event::KeyPressed>()->code == sf::Keyboard::Key::Escape)
window.close();
else if (event.type == sf::Event::KeyPressed)
else if (const auto* keyPressed = event->getIf<sf::Event::KeyPressed>())
{
if (event.key.code == sf::Keyboard::F1) // toggle pause
if (keyPressed->code == sf::Keyboard::Key::F1) // toggle pause
isPaused = !isPaused;
else if (event.key.code == sf::Keyboard::Space) // toggle bezier/linear curve mode
else if (keyPressed->code == sf::Keyboard::Key::Space) // toggle bezier/linear curve mode
spline.setBezierInterpolation(!spline.getBezierInterpolation());
else if (event.key.code == sf::Keyboard::Tab) // toggle primitive type
else if (keyPressed->code == sf::Keyboard::Key::Tab) // toggle primitive type
{
if (spline.getPrimitiveType() == sf::PrimitiveType::LinesStrip)
if (spline.getPrimitiveType() == sf::PrimitiveType::LineStrip)
spline.setPrimitiveType(sf::PrimitiveType::Points);
else
spline.setPrimitiveType(sf::PrimitiveType::LinesStrip);
spline.setPrimitiveType(sf::PrimitiveType::LineStrip);
}
}
else if (event.type == sf::Event::MouseWheelScrolled)
else if (const auto* mouseWheel = event->getIf<sf::Event::MouseWheelScrolled>())
{
const float thickness{ spline.getThickness() + event.mouseWheelScroll.delta };
const float thickness{ spline.getThickness() + mouseWheel->delta };
spline.setThickness((thickness < 0) ? 0.f : thickness);
}
}
Expand Down
Loading

0 comments on commit 4140763

Please sign in to comment.