Hi!
I want a behaviour like this : (I also need to have generic events, no only sfml event) so I've a function pointer array for event conversions, now what I want is to be able to generates event for every keys which are pressed and to stop to generate events when keys are released, I also want to set up a timer for events repetition, so, I've start to encode something like this :
void SFMLWindow::checkEvents(void) {
sf::Event event;
while (m_window.pollEvent(event)) {
SystemEvent curr_sys_event(event.type);
m_current_mapper.setEvent(event);
m_current_mapper[curr_sys_event];
std::map<SystemEvent, IEventMapperManager::EventMapperID>::iterator it = m_mappers.find(curr_sys_event);
if (it == m_mappers.end()) {
SFMLEventMapper mapper;
mapper.setEvent(event);
m_mappers.insert(std::make_pair(curr_sys_event, m_eventManager.registerEventMapper(mapper)));
}
for (it = m_mappers.begin(); it != m_mappers.end();it++) {
SystemEvent sysEvent(event.type);
m_eventManager.changeCurrentMapping(it->second);
m_eventManager[sysEvent];
m_events.insert(m_events.begin(), sysEvent);
}
for (it = m_mappers.begin(); it != m_mappers.end();) {
if (event.type != sf::Event::KeyPressed && event.type != sf::Event::MouseButtonPressed) {
m_eventManager.deleteEventMapper(it->second);
it = m_mappers.erase(it);
} else {
it++;
}
}
if (event.type == sf::Event::KeyReleased || event.type == sf::Event::MouseButtonReleased) {
curr_sys_event.eventInfos.type = SystemEvent::Type::Pressed;
it = m_mappers.find(curr_sys_event);
m_eventManager.deleteEventMapper(it->second);
it = m_mappers.erase(it);
}
}
}
SystemEvent SFMLWindow::popEvent() {
checkEvents();
if (m_events.size() == 0) {
SystemEvent event(-1);
event.eventInfos.origin = SystemEvent::Origin::NoEvent;
event.eventInfos.typeID = SystemEvent::Type::NoType;
event.eventInfos.type = SystemEvent::Type::NoType;
event.paramTypeID = SystemEvent::Type::NoType;
return event;
} else {
SystemEvent event = m_events.back();
m_events.pop_back();
return event;
}
}
It seems to work fine for event conversion but I haven't tested yet for event repetition, and I haven't set up the timer yet.