parent
82c0be37cd
commit
77ab328e48
3 changed files with 68 additions and 21 deletions
@ -1,35 +1,82 @@ |
|||||||
#pragma once |
#pragma once |
||||||
|
|
||||||
|
/*! \file application.h
|
||||||
|
This file contains the main app abstraction. |
||||||
|
*/ |
||||||
|
|
||||||
#include <bkpch.h> |
#include <bkpch.h> |
||||||
#include <bakara/io/window.h> |
#include <bakara/io/window.h> |
||||||
#include <bakara/events/events.h> |
#include <bakara/events/events.h> |
||||||
#include <bakara/core/layer_stack.h> |
#include <bakara/core/layer_stack.h> |
||||||
|
|
||||||
namespace Bk { |
namespace Bk { |
||||||
|
/*! \class Bk::Application
|
||||||
#define BK_BIND_EVENT_FN(fn) [this](Event& e) { fn(e); } |
Serves as the entry for the users program. |
||||||
#define BK_BIND_DISPACHER_FN(event, fn) [this](event& e) -> bool{ return fn(e); } |
This handles layers, the main window, and events. It makes sure to propegate events and updates through the layers. |
||||||
|
*/ |
||||||
class Application
|
class Application
|
||||||
{ |
{ |
||||||
public: |
public: |
||||||
Application(); |
Application(); |
||||||
|
/*! \fn Bk::Application::~Application
|
||||||
|
Virtual destructor enables subclasses to cleanup on termination |
||||||
|
*/ |
||||||
virtual ~Application(); |
virtual ~Application(); |
||||||
|
|
||||||
|
/*! \fn Bk::Application::on_event
|
||||||
|
Function bound to the window to get all event from it |
||||||
|
@param e : Event to be processed
|
||||||
|
*/ |
||||||
void on_event(Event& e); |
void on_event(Event& e); |
||||||
bool on_window_close(WindowCloseEvent& e); |
|
||||||
bool on_window_resize(WindowResizeEvent& e); |
|
||||||
|
|
||||||
void push_overlay(Layer* layer) { layer_stack.push_overlay(layer); } |
/*! \fn Bk::Application::on_window_close
|
||||||
std::unique_ptr<Layer> pop_overlay() { return layer_stack.pop_overlay(); } |
Handler of Bk::WindowCloseEvent and will be bind to a event dispacher |
||||||
void push_layer(Layer* layer) { layer_stack.push_layer(layer); } |
@param e : event to handled |
||||||
std::unique_ptr<Layer> pop_layer() { return layer_stack.pop_layer(); } |
*/ |
||||||
|
virtual bool on_window_close(WindowCloseEvent& e); |
||||||
|
/*! \fn Bk::Application::on_window_resize
|
||||||
|
Handler of Bk::WindowResizeEvent and will be bind to a event dispacher |
||||||
|
@param e : event to handled |
||||||
|
*/ |
||||||
|
virtual bool on_window_resize(WindowResizeEvent& e); |
||||||
|
|
||||||
|
/*! \fn Bk::Application::push_overlay
|
||||||
|
Push's the layer on top of the layer stack |
||||||
|
@param layer : Layer pointer to push |
||||||
|
*/ |
||||||
|
inline void push_overlay(Layer* layer) { p_layer_stack.push_overlay(layer); } |
||||||
|
/*! \fn Bk::Application::pop_overlay
|
||||||
|
Pop's the layer on top of the layer stack |
||||||
|
@return a unique ptr to the layer ressource |
||||||
|
*/ |
||||||
|
inline std::unique_ptr<Layer> pop_overlay() { return p_layer_stack.pop_overlay(); } |
||||||
|
/*! \fn Bk::Application::push_overlay
|
||||||
|
Push's the layer at the bottom of the layer stack |
||||||
|
@param layer : Layer pointer to push |
||||||
|
*/ |
||||||
|
inline void push_layer(Layer* layer) { p_layer_stack.push_layer(layer); } |
||||||
|
/*! \fn Bk::Application::push_overlay
|
||||||
|
Pop's the layer at the bottom of the layer stack |
||||||
|
@return a unique ptr to the layer ressource |
||||||
|
*/ |
||||||
|
inline std::unique_ptr<Layer> pop_layer() { return p_layer_stack.pop_layer(); } |
||||||
|
|
||||||
|
/*! \fn Bk::Application::run
|
||||||
|
Starts the application and the update loop. |
||||||
|
*/ |
||||||
void run(); |
void run(); |
||||||
|
|
||||||
|
protected: |
||||||
|
std::unique_ptr<Window> h_window; //!< Pointer to the main window
|
||||||
|
|
||||||
private: |
private: |
||||||
std::unique_ptr<Window> p_window; |
LayerStack p_layer_stack; //!< Layer stack of the application
|
||||||
LayerStack layer_stack; |
bool p_running = true; //!< Flag that indicates if the update loop should stop or not
|
||||||
bool p_running = true; |
|
||||||
}; |
}; |
||||||
|
/*! \fn Bk::create_app
|
||||||
|
Is used to retrive the user app class instance, made from inheritance. |
||||||
|
Must be defined in the user program |
||||||
|
@return User defined application |
||||||
|
*/ |
||||||
std::unique_ptr<Application> create_app(); |
std::unique_ptr<Application> create_app(); |
||||||
} |
} |
Loading…
Reference in New Issue