source: trunk/src/sdlinput.cpp @ 840

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

ps3: add a build-ps3 script that uses autoconf and automake.

  • Property svn:keywords set to Id
File size: 2.3 KB
RevLine 
[103]1//
[221]2// Lol Engine
[103]3//
[221]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//
[103]10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
[840]15#if defined USE_SDL
16#   include <SDL.h>
17#endif
[103]18
[150]19#include "core.h"
[103]20#include "sdlinput.h"
21
[686]22namespace lol
23{
24
[103]25/*
26 * SDL Input implementation class
27 */
28
29class SdlInputData
30{
31    friend class SdlInput;
32
33private:
[781]34    static vec2i GetMousePos();
[103]35};
36
37/*
38 * Public SdlInput class
39 */
40
[170]41SdlInput::SdlInput()
[259]42  : data(new SdlInputData())
[103]43{
[840]44#if defined USE_SDL
[117]45    SDL_Init(SDL_INIT_TIMER);
46
[210]47    gamegroup = GAMEGROUP_BEFORE;
[840]48#endif
[103]49}
50
[149]51void SdlInput::TickGame(float deltams)
[103]52{
[840]53#if defined USE_SDL
[149]54    Entity::TickGame(deltams);
[103]55
56    /* Handle mouse input */
[781]57    vec2i mouse = SdlInputData::GetMousePos();;
[233]58    Input::SetMousePos(mouse);
[103]59
[150]60    /* Handle keyboard and WM events */
[103]61    SDL_Event event;
62    while (SDL_PollEvent(&event))
63    {
[781]64        switch (event.type)
65        {
66        case SDL_QUIT:
[170]67            Ticker::Shutdown();
[781]68            break;
[103]69#if 0
[781]70        case SDL_KEYDOWN:
[150]71            Input::KeyPressed(event.key.keysym.sym, deltams);
[781]72            break;
[103]73#endif
[781]74        case SDL_MOUSEBUTTONDOWN:
75        case SDL_MOUSEBUTTONUP:
76        {
77            vec2i newmouse = SdlInputData::GetMousePos();
78            if (newmouse != mouse)
79                Input::SetMousePos(mouse = newmouse);
80            if (event.type == SDL_MOUSEBUTTONDOWN)
81                Input::SetMouseButton(event.button.button - 1);
82            else
83                Input::UnsetMouseButton(event.button.button - 1);
84            break;
85        }
86        }
[103]87    }
88
[150]89    /* Send the whole keyboard state to the input system */
90#if 0
91    Uint8 *keystate = SDL_GetKeyState(NULL);
92    for (int i = 0; i < 256; i++)
93        if (keystate[i])
94            Input::KeyPressed(i, deltams);
95#endif
[840]96#endif
[103]97}
98
99SdlInput::~SdlInput()
100{
101    delete data;
102}
103
[781]104vec2i SdlInputData::GetMousePos()
105{
106    vec2i ret(-1, -1);
107
[840]108#if defined USE_SDL
[781]109    if (SDL_GetAppState() & SDL_APPMOUSEFOCUS)
110    {
111        SDL_GetMouseState(&ret.x, &ret.y);
112        ret.y = Video::GetSize().y - 1 - ret.y;
113    }
[840]114#endif
[781]115    return ret;
116}
117
[686]118} /* namespace lol */
119
Note: See TracBrowser for help on using the repository browser.