source: trunk/src/sdlinput.cpp @ 112

Last change on this file since 112 was 103, checked in by sam, 11 years ago

Reimplement the SDL input as a ticked asset object.

  • 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 "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    data = new SdlInputData();
33
34    data->game = game;
35}
36
37Asset::Group SdlInput::GetGroup()
38{
39    return GROUP_BEFORE;
40}
41
42void SdlInput::TickGame(float delta_time)
43{
44    Asset::TickGame(delta_time);
45
46    if (data->game->Finished())
47        destroy = 1;
48
49    /* Handle mouse input */
50    int mx, my;
51    SDL_GetMouseState(&mx, &my);
52    data->game->SetMouse(mx * (640 - 32) / 640, my * (480 - 32) / 480);
53
54    /* Handle keyboard and WM input */
55    SDL_Event event;
56    while (SDL_PollEvent(&event))
57    {
58        if (event.type == SDL_QUIT)
59            data->game->Quit();
60        if (event.type == SDL_KEYDOWN)
61        {
62            if (event.key.keysym.sym == SDLK_ESCAPE)
63                data->game->Quit();
64#if 0
65            else if (event.key.keysym.sym == SDLK_RETURN)
66                video->FullScreen();
67#endif
68        }
69    }
70
71}
72
73SdlInput::~SdlInput()
74{
75    delete data;
76}
77
Note: See TracBrowser for help on using the repository browser.