116 lines · 3.0 KB · C
RawDownload
#include "input.h" #include <SDL2/SDL.h>#include "gui.h" /*Copyright (c) 2013-2021 Devine Lu Linvega2018 web port by rezmason2021 C89 port by rezmason Permission to use, copy, modify, and distribute this software for anypurpose with or without fee is hereby granted, provided that the abovecopyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS SOFTWARE.*/ static void (*_handler)(InputType, int);static int mousePressed; static voidprocessKey(SDL_Keycode sym, int down){	int found = 1;	InputType inputType = -1;	switch(sym) {#ifdef DEBUG	case SDLK_1:	case SDLK_KP_1: inputType = DEBUGINPUTTYPE_ENERGY; break;	case SDLK_2:	case SDLK_KP_2: inputType = DEBUGINPUTTYPE_CLOCK; break;	case SDLK_3:	case SDLK_KP_3: inputType = DEBUGINPUTTYPE_STUDIO; break;	case SDLK_4:	case SDLK_KP_4: inputType = DEBUGINPUTTYPE_SEAL_1; break;	case SDLK_5:	case SDLK_KP_5: inputType = DEBUGINPUTTYPE_SEAL_2; break;	case SDLK_6:	case SDLK_KP_6: inputType = DEBUGINPUTTYPE_SECRET; break;	case SDLK_7:	case SDLK_KP_7: inputType = DEBUGINPUTTYPE_TIME; break;	case SDLK_8:	case SDLK_KP_8: inputType = DEBUGINPUTTYPE_CHAPTER; break;	case SDLK_9:	case SDLK_KP_9: inputType = DEBUGINPUTTYPE_UNLOCK_DOORS; break;#endif	case SDLK_a:	case SDLK_LEFT: inputType = INPUTTYPE_LEFT; break;	case SDLK_d:	case SDLK_RIGHT: inputType = INPUTTYPE_RIGHT; break;	case SDLK_w:	case SDLK_UP: inputType = INPUTTYPE_CENTER; break;	case SDLK_s:	case SDLK_DOWN: inputType = INPUTTYPE_BACK; break;	case SDLK_r: inputType = INPUTTYPE_RESET; break;	case SDLK_q: inputType = INPUTTYPE_WALKTHROUGH; break;	default: found = 0; break;	} 	if(found) {		(*_handler)(inputType, down);	}	GUI_HideCursor();} static voidprocessClick(int mouseX, int mouseY){	int found = 1;	InputType inputType;	RegionName clickedRegionName = GUI_GetRegionNameAt(mouseX, mouseY);	switch(clickedRegionName) {	case TRIGGER_ACTION: inputType = INPUTTYPE_ACTION; break;	case TRIGGER_MOVE_FORWARD: inputType = INPUTTYPE_FORWARD; break;	case TRIGGER_MOVE_LEFT: inputType = INPUTTYPE_LEFT; break;	case TRIGGER_MOVE_RIGHT: inputType = INPUTTYPE_RIGHT; break;	default: found = 0; break;	} 	if(found) {		(*_handler)(inputType, 1);	}} voidInput_Init(void (*handler)(InputType, int)){	_handler = handler;	mousePressed = 0;} voidInput_Quit(){	_handler = NULL;} voidInput_ProcessEvent(SDL_Event *event){	switch(event->type) {	case SDL_KEYDOWN: processKey(event->key.keysym.sym, 1); break;	case SDL_KEYUP: processKey(event->key.keysym.sym, 0); break;	case SDL_MOUSEMOTION: GUI_UpdateCursor(event->motion.x, event->motion.y, mousePressed); break;	case SDL_MOUSEBUTTONDOWN:		mousePressed = 1;		processClick(event->button.x, event->button.y);		GUI_UpdateCursor(event->motion.x, event->motion.y, mousePressed);		break;	case SDL_MOUSEBUTTONUP:		mousePressed = 0;		GUI_UpdateCursor(event->motion.x, event->motion.y, mousePressed);		break;	}}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t