From 688b5d992d9c8144ac8a444fdc48adc0f0c9db75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Fri, 21 May 2021 16:09:18 +0200 Subject: [PATCH] fixing image getter not const and adding the window flags and icon support --- lib/Ray/sources/Drawables/Image.cpp | 4 ++-- lib/Ray/sources/Drawables/Image.hpp | 2 +- lib/Ray/sources/Window.cpp | 21 +++++++++++++++++---- lib/Ray/sources/Window.hpp | 10 ++++++++-- sources/main.cpp | 2 +- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/lib/Ray/sources/Drawables/Image.cpp b/lib/Ray/sources/Drawables/Image.cpp index 3f5f9c70..70b96e0d 100644 --- a/lib/Ray/sources/Drawables/Image.cpp +++ b/lib/Ray/sources/Drawables/Image.cpp @@ -40,7 +40,7 @@ bool RAY::Image::unload() return true; } -::Image &RAY::Image::getImage(void) +const ::Image &RAY::Image::getImage(void) const { return _image; -} +} \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/Image.hpp b/lib/Ray/sources/Drawables/Image.hpp index e0e81efc..fb70112e 100644 --- a/lib/Ray/sources/Drawables/Image.hpp +++ b/lib/Ray/sources/Drawables/Image.hpp @@ -49,7 +49,7 @@ namespace RAY bool unload() override; //! @brief get image - ::Image &getImage(void); + const ::Image &getImage(void) const; //! @brief draw drawable void draw(Drawables::ADrawable2D &); diff --git a/lib/Ray/sources/Window.cpp b/lib/Ray/sources/Window.cpp index eb40618d..112462d2 100644 --- a/lib/Ray/sources/Window.cpp +++ b/lib/Ray/sources/Window.cpp @@ -6,17 +6,22 @@ */ #include "Window.hpp" + +#include #include "Controllers/Mouse.hpp" -RAY::Window &RAY::Window::getInstance(int width, int height, const std::string &title, bool openNow) +RAY::Window &RAY::Window::getInstance(int width, int height, const std::string &title, unsigned flags, bool openNow) { - static RAY::Window window(width, height, title, openNow); + static RAY::Window window(width, height, title, flags, openNow); return window; } -RAY::Window::Window(int width, int height, const std::string &title, bool openNow): - _dimensions({(float)width, (float)height}), _title(title), _isOpen(openNow) +RAY::Window::Window(int width, int height, std::string title, unsigned flags, bool openNow): + _dimensions({(float)width, (float)height}), + _title(std::move(title)), + _isOpen(openNow), + _flags(flags) { if (openNow) this->open(); @@ -24,6 +29,9 @@ RAY::Window::Window(int width, int height, const std::string &title, bool openNo bool RAY::Window::open(void) { + if (this->_flags) { + SetConfigFlags(this->_flags); + } InitWindow(this->_dimensions.x, this->_dimensions.y, this->_title.c_str()); this->_isOpen = true; return true; @@ -133,4 +141,9 @@ void RAY::Window::draw(const RAY::Texture &texture, const Vector2 &position, con void RAY::Window::draw(const Mesh &mesh, const Material &material, const Matrix &transform) { DrawMesh(mesh, material, transform); +} + +void RAY::Window::setIcon(const RAY::Image &img) +{ + SetWindowIcon(img.getImage()); } \ No newline at end of file diff --git a/lib/Ray/sources/Window.hpp b/lib/Ray/sources/Window.hpp index 3b7db92c..bb0b6c3c 100644 --- a/lib/Ray/sources/Window.hpp +++ b/lib/Ray/sources/Window.hpp @@ -23,7 +23,7 @@ namespace RAY { class Window: public Canvas { public: //! @return A widow insta,ce. Only one window can be open at a time - static Window &getInstance(int width, int height, const std::string &title, bool openNow = true); + static Window &getInstance(int width, int height, const std::string &title, unsigned flags = 0, bool openNow = true); //! @brief A default copy constructor Window(const Window &window) = delete; @@ -60,6 +60,9 @@ namespace RAY { //! @brief Check if cursor is not visible bool cursorIsVisible(void) const; + //! @brief set the window icon + void setIcon(const Image &img); + //! @brief Get the cursor position Vector2 getCursorPosition() const; @@ -109,7 +112,7 @@ namespace RAY { private: //! @brief Creates window, and opens it if openNow is set to true - Window(int width, int height, const std::string &title, bool openNow = true); + Window(int width, int height, std::string title, unsigned flags = 0, bool openNow = true); //! @brief Dimension of window RAY::Vector2 _dimensions; @@ -118,6 +121,9 @@ namespace RAY { //! @brief has the window been open? bool _isOpen; + + //! @brief flags for the window (ex: FLAG_WINDOW_RESIZABLE) + unsigned int _flags; }; } diff --git a/sources/main.cpp b/sources/main.cpp index b0159f84..4a3e06cb 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -24,7 +24,7 @@ int main() const int screenHeight = 450; RAY::Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 }; - RAY::Window &window = RAY::Window::getInstance(screenWidth, screenHeight, "Ta mère en slip"); + RAY::Window &window = RAY::Window::getInstance(screenWidth, screenHeight, "Ta mère en slip", FLAG_WINDOW_RESIZABLE); RAY::Camera::Camera3D camera((RAY::Vector3){ 30.0f, 20.0f, 30.0f }, (RAY::Vector3){ 0.0f, 0.0f, 0.0f }, (RAY::Vector3){ 0.0f, 1.0f, 0.0f }, 70.0, CAMERA_PERSPECTIVE); RAY::Drawables::Drawables3D::Grid grid(10, 5.0f);