source: trunk/src/sdlinput.cpp @ 170

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

Properly implement program termination, including in the GTK program.

  • Property svn:keywords set to Id
File size: 1.2 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 "core.h"
13#include "sdlinput.h"
14
15/*
16 * SDL Input implementation class
17 */
18
19class SdlInputData
20{
21    friend class SdlInput;
22
23private:
24    int mx, my;
25};
26
27/*
28 * Public SdlInput class
29 */
30
31SdlInput::SdlInput()
32{
33    SDL_Init(SDL_INIT_TIMER);
34
35    data = new SdlInputData();
36    SDL_GetMouseState(&data->mx, &data->my);
37}
38
39Entity::Group SdlInput::GetGroup()
40{
41    return GROUP_BEFORE;
42}
43
44void SdlInput::TickGame(float deltams)
45{
46    Entity::TickGame(deltams);
47
48    /* Handle mouse input */
49    SDL_GetMouseState(&data->mx, &data->my);
50
51    /* Handle keyboard and WM events */
52    SDL_Event event;
53    while (SDL_PollEvent(&event))
54    {
55        if (event.type == SDL_QUIT)
56            Ticker::Shutdown();
57#if 0
58        else if (event.type == SDL_KEYDOWN)
59            Input::KeyPressed(event.key.keysym.sym, deltams);
60#endif
61    }
62
63    /* Send the whole keyboard state to the input system */
64#if 0
65    Uint8 *keystate = SDL_GetKeyState(NULL);
66    for (int i = 0; i < 256; i++)
67        if (keystate[i])
68            Input::KeyPressed(i, deltams);
69#endif
70}
71
72SdlInput::~SdlInput()
73{
74    delete data;
75}
76
Note: See TracBrowser for help on using the repository browser.