File: fweelin_sdlio.h

package info (click to toggle)
freewheeling 0.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,244 kB
  • sloc: cpp: 24,079; xml: 3,631; ansic: 1,818; sh: 1,232; makefile: 31
file content (122 lines) | stat: -rw-r--r-- 2,965 bytes parent folder | download | duplicates (2)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef __FWEELIN_SDLIO_H
#define __FWEELIN_SDLIO_H

/* Copyright 2004-2011 Jan Pekau
   
   This file is part of Freewheeling.
   
   Freewheeling is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 2 of the License, or
   (at your option) any later version.
   
   Freewheeling is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with Freewheeling.  If not, see <http://www.gnu.org/licenses/>. */

#include <pthread.h>

#include "fweelin_event.h"

#ifdef __MACOSX__
#include "FweelinMac.h"
#endif

class Fweelin;

// Deprecated!
class KeySettings {
 public:
  KeySettings() :
    leftshift(0), rightshift(0), leftctrl(0), rightctrl(0),
    leftalt(0), rightalt(0), upkey(0), downkey(0), spacekey(0) {};

  // Function modifier keys
  char leftshift,
    rightshift,
    leftctrl,
    rightctrl,
    leftalt,
    rightalt,
    upkey,
    downkey,
    spacekey;
};

class SDLKeyList {
 public:
  SDLKeyList (SDLKey k) : k(k), next(0) {};

  SDLKey k;
  SDLKeyList *next;
};

// SDL Input Handler
class SDLIO : public EventProducer, public EventListener {
public:
  SDLIO (Fweelin *app) : app(app), sdlthreadgo(0) {
    keyheld = new char[SDLK_LAST];
    for (int i = 0; i < SDLK_LAST; i++)
      keyheld[i] = 0;
  };
  virtual ~SDLIO() { 
    delete[] keyheld;
  };

  int activate ();
  void close ();

  char IsActive () { return sdlthreadgo; };
  char *GetKeysHeld () { return keyheld; };

  KeySettings *getSETS() { return &sets; };

  void ReceiveEvent(Event *ev, EventProducer *from);

  // We use slightly modified keynames for the config system:
  // Gets the SDL keysym that corresponds to key with a given name
  static SDLKey GetSDLKey(char *keyname);
  // And the name corresponding to the keysym..
  static const char *GetSDLName(SDLKey sym);

  inline void EnableUNICODE(int enable) { SDL_EnableUNICODE(enable); };
  inline void EnableKeyRepeat(int enable) { 
    if (enable)
      SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
                          SDL_DEFAULT_REPEAT_INTERVAL);
    else 
      SDL_EnableKeyRepeat(0,0);
  };

  // SDL event handler thread
  static void *run_sdl_thread (void *ptr);

protected:
#ifdef __MACOSX__
  FweelinMac cocoa; // Cocoa thread setup
#endif

  // Core app
  Fweelin *app;

  // Joysticks
  int numjoy;           // Number of joysticks
  SDL_Joystick **joys;  // Control structure for each joystick

  // Keys currently held down- array for all SDLKeys, nonzero if held
  char *keyheld;

  // Deprecated
  KeySettings sets;

  void handle_key(int keycode, char press);

  pthread_t sdl_thread;
  char sdlthreadgo;
};

#endif