diff --git a/src/Button.cpp b/src/Button.cpp index cb79699..fda7d0c 100644 --- a/src/Button.cpp +++ b/src/Button.cpp @@ -2,28 +2,38 @@ Button::Button(std::string text, point_t top_left_corner, unsigned int width, unsigned int height, void (*callback)(void), MenuLevel* next_level) - : mText{text}, + : mTextContent{text}, mCallback{callback}, MenuItem{top_left_corner}, mWidth{width}, mHeight{height}, mNextLevel{next_level} {} -bool Button::is_clicked(const sf::Event& event) {} - -void Button::draw(sf::RenderWindow& window) { +void Button::draw(sf::RenderWindow& window, const sf::Font& font) { + // draw rectangle sf::RectangleShape rectangle(sf::Vector2f(mWidth, mHeight)); + // draw rectangle outline if (mIsSelected) { rectangle.setOutlineThickness(10.0f); rectangle.setOutlineColor(sf::Color(255, 0, 0)); } else { rectangle.setOutlineThickness(0.0f); } + + // set text + mText.setFont(font); + mText.setCharacterSize(24); + mText.setColor(sf::Color::Red); + mText.setString(mTextContent); + + // move objects in window and draw rectangle.move(mPosition); window.draw(rectangle); + mText.move(mPosition); + window.draw(mText); } void Button::select() { mIsSelected = true; } -void Button::deselect() { mIsSelected = false; } \ No newline at end of file +void Button::deselect() { mIsSelected = false; } diff --git a/src/Button.hpp b/src/Button.hpp index 71f0646..bc4834f 100644 --- a/src/Button.hpp +++ b/src/Button.hpp @@ -12,21 +12,18 @@ using point_t = sf::Vector2f; class MenuLevel; class Button : MenuItem { - std::string mText; + std::string mTextContent; + sf::Text mText; unsigned int mWidth; unsigned int mHeight; - void (*mCallback)(void); - bool mIsSelected = false; - MenuLevel* mNextLevel; public: Button(std::string text, point_t top_left_corner, unsigned int width, unsigned int height, void (*callback)(void), MenuLevel* next_level = nullptr); - bool is_clicked(const sf::Event& event); - void draw(sf::RenderWindow& window); + void draw(sf::RenderWindow& window, const sf::Font& font); void select(); void deselect(); }; \ No newline at end of file diff --git a/src/GameManager.hpp b/src/GameManager.hpp index f7b9bb6..4e09d74 100644 --- a/src/GameManager.hpp +++ b/src/GameManager.hpp @@ -3,7 +3,7 @@ #include #include "Board.hpp" -#include "MainMenu.h" +#include "MainMenu.hpp" enum class GameManagerState { MainMenu, diff --git a/src/MainMenu.cpp b/src/MainMenu.cpp index a186168..7633cb6 100644 --- a/src/MainMenu.cpp +++ b/src/MainMenu.cpp @@ -1,14 +1,19 @@ -#include "MainMenu.h" +#include "MainMenu.hpp" + +#include "Files.hpp" MainMenu::MainMenu(sf::RenderWindow& window, std::initializer_list menu_level_ptrs, MenuLevel* current_level) - : mWindow{window}, mMenuLevelPtrs{menu_level_ptrs}, mCurrentLevel{current_level} {} + : mWindow{window}, mMenuLevelPtrs{menu_level_ptrs}, mCurrentLevel{current_level} { + mFont.loadFromFile(files::asset_path() + "DejaVuSans.ttf"); +} void MainMenu::process_and_draw(const sf::Event& event) { // process inputs - mCurrentLevel->draw(mWindow, event); + mCurrentLevel->processEvents(event); // draw menu + mCurrentLevel->draw(mWindow, mFont); // perform actions } diff --git a/src/MenuLevel.cpp b/src/MenuLevel.cpp index 6899d8c..62f2575 100644 --- a/src/MenuLevel.cpp +++ b/src/MenuLevel.cpp @@ -2,7 +2,7 @@ MenuLevel::MenuLevel(std::initializer_list