summaryrefslogtreecommitdiff
path: root/src/keyboard.cpp
blob: 8c94c68a81951551ecdcd7b6c32b6ee8624bef73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "keyboard.h"

Keyboard::Keyboard(){
    nop = new Nop;

    pressedDown   = new KeyboardDownPressed;
    releasedDown  = new KeyboardDownReleased;
    pressedLeft   = new KeyboardLeftPressed;
    pressedRight  = new KeyboardRightPressed;
    pressedSpace  = new KeyboardSpacePressed;
}
Keyboard::~Keyboard(){
    delete nop;
    delete pressedDown;
    delete releasedDown;
    delete pressedLeft;
    delete pressedRight;
    delete pressedSpace;
}

Command* Keyboard::handleEvent( SDL_Event e ){
    switch( e.type ){
    case SDL_KEYDOWN:
        return pressed( e.key.keysym.sym, e.key.keysym.mod );
    case SDL_KEYUP:
        return released( e.key.keysym.sym, e.key.keysym.mod );
    default:
        return nop;
    }
}

Command* Keyboard::pressed( SDL_Keycode k, Uint16 mod ){
    switch(k){
        case SDLK_DOWN:
            return pressedDown;
        case SDLK_LEFT:
            return pressedLeft;
        case SDLK_RIGHT:
            return pressedRight;
        case SDLK_SPACE:
            return pressedSpace;
        default:
            return nop;
    }
}

Command* Keyboard::released( SDL_Keycode k, Uint16 mod ){
    switch(k){
        case SDLK_DOWN:
            return releasedDown;
        default:
            return nop;
    }
}