source: trunk/src/sdlinput.cpp @ 236

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

Mouse button support in Lol Engine.

  • Property svn:keywords set to Id
File size: 1.8 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{
38    SDL_Init(SDL_INIT_TIMER);
39
40    data = new SdlInputData();
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        SDL_GetMouseState(&mouse.x, &mouse.y);
54    else
55        mouse.x = mouse.y = -1;
56    Input::SetMousePos(mouse);
57
58    /* Handle keyboard and WM events */
59    SDL_Event event;
60    while (SDL_PollEvent(&event))
61    {
62        if (event.type == SDL_QUIT)
63            Ticker::Shutdown();
64#if 0
65        else if (event.type == SDL_KEYDOWN)
66            Input::KeyPressed(event.key.keysym.sym, deltams);
67#endif
68        else if (event.type == SDL_MOUSEBUTTONDOWN)
69            Input::SetMouseButton(event.button.button - 1);
70        else if (event.type == SDL_MOUSEBUTTONUP)
71            Input::UnsetMouseButton(event.button.button - 1);
72    }
73
74    /* Send the whole keyboard state to the input system */
75#if 0
76    Uint8 *keystate = SDL_GetKeyState(NULL);
77    for (int i = 0; i < 256; i++)
78        if (keystate[i])
79            Input::KeyPressed(i, deltams);
80#endif
81}
82
83SdlInput::~SdlInput()
84{
85    delete data;
86}
87
Note: See TracBrowser for help on using the repository browser.