| 1 |
/*************************************************************************** |
| 2 |
eventmanager.cpp - description |
| 3 |
------------------- |
| 4 |
begin : Fri Sep 15 2000 |
| 5 |
copyright : (C) 2000 by Waldemar Baraldi |
| 6 |
email : [email protected] |
| 7 |
***************************************************************************/ |
| 8 |
|
| 9 |
/*************************************************************************** |
| 10 |
* * |
| 11 |
* This program is free software; you can redistribute it and/or modify * |
| 12 |
* it under the terms of the GNU General Public License as published by * |
| 13 |
* the Free Software Foundation; either version 2 of the License, or * |
| 14 |
* (at your option) any later version. * |
| 15 |
* * |
| 16 |
***************************************************************************/ |
| 17 |
|
| 18 |
#include "eventmanager.h" |
| 19 |
|
| 20 |
EventManager::EventManager(){ |
| 21 |
|
| 22 |
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); |
| 23 |
SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE); |
| 24 |
SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE); |
| 25 |
SDL_EventState(SDL_KEYUP, SDL_IGNORE); |
| 26 |
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
| 27 |
lista_streams=new List(); |
| 28 |
} |
| 29 |
|
| 30 |
EventManager::~EventManager(){ |
| 31 |
lista_streams->empty(true); |
| 32 |
delete lista_streams; |
| 33 |
} |
| 34 |
|
| 35 |
void EventManager::addStream(EventStream * s){ |
| 36 |
lista_streams->insert(lista_streams->getEnd(), s); |
| 37 |
} |
| 38 |
|
| 39 |
void EventManager::removeStream(EventStream * s){ |
| 40 |
lista_streams->remove(lista_streams->indexOf(s)); |
| 41 |
} |
| 42 |
|
| 43 |
void EventManager::pumpEvents(bool wait=false){ |
| 44 |
SDL_Event event; |
| 45 |
Index * stream; |
| 46 |
bool got=false; |
| 47 |
|
| 48 |
do{ |
| 49 |
while (SDL_PollEvent(&event)>0){ |
| 50 |
got=true; |
| 51 |
switch (event.type){ |
| 52 |
case SDL_KEYDOWN:{ |
| 53 |
stream=lista_streams->getFirst(); |
| 54 |
while ((stream!=lista_streams->getEnd()) && |
| 55 |
((EventStream*)(lista_streams->getObject(stream)))->put(event.key.keysym.sym)){ |
| 56 |
stream=lista_streams->getNext(stream); |
| 57 |
} |
| 58 |
} |
| 59 |
default:break; |
| 60 |
} |
| 61 |
} |
| 62 |
if (wait && !got) SDL_WaitEvent(NULL); |
| 63 |
}while (wait && !got); |
| 64 |
} |
| 65 |
|