parent
8cc987d5db
commit
d9b7f096fd
2 changed files with 286 additions and 199 deletions
@ -1,40 +1,103 @@ |
|||||||
#pragma once |
#pragma once |
||||||
|
|
||||||
|
/*! \file window.h
|
||||||
|
This file contiens all the interfaces to create a window. |
||||||
|
Implementation possible with GLFW, Win32, etc. |
||||||
|
*/ |
||||||
|
|
||||||
#include <bkpch.h> |
#include <bkpch.h> |
||||||
#include <bakara/events/event.h> |
#include <bakara/events/event.h> |
||||||
|
|
||||||
namespace Bk { |
namespace Bk { |
||||||
struct WindowPros
|
|
||||||
|
/* \struct Bk::WindowProps
|
||||||
|
Structure containing the essential data to create a window. |
||||||
|
*/ |
||||||
|
struct WindowProps
|
||||||
{ |
{ |
||||||
std::string title; |
std::string title; //!< Title at the top of the window
|
||||||
uint width; |
uint width; //!< Width of the window
|
||||||
uint height; |
uint height; //!< Height of the window
|
||||||
|
|
||||||
WindowPros(std::string title = "Bakara engine", uint width = 1000, uint height = 800) |
/*! \fn Bk::WindowProps::WindowProps
|
||||||
|
Default window is initialized with a width of 1000 and a height 800 |
||||||
|
@param title : Title of the window |
||||||
|
@param width : Width of the window |
||||||
|
@param height : Height of the window |
||||||
|
*/ |
||||||
|
WindowProps(std::string title = "Bakara engine", uint width = 1000, uint height = 800) |
||||||
: title(title), width(width), height(height) {} |
: title(title), width(width), height(height) {} |
||||||
}; |
}; |
||||||
|
|
||||||
|
/*! \class Bk::Window
|
||||||
|
Window is an interface to abstract witch window api is used. This enable compilation with multiple api,
|
||||||
|
so that it's possible to use the native api of the platform or to implement a graphics api's with more ease.
|
||||||
|
*/ |
||||||
class Window
|
class Window
|
||||||
{ |
{ |
||||||
public:
|
public:
|
||||||
|
/*! \typedef Bk::Window::EventCallback
|
||||||
|
The EventCallback is a function pointer that takes a Event as parameter
|
||||||
|
and that reponses to them.
|
||||||
|
*/ |
||||||
using EventCallback = std::function<void(Event& e)>; |
using EventCallback = std::function<void(Event& e)>; |
||||||
|
|
||||||
|
/*! \fn Bk::Window::~Window
|
||||||
|
Virtual destructor enables subclasses to cleanup on termination. |
||||||
|
*/ |
||||||
virtual ~Window() {} |
virtual ~Window() {} |
||||||
|
|
||||||
|
/*! \fn Bk::Window::get_width
|
||||||
|
@return The width of the window |
||||||
|
*/ |
||||||
virtual uint get_width() const = 0; |
virtual uint get_width() const = 0; |
||||||
|
/*! \fn Bk::Window::get_height
|
||||||
|
@return The height of the window |
||||||
|
*/ |
||||||
virtual uint get_height() const = 0; |
virtual uint get_height() const = 0; |
||||||
|
|
||||||
|
/*! \fn Bk::Window::on_update
|
||||||
|
Updates the frame of the window |
||||||
|
*/ |
||||||
virtual void on_update() = 0; |
virtual void on_update() = 0; |
||||||
|
/*! \fn Bk::Window::set_event_callback
|
||||||
|
Sets the function pointer for events of the window |
||||||
|
@param callback : function called when a new event occures |
||||||
|
*/ |
||||||
virtual void set_event_callback(const EventCallback callback) = 0; |
virtual void set_event_callback(const EventCallback callback) = 0; |
||||||
|
|
||||||
|
/*! \fn Bk::Window::set_vsync
|
||||||
|
Sets the window buffer swap interval. Is enabled by default.
|
||||||
|
If set to false the frame rate should be more constant, but more slow.
|
||||||
|
*/ |
||||||
virtual void set_vsync(bool enable) = 0; |
virtual void set_vsync(bool enable) = 0; |
||||||
|
/*! \fn Bk::Window::is_vsync
|
||||||
|
Indicates if window is vsync |
||||||
|
@return Vsync flag |
||||||
|
*/ |
||||||
virtual bool is_vsync() const = 0; |
virtual bool is_vsync() const = 0; |
||||||
|
|
||||||
|
/*! \fn Bk::Window::close
|
||||||
|
Closes the window
|
||||||
|
*/ |
||||||
virtual void close() = 0; |
virtual void close() = 0; |
||||||
|
/*! \fn Bk::Window::open
|
||||||
|
Opens and initializes the window |
||||||
|
*/ |
||||||
virtual void open() = 0; |
virtual void open() = 0; |
||||||
bool is_open() { return p_is_open; } |
/*! \fn Bk::Window::is_open
|
||||||
|
Indicates if the window is opened |
||||||
|
@return Open flag |
||||||
|
*/ |
||||||
|
bool is_open() { return h_is_open; } |
||||||
|
|
||||||
static std::unique_ptr<Window> create_window(const WindowPros& props = WindowPros()); |
/*! \fn Bk::Window::create_window()
|
||||||
|
Static function implemented in the api window class to get a window specifique api. |
||||||
|
If no parameter is specified, creates the window with the default settings. |
||||||
|
@param props : Window information |
||||||
|
*/ |
||||||
|
static std::unique_ptr<Window> create_window(const WindowProps& props = WindowProps()); |
||||||
protected: |
protected: |
||||||
bool p_is_open; |
bool h_is_open; //!< indicaste if the window is opened or not
|
||||||
}; |
}; |
||||||
} |
} |
Loading…
Reference in New Issue