source: trunk/src/sdlinput.cpp @ 150

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

Replace mouse scrolling with a joystick simulated by the e/s/d/f keys.

  • 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 "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    Game *game;
25    int mx, my;
26};
27
28/*
29 * Public SdlInput class
30 */
31
32SdlInput::SdlInput(Game *game)
33{
34    SDL_Init(SDL_INIT_TIMER);
35
36    data = new SdlInputData();
37    data->game = game;
38    SDL_GetMouseState(&data->mx, &data->my);
39}
40
41Entity::Group SdlInput::GetGroup()
42{
43    return GROUP_BEFORE;
44}
45
46void SdlInput::TickGame(float deltams)
47{
48    Entity::TickGame(deltams);
49
50    if (data->game->Finished())
51        destroy = 1;
52
53    /* Handle mouse input */
54    SDL_GetMouseState(&data->mx, &data->my);
55
56    /* Handle keyboard and WM events */
57    SDL_Event event;
58    while (SDL_PollEvent(&event))
59    {
60        if (event.type == SDL_QUIT)
61            data->game->Quit();
62#if 0
63        else if (event.type == SDL_KEYDOWN)
64            Input::KeyPressed(event.key.keysym.sym, deltams);
65#endif
66    }
67
68    /* Send the whole keyboard state to the input system */
69#if 0
70    Uint8 *keystate = SDL_GetKeyState(NULL);
71    for (int i = 0; i < 256; i++)
72        if (keystate[i])
73            Input::KeyPressed(i, deltams);
74#endif
75}
76
77SdlInput::~SdlInput()
78{
79    delete data;
80}
81
Note: See TracBrowser for help on using the repository browser.