| 1 |
/* LICENSE BLOCK |
|---|
| 2 |
Part of mde: a Modular D game-oriented Engine |
|---|
| 3 |
Copyright © 2007-2008 Diggory Hardy |
|---|
| 4 |
|
|---|
| 5 |
This program is free software: you can redistribute it and/or modify it under the terms |
|---|
| 6 |
of the GNU General Public License as published by the Free Software Foundation, either |
|---|
| 7 |
version 2 of the License, or (at your option) any later version. |
|---|
| 8 |
|
|---|
| 9 |
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|---|
| 10 |
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 11 |
See the GNU General Public License for more details. |
|---|
| 12 |
|
|---|
| 13 |
You should have received a copy of the GNU General Public License |
|---|
| 14 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
|---|
| 15 |
|
|---|
| 16 |
/** Handling for all events from SDL_PollEvent. |
|---|
| 17 |
* |
|---|
| 18 |
* Handles some events, including a quit-request and window resizing, and passes the rest on to the |
|---|
| 19 |
* input system. */ |
|---|
| 20 |
module mde.events; |
|---|
| 21 |
|
|---|
| 22 |
import imde = mde.imde; |
|---|
| 23 |
import mde.setup.Screen; |
|---|
| 24 |
import mde.input.Input; |
|---|
| 25 |
|
|---|
| 26 |
import derelict.sdl.events; |
|---|
| 27 |
import tango.time.Time; |
|---|
| 28 |
import tango.util.log.Log : Log, Logger; |
|---|
| 29 |
|
|---|
| 30 |
private Logger logger; |
|---|
| 31 |
static this() { |
|---|
| 32 |
logger = Log.getLogger ("mde.events"); |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
void pollEvents (TimeSpan) { |
|---|
| 36 |
SDL_Event event; |
|---|
| 37 |
while (SDL_PollEvent (&event)) { |
|---|
| 38 |
switch (event.type) { |
|---|
| 39 |
case SDL_QUIT: |
|---|
| 40 |
logger.info ("Quit requested"); |
|---|
| 41 |
imde.run = false; |
|---|
| 42 |
break; |
|---|
| 43 |
case SDL_VIDEORESIZE: |
|---|
| 44 |
Screen.resizeEvent (event.resize.w, event.resize.h); |
|---|
| 45 |
imde.mainSchedule.request(imde.SCHEDULE.DRAW); |
|---|
| 46 |
break; |
|---|
| 47 |
case SDL_ACTIVEEVENT: |
|---|
| 48 |
case SDL_VIDEOEXPOSE: |
|---|
| 49 |
imde.mainSchedule.request(imde.SCHEDULE.DRAW); |
|---|
| 50 |
break; |
|---|
| 51 |
default: |
|---|
| 52 |
try { |
|---|
| 53 |
if (!imde.input (event)) |
|---|
| 54 |
logger.warn ("Unrecognised event with code {}", event.type); |
|---|
| 55 |
} catch (Exception e) { |
|---|
| 56 |
logger.error ("Caught input exception; event will be ignored. Exception was:"); |
|---|
| 57 |
logger.error (e.msg); |
|---|
| 58 |
} |
|---|
| 59 |
} |
|---|
| 60 |
} |
|---|
| 61 |
} |
|---|