Skip to content

Commit

Permalink
Merge pull request #31 from G-Epitech/rc-add-sfml-graphic-library
Browse files Browse the repository at this point in the history
feat(graphics): add sfml graphic library
  • Loading branch information
flavien-chenu authored Apr 2, 2024
2 parents 99fb840 + cafa20b commit 4df5a68
Show file tree
Hide file tree
Showing 59 changed files with 1,995 additions and 28 deletions.
1 change: 0 additions & 1 deletion core/src/loader/Loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

class Loader {
public:

/**
* @brief Construct a new Loader object
*/
Expand Down
3 changes: 2 additions & 1 deletion graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(ncurses)
#add_subdirectory(ncurses)
add_subdirectory(sfml)
3 changes: 3 additions & 0 deletions graphics/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_subdirectory(events)
add_subdirectory(exceptions)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../..)
3 changes: 3 additions & 0 deletions graphics/common/events/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_subdirectory(mouse)
add_subdirectory(key)
add_subdirectory(window)
46 changes: 46 additions & 0 deletions graphics/common/events/key/AKeyEvent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** AKeyEvent.hpp
*/

#pragma once

#include "shared/graphics/events/IKeyEvent.hpp"

using namespace shared::graphics::events;

namespace arcade::graphics::common::events {
template<EventType T>
concept KeyEventType = T == EventType::KEY_PRESS || T == EventType::KEY_RELEASE;

template<EventType T> requires KeyEventType<T>
class AKeyEvent;
}

using namespace arcade::graphics::common::events;

template<EventType T> requires KeyEventType<T>
class arcade::graphics::common::events::AKeyEvent: public IKeyEvent {
public:
~AKeyEvent() override = default;

EventType getType() const noexcept override {
return T;
}

const KeyCode getKeyCode() const noexcept override {
return _code;
}

const KeyType getKeyType() const noexcept override {
return _keyType;
}

protected:
AKeyEvent(const KeyType keyType, const KeyCode code) : _keyType(keyType), _code(code) {};

const KeyType _keyType;
const KeyCode _code;
};
6 changes: 6 additions & 0 deletions graphics/common/events/key/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target_sources(${PROJECT_NAME} PUBLIC
AKeyEvent.hpp
KeyPressEvent.hpp
KeyReleaseEvent.hpp
key.hpp
)
21 changes: 21 additions & 0 deletions graphics/common/events/key/KeyPressEvent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** KeyPressEvent.hpp
*/

#pragma once

#include "AKeyEvent.hpp"

namespace arcade::graphics::common::events {
class KeyPressEvent;
}

class arcade::graphics::common::events::KeyPressEvent: public AKeyEvent<EventType::KEY_PRESS> {
public:
explicit KeyPressEvent(const KeyType type, const KeyCode code = { .character = 0 })
: AKeyEvent(type, code) {};
~KeyPressEvent() override = default;
};
20 changes: 20 additions & 0 deletions graphics/common/events/key/KeyReleaseEvent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** KeyPressEvent.hpp
*/

#pragma once

#include "AKeyEvent.hpp"

namespace arcade::graphics::common::events {
class KeyReleaseEvent;
}

class arcade::graphics::common::events::KeyReleaseEvent: public AKeyEvent<EventType::KEY_RELEASE> {
public:
KeyReleaseEvent(const KeyType type, const KeyCode code) : AKeyEvent(type, code) {};
~KeyReleaseEvent() override = default;
};
11 changes: 11 additions & 0 deletions graphics/common/events/key/key.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** mouse.hpp
*/

#pragma once

#include "KeyPressEvent.hpp"
#include "KeyReleaseEvent.hpp"
52 changes: 52 additions & 0 deletions graphics/common/events/mouse/AMouseButtonEvent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** AMouseEvent.hpp
*/

#pragma once

#include "AMouseEvent.hpp"
#include "shared/graphics/events/IMouseButtonEvent.hpp"

using namespace shared::graphics::events;
using namespace shared::types;
using namespace arcade::graphics::common::events;

namespace arcade::graphics::common::events {
template<EventType T>
concept MouseButtonEventType = T == EventType::MOUSE_BTN_PRESS || T == EventType::MOUSE_BTN_RELEASE;

template<EventType T> requires MouseButtonEventType<T>
class AMouseButtonEvent;
}

template<EventType T> requires MouseButtonEventType<T>
class arcade::graphics::common::events::AMouseButtonEvent: public AMouseEvent<T>, public virtual IMouseButtonEvent {
public:
/**
* @brief Construct a new AMouseButtonEvent object
*
* @param pos Position of the mouse
* @param button Targeted button
*/
explicit AMouseButtonEvent(
Vector2i pos,
MouseButton button
): AMouseEvent<T>(pos), _button(button) {};

~AMouseButtonEvent() override = default;

/**
* @brief Get the button object
*
* @return Target button type
*/
const MouseButton getButton() const noexcept override {
return _button;
}

protected:
const MouseButton _button;
};
42 changes: 42 additions & 0 deletions graphics/common/events/mouse/AMouseEvent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** AMouseEvent.hpp
*/

#pragma once

#include "shared/graphics/events/IMouseEvent.hpp"

using namespace shared::graphics::events;
using namespace shared::types;

namespace arcade::graphics::common::events {
template <EventType T>
class AMouseEvent;
}

template <EventType T>
class arcade::graphics::common::events::AMouseEvent: public virtual IMouseEvent {
public:
~AMouseEvent() override = default;

EventType getType() const noexcept override {
return T;
}

const Vector2i getPosition() const noexcept override {
return _pos;
}

protected:
/**
* @brief Construct a new AMouseEvent object
*
* @param pos Position of the mouse
*/
explicit AMouseEvent(Vector2i pos): _pos(pos){};

Vector2i _pos;
};
8 changes: 8 additions & 0 deletions graphics/common/events/mouse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
target_sources(${PROJECT_NAME} PUBLIC
AMouseEvent.hpp
MouseButtonPressEvent.hpp
MouseButtonReleaseEvent.hpp
AMouseButtonEvent.hpp
MouseMoveEvent.hpp
mouse.hpp
)
24 changes: 24 additions & 0 deletions graphics/common/events/mouse/MouseButtonPressEvent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** MouseButtonPressEvent.hpp
*/

#pragma once

#include "AMouseButtonEvent.hpp"

using namespace shared::graphics::events;
using namespace arcade::graphics::common::events;

namespace arcade::graphics::common::events {
class MouseButtonPressEvent;
};

class arcade::graphics::common::events::MouseButtonPressEvent :
public AMouseButtonEvent<EventType::MOUSE_BTN_PRESS> {
public:
MouseButtonPressEvent(Vector2i pos, MouseButton button) : AMouseButtonEvent(pos, button){};
~MouseButtonPressEvent() override = default;
};
23 changes: 23 additions & 0 deletions graphics/common/events/mouse/MouseButtonReleaseEvent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** MouseButtonPressEvent.hpp
*/

#pragma once

#include "AMouseButtonEvent.hpp"

using namespace shared::graphics::events;
using namespace arcade::graphics::common::events;

namespace arcade::graphics::common::events {
class MouseButtonReleaseEvent;
};

class arcade::graphics::common::events::MouseButtonReleaseEvent :
public AMouseButtonEvent<EventType::MOUSE_BTN_RELEASE> {
public:
using AMouseButtonEvent::AMouseButtonEvent;
};
24 changes: 24 additions & 0 deletions graphics/common/events/mouse/MouseMoveEvent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** AMouseEvent.hpp
*/

#pragma once

#include "AMouseEvent.hpp"

using namespace shared::graphics::events;
using namespace shared::types;

namespace arcade::graphics::common::events {
class MouseMoveEvent;
}

class arcade::graphics::common::events::MouseMoveEvent: public AMouseEvent<EventType::MOUSE_MOVE> {
public:
explicit MouseMoveEvent(const Vector2i pos): AMouseEvent<EventType::MOUSE_MOVE>(pos) {}

~MouseMoveEvent() override = default;
};
12 changes: 12 additions & 0 deletions graphics/common/events/mouse/mouse.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** mouse.hpp
*/

#pragma once

#include "MouseButtonPressEvent.hpp"
#include "MouseButtonReleaseEvent.hpp"
#include "MouseMoveEvent.hpp"
5 changes: 5 additions & 0 deletions graphics/common/events/window/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target_sources(${PROJECT_NAME} PUBLIC
WindowCloseEvent.hpp
WindowResizeEvent.hpp
window.hpp
)
27 changes: 27 additions & 0 deletions graphics/common/events/window/WindowCloseEvent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** WindowCloseEvent.hpp
*/

#pragma once

#include "shared/graphics/events/IEvent.hpp"

using namespace shared::graphics::events;

namespace arcade::graphics::common::events {
class WindowCloseEvent;
}


class arcade::graphics::common::events::WindowCloseEvent: public IEvent {
public:
WindowCloseEvent() = default;
~WindowCloseEvent() override = default;

EventType getType() const noexcept override {
return WINDOW_CLOSE;
}
};
27 changes: 27 additions & 0 deletions graphics/common/events/window/WindowResizeEvent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** WindowCloseEvent.hpp
*/

#pragma once

#include "shared/graphics/events/IEvent.hpp"

using namespace shared::graphics::events;

namespace arcade::graphics::common::events {
class WindowResizeEvent;
}


class arcade::graphics::common::events::WindowResizeEvent: public IEvent {
public:
WindowResizeEvent() = default;
~WindowResizeEvent() override = default;

EventType getType() const noexcept override {
return WINDOW_RESIZE;
}
};
11 changes: 11 additions & 0 deletions graphics/common/events/window/window.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
** EPITECH PROJECT, 2024
** arcade
** File description:
** window.hpp
*/

#pragma once

#include "WindowCloseEvent.hpp"
#include "WindowResizeEvent.hpp"
Loading

0 comments on commit 4df5a68

Please sign in to comment.