Add project files.

This commit is contained in:
2018-06-25 21:48:45 -04:00
parent b04a25689b
commit 3c1b7d28e8
425 changed files with 35333 additions and 0 deletions
@@ -0,0 +1,167 @@
#include "cInput.hpp"
/*** Custom Header Files ***/
#include "../UtilityEngine/cUtility.hpp"
using InputEngine::cInput;
using UtilityEngine::cUtility;
/*static*/ cInput* cInput::sp_inst = nullptr;
//Private
cInput::cInput()
{}
cInput::~cInput()
{
CleanUp();
}
//Public
/*static*/ cInput& cInput::Inst()
{
if (sp_inst == nullptr)
sp_inst = new cInput();
return *sp_inst;
}
/*static*/ void cInput::Delete()
{
delete sp_inst;
sp_inst = nullptr;
}
//Functions
const bool cInput::Initialize() const
{
bool rtn = IsInit();
if (rtn == false) {
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0) {
cUtility::Inst().Message("Input initialized.");
rtn = true;
} else
cUtility::Inst().Message("Could not initialize Input.hpp SDL_InitSubSystem(SDL_INIT_JOYSTICK):", __AT__, cUtility::eTypeSDL::SDL);
}
return rtn;
}
const bool cInput::Setup()
{
return true;
}
void cInput::CleanUp()
{
DeleteAllInputs();
}
void cInput::CheckInputs( const SDL_Event& event )
{
m_event = event;
switch(m_event.type)
{
case SDL_KEYUP:
case SDL_KEYDOWN:
CheckKeyboards();
break;
case SDL_JOYAXISMOTION:
case SDL_JOYBALLMOTION:
case SDL_JOYHATMOTION:
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
CheckJoysticks();
break;
}
}
void cInput::CheckKeyboards()
{
std::vector<InputEngine::cKeyboard*>::iterator it;
for ( it = m_keyboards.begin() ; it < m_keyboards.end(); it++ ) {
InputEngine::cKeyboard* temp = (*it);
temp->KeyboardCheck(m_event);
}
}
void cInput::CheckJoysticks()
{
}
/* Adds a keyboard to cInput internal list to be called when CheckInputs is called */
void cInput::AddKeyboard( InputEngine::cKeyboard* keyboard )
{
m_keyboards.push_back(keyboard);
}
/* Deletes a keyboard in cInput internal list */
void cInput::DeletesKeyboard( const cString& label )
{
std::vector<InputEngine::cKeyboard*>::iterator it;
for ( it = m_keyboards.begin() ; it < m_keyboards.end(); it++ ) {
if (label == (*it)->getLabel()) {
InputEngine::cKeyboard* temp = (*it);
delete temp;
temp = nullptr;
m_keyboards.erase(it);
//break out of the for loop
break;
}
}
}
/* Deletes all keyboards in cInput internal list */
void cInput::DeleteAllKeyboards()
{
m_keyboards.clear();
}
/* Removes the keyboard from cInput internal list */
void cInput::RemoveKeyboard( const cString& label )
{
std::vector<InputEngine::cKeyboard*>::iterator it;
for ( it = m_keyboards.begin() ; it < m_keyboards.end(); it++ ) {
if (label == (*it)->getLabel()) {
m_keyboards.erase(it);
//break out of the for loop
break;
}
}
}
/* Removes all keyboards from cInput internal list. */
void cInput::RemoveAllKeyboards()
{
m_keyboards.erase(m_keyboards.begin(), m_keyboards.end());
}
void cInput::DeleteAllInputs()
{
DeleteAllKeyboards();
}
void cInput::RemoveAllInputs()
{
RemoveAllKeyboards();
}
///Sets
///Gets
/* Gets return true if Input was initialized */
const bool cInput::IsInit() const
{
bool rtn = false;
if (SDL_WasInit(SDL_INIT_JOYSTICK) != 0) {
cUtility::Inst().Message("Input is initialized.");
rtn = true;
} else
cUtility::Inst().Message("Input is not initialized.");
return rtn;
}
@@ -0,0 +1,71 @@
#ifndef _CINPUT_HPP_
#define _CINPUT_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
/*** Custom Header Files ***/
#include "cKeyboard.hpp"
/*** DLL Header File ***/
#include "dllExport.h"
/*** Custom Header Files ***/
#include "../UtilityEngine/cString.hpp"
using UtilityEngine::cString;
namespace InputEngine {
/* Singleton */
class EXPORT_FROM_MYDLL cInput
{
private:
cInput();
~cInput();
public:
static cInput& Inst();
static void Delete();
//Functions
const bool Initialize() const;
const bool Setup();
void CleanUp();
/* Checks all inputs */
void CheckInputs( const SDL_Event& event );
/* Checks all keyboards */
void CheckKeyboards();
/* Checks all Joysticks */
void CheckJoysticks();
/* Adds a keyboard to cInput interneal list to be called when CheckInputs is called */
void AddKeyboard( InputEngine::cKeyboard* keyboard );
/* Deletes a keyboard in cInput internal list */
void DeletesKeyboard( const cString& label );
/* Deletes all keyboards in cInput internal list */
void DeleteAllKeyboards();
/* Removes the keyboard from cInput internal list */
void RemoveKeyboard( const cString& label );
/* Removes all keyboards from cInput internal list. */
void RemoveAllKeyboards();
void DeleteAllInputs();
void RemoveAllInputs();
///Sets
///Gets
/* Gets return true if Input was initialized */
const bool IsInit() const;
private:
std::vector<InputEngine::cKeyboard*> m_keyboards;
SDL_Event m_event;
static cInput* sp_inst;// = nullptr
};/// END CLASS DEFINITION cInput
}/// END NAMESPACE DEFINITION InputEngine
#endif/// END IFNDEF _CINPUT_HPP_
@@ -0,0 +1,10 @@
#include "cJoystick.hpp"
using InputEngine::cJoystick;
cJoystick::cJoystick()
{}
/*virtual*/ cJoystick::~cJoystick()
{}
@@ -0,0 +1,38 @@
#ifndef _CJOYSTICK_HPP_
#define _CJOYSTICK_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
/*** Custom Header Files ***/
#include "../EventEngine/cEvent.hpp"
/*** DLL Header File ***/
#include "dllExport.h"
namespace InputEngine {
class EXPORT_FROM_MYDLL cJoystick : public EventEngine::cEvent
{
public:
cJoystick();
virtual ~cJoystick();
///Functions
virtual void OnEvent(const SDL_Event& event);
virtual void OnJoyAxis(SDL_JoystickID which, Uint8 axis, Sint16 value);
virtual void OnJoyButtonDown(SDL_JoystickID which, Uint8 button);
virtual void OnJoyButtonUp(SDL_JoystickID which, Uint8 button);
virtual void OnJoyHat(SDL_JoystickID which, Uint8 hat, Uint8 value);
virtual void OnJoyBall(SDL_JoystickID which, Uint8 ball, Sint16 xrel, Sint16 yrel);
//Used when looking for keys that have been add to the check list
void JoystickCheck();
};/// END CLASS DEFINITION cJoystick
}/// END NAMESPACE DEFINITION InputEngine
#endif/// END IFNDEF _CJOYSTICK_HPP_
@@ -0,0 +1,39 @@
#include "cKey.hpp"
/*** Custom Header Files ***/
#include "cKeyboard.hpp"
using InputEngine::cKey;
cKey::cKey( const SDL_Keycode& key )
: m_key(key)
{}
cKey::cKey( const cKey& copy )
: m_key(copy.getKey())
{}
/*virtual*/ cKey::~cKey()
{}
///Funtions
/*virtual*/ void cKey::KeyPress()
{}
/*virtual*/ void cKey::KeyUP()
{}
/*virtual*/ void cKey::KeyDown()
{}
///Sets
void cKey::setKey( const SDL_Keycode& key )
{
m_key = key;
}
///Gets
const SDL_Keycode& cKey::getKey() const
{
return m_key;
}
@@ -0,0 +1,37 @@
#ifndef _CKEY_HPP_
#define _CKEY_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
/*** DLL Header File ***/
#include "dllExport.h"
namespace InputEngine {
class EXPORT_FROM_MYDLL cKey
{
public:
cKey( const SDL_Keycode& key );
cKey( const cKey& copy );
virtual ~cKey();
///Funtions
/* Call to check if the key is pressed */
virtual void KeyPress();
/* Call to check if the key is released */
virtual void KeyUP();
/* Call to check if the key is pressed */
virtual void KeyDown();
///Sets
void setKey( const SDL_Keycode& key );
///Gets
const SDL_Keycode& getKey() const;
private:
private:
SDL_Keycode m_key;
};/// END CLASS DEFINITION cKey
}/// END NAMESPACE DEFINITION InputEngine
#endif/// END IFNDEF _CKEY_HPP_
@@ -0,0 +1,72 @@
#include "cKeyboard.hpp"
using InputEngine::cKeyboard;
cKeyboard::cKeyboard( const cString& label )
: m_label(label)
{}
cKeyboard::cKeyboard( const cKeyboard& copy )
:m_label(copy.getLabel())
{}
/*virtual*/ cKeyboard::~cKeyboard()
{
DeleteAllKeys();
}
///Functions
/*virtual*/ void cKeyboard::KeyboardCheck( const SDL_Event& event )
{
SDL_Keycode key = event.key.keysym.sym;
std::vector<InputEngine::cKey*>::iterator it;
for ( it = m_keys.begin() ; it < m_keys.end(); it++ ) {
if (key == (*it)->getKey()) {
switch( event.type )
{
case SDL_KEYUP:
(*it)->KeyUP();
break;
case SDL_KEYDOWN:
(*it)->KeyDown();
break;
}
//break out of the for loop
break;
}
}
}
void cKeyboard::AddKey( InputEngine::cKey* key )
{
m_keys.push_back(key);
}
void cKeyboard::DeleteKey( const SDL_Keycode& key )
{
std::vector<InputEngine::cKey*>::iterator it;
for ( it = m_keys.begin() ; it < m_keys.end(); it++ ) {
if (key == (*it)->getKey()) {
InputEngine::cKey* temp = (*it);
delete temp;
temp = nullptr;
m_keys.erase(it);
//break out of the for loop
break;
}
}
}
void cKeyboard::DeleteAllKeys()
{
m_keys.clear();
}
///Sets
const cString& cKeyboard::getLabel() const
{
return m_label;
}
@@ -0,0 +1,55 @@
#ifndef _CKEYBOARD_HPP_
#define _CKEYBOARD_HPP_
/*** C++ STL Files ***/
#include <vector>
/*** SDL Header Files ***/
#include <SDL.h>
/*** Custom Header Files ***/
#include "cKey.hpp"
/*** DLL Header File ***/
#include "dllExport.h"
/*** Custom Header Files ***/
#include "../UtilityEngine/cString.hpp"
using UtilityEngine::cString;
/*#pragma warning (disable : 4231)*/
EXPIMP_TEMPLATE template class EXPORT_FROM_MYDLL std::allocator<InputEngine::cKey*>;
EXPIMP_TEMPLATE template class EXPORT_FROM_MYDLL std::vector<InputEngine::cKey*, std::allocator<InputEngine::cKey*> >;
/*#pragma warning (default : 4231)*/
namespace InputEngine {
/* Singleton */
class EXPORT_FROM_MYDLL cKeyboard
{
public:
cKeyboard( const cString& label );
cKeyboard( const cKeyboard& copy );
virtual ~cKeyboard();
///Funtions
//Used when looking for keys that have been add to the check list
virtual void KeyboardCheck( const SDL_Event& event );
void AddKey( InputEngine::cKey* key );
void DeleteKey( const SDL_Keycode& key );
void DeleteAllKeys();
///Sets
///Gets
const cString& getLabel() const;
private:
cString m_label;// = ""
std::vector<InputEngine::cKey*> m_keys;
};/// END CLASS DEFINITION cKeyboard
}/// END NAMESPACE DEFINITION InputEngine
#endif/// END IFNDEF _CKEYBOARD_HPP_
@@ -0,0 +1,11 @@
#include "cMouse.hpp"
using InputEngine::cMouse;
cMouse::cMouse()
{}
cMouse::~cMouse()
{}
@@ -0,0 +1,21 @@
#ifndef _CMOUSE_HPP_
#define _CMOUSE_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
/*** Custom Header Files ***/
#include "cInput.hpp"
/*** DLL Header File ***/
#include "dllExport.h"
namespace InputEngine {
class EXPORT_FROM_MYDLL cMouse
{
public:
cMouse();
~cMouse();
};/// END CLASS DEFINITION cMouse
}/// END NAMESPACE DEFINITION InputEngine
#endif/// END IFNDEF _CMOUSE_HPP_
@@ -0,0 +1,90 @@
#include "cTextInput.hpp"
using InputEngine::cTextInput;
cTextInput::cTextInput()
: cKeyboard("TextInput"), m_text(""), m_caps(false), m_shift(false), INTERNATIONAL_MASK(0xFF80), UNICODE_MASK(0x7F)
{
/*if (SDL_EnableUNICODE(SDL_QUERY) != SDL_ENABLE) {
SDL_EnableUNICODE(SDL_ENABLE);
}*/
}
cTextInput::cTextInput( const cTextInput& copy )
: cKeyboard(copy), m_text(copy.getText()), m_caps(false), m_shift(false), INTERNATIONAL_MASK(0xFF80), UNICODE_MASK(0x7F)
{
/*if (SDL_EnableUNICODE(SDL_QUERY) != SDL_ENABLE) {
SDL_EnableUNICODE(SDL_ENABLE);
}*/
}
/*virtual*/ cTextInput::~cTextInput()
{}
///Functions
/* */
/*virtual*/ void cTextInput::KeyboardCheck( const SDL_Event& event )
{
switch(event.key.keysym.sym)
{
case SDLK_BACKSPACE:
case SDLK_DELETE:
if(m_text.size() == 0)
//m_text.erase(m_text.end() - 1);
break;
default:
{
char key = UnicodeValue(event);
if(key != 0)
m_text += key;
}
break;
}
}
/* Clears out the Text */
void cTextInput::ClearText()
{
m_text = "";
}
///Sets
void cTextInput::setText( const cString& text )
{
m_text = text;
}
///Gets
const cString& cTextInput::getText() const
{
return m_text;
}
//Private
const char cTextInput::UnicodeValue( const SDL_Event& event )
{
event;
/* if (SDL_EnableUNICODE(SDL_QUERY) != SDL_ENABLE)
return 0;
unsigned long int uni = event.key.keysym.unicode;
if( uni == 0 ) // not translatable key (like up or down arrows)
{
// probably not useful as string input
// we could optionally use this to get some value
// for it: SDL_GetKeyName( key );
return 0;
}
else if( ( uni & INTERNATIONAL_MASK ) == 0 )
{
return static_cast<char>(uni & UNICODE_MASK);
}
else // we have a funky international character. one we can't read :(
{
// we could do nothing, or we can just show some sign of input, like so:
return 0;
}*/
return 0;
}
@@ -0,0 +1,50 @@
#ifndef _CTEXTINPUT_HPP_
#define _CTEXTINPUT_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
/*** Custom Header Files ***/
#include "cKeyboard.hpp"
/*** DLL Header File ***/
#include "dllExport.h"
/*** Custom Header Files ***/
#include "../UtilityEngine/cString.hpp"
using UtilityEngine::cString;
namespace InputEngine {
/* Singleton */
class EXPORT_FROM_MYDLL cTextInput : public cKeyboard
{
public:
cTextInput();
cTextInput( const cTextInput& copy );
virtual ~cTextInput();
///Functions
/* */
virtual void KeyboardCheck( const SDL_Event& event );
/* Clears out the Text */
void ClearText();
///Sets
void setText( const cString& text );
///Gets
const cString& getText() const;
private:
const char UnicodeValue( const SDL_Event& event );
private:
cString m_text;// = ""
bool m_caps;// = false
bool m_shift;// = false
// magic numbers courtesy of SDL docs
const unsigned long int INTERNATIONAL_MASK;// = 0xFF80
const unsigned long int UNICODE_MASK;// = 0x7F
};/// END CLASS DEFINITION cTextInput
}/// END NAMESPACE DEFINITION InputEngine
#endif/// END IFNDEF _CTEXTINPUT_HPP_