source: trunk/src/sdlinput.cpp @ 149

Last change on this file since 149 was 149, checked in by sam, 10 years ago

Get the timer to talk milliseconds instead of seconds.

  • Property svn:keywords set to Id
File size: 1.3 KB
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
4//
5
6#if defined HAVE_CONFIG_H
7#   include "config.h"
8#endif
9
10#include <SDL.h>
11
12#include "sdlinput.h"
13
14/*
15 * SDL Input implementation class
16 */
17
18class SdlInputData
19{
20    friend class SdlInput;
21
22private:
23    Game *game;
24};
25
26/*
27 * Public SdlInput class
28 */
29
30SdlInput::SdlInput(Game *game)
31{
32    SDL_Init(SDL_INIT_TIMER);
33
34    data = new SdlInputData();
35    data->game = game;
36}
37
38Entity::Group SdlInput::GetGroup()
39{
40    return GROUP_BEFORE;
41}
42
43void SdlInput::TickGame(float deltams)
44{
45    Entity::TickGame(deltams);
46
47    if (data->game->Finished())
48        destroy = 1;
49
50    /* Handle mouse input */
51    int mx, my;
52    SDL_GetMouseState(&mx, &my);
53    data->game->SetMouse(mx * (640 - 32) / 320 - 320, my * (480 - 32) / 240 - 240);
54
55    /* Handle keyboard and WM input */
56    SDL_Event event;
57    while (SDL_PollEvent(&event))
58    {
59        if (event.type == SDL_QUIT)
60            data->game->Quit();
61        if (event.type == SDL_KEYDOWN)
62        {
63            if (event.key.keysym.sym == SDLK_ESCAPE)
64                data->game->Quit();
65#if 0
66            else if (event.key.keysym.sym == SDLK_RETURN)
67                video->FullScreen();
68#endif
69        }
70    }
71
72}
73
74SdlInput::~SdlInput()
75{
76    delete data;
77}
78
Note: See TracBrowser for help on using the repository browser.