Added documentation to io files

dev
anulax1225 ago%!(EXTRA string=1 year)
parent 8cc987d5db
commit d9b7f096fd
  1. 170
      bakara/src/bakara/io/io_codes.h
  2. 79
      bakara/src/bakara/io/window.h

@ -1,31 +1,42 @@
#pragma once #pragma once
/*! \file io_codes.h
Input codes abstraction to be able to use different window api.
Can be converte in the good code for the window api by using a lookup table or defines at compilation.
*/
namespace Bk { namespace Bk {
/*! \typedef Bk::KeyCode
Unsigned integer representing a unique keyboard key
*/
using KeyCode = uint16_t; using KeyCode = uint16_t;
namespace Key {
enum : KeyCode /*! \enum Bk::KeyCodes
Enumerator made to bind every keyboard keys with a Bk::KeyCode
*/
typedef enum : KeyCode
{ {
// From glfw3.h Space = 32, /*!< _ */
Space = 32, Apostrophe = 39, /*!< ' */
Apostrophe = 39, /* ' */ Comma = 44, /*!< , */
Comma = 44, /* , */ Minus = 45, /*!< - */
Minus = 45, /* - */ Period = 46, /*!< . */
Period = 46, /* . */ Slash = 47, /*!< / */
Slash = 47, /* / */
D0 = 48, /*!< 0 */
D0 = 48, /* 0 */ D1 = 49, /*!< 1 */
D1 = 49, /* 1 */ D2 = 50, /*!< 2 */
D2 = 50, /* 2 */ D3 = 51, /*!< 3 */
D3 = 51, /* 3 */ D4 = 52, /*!< 4 */
D4 = 52, /* 4 */ D5 = 53, /*!< 5 */
D5 = 53, /* 5 */ D6 = 54, /*!< 6 */
D6 = 54, /* 6 */ D7 = 55, /*!< 7 */
D7 = 55, /* 7 */ D8 = 56, /*!< 8 */
D8 = 56, /* 8 */ D9 = 57, /*!< 9 */
D9 = 57, /* 9 */
Semicolon = 59, /*!< ; */
Semicolon = 59, /* ; */ Equal = 61, /*!< = */
Equal = 61, /* = */
A = 65, A = 65,
B = 66, B = 66,
@ -54,15 +65,14 @@ namespace Bk {
Y = 89, Y = 89,
Z = 90, Z = 90,
LeftBracket = 91, /* [ */ LeftBracket = 91, /*!< [ */
Backslash = 92, /* \ */ Backslash = 92, /*!< \ */
RightBracket = 93, /* ] */ RightBracket = 93, /*!< ] */
GraveAccent = 96, /* ` */ GraveAccent = 96, /*!< ` */
World1 = 161, /* non-US #1 */ World1 = 161, /*!< non-US #1 */
World2 = 162, /* non-US #2 */ World2 = 162, /*!< non-US #2 */
/* Function keys */
Escape = 256, Escape = 256,
Enter = 257, Enter = 257,
Tab = 258, Tab = 258,
@ -108,7 +118,6 @@ namespace Bk {
F24 = 313, F24 = 313,
F25 = 314, F25 = 314,
/* Keypad */
KP0 = 320, KP0 = 320,
KP1 = 321, KP1 = 321,
KP2 = 322, KP2 = 322,
@ -136,55 +145,71 @@ namespace Bk {
RightAlt = 346, RightAlt = 346,
RightSuper = 347, RightSuper = 347,
Menu = 348 Menu = 348
}; } KeyCodes;
}
/*! \typedef Bk::MouseCode
Unsigned integer representing a unique mouse button
*/
using MouseCode = uint16_t; using MouseCode = uint16_t;
namespace Mouse {
enum : MouseCode /*! \enum Bk::MouseCodes
Enumerator made to bind every mouse buttons with a Bk::MouseCode
*/
typedef enum : MouseCode
{ {
// From glfw3.h Button0 = 0, /*!< Button left */
Button0 = 0, Button1 = 1, /*!< Button right */
Button1 = 1, Button2 = 2, /*!< Button middle */
Button2 = 2, Button3 = 3, /*!< Macro1 */
Button3 = 3, Button4 = 4, /*!< Macro2 */
Button4 = 4, Button5 = 5, /*!< Macro3 */
Button5 = 5, Button6 = 6, /*!< Macro4 */
Button6 = 6, Button7 = 7, /*!< Button last */
Button7 = 7,
ButtonLast = Button7, ButtonLast = Button7,
ButtonLeft = Button0, ButtonLeft = Button0,
ButtonRight = Button1, ButtonRight = Button1,
ButtonMiddle = Button2 ButtonMiddle = Button2
}; } MouseCodes;
}
namespace Controller { /*! \typedef Bk::ControllerCode
enum class Button Unsigned integer representing a unique controller button
*/
using ControllerCode = uint16_t;
/*! \typedef Bk::ControllerAxesCode
Unsigned integer representing a unique controller axe
*/
using ControllerAxesCode = uint16_t;
/*! \enum Bk::ControllerButton
Enumerator made to bind every controller buttons with a Bk::ControllerCode
*/
typedef enum : ControllerCode
{ {
// analog input button values BTN_DOWN = 0, //!< Cross, A
// PS | XBOX BTN_LEFT = 1, //!< Square, X
BTN_DOWN = 0, // X | A BTN_UP = 2, //!< Triangle, Y
BTN_LEFT = 1, // Square | X BTN_RIGHT = 3, //!< Circle, B
BTN_UP = 2, // Triangle | Y SHOULDER_LEFT = 4, //!< L1, LB
BTN_RIGHT = 3, // Circle | B SHOULDER_RIGHT = 5, //!< R1, RB
SHOULDER_LEFT = 4, // L1 | LB TRIGGER_LEFT = 6, //!< L2, LT
SHOULDER_RIGHT = 5, // R1 | RB TRIGGER_RIGHT = 7, //!< R2, RT
TRIGGER_LEFT = 6, // L2 | LT SELECT = 8, //!< Share, Address
TRIGGER_RIGHT = 7, // R2 | RT START = 9, //!< Options, Menu
SELECT = 8, // Share | Address LEFT_STICK = 10, //!< L3, LS
START = 9, // Options | Menu RIGHT_STICK = 11, //!< R3, RS
LEFT_STICK = 10, // L3 | LS HOME = 12, //!< Home, Home
RIGHT_STICK = 11, // R3 | RS CLICK = 13, //!< Touch pad, n/a
HOME = 12, // Home | Home DPAD_UP = 14, //!< Dpad up, Dpad up
CLICK = 13, // Touch pad | n/a DPAD_RIGHT = 15, //!< Dpad right, Dpad right
DPAD_UP = 14, // Dpad up | Dpad up DPAD_DOWN = 16, //!< Dpad down, Dpad down
DPAD_RIGHT = 15, // Dpad right | Dpad right DPAD_LEFT = 17, //!< Dpad left, Dpad left
DPAD_DOWN = 16, // Dpad down | Dpad down } ControllerButton;
DPAD_LEFT = 17, // Dpad left | Dpad left
}; /*! \enum Bk::ControllerJoystick
Enum made to bind every controller axes with a Bk::ControllerAxesCode
enum class Joystick */
typedef enum : ControllerAxesCode
{ {
AXES_LEFT_STICK_X = 0, AXES_LEFT_STICK_X = 0,
AXES_LEFT_STICK_Y = 1, AXES_LEFT_STICK_Y = 1,
@ -192,6 +217,5 @@ namespace Bk {
AXES_LEFT_TRIGGER = 3, AXES_LEFT_TRIGGER = 3,
AXES_RIGHT_TRIGGER = 4, AXES_RIGHT_TRIGGER = 4,
AXES_RIGHT_STICK_Y = 5, AXES_RIGHT_STICK_Y = 5,
}; } ControllerJoystick;
}
} }

@ -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…
Cancel
Save