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