Basic mouse/touch usage
This commit is contained in:
@@ -451,26 +451,47 @@ int Draw_LoopIteration(){
|
||||
SDL_GL_SwapBuffers();
|
||||
|
||||
// Process Events
|
||||
#ifdef EMSCRIPTEN
|
||||
while(SDL_PollEvent(&event) ){
|
||||
if(event.type == SDL_QUIT ){
|
||||
Input_SetKey(InputKey_Exit,1);
|
||||
#ifndef EMSCRIPTEN
|
||||
if(!_draw_exitoverrided){
|
||||
_draw_looping=0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if(event.type == SDL_KEYDOWN ){
|
||||
if(event.key.keysym.sym == SDLK_ESCAPE ) {
|
||||
Input_SetKey(InputKey_Exit,1);
|
||||
#ifndef EMSCRIPTEN
|
||||
}
|
||||
}
|
||||
if(event.type==SDL_MOUSEBUTTONDOWN || event.type==SDL_FINGERDOWN || event.type==SDL_TOUCHBUTTONDOWN){
|
||||
Input_SetPointerDown(1);
|
||||
}
|
||||
if(event.type==SDL_MOUSEBUTTONUP || event.type==SDL_FINGERUP || event.type==SDL_TOUCHBUTTONUP){
|
||||
Input_SetPointerDown(0);
|
||||
}
|
||||
}
|
||||
#else
|
||||
while(SDL_PollEvent(&event) ){
|
||||
if(event.type == SDL_QUIT ){
|
||||
Input_SetKey(InputKey_Exit,1);
|
||||
if(!_draw_exitoverrided){
|
||||
_draw_looping=0;
|
||||
}
|
||||
}
|
||||
if(event.type == SDL_KEYDOWN ){
|
||||
if(event.key.keysym.sym == SDLK_ESCAPE ) {
|
||||
Input_SetKey(InputKey_Exit,1);
|
||||
if(!_draw_exitoverrided){
|
||||
_draw_looping=0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if(event.type==SDL_MOUSEBUTTONDOWN){
|
||||
Input_SetPointerDown(1);
|
||||
}
|
||||
if(event.type==SDL_MOUSEBUTTONUP){
|
||||
Input_SetPointerDown(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef EMSCRIPTEN
|
||||
// Process keys for Draw
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
|
||||
// Globals
|
||||
InputKeyStatus _keys[InputKey_Max];
|
||||
int _pointerDown=0;
|
||||
SDL_Joystick *_joy;
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_Init
|
||||
//
|
||||
@@ -56,8 +58,10 @@ int Input_Init(){
|
||||
void Input_Frame(){
|
||||
Uint8* keys;
|
||||
|
||||
// Process Keys
|
||||
// Get keyboard state
|
||||
keys=(Uint8 *)SDL_GetKeyState(NULL);
|
||||
|
||||
// Process Keys
|
||||
Input_SetKey(InputKey_Action1,keys[SDLK_z]);
|
||||
Input_SetKey(InputKey_Action2,keys[SDLK_x]);
|
||||
Input_SetKey(InputKey_Up,keys[SDLK_UP]);
|
||||
@@ -65,7 +69,7 @@ void Input_Frame(){
|
||||
Input_SetKey(InputKey_Left,keys[SDLK_LEFT]);
|
||||
Input_SetKey(InputKey_Right,keys[SDLK_RIGHT]);
|
||||
Input_SetKey(InputKey_Jump,keys[SDLK_SPACE]);
|
||||
Input_SetKey(InputKey_Continue,keys[SDLK_RETURN]|keys[SDLK_KP_ENTER]);
|
||||
Input_SetKey(InputKey_Continue,keys[SDLK_RETURN]|keys[SDLK_KP_ENTER]|_pointerDown);
|
||||
|
||||
Input_SetKey(InputKey_DumpProfiling,keys[SDLK_p]);
|
||||
}
|
||||
@@ -97,6 +101,14 @@ InputKeyStatus Input_GetKey(InputKey key){
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_SetPointerDown
|
||||
//
|
||||
void Input_SetPointerDown(int pointerDown){
|
||||
_pointerDown=pointerDown;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_AnyKey
|
||||
//
|
||||
|
||||
@@ -66,6 +66,12 @@ typedef enum {
|
||||
InputKeyStatus Input_GetKey(InputKey key);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_SetPointerDown
|
||||
//
|
||||
void Input_SetPointerDown(int pointerDown);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_AnyKey
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user