40 #ifndef _EVENTUSERINPUT_CPP
41 #define _EVENTUSERINPUT_CPP
52 #include "eventuserinput.h"
54 #include "exception.h"
55 #include "stringtool.h"
70 EventUserInput::EventUserInput()
74 { this->push_back(Code_); }
76 EventUserInput::EventUserInput(
const vector<Input::MetaCode>& Code_)
79 EventUserInput::~EventUserInput()
83 {
return this->at(Index); }
85 size_t EventUserInput::GetMetaCodeCount()
86 {
return this->size(); }
90 this->push_back(Code_);
97 return this->AddCode(CurrentMetaCode);
103 return this->AddCode(CurrentMetaCode);
109 return this->AddCode(CurrentMetaCode);
112 void EventUserInput::AddCodes(
const vector<Input::MetaCode>& Codes)
114 for(
unsigned int c=0; Codes.size()>c ; c++)
115 { this->push_back(Codes.at(c)); }
120 vector<Input::MetaCode>::iterator iter;
122 for(iter=this->begin(); this->end()!=iter ; iter++)
131 void EventUserInput::EraseCode(
const unsigned int& Index)
132 { this->erase(this->begin()+Index); }
135 {
return UserInput; }
137 vector<Input::MetaCode> EventUserInput::AddCodesFromRawEvent(
const RawEvent& RawEvent_)
139 vector<Input::MetaCode> Results;
140 switch(RawEvent_.type)
142 case SDL_KEYUP:
case SDL_KEYDOWN:
143 case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN:
144 case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
145 Results.push_back(this->AddCode(RawEvent_));
148 case SDL_MOUSEMOTION:{
149 std::vector<Input::MetaCode> Transport(this->AddCodesFromSDLMouseMotion(RawEvent_));
150 Results.insert(Results.end(), Transport.begin(),Transport.end());
153 case SDL_JOYAXISMOTION: {
154 std::vector<Input::MetaCode> Transport(this->AddCodesFromSDLJoyStickMotion(RawEvent_));
155 Results.insert(Results.end(), Transport.begin(),Transport.end());
158 case SDL_JOYBALLMOTION:{
159 std::vector<Input::MetaCode> Transport(this->AddCodeFromSDLJoyStickBall(RawEvent_));
160 Results.insert(Results.end(), Transport.begin(),Transport.end());
163 case SDL_JOYHATMOTION:{
164 std::vector<Input::MetaCode> Transport(this->AddCodeFromSDLJoyStickHat(RawEvent_));
165 Results.insert(Results.end(), Transport.begin(),Transport.end());
169 MEZZ_EXCEPTION(Exception::PARAMETERS_EXCEPTION,
"Unknown SDL Event Inserted");
180 vector<Input::MetaCode> EventUserInput::AddCodesFromSDLMouseMotion(
const RawEvent& RawEvent_)
182 vector<Input::MetaCode> Results;
184 Results.push_back(this->AddCode(RawEvent_.motion.x, Input::MOUSEABSOLUTEHORIZONTAL));
185 Results.push_back(this->AddCode(RawEvent_.motion.y, Input::MOUSEABSOLUTEVERTICAL));
187 if(0 != RawEvent_.motion.xrel)
188 { Results.push_back(this->AddCode(RawEvent_.motion.xrel, Input::MOUSEHORIZONTAL));}
190 if(0 != RawEvent_.motion.yrel)
191 { Results.push_back(this->AddCode(RawEvent_.motion.yrel, Input::MOUSEVERTICAL));}
195 vector<Input::MetaCode> EventUserInput::AddCodesFromSDLJoyStickMotion(
const RawEvent& RawEvent_)
197 vector<Input::MetaCode> Results;
199 Results.push_back(this->AddCode(RawEvent_.jaxis.value, Input::MetaCode::GetControllerAxisCode(RawEvent_.jaxis.axis+1), RawEvent_.jaxis.which));
204 vector<Input::MetaCode> EventUserInput::AddCodeFromSDLJoyStickHat(
const RawEvent& RawEvent_)
206 vector<Input::MetaCode> Results;
209 if( Input::CONTROLLERHAT_FIRST > Hat || Input::CONTROLLERHAT_LAST < Hat )
211 MEZZ_EXCEPTION(Exception::NOT_IMPLEMENTED_EXCEPTION,
"Unsupported Controller Hat Event");
214 Results.push_back(this->AddCode( RawEvent_.jhat.value, Hat, RawEvent_.jhat.which ));
218 vector<Input::MetaCode> EventUserInput::AddCodeFromSDLJoyStickBall(
const RawEvent& RawEvent_)
220 vector<Input::MetaCode> Results;
222 if( 0 == RawEvent_.jball.ball )
224 if( RawEvent_.jball.yrel != 0 )
225 { Results.push_back(this->AddCode(RawEvent_.jball.yrel, Input::CONTROLLERBALL_1_VERTICAL, RawEvent_.jball.which)); }
226 if( RawEvent_.jball.xrel != 0 )
227 { Results.push_back(this->AddCode(RawEvent_.jball.xrel, Input::CONTROLLERBALL_1_HORIZONTAL, RawEvent_.jball.which)); }
228 }
else if( 1 == RawEvent_.jball.ball ){
229 if( RawEvent_.jball.yrel != 0 )
230 { Results.push_back(this->AddCode(RawEvent_.jball.yrel, Input::CONTROLLERBALL_2_VERTICAL, RawEvent_.jball.which)); }
231 if( RawEvent_.jball.xrel != 0 )
232 { Results.push_back(this->AddCode(RawEvent_.jball.xrel, Input::CONTROLLERBALL_2_HORIZONTAL, RawEvent_.jball.which)); }
234 MEZZ_EXCEPTION(Exception::NOT_IMPLEMENTED_EXCEPTION,
"More then 2 trackballs is currently not supported. Perhaps we should expand our enum.");
246 stream <<
"<EventUserInput Version=\"1\">";
247 for (vector<Mezzanine::Input::MetaCode>::const_iterator Iter = Ev.begin(); Iter!=Ev.end(); ++Iter)
251 stream <<
"</EventUserInput>";
261 Doc->GetFirstChild() >> Ev;