source: trunk/src/sdlinput.cpp @ 294

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

Rename Float3 to float3, Int3 to int3 etc. and add the 4-member versions.

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <SDL.h>
16
17#include "core.h"
18#include "sdlinput.h"
19
20/*
21 * SDL Input implementation class
22 */
23
24class SdlInputData
25{
26    friend class SdlInput;
27
28private:
29    int mx, my;
30};
31
32/*
33 * Public SdlInput class
34 */
35
36SdlInput::SdlInput()
37  : data(new SdlInputData())
38{
39    SDL_Init(SDL_INIT_TIMER);
40
41    SDL_GetMouseState(&data->mx, &data->my);
42
43    gamegroup = GAMEGROUP_BEFORE;
44}
45
46void SdlInput::TickGame(float deltams)
47{
48    Entity::TickGame(deltams);
49
50    /* Handle mouse input */
51    int2 mouse;
52    if (SDL_GetAppState() & SDL_APPMOUSEFOCUS)
53    {
54        SDL_GetMouseState(&mouse.x, &mouse.y);
55        mouse.y = Video::GetHeight() - 1 - mouse.y;
56    }
57    else
58        mouse.x = mouse.y = -1;
59    Input::SetMousePos(mouse);
60
61    /* Handle keyboard and WM events */
62    SDL_Event event;
63    while (SDL_PollEvent(&event))
64    {
65        if (event.type == SDL_QUIT)
66            Ticker::Shutdown();
67#if 0
68        else if (event.type == SDL_KEYDOWN)
69            Input::KeyPressed(event.key.keysym.sym, deltams);
70#endif
71        else if (event.type == SDL_MOUSEBUTTONDOWN)
72            Input::SetMouseButton(event.button.button - 1);
73        else if (event.type == SDL_MOUSEBUTTONUP)
74            Input::UnsetMouseButton(event.button.button - 1);
75    }
76
77    /* Send the whole keyboard state to the input system */
78#if 0
79    Uint8 *keystate = SDL_GetKeyState(NULL);
80    for (int i = 0; i < 256; i++)
81        if (keystate[i])
82            Input::KeyPressed(i, deltams);
83#endif
84}
85
86SdlInput::~SdlInput()
87{
88    delete data;
89}
90
Note: See TracBrowser for help on using the repository browser.