mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-26 07:49:33 +00:00
singleton for window
This commit is contained in:
+3
-1
@@ -1,4 +1,6 @@
|
||||
.idea
|
||||
cmake-build-debug
|
||||
./bomberman
|
||||
.vscode
|
||||
.vscode
|
||||
build/*
|
||||
docs/*
|
||||
+2
-2
@@ -1,2 +1,2 @@
|
||||
build/
|
||||
docs/
|
||||
build/*
|
||||
docs/*
|
||||
@@ -18,7 +18,7 @@ namespace RAY {
|
||||
virtual ~Canvas() = default;
|
||||
|
||||
//! @brief draw drawable
|
||||
virtual void draw(const Drawables::IDrawable &) = 0;
|
||||
virtual void draw(Drawables::IDrawable &) = 0;
|
||||
|
||||
protected:
|
||||
private:
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace RAY::Drawables::Drawables2D {
|
||||
ADrawable2D(const ADrawable2D &) = default;
|
||||
|
||||
//! @brief A default destructor
|
||||
virtual ~ADrawable2D() = 0;
|
||||
virtual ~ADrawable2D() = default;
|
||||
|
||||
//! @return the top-left position of the ADrawable
|
||||
const Vector2 &getPosition(void) const;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace RAY
|
||||
namespace Drawables {
|
||||
class IDrawable {
|
||||
public:
|
||||
virtual ~IDrawable() = 0;
|
||||
virtual ~IDrawable() = default;
|
||||
|
||||
virtual void drawOn(RAY::Window &window) = 0;
|
||||
protected:
|
||||
|
||||
@@ -34,6 +34,12 @@ bool RAY::Texture::load(const std::string &filename)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RAY::Texture::unload()
|
||||
{
|
||||
UnloadTexture(this->_texture);
|
||||
return true;
|
||||
}
|
||||
|
||||
Image RAY::Texture::toImage(void) const
|
||||
{
|
||||
return GetTextureData(_texture);
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace RAY
|
||||
bool load(const std::string &filename);
|
||||
|
||||
//! @brief unload ressources
|
||||
bool unload();
|
||||
bool unload() override;
|
||||
|
||||
//! @brief get image
|
||||
::Image toImage(void) const;
|
||||
|
||||
@@ -8,7 +8,14 @@
|
||||
#include "Window.hpp"
|
||||
#include "Controllers/Mouse.hpp"
|
||||
|
||||
RAY::Window::Window(int width, int height, const std::string title, bool openNow):
|
||||
RAY::Window &RAY::Window::getInstance(int width, int height, const std::string &title, bool openNow)
|
||||
{
|
||||
static RAY::Window window(width, height, title, 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)
|
||||
{
|
||||
if (openNow)
|
||||
|
||||
@@ -22,14 +22,14 @@
|
||||
namespace RAY {
|
||||
class Window: public Canvas {
|
||||
public:
|
||||
//! @brief Creates window, and opens it if openNow is set to true
|
||||
Window(int width, int height, const std::string title, bool openNow = false);
|
||||
|
||||
//! @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);
|
||||
|
||||
//! @brief A default copy constructor
|
||||
Window(const Window &window) = default;
|
||||
Window(const Window &window) = delete;
|
||||
|
||||
//! @brief A window is assignable
|
||||
Window &operator=(const Window &window) = default;
|
||||
Window &operator=(const Window &window) = delete;
|
||||
|
||||
//! @brief Closes window if still open
|
||||
~Window() = default;
|
||||
@@ -108,6 +108,8 @@ namespace RAY {
|
||||
void draw(const Mesh &mesh, const Material &material, const Matrix &transform);
|
||||
|
||||
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);
|
||||
//! @brief Dimension of window
|
||||
RAY::Vector2 _dimensions;
|
||||
|
||||
|
||||
@@ -38,5 +38,5 @@ add_executable(wal_tests EXCLUDE_FROM_ALL
|
||||
)
|
||||
|
||||
target_link_libraries(wal_tests PRIVATE wal)
|
||||
find_package(Catch2 REQUIRED)
|
||||
target_link_libraries(wal_tests PRIVATE Catch2::Catch2)
|
||||
#find_package(Catch2 REQUIRED)
|
||||
#target_link_libraries(wal_tests PRIVATE Catch2::Catch2)
|
||||
+15
-9
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include "Wal.hpp"
|
||||
#include "Window.hpp"
|
||||
#include "Drawables/2D/Text.hpp"
|
||||
#include "Drawables/2D/Circle.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -9,13 +10,17 @@ int main()
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||
RAY::Window &window = RAY::Window::getInstance(screenWidth, screenHeight, "Ta mère en slip", false);
|
||||
RAY::Drawables::Drawables2D::Text text("Hello World", 10, {190, 200}, RED);
|
||||
RAY::Drawables::Drawables2D::Circle circle(400, 225, 50, RED);
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
window.open();
|
||||
|
||||
window.setFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
while (!window.shouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
@@ -24,19 +29,20 @@ int main()
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
window.beginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
window.clear();
|
||||
|
||||
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||
window.draw(circle);
|
||||
window.draw(text);
|
||||
|
||||
EndDrawing();
|
||||
window.endDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
window.close(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user