Input: Detectar clicks.
This commit is contained in:
@@ -475,16 +475,50 @@ int Draw_LoopIteration(){
|
||||
Input_SetKey(InputKey_Exit,1);
|
||||
}
|
||||
}
|
||||
if(event.type==SDL_MOUSEBUTTONDOWN ||
|
||||
event.type==SDL_FINGERDOWN ||
|
||||
event.type==SDL_TOUCHBUTTONDOWN)
|
||||
{
|
||||
if(event.type==SDL_MOUSEMOTION){
|
||||
Input_SetPointerPosition(
|
||||
event.motion.x/(float)_width,
|
||||
event.motion.y/(float)_height);
|
||||
}
|
||||
if(event.type==SDL_MOUSEBUTTONDOWN){
|
||||
Input_SetPointerPosition(
|
||||
event.button.x/(float)_width,
|
||||
event.button.y/(float)_height);
|
||||
Input_SetPointerDown(1);
|
||||
}
|
||||
if(event.type==SDL_MOUSEBUTTONUP ||
|
||||
event.type==SDL_FINGERUP ||
|
||||
event.type==SDL_TOUCHBUTTONUP)
|
||||
{
|
||||
if(event.type==SDL_FINGERMOTION){
|
||||
Input_SetPointerPosition(
|
||||
event.tfinger.x,
|
||||
event.tfinger.y);
|
||||
}
|
||||
if(event.type==SDL_FINGERDOWN){
|
||||
Input_SetPointerPosition(
|
||||
event.tfinger.x,
|
||||
event.tfinger.y);
|
||||
Input_SetPointerDown(1);
|
||||
}
|
||||
if(event.type==SDL_TOUCHBUTTONDOWN){
|
||||
Input_SetPointerPosition(
|
||||
event.tfinger.x,
|
||||
event.tfinger.y);
|
||||
Input_SetPointerDown(1);
|
||||
}
|
||||
if(event.type==SDL_MOUSEBUTTONUP){
|
||||
Input_SetPointerPosition(
|
||||
event.button.x/(float)_width,
|
||||
event.button.y/(float)_height);
|
||||
Input_SetPointerDown(0);
|
||||
}
|
||||
if(event.type==SDL_FINGERUP){
|
||||
Input_SetPointerPosition(
|
||||
event.tfinger.x,
|
||||
event.tfinger.y);
|
||||
Input_SetPointerDown(0);
|
||||
}
|
||||
if(event.type==SDL_TOUCHBUTTONUP){
|
||||
Input_SetPointerPosition(
|
||||
event.tfinger.x,
|
||||
event.tfinger.y);
|
||||
Input_SetPointerDown(0);
|
||||
}
|
||||
}
|
||||
@@ -504,10 +538,21 @@ int Draw_LoopIteration(){
|
||||
}
|
||||
}
|
||||
}
|
||||
if(event.type==SDL_MOUSEMOTION){
|
||||
Input_SetPointerPosition(
|
||||
event.motion.x/(float)_width,
|
||||
event.motion.y/(float)_height);
|
||||
}
|
||||
if(event.type==SDL_MOUSEBUTTONDOWN){
|
||||
Input_SetPointerPosition(
|
||||
event.button.x/(float)_width,
|
||||
event.button.y/(float)_height);
|
||||
Input_SetPointerDown(1);
|
||||
}
|
||||
if(event.type==SDL_MOUSEBUTTONUP){
|
||||
Input_SetPointerPosition(
|
||||
event.button.x/(float)_width,
|
||||
event.button.y/(float)_height);
|
||||
Input_SetPointerDown(0);
|
||||
}
|
||||
}
|
||||
@@ -532,7 +577,7 @@ int Draw_LoopIteration(){
|
||||
Input_Frame();
|
||||
_proc_func(_data);
|
||||
_accTime-=proc_t_frame;
|
||||
Input_SetKey(InputKey_Exit,0);
|
||||
Input_PostFrame();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -624,3 +624,21 @@ void GameLib_EntitySetLight(Entity e,float r,float g,float b,float rad){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// GameLib_ConvertScreenPositionToGamePosition
|
||||
//
|
||||
//
|
||||
void GameLib_ConvertScreenPositionToGamePosition(
|
||||
vec2 screenPos, vec2 gamePos)
|
||||
{
|
||||
float f;
|
||||
int game_pos[2];
|
||||
|
||||
game_pos[0]=_game_pos0[0]+f*(_game_pos1[0]-_game_pos0[0]);
|
||||
game_pos[1]=_game_pos0[1]+f*(_game_pos1[1]-_game_pos0[1]);
|
||||
|
||||
gamePos[0]=(screenPos[0]*_game_size[0])+game_pos[0];
|
||||
gamePos[1]=(screenPos[1]*_game_size[1])+game_pos[1];
|
||||
}
|
||||
|
||||
|
||||
@@ -115,4 +115,12 @@ void GameLib_PlaySound(AudioSnd snd,int x,int y);
|
||||
void GameLib_EntitySetLight(Entity e,float r,float g,float b,float rad);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// GameLib_ConvertScreenPositionToGamePosition
|
||||
//
|
||||
//
|
||||
void GameLib_ConvertScreenPositionToGamePosition(
|
||||
vec2 screenPos, vec2 gamePos);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,14 @@
|
||||
|
||||
// Globals
|
||||
InputKeyStatus _keys[InputKey_Max];
|
||||
|
||||
int _pointerDown=0;
|
||||
float _pointerX=0;
|
||||
float _pointerY=0;
|
||||
|
||||
int _clicked=0;
|
||||
float _clickedPositionX=0;
|
||||
float _clickedPositionY=0;
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
@@ -56,6 +63,16 @@ void Input_Frame(){
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_PostFrame
|
||||
//
|
||||
// Notify a frame update to the input subsystem.
|
||||
void Input_PostFrame(){
|
||||
Input_SetKey(InputKey_Exit,0);
|
||||
_clicked=0;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_SetKey
|
||||
//
|
||||
@@ -82,14 +99,48 @@ InputKeyStatus Input_GetKey(InputKey key){
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_SetPointerPosition
|
||||
//
|
||||
void Input_SetPointerPosition(float x, float y){
|
||||
_pointerX=x;
|
||||
_pointerY=y;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_SetPointerDown
|
||||
//
|
||||
void Input_SetPointerDown(int pointerDown){
|
||||
if(pointerDown==0 && _pointerDown==1){
|
||||
_clicked=1;
|
||||
_clickedPositionX=_pointerX;
|
||||
_clickedPositionY=_pointerY;
|
||||
}
|
||||
_pointerDown=pointerDown;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_GetPointerPosition
|
||||
//
|
||||
int Input_GetPointerPosition(vec2 pointer){
|
||||
pointer[0]=_pointerX;
|
||||
pointer[1]=_pointerY;
|
||||
return _pointerDown;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_GetClickedPosition
|
||||
//
|
||||
int Input_GetClickedPosition(vec2 clickPosition){
|
||||
clickPosition[0]=_clickedPositionX;
|
||||
clickPosition[1]=_clickedPositionY;
|
||||
return _clicked;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_AnyKey
|
||||
//
|
||||
@@ -116,7 +167,6 @@ int Input_GetDir(vec2 dir){
|
||||
float dlen;
|
||||
extern int _width,_height;
|
||||
|
||||
|
||||
// Get mouse state
|
||||
buttons=SDL_GetMouseState(&mx,&my);
|
||||
if(buttons){
|
||||
|
||||
@@ -20,6 +20,13 @@ int Input_Init();
|
||||
void Input_Frame();
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_PostFrame
|
||||
//
|
||||
// Notify a frame update end to the input subsystem.
|
||||
void Input_PostFrame();
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// InputKey //
|
||||
//////////////
|
||||
@@ -66,12 +73,30 @@ typedef enum {
|
||||
InputKeyStatus Input_GetKey(InputKey key);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_SetPointerPosition
|
||||
//
|
||||
void Input_SetPointerPosition(float x, float y);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_SetPointerDown
|
||||
//
|
||||
void Input_SetPointerDown(int pointerDown);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_GetPointerPosition
|
||||
//
|
||||
int Input_GetPointerPosition(vec2 pointer);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_GetClickedPosition
|
||||
//
|
||||
int Input_GetClickedPosition(vec2 clickPosition);
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Input_AnyKey
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user