Example #1
0
bool InputHandler::isHeldDown(const sf::Input& input, std::string control)
{
	//b1 : a corresponding key has been pressed
	//b2 : a corresponding mouse button has been pressed
	bool b1 = false, b2 = false;
	unsigned int i;

	std::map<std::string, std::vector<sf::Key::Code>>::iterator it1 = boundKeys.find(control);
	if(it1 != boundKeys.end()) //if the control is found in the map
	{
		i = 0;
		while(i < it1->second.size() && !b1)
		{
			b1 = input.IsKeyDown(it1->second.at(i));
			i++;
		}
	}

	std::map<std::string, std::vector<sf::Mouse::Button>>::iterator it2 = boundMouseButtons.find(control);
	if(it2 != boundMouseButtons.end()) //if the control is found in the map
	{
		i = 0;
		while(i < it2->second.size() && !b2)
		{
			b2 = input.IsMouseButtonDown(it2->second.at(i));
			i++;
		}
	}
	return (b1 || b2);
}
Example #2
0
bool Slider::relayEvents(sf::Event const &event, sf::Input const &input) {
    if (WidgetBase::relayEvents(event, input)) { // evenement capture : traitement
	if (input.IsMouseButtonDown(sf::Mouse::Left)) {
	    // on doit deplacer le curseur en consequence et modifier la valeur du slider
	    float px = input.GetMouseX();
	    float d = _max - _min;
	    float w = _frame.getWidth() / d;
	    int value = (px - _frame.getPX() + w/2) / w + _min; // valeur pointee par le curseur
	    setValue(value);

            // notification
            if (_pListener)
                _pListener->notifyChangedValue(*this);
	}
	return true;
    }

    return false;
}