Пример #1
0
void Control::mouseEvent(KeyState state, Keys key, int x, int y) {
	if(_keys[key] == state) return;
	setMouseX(x, key);
	setMouseY(y, key);

	_keys[key] = state;
	state = state == STATE_NO_PRESSED ? STATE_UP : STATE_DOWN;

	if(key >= MOUSE_LEFT && key <= MOUSE_BUTTON_5) {
		switch(state) {
		case STATE_UP:
			for(std::vector<Hud*>::const_iterator it = _huds.begin(); it != _huds.end(); it++)
				reinterpret_cast<Hud*>(*it)->end(key);
			break;
		case STATE_DOWN:
			for(std::vector<Hud*>::const_iterator it = _huds.begin(); it != _huds.end(); it++)
				reinterpret_cast<Hud*>(*it)->start(getMouseX(key), getMouseY(key), key);
			break;
		default: break;
		}
	}

	for(std::vector<Event>::iterator it = _events.begin(); it != _events.end(); it++) {
		Event e = *it;
		if(e.key == key && (state == e.state || e.state == STATE_ANY))
			callCallBack(e.instance, e.callback, state, key, getMouseX(e.key), getMouseY(e.key));
	}
}
Пример #2
0
void Checkbox::pressed()
{
    INF ( "Widget <" << getName() << "> has been pressed." );
    if(selected) {
        selected = false;
        checked->setVisibility(selected);
        if(callbackDeselected)
            callCallBack ( getName(), callbackDeselected->c_str() );
    } else {
        selected = true;
        checked->setVisibility(selected);
        if(callbackSelected)
            callCallBack ( getName(), callbackSelected->c_str() );
    }
    if(animationName)
        callAnimate ( this, animationName->c_str() );
}
Пример #3
0
void Control::keyboardEvent(KeyState state, Keys key) {
	if(_keys[key] == state) return;

	_keys[key] = state;
	state = state == STATE_NO_PRESSED ? STATE_UP : STATE_DOWN;

	for(std::vector<Event>::iterator it = _events.begin(); it != _events.end(); it++) {
		Event e = *it;
		if(e.key == key && (state == e.state || e.state == STATE_ANY))
			callCallBack(e.instance, e.callback, state, key, getMouseX(e.key), getMouseY(e.key));
	}
}
Пример #4
0
void Control::idle() {
	if(getCurrentTime() < _lastIdleTime + 50) return;
	_lastIdleTime = getCurrentTime();

	for(std::vector<Event>::const_iterator it = _events.begin(); it != _events.end(); it++) {
		Event e = *it;
		if(e.key == NO_KEY) continue;
		if(((_keys[e.key] == STATE_NO_PRESSED || _keys[e.key] == STATE_PRESSED)
							&& e.state == _keys[e.key]) || e.state == STATE_ANY)
			callCallBack(e.instance, e.callback, _keys[e.key], e.key, getMouseX(e.key), getMouseY(e.key));
	}
}
Пример #5
0
void Control::mouseMoveEvent(int x, int y, int pointer) {
	if(!_multiPointer) pointer = MOUSE_LEFT;
	setMouseX(x, pointer);
	setMouseY(y, pointer);

	if(isKeyPressed(static_cast<Control::Keys>(pointer))) {
		for(std::vector<Hud*>::const_iterator it = _huds.begin(); it != _huds.end(); it++)
			reinterpret_cast<Hud*>(*it)->update(getMouseX(pointer), getMouseY(pointer), pointer);
	}

	for(std::vector<Event>::iterator it = _events.begin(); it != _events.end(); it++) {
		Event e = *it;
		if(e.state == STATE_MOUSE_MOVE && isKeyPressed(e.key))
			callCallBack(e.instance, e.callback, STATE_MOUSE_MOVE, e.key, x, y);
	}
}