~gunchleoc/widelands/bug-1818494-ingame-zoom-freezes

« back to all changes in this revision

Viewing changes to src/input.h

  • Committer: sirver
  • Date: 2002-02-05 20:54:08 UTC
  • Revision ID: git-v1:df384fd3a5e53be1f37803d1c0381fa993844bf5
Initial revision


git-svn-id: https://widelands.svn.sourceforge.net/svnroot/widelands/trunk@2 37b2a8de-5219-0410-9f54-a31bc463ab9c

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2001 by Holger Rapp 
 
3
 * 
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 * 
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 * 
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 *
 
18
 */
 
19
 
 
20
#ifndef __S__INPUT_H
 
21
#define __S__INPUT_H
 
22
 
 
23
typedef void (*MOUSE_CLICK_FUNCTION)(const bool, void*);
 
24
typedef void (*MOUSE_MOVE_FUNCTION)(const unsigned int, const unsigned int, const signed int, const signed int, void*);
 
25
typedef void (*KBD_HANDLER)(const char*, void*);
 
26
 
 
27
#include "singleton.h"
 
28
 
 
29
/** class Input 
 
30
 *
 
31
 * This class cares for mouse and keyboard input
 
32
 * You register the functions, that should be called on several input
 
33
 * states and the class makes sure that they get checked
 
34
 *
 
35
 * It's a singleton
 
36
 */
 
37
class Input : public Singleton<Input> {
 
38
                  Input(const Input&);
 
39
                  Input& operator=(const Input&);
 
40
 
 
41
                  public:
 
42
                                         Input();
 
43
                                         ~Input();
 
44
 
 
45
                                         enum   Button {
 
46
                                                                BUT1,
 
47
                                                                BUT2
 
48
                                         };
 
49
 
 
50
                                         void register_mmf(const MOUSE_MOVE_FUNCTION, void* = 0);
 
51
                                         void register_mcf(const MOUSE_CLICK_FUNCTION, const Button, void* = 0);
 
52
                                         void register_kbdh(const KBD_HANDLER, void* = 0);
 
53
                                         void set_mouse_pos(const unsigned int, const unsigned int);
 
54
                                         void handle_pending_input(void);
 
55
                                         void grab_input(const bool);
 
56
                                         void swap_buttons(const bool);
 
57
                                         void set_mouse_speed(const unsigned int);
 
58
                                         void set_max_cords(const unsigned int, const unsigned int);
 
59
 
 
60
                                         /** inline bool Input::should_die(void) 
 
61
                                          *
 
62
                                          * This functions indicate if the user requested by user input to exit
 
63
                                          * (By clicking the Close button in the menu bar e.g.)
 
64
                                          *
 
65
                                          * Args: None
 
66
                                          * Returns: if the app should die
 
67
                                          */
 
68
                                         inline bool should_die(void) { return bshould_die; }
 
69
                                         
 
70
                                         /** inline unsigned int Input::get_mpx(void) 
 
71
                                          *
 
72
                                          * This returns the X mouse pos
 
73
                                          * 
 
74
                                          * Args: None
 
75
                                          * Returns: mouse x cord
 
76
                                          */
 
77
                                         inline unsigned int get_mpx(void) { return mpx; }
 
78
 
 
79
                                         /** inline unsigned int Input::get_mpy(void) 
 
80
                                          *
 
81
                                          * This returns the Y mouse pos
 
82
                                          * 
 
83
                                          * Args: None
 
84
                                          * Returns: mouse y cord
 
85
                                          */
 
86
                                         inline unsigned int get_mpy(void) { return mpy; }
 
87
 
 
88
                                         /** inline bool Input::is_but_pressed(const Button b) 
 
89
                                          *
 
90
                                          * Checks if a button is pressed
 
91
                                          *
 
92
                                          * Args: b     button to check
 
93
                                          * Returns: true if button is pressed
 
94
                                          */
 
95
                                         inline bool is_but_pressed(const Button b) { if(b==BUT1) return b1_pressed; else return b2_pressed; }
 
96
                 
 
97
                  private:
 
98
                                        MOUSE_CLICK_FUNCTION cf[2];
 
99
                                        MOUSE_MOVE_FUNCTION mmf;
 
100
                                        void* cfa[2];
 
101
                                        void* mmfa;
 
102
                                        KBD_HANDLER kbdh;
 
103
                                        void *kbdha;
 
104
                                        unsigned int mpx, mpy, mplx, mply;
 
105
                                        float mouse_speed;
 
106
                                        unsigned int maxx, maxy;
 
107
                                        bool buts_swapped;
 
108
                                        bool input_grabbed;
 
109
                                        bool b1_pressed, b2_pressed;
 
110
                                        bool bshould_die;
 
111
};
 
112
 
 
113
#define g_ip    Input::get_singleton()
 
114
 
 
115
#endif /* __S__INPUT_H */