void InputHandler::Unregister(int key, bool down, bool up)
{
	InputHandler * ih = Get();

	for (std::vector<InputBind*>::iterator itr = ih->Binds.begin(); itr != ih->Binds.end();)
	{
		if ((*itr)->Key == key)
		{
			if (down)
				(*itr)->ProfileDown = 0;
			if (up)
			{
				if ((*itr)->IsDown)
					ih->DoKey(*itr, false);
				(*itr)->ProfileUp = 0;
			}
			if ((*itr)->ProfileDown == 0 && (*itr)->ProfileUp == 0)
			{
				delete *itr;
				itr = ih->Binds.erase(itr);
				continue;
			}
		}

		itr++;
	}
}
Beispiel #2
0
void MenuButton::update()
{
    InputHandler* pIH = InputHandler::Instance();
    Vector2D* pMousePos = pIH->getMousePosition();

    if (pMousePos->getX() >= m_position.getX() &&
            pMousePos->getX() <= m_position.getX() + m_width &&
            pMousePos->getY() >= m_position.getY() &&
            pMousePos->getY() <= m_position.getY() + m_height)
    {
        m_currentFrame = MOUSE_OVER;

        if (pIH->getMouseButtonState(LEFT))
        {
            m_currentFrame = CLICKED;
            if (m_bReleased)
            {
                m_callback();
                m_bReleased = false;
            }
        }
        else
        {
            m_bReleased = true;
        }
    }
    else
    {
        m_currentFrame = MOUSE_OUT;
        m_bReleased = true;
    }
}
Beispiel #3
0
void mouseScroll_callback(GLFWwindow* window, double offsetX, double offSetY)
{

	std::map<int, std::function<void()>> activeMap = iH.getActiveInputMap()->getMap();

	iH.getActiveInputMap()->setGLFWwindow(window);

	if (offSetY < 0)
	{
		for (std::map<int, std::function<void()>>::iterator it = activeMap.begin(); it != activeMap.end(); it++){
			if (it->first == 001)
				activeMap.at(001)();
			if (it == activeMap.end())
				std::cout << "Key is not mapped to an action" << std::endl;
		}
	}
	else{
		for (std::map<int, std::function<void()>>::iterator it = activeMap.begin(); it != activeMap.end(); it++){
			if (it->first == 002)
				activeMap.at(002)();
			if (it == activeMap.end())
				std::cout << "Key is not mapped to an action" << std::endl;
		}
	}
}
void InputComponent::enterScene(Scene* scene) {
    Component::enterScene(scene);

    InputHandler* inputHandler = scene->getEngine()->getInputHandler();
    inputHandler->registerKeyListener(this);
    inputHandler->registerMouseListener(this);
}
Beispiel #5
0
void Player::handleInput()
{
    InputHandler *inputHandler = TheInputHandler::getInstance();

    Vector2D *mousePosition = inputHandler->getMousePosition();

    velocity = (*mousePosition - position) / 50;
}
Beispiel #6
0
        void update(const InputHandler& input) {
                camera = input.get6DOFRotationInput() * camera;

                auto motion = input.getMotionInput() * 0.2f;
                auto inv = glm::inverse(camera);
                auto worldMotion = inv * glm::vec4(-motion,1) - inv * glm::vec4(glm::vec3(0),1);
                camera = glm::translate(camera, glm::vec3{worldMotion});
        }
void InputComponent::leaveScene() {
    Scene* scene = getScene();

    InputHandler* inputHandler = scene->getEngine()->getInputHandler();
    inputHandler->unregisterKeyListener(this);
    inputHandler->unregisterMouseListener(this);

    Component::leaveScene();
}
Beispiel #8
0
void CreditsMenu::Update(sf::RenderWindow& window, InputHandler &input)
{
	for(it = menuItems.begin(); it != menuItems.end(); it++)
	{
		if(isInRect(input.getMousePos(window),it->second) &&  input.clicked(window))
		{
			menuValue = it->first;
			break;
		}
	}
}
Beispiel #9
0
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods){
	// The active InputMap is fetched
	std::map<int, std::function<void()>> activeMap = iH.getActiveInputMap()->getMap();

	// You go over the active InputMap, if it's the key that is pressed, a method is called and the mapped action is executed else the key is ignored
	for (std::map<int, std::function<void()>>::iterator it = activeMap.begin(); it != activeMap.end(); it++){
		if (it->first == key)
			iH.getActiveInputMap()->checkMultipleMappedKeys(key, *window);
		if (it == activeMap.end())
			std::cout << "Key is not mapped to an action" << std::endl;
	}
}
TextBoxInputComponent::TextBoxInputComponent(InputHandler& ih, TextBoxRenderComponent &r): inputHandle(ih), textBox(r) {

	ih.addHandle(sf::Event::TextEntered);
	ih.addHandle(sf::Event::KeyPressed);

	watch(ih, sf::Event::TextEntered);
	watch(ih, sf::Event::KeyPressed);

	str.push_back((char)'> ');
	textBox.updateLabelString(str);

}
Beispiel #11
0
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods){
	std::map<int, std::function<void()>> activeMap = iH.getActiveInputMap()->getMap();

	iH.getActiveInputMap()->setGLFWwindow(window);

	for (std::map<int, std::function<void()>>::iterator it = activeMap.begin(); it != activeMap.end(); it++){
		if (it->first == key)
			activeMap.at(key)();
		if (it == activeMap.end())
			std::cout << "Key is not mapped to an action" << std::endl;
	}
}
Beispiel #12
0
static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos) {
    if (iH.getActiveInputMap()->getType() == MapType::CAMPLAYERVIEW) {
        cam.turn(xpos, ypos);
    }
    if (iH.getActiveInputMap()->getType() == MapType::CAMSTRATEGY) {
        if (glfwGetMouseButton(window, 0) == GLFW_PRESS) {
            cam.turn(xpos, ypos);
        }
        else {
            cam.updateCursor(window);
        }
    }
}
Beispiel #13
0
void InputHub::PrintInputHandler( InputHandler& input_handler, const std::string& indent, std::string& dest )
{
	dest += indent + typeid(input_handler).name();
	dest += ( input_handler.IsActive() ? " (active)" : " (inactive)" );
	dest += "\n";

	const std::vector<InputHandler *> children = input_handler.GetChildren();
	const int num_children = (int)children.size();
	for( int i=0; i<num_children; i++ )
	{
		if( children[i] )
			PrintInputHandler( *children[i], indent + "  ", dest );
	}
}
Beispiel #14
0
        void update(const InputHandler& input) {
                rotation += input.getRotationInput();
                rotation.y = glm::clamp(rotation.y, (float)-M_PI/2.0f, (float)M_PI/2.0f);

                matrix = glm::rotate(rotation.y, glm::vec3(1.0, 0.0, 0.0));
                matrix = glm::rotate(matrix, rotation.x, glm::vec3(0.0, 1.0, 0.0));

                glm::vec3 movement = input.getMotionInput() * 0.2f;

                movement = glm::vec3(glm::inverse(matrix) * glm::vec4(movement, 0.0f));
                position += movement;

                matrix = glm::translate(matrix, -position);
        }
Beispiel #15
0
int main()
{
	//The window we'll be rendering to
	SDL_Window* window = NULL;

	Mix_Music *music = NULL;
	Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1;
	music = Mix_LoadMUS(("Assets/background.wav"));
	Mix_PlayMusic(music, -1);


	//SDL
#pragma region SDL STUFF
	//Initialize SDL
	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
	}
	else
	{
		//Create window
		window = SDL_CreateWindow("SDL Template", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
		if (window == NULL)
		{
			printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
		}
		else
		{
			//Create Renderer for the Window
			if (!Renderer::GetInstance()->Init(window, SCREEN_WIDTH, SCREEN_HEIGHT))
			{
				return 0;
			}

			bool quit = false;
			Init();


			SDL_Event e;
			while (!quit)
			{
				while (SDL_PollEvent(&e) != 0)
				{
					if (inputHandler.CheckInput(SDLK_ESCAPE, e))
					{
						quit = true;
					}
				}//Key Input Update

				//*******************
				// Update Method
				//*******************
				DrawGame();

			}

			return 0;
		}
	}
}
Beispiel #16
0
void SplashScreen::Show(sf::RenderWindow& window, std::string& filepath , InputHandler &input)
{	
	splashTexture.loadFromFile(filepath);
	splashSprite.setTexture(splashTexture);
	splashSprite.setScale((float)window.getSize().x / splashSprite.getTexture()->getSize().x, (float)window.getSize().y / splashSprite.getTexture()->getSize().y);
	splashSprite.setColor(sf::Color(splashSprite.getColor().r, splashSprite.getColor().g, splashSprite.getColor().b,0));

	fadeIn = true;
	stopSplash = false;

	
	while(true)
	{
		if(input.clicked(window) || stopSplash)
		{
			break;
		}

		window.clear();
		
		if(fadeIn == true)
		{
			fadeSpriteIn(window, splashSprite);
		}else{
			fadeSpriteOut(window,splashSprite);
		}
		
		window.draw(splashSprite);
		window.display();
		
	}
}
void MyMouseCursor::update(InputHandler inputhandler, HWND hwnd)
{
	inputhandler.checkClick(hwnd);

	mouse0 = false;
	mouse1 = false;
	mouse2 = false;
	mouse3 = false;
	mouse4 = false;

	mouseX = inputhandler.mouseX;
	mouseY = inputhandler.mouseY;
	
	if (Mouse_Button(0))
	{
		mouse0 = true;
	}
	if (Mouse_Button(1))
	{
		mouse1 = true;
	}
	if (Mouse_Button(2))
	{
		mouse2 = true;
	}
	if (Mouse_Button(3))
	{
		mouse3 = true;
	}
	if (Mouse_Button(4))
	{
		mouse4 = true;
	}
}
Beispiel #18
0
/* Input */
void CameraHandler::resolveInput(InputHandler &input)
{
	if (input.keyIsDown(input.getKey(THIRD_PERSON_CAMERA))) setActiveCamera(THIRD_PERSON);
	else if (input.keyIsDown(input.getKey(FREE_CAMERA)))	setActiveCamera(FREE);
	else if (input.keyIsDown(input.getKey(STATIC1_CAMERA))) setActiveCamera(STATIC1);
	else if (input.keyIsDown(input.getKey(STATIC2_CAMERA))) setActiveCamera(STATIC2);
	else if (input.keyIsDown(input.getKey(STATIC3_CAMERA))) setActiveCamera(STATIC3);
	else if (input.keyIsDown(input.getKey(STATIC4_CAMERA))) setActiveCamera(STATIC4);
}
Beispiel #19
0
int main()
{
    House house;
    Player player;
    player.moveTo(house.getRoom("living room"));

    InputHandler input;
    generateControls(input, player);
    
    do 
    {
        input.updateInput();
    } while (!input.isEndSignal);

    std::cout << "Thanks for playing." << std::endl;

    return 0;
}
Beispiel #20
0
void R_runHandlers(InputHandler *handlers, fd_set *readMask)
{
    InputHandler *tmp = handlers, *next;

    if (readMask == NULL) {
	Rg_PolledEvents();
	R_PolledEvents();
    } else
	while(tmp) {
	    /* Do this way as the handler function might call 
	       removeInputHandlers */
	    next = tmp->next;
	    if(FD_ISSET(tmp->fileDescriptor, readMask)
	       && tmp->handler != NULL)
		tmp->handler((void*) tmp->userData);
	    tmp = next;
	}
}
Beispiel #21
0
void mouse_callback(GLFWwindow* window)
{
	int i = 0;
	if (glfwGetMouseButton(window, i) == GLFW_PRESS)
	{
		std::map<int, std::function<void()>> activeMap = iH.getActiveInputMap()->getMap();

		iH.getActiveInputMap()->setGLFWwindow(window);

		for (std::map<int, std::function<void()>>::iterator it = activeMap.begin(); it != activeMap.end(); it++){
			if (it->first == i)
				activeMap.at(i)();
			if (it == activeMap.end())
				std::cout << "Key is not mapped to an action" << std::endl;
		}
	}
	else{
		cam.updateCursor(window);
	}
}
Beispiel #22
0
static void processUserInput (CallControlManagerPtr ccmPtr)
{
	InputHandler input;
	MyUserOperationCallback callback;
	input.setCallback(&callback);

    while (1)
    {
        _userOperationRequestEvent.TimedWait(base::TimeDelta::FromMilliseconds(1000));

        if (!handleAllUserRequests(ccmPtr))
        {
            break;
        }
    }

    CSFLogDebugS(logTag, "User chose to stop test application.\nWaiting on user input thread to finish...");

	input.setCallback(NULL);
}
Beispiel #23
0
void generateControls(InputHandler& input, Player &player)
{
    input.addAction("survey", stdex::make_unique<SurveyAction>(&player));
    input.addAction("enter", stdex::make_unique<EnterAction>(&player));
    input.addAction("use", stdex::make_unique<UseAction>(&player));
    input.addAction("retrieve", stdex::make_unique<RetrieveItemAction>(&player));
    input.addAction("drop", nullptr);
    input.addAction("quit", stdex::make_unique<QuitAction>(&input));
    input.addAction("inventory", stdex::make_unique<InventoryAction>(&player));
}
Beispiel #24
0
  void Graphics::Update(float dt)
  {
    recompile_timer_ += dt;
    if(recompile_timer_ > 2.0f)
    {
      RecompileShaders();
      recompile_timer_ = 0.0f;
    }
    
    particle_manager_->Update(dt);
    camera_->Orient();
    Render();

    Input* input = (Input*) Engine::GetCore()->GetSystem(ST_Input);
    InputHandler* handler = input->GetHandler();
    if(handler->Check("UIToggle"))
    {
      draw_ui_ = !draw_ui_;
    }

  }
void InputHandler::Update()
{
	{
		const int shouldProcess = 0x772A50;
		int procResult = 0;
		_asm
		{
			pushad
				pushfd
				mov ecx, 0x12E7454
				mov ecx, [ecx]
				call shouldProcess
				mov procResult, eax
				popfd
				popad
		}

		if ((procResult & 0xFF) == 0)
			return;
	}

	int gMain = *((int*)0x1B2E860);
	if (gMain == 0)
		return;

	int hwnd = *((int*)(gMain + 0xC));
	if (hwnd == 0 || GetActiveWindow() != (HWND)hwnd)
		return;

	InputHandler * ih = Get();

	for (std::vector<InputBind*>::iterator itr = ih->Binds.begin(); itr != ih->Binds.end(); itr++)
	{
		if ((*itr)->Key <= 0)
			continue;

		bool isDown = IsKeyDown((*itr)->Key, (*itr)->Modifiers);
		ih->DoKey(*itr, isDown);
	}
}
int main()
{
	// Create the main window 
	sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Swarm-wars");

	InputHandler myInputHandler = InputHandler();

	// Start game loop 
	while (window.isOpen())
	{
		// Process events 
		sf::Event Event;
		while (window.pollEvent(Event))
		{
			// Close window : exit 
			if (Event.type == sf::Event::Closed)
				window.close();

			// Escape key : exit 
			if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
				window.close();


		}

		myInputHandler.HandleInput();
		//prepare frame
		window.clear();

		//draw frame items
		//window.draw(myShape);

		// Finally, display rendered frame on screen 
		window.display();

	} //loop back for next frame

	return EXIT_SUCCESS;
}
Beispiel #27
0
int main(void)
{
    glfwInit();

    GLFWwindow* window;
    window = glfwCreateWindow(640, 480, "InputTest", NULL, NULL);
    glfwMakeContextCurrent(window);

    iH.setAllInputMaps(alibiCam);
    // Setting an InputMap active so that action can be performed
    iH.changeActiveInputMap("Trackball");

    //Callback
    glfwSetKeyCallback(window, key_callback);

    while (!glfwWindowShouldClose(window))
    {
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwDestroyWindow(window);
    glfwTerminate();
}
  void ModelComponent::Update(float dt)
  {
    Graphics* gSys = (Graphics*)Engine::GetCore()->GetSystem(ST_Graphics);
    gSys->AddDebugModel(this);

    Input* input = (Input*) Engine::GetCore()->GetSystem(ST_Input);
    InputHandler* handler = input->GetHandler();
    Transform* tr = (Transform*)GetSibling(CT_Transform);
    PhysicsComponent* phys = (PhysicsComponent*) GetSibling(CT_PhysicsComponent);
    if(handler->Check("MoveRight"))
    {
      tr->SetPosition(tr->GetPosition() + Vector3(1.0f,0.0f,0.0f) * dt);
      phys->Reset();
    }
    Model* newModel = gSys->GetModel(model_);
    if(newModel && base_ != newModel)
    {
      base_->RemoveInstance(this);
      base_ = newModel;
      base_->AddInstance(this);
    }


  }
Beispiel #29
0
void gameInputTest(unsigned long vkCode) {
	GameActor* actor = new GameActor();
	InputHandler* inputHandler = new InputHandler();
	inputHandler->setInput();
	
	Command* command;
	if (vkCode == 88)
	{
		command = inputHandler->handleInput(kButtonX);
	}
	else if (vkCode == 89)
	{
		command = inputHandler->handleInput(kButtonY);
	}
	else
	{
		command = NULL;
	}

	if (command)
	{
		command->excute(*actor);
	}
}
Beispiel #30
0
void Menu::input()
{
	InputHandler* input = InputHandler::getInstance();
	if (!once){
		//AudioManager::instance()->PlayGameSound("menuSong", false, 1, Vector2D(0, 0), 1);
		once = true;
	}
	
	
	if (m_state == MENUSTATE::READY)
	{
		if (input->isPressed(InputHandler::DPAD_DOWN))
		{
			AudioManager::instance()->PlayGameSound("select", false, 0.3f, m_curr->getPosition(), 1);
			nextElement();
			
		}
		else if (input->isPressed(InputHandler::DPAD_UP))
		{
			AudioManager::instance()->PlayGameSound("select", false, 0.3f, m_curr->getPosition(), 1);
			previousElement();
			
		}
		else if (input->isPressed(InputHandler::DPAD_RIGHT))
		{
			AudioManager::instance()->PlayGameSound("select", false, 0.3f, m_curr->getPosition(), 1);
			previousElement();

		}
		else if (input->isPressed(InputHandler::DPAD_LEFT))
		{
			AudioManager::instance()->PlayGameSound("select", false, 0.3f, m_curr->getPosition(), 1);
			previousElement();

		}
		else if (input->isPressed(InputHandler::A))
		{
			AudioManager::instance()->PlayGameSound("click", false, 0.3f, m_curr->getPosition(), 1);
			m_curr->invoke();
		}
	}
}