-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79afecb
commit b2cfb7d
Showing
11 changed files
with
124 additions
and
22 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
-Isrc | ||
-Isrc/menu/firstmenu | ||
-Isrc/utils | ||
-Ibuild/_deps/date-src/include | ||
-Ibuild/_deps/raylibcpp-src/include | ||
-std=c++20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
|
||
add_subdirectory(firstmenu) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "FirstMenu.hpp" | ||
#include <algorithm> | ||
#include <memory> | ||
#include "PathResolver.hpp" | ||
#include "Logger.hpp" | ||
|
||
FirstMenu::FirstMenu(raylib::Window & /*unused*/) : _icon(PathResolver::resolve("assets/icons/favicon.png")) | ||
{ | ||
_buttons["ok"] = std::make_unique<Button>(raylib::Vector2(0, 0), PathResolver::resolve("assets/icons/house.png"), "test"); | ||
} | ||
|
||
void FirstMenu::update(raylib::Window &window) | ||
{ | ||
for (const auto &button : _buttons) { | ||
if (button.first == "ok" && button.second->isClicked(window)) { | ||
Logger::error("TEST"); | ||
} | ||
} | ||
} | ||
|
||
void FirstMenu::draw(raylib::Window &window) | ||
{ | ||
_icon.Draw( | ||
window.GetWidth() / 2 - FirstMenu::_icon.GetWidth() / 2, | ||
window.GetHeight() / 2 - FirstMenu::_icon.GetHeight() / 2); | ||
for (const auto &button : _buttons) { | ||
button.second->draw(window); | ||
} | ||
} | ||
|
||
void FirstMenu::free(raylib::Window & /*unused*/) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "Button.hpp" | ||
#include "Logger.hpp" | ||
|
||
Button::Button(raylib::Vector2 position, std::string texture, std::string text) | ||
: _position(position), | ||
_texture(texture) | ||
{ | ||
_text.text = text; | ||
} | ||
|
||
bool Button::isClicked(raylib::Window &window) const | ||
{ | ||
if (!window.IsFocused()) { | ||
return false; | ||
} | ||
if (!raylib::Mouse::IsButtonPressed(MOUSE_BUTTON_LEFT)) { | ||
return false; | ||
} | ||
const auto x = raylib::Mouse::GetX(); | ||
const auto y = raylib::Mouse::GetY(); | ||
const auto size_y = _texture.GetHeight(); | ||
const auto size_x = _texture.GetWidth(); | ||
if (y < _position.GetY() || x < _position.GetX() || y > _position.GetY() + size_y | ||
|| x > _position.GetX() + size_x) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
void Button::draw(raylib::Window & /*unused*/) const | ||
{ | ||
_texture.Draw(_position); | ||
const auto size_text = _text.MeasureEx(); | ||
auto pos_text = _position; | ||
pos_text.SetX(pos_text.GetX() + (size_text.GetX() / 2)); | ||
pos_text.SetY(pos_text.GetY() + (size_text.GetY() / 2)); | ||
_text.Draw(pos_text); | ||
} | ||
|
||
Button &Button::operator=(const Button &src) | ||
{ | ||
this->_text.text = src._text.text; | ||
this->_position = src._position; | ||
this->_texture = raylib::Texture(src._texture.GetData()); | ||
return *this; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <list> | ||
#include <string> | ||
#include <vector> | ||
#include "raylib-cpp.hpp" | ||
|
||
class Button { | ||
public: | ||
Button(raylib::Vector2 position, std::string texture, std::string text); | ||
|
||
bool isClicked(raylib::Window &window) const; | ||
void draw(raylib::Window &window) const; | ||
|
||
Button &operator=(const Button &src); | ||
|
||
private: | ||
raylib::Vector2 _position; | ||
raylib::Texture _texture; | ||
raylib::Text _text; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
|
||
target_include_directories( | ||
${PROJECT_NAME} | ||
PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
|
||
target_sources( | ||
${PROJECT_NAME} | ||
PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR}/Button.cpp | ||
) |