parent
8cc987d5db
commit
d9b7f096fd
2 changed files with 286 additions and 199 deletions
@ -1,197 +1,221 @@ |
||||
#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 { |
||||
|
||||
/*! \typedef Bk::KeyCode
|
||||
Unsigned integer representing a unique keyboard key |
||||
*/ |
||||
using KeyCode = uint16_t; |
||||
namespace Key { |
||||
enum : KeyCode |
||||
{ |
||||
// From glfw3.h
|
||||
Space = 32, |
||||
Apostrophe = 39, /* ' */ |
||||
Comma = 44, /* , */ |
||||
Minus = 45, /* - */ |
||||
Period = 46, /* . */ |
||||
Slash = 47, /* / */ |
||||
|
||||
D0 = 48, /* 0 */ |
||||
D1 = 49, /* 1 */ |
||||
D2 = 50, /* 2 */ |
||||
D3 = 51, /* 3 */ |
||||
D4 = 52, /* 4 */ |
||||
D5 = 53, /* 5 */ |
||||
D6 = 54, /* 6 */ |
||||
D7 = 55, /* 7 */ |
||||
D8 = 56, /* 8 */ |
||||
D9 = 57, /* 9 */ |
||||
|
||||
Semicolon = 59, /* ; */ |
||||
Equal = 61, /* = */ |
||||
|
||||
A = 65, |
||||
B = 66, |
||||
C = 67, |
||||
D = 68, |
||||
E = 69, |
||||
F = 70, |
||||
G = 71, |
||||
H = 72, |
||||
I = 73, |
||||
J = 74, |
||||
K = 75, |
||||
L = 76, |
||||
M = 77, |
||||
N = 78, |
||||
O = 79, |
||||
P = 80, |
||||
Q = 81, |
||||
R = 82, |
||||
S = 83, |
||||
T = 84, |
||||
U = 85, |
||||
V = 86, |
||||
W = 87, |
||||
X = 88, |
||||
Y = 89, |
||||
Z = 90, |
||||
|
||||
LeftBracket = 91, /* [ */ |
||||
Backslash = 92, /* \ */ |
||||
RightBracket = 93, /* ] */ |
||||
GraveAccent = 96, /* ` */ |
||||
|
||||
World1 = 161, /* non-US #1 */ |
||||
World2 = 162, /* non-US #2 */ |
||||
|
||||
/* Function keys */ |
||||
Escape = 256, |
||||
Enter = 257, |
||||
Tab = 258, |
||||
Backspace = 259, |
||||
Insert = 260, |
||||
Delete = 261, |
||||
Right = 262, |
||||
Left = 263, |
||||
Down = 264, |
||||
Up = 265, |
||||
PageUp = 266, |
||||
PageDown = 267, |
||||
Home = 268, |
||||
End = 269, |
||||
CapsLock = 280, |
||||
ScrollLock = 281, |
||||
NumLock = 282, |
||||
PrintScreen = 283, |
||||
Pause = 284, |
||||
F1 = 290, |
||||
F2 = 291, |
||||
F3 = 292, |
||||
F4 = 293, |
||||
F5 = 294, |
||||
F6 = 295, |
||||
F7 = 296, |
||||
F8 = 297, |
||||
F9 = 298, |
||||
F10 = 299, |
||||
F11 = 300, |
||||
F12 = 301, |
||||
F13 = 302, |
||||
F14 = 303, |
||||
F15 = 304, |
||||
F16 = 305, |
||||
F17 = 306, |
||||
F18 = 307, |
||||
F19 = 308, |
||||
F20 = 309, |
||||
F21 = 310, |
||||
F22 = 311, |
||||
F23 = 312, |
||||
F24 = 313, |
||||
F25 = 314, |
||||
|
||||
/* Keypad */ |
||||
KP0 = 320, |
||||
KP1 = 321, |
||||
KP2 = 322, |
||||
KP3 = 323, |
||||
KP4 = 324, |
||||
KP5 = 325, |
||||
KP6 = 326, |
||||
KP7 = 327, |
||||
KP8 = 328, |
||||
KP9 = 329, |
||||
KPDecimal = 330, |
||||
KPDivide = 331, |
||||
KPMultiply = 332, |
||||
KPSubtract = 333, |
||||
KPAdd = 334, |
||||
KPEnter = 335, |
||||
KPEqual = 336, |
||||
|
||||
LeftShift = 340, |
||||
LeftControl = 341, |
||||
LeftAlt = 342, |
||||
LeftSuper = 343, |
||||
RightShift = 344, |
||||
RightControl = 345, |
||||
RightAlt = 346, |
||||
RightSuper = 347, |
||||
Menu = 348 |
||||
}; |
||||
} |
||||
|
||||
/*! \enum Bk::KeyCodes
|
||||
Enumerator made to bind every keyboard keys with a Bk::KeyCode
|
||||
*/ |
||||
typedef enum : KeyCode |
||||
{ |
||||
Space = 32, /*!< _ */ |
||||
Apostrophe = 39, /*!< ' */ |
||||
Comma = 44, /*!< , */ |
||||
Minus = 45, /*!< - */ |
||||
Period = 46, /*!< . */ |
||||
Slash = 47, /*!< / */ |
||||
|
||||
D0 = 48, /*!< 0 */ |
||||
D1 = 49, /*!< 1 */ |
||||
D2 = 50, /*!< 2 */ |
||||
D3 = 51, /*!< 3 */ |
||||
D4 = 52, /*!< 4 */ |
||||
D5 = 53, /*!< 5 */ |
||||
D6 = 54, /*!< 6 */ |
||||
D7 = 55, /*!< 7 */ |
||||
D8 = 56, /*!< 8 */ |
||||
D9 = 57, /*!< 9 */ |
||||
|
||||
Semicolon = 59, /*!< ; */ |
||||
Equal = 61, /*!< = */ |
||||
|
||||
A = 65, |
||||
B = 66, |
||||
C = 67, |
||||
D = 68, |
||||
E = 69, |
||||
F = 70, |
||||
G = 71, |
||||
H = 72, |
||||
I = 73, |
||||
J = 74, |
||||
K = 75, |
||||
L = 76, |
||||
M = 77, |
||||
N = 78, |
||||
O = 79, |
||||
P = 80, |
||||
Q = 81, |
||||
R = 82, |
||||
S = 83, |
||||
T = 84, |
||||
U = 85, |
||||
V = 86, |
||||
W = 87, |
||||
X = 88, |
||||
Y = 89, |
||||
Z = 90, |
||||
|
||||
LeftBracket = 91, /*!< [ */ |
||||
Backslash = 92, /*!< \ */ |
||||
RightBracket = 93, /*!< ] */ |
||||
GraveAccent = 96, /*!< ` */ |
||||
|
||||
World1 = 161, /*!< non-US #1 */ |
||||
World2 = 162, /*!< non-US #2 */ |
||||
|
||||
Escape = 256, |
||||
Enter = 257, |
||||
Tab = 258, |
||||
Backspace = 259, |
||||
Insert = 260, |
||||
Delete = 261, |
||||
Right = 262, |
||||
Left = 263, |
||||
Down = 264, |
||||
Up = 265, |
||||
PageUp = 266, |
||||
PageDown = 267, |
||||
Home = 268, |
||||
End = 269, |
||||
CapsLock = 280, |
||||
ScrollLock = 281, |
||||
NumLock = 282, |
||||
PrintScreen = 283, |
||||
Pause = 284, |
||||
F1 = 290, |
||||
F2 = 291, |
||||
F3 = 292, |
||||
F4 = 293, |
||||
F5 = 294, |
||||
F6 = 295, |
||||
F7 = 296, |
||||
F8 = 297, |
||||
F9 = 298, |
||||
F10 = 299, |
||||
F11 = 300, |
||||
F12 = 301, |
||||
F13 = 302, |
||||
F14 = 303, |
||||
F15 = 304, |
||||
F16 = 305, |
||||
F17 = 306, |
||||
F18 = 307, |
||||
F19 = 308, |
||||
F20 = 309, |
||||
F21 = 310, |
||||
F22 = 311, |
||||
F23 = 312, |
||||
F24 = 313, |
||||
F25 = 314, |
||||
|
||||
KP0 = 320, |
||||
KP1 = 321, |
||||
KP2 = 322, |
||||
KP3 = 323, |
||||
KP4 = 324, |
||||
KP5 = 325, |
||||
KP6 = 326, |
||||
KP7 = 327, |
||||
KP8 = 328, |
||||
KP9 = 329, |
||||
KPDecimal = 330, |
||||
KPDivide = 331, |
||||
KPMultiply = 332, |
||||
KPSubtract = 333, |
||||
KPAdd = 334, |
||||
KPEnter = 335, |
||||
KPEqual = 336, |
||||
|
||||
LeftShift = 340, |
||||
LeftControl = 341, |
||||
LeftAlt = 342, |
||||
LeftSuper = 343, |
||||
RightShift = 344, |
||||
RightControl = 345, |
||||
RightAlt = 346, |
||||
RightSuper = 347, |
||||
Menu = 348 |
||||
} KeyCodes; |
||||
|
||||
/*! \typedef Bk::MouseCode
|
||||
Unsigned integer representing a unique mouse button |
||||
*/ |
||||
using MouseCode = uint16_t; |
||||
namespace Mouse { |
||||
enum : MouseCode |
||||
{ |
||||
// From glfw3.h
|
||||
Button0 = 0, |
||||
Button1 = 1, |
||||
Button2 = 2, |
||||
Button3 = 3, |
||||
Button4 = 4, |
||||
Button5 = 5, |
||||
Button6 = 6, |
||||
Button7 = 7, |
||||
|
||||
ButtonLast = Button7, |
||||
ButtonLeft = Button0, |
||||
ButtonRight = Button1, |
||||
ButtonMiddle = Button2 |
||||
}; |
||||
} |
||||
|
||||
namespace Controller { |
||||
enum class Button |
||||
{ |
||||
// analog input button values
|
||||
// PS | XBOX
|
||||
BTN_DOWN = 0, // X | A
|
||||
BTN_LEFT = 1, // Square | X
|
||||
BTN_UP = 2, // Triangle | Y
|
||||
BTN_RIGHT = 3, // Circle | B
|
||||
SHOULDER_LEFT = 4, // L1 | LB
|
||||
SHOULDER_RIGHT = 5, // R1 | RB
|
||||
TRIGGER_LEFT = 6, // L2 | LT
|
||||
TRIGGER_RIGHT = 7, // R2 | RT
|
||||
SELECT = 8, // Share | Address
|
||||
START = 9, // Options | Menu
|
||||
LEFT_STICK = 10, // L3 | LS
|
||||
RIGHT_STICK = 11, // R3 | RS
|
||||
HOME = 12, // Home | Home
|
||||
CLICK = 13, // Touch pad | n/a
|
||||
DPAD_UP = 14, // Dpad up | Dpad up
|
||||
DPAD_RIGHT = 15, // Dpad right | Dpad right
|
||||
DPAD_DOWN = 16, // Dpad down | Dpad down
|
||||
DPAD_LEFT = 17, // Dpad left | Dpad left
|
||||
}; |
||||
|
||||
enum class Joystick |
||||
{ |
||||
AXES_LEFT_STICK_X = 0, |
||||
AXES_LEFT_STICK_Y = 1, |
||||
AXES_RIGHT_STICK_X = 2, |
||||
AXES_LEFT_TRIGGER = 3, |
||||
AXES_RIGHT_TRIGGER = 4, |
||||
AXES_RIGHT_STICK_Y = 5, |
||||
}; |
||||
} |
||||
|
||||
/*! \enum Bk::MouseCodes
|
||||
Enumerator made to bind every mouse buttons with a Bk::MouseCode |
||||
*/ |
||||
typedef enum : MouseCode |
||||
{ |
||||
Button0 = 0, /*!< Button left */ |
||||
Button1 = 1, /*!< Button right */ |
||||
Button2 = 2, /*!< Button middle */ |
||||
Button3 = 3, /*!< Macro1 */ |
||||
Button4 = 4, /*!< Macro2 */ |
||||
Button5 = 5, /*!< Macro3 */ |
||||
Button6 = 6, /*!< Macro4 */ |
||||
Button7 = 7, /*!< Button last */ |
||||
|
||||
ButtonLast = Button7, |
||||
ButtonLeft = Button0, |
||||
ButtonRight = Button1, |
||||
ButtonMiddle = Button2 |
||||
} MouseCodes; |
||||
|
||||
/*! \typedef Bk::ControllerCode
|
||||
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 |
||||
{
|
||||
BTN_DOWN = 0, //!< Cross, A
|
||||
BTN_LEFT = 1, //!< Square, X
|
||||
BTN_UP = 2, //!< Triangle, Y
|
||||
BTN_RIGHT = 3, //!< Circle, B
|
||||
SHOULDER_LEFT = 4, //!< L1, LB
|
||||
SHOULDER_RIGHT = 5, //!< R1, RB
|
||||
TRIGGER_LEFT = 6, //!< L2, LT
|
||||
TRIGGER_RIGHT = 7, //!< R2, RT
|
||||
SELECT = 8, //!< Share, Address
|
||||
START = 9, //!< Options, Menu
|
||||
LEFT_STICK = 10, //!< L3, LS
|
||||
RIGHT_STICK = 11, //!< R3, RS
|
||||
HOME = 12, //!< Home, Home
|
||||
CLICK = 13, //!< Touch pad, n/a
|
||||
DPAD_UP = 14, //!< Dpad up, Dpad up
|
||||
DPAD_RIGHT = 15, //!< Dpad right, Dpad right
|
||||
DPAD_DOWN = 16, //!< Dpad down, Dpad down
|
||||
DPAD_LEFT = 17, //!< Dpad left, Dpad left
|
||||
} ControllerButton; |
||||
|
||||
/*! \enum Bk::ControllerJoystick
|
||||
Enum made to bind every controller axes with a Bk::ControllerAxesCode |
||||
*/ |
||||
typedef enum : ControllerAxesCode |
||||
{ |
||||
AXES_LEFT_STICK_X = 0, |
||||
AXES_LEFT_STICK_Y = 1, |
||||
AXES_RIGHT_STICK_X = 2, |
||||
AXES_LEFT_TRIGGER = 3, |
||||
AXES_RIGHT_TRIGGER = 4, |
||||
AXES_RIGHT_STICK_Y = 5, |
||||
} ControllerJoystick; |
||||
} |
@ -1,40 +1,103 @@ |
||||
#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 <bakara/events/event.h> |
||||
|
||||
namespace Bk { |
||||
struct WindowPros
|
||||
|
||||
/* \struct Bk::WindowProps
|
||||
Structure containing the essential data to create a window. |
||||
*/ |
||||
struct WindowProps
|
||||
{ |
||||
std::string title; |
||||
uint width; |
||||
uint height; |
||||
std::string title; //!< Title at the top of the window
|
||||
uint width; //!< Width of the window
|
||||
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) {} |
||||
}; |
||||
|
||||
/*! \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
|
||||
{ |
||||
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)>; |
||||
|
||||
/*! \fn Bk::Window::~Window
|
||||
Virtual destructor enables subclasses to cleanup on termination. |
||||
*/ |
||||
virtual ~Window() {} |
||||
|
||||
/*! \fn Bk::Window::get_width
|
||||
@return The width of the window |
||||
*/ |
||||
virtual uint get_width() const = 0; |
||||
/*! \fn Bk::Window::get_height
|
||||
@return The height of the window |
||||
*/ |
||||
virtual uint get_height() const = 0; |
||||
|
||||
/*! \fn Bk::Window::on_update
|
||||
Updates the frame of the window |
||||
*/ |
||||
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; |
||||
|
||||
/*! \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; |
||||
/*! \fn Bk::Window::is_vsync
|
||||
Indicates if window is vsync |
||||
@return Vsync flag |
||||
*/ |
||||
virtual bool is_vsync() const = 0; |
||||
|
||||
/*! \fn Bk::Window::close
|
||||
Closes the window
|
||||
*/ |
||||
virtual void close() = 0; |
||||
/*! \fn Bk::Window::open
|
||||
Opens and initializes the window |
||||
*/ |
||||
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: |
||||
bool p_is_open; |
||||
bool h_is_open; //!< indicaste if the window is opened or not
|
||||
}; |
||||
} |
Loading…
Reference in New Issue