source: golgotha/src/i4/device/key_man.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 3.8 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef I4_KEY_MAN_HH
10#define I4_KEY_MAN_HH
11
12
13
14#include "device/device.hh"
15#include "device/keys.hh"
16#include "memory/array.hh"
17#include "memory/binary_tree.hh"
18#include "time/time.hh"
19
20class i4_key_man_class : public i4_device_class
21{
22  int context_id;
23
24  struct context
25  {
26    char *name;
27    w16 modifiers_taken;  // in this context these modifiers cannot be used as combo-keys
28    w16 modifiers_used;
29    context() { modifiers_used=modifiers_taken=0; }
30  };
31
32  i4_array<context> *context_list;     // list of context's we've seen so far
33  i4_array<char *> *command_list;
34  i4_grow_heap_class *char_heap;
35  struct key_item
36  {
37    i4_key key;
38    w16 context_mask;
39    w16 command_id;
40
41    key_item *next;   
42    key_item *next_active;
43   
44    w8 command_active;;
45    w8 modifier_flags;
46
47    key_item(w16 context_mask, w16 command_id, w8 modifier_flags, i4_key key, key_item *next)
48      : context_mask(context_mask), command_id(command_id),
49        modifier_flags(modifier_flags), next(next), key(key)
50    {
51      command_active=0;
52    }
53  };
54 
55  key_item *keys[I4_NUM_KEYS];
56  key_item *active_list;
57
58  void add_active(i4_key_man_class::key_item *i, i4_time_class &time);
59  void get_modifiers(int k_mod);
60  void end_actives(int matches_key, i4_time_class &time);
61
62  void receive_event(i4_event *ev);
63  i4_bool process_events() { return i4_F; }
64  void check_init();
65  char *alloc_str(char *s);
66  int use_modifiers_for_contexts(int context_mask, int mod, char *key_name);
67  int acquire_modifiers_for_contexts(int context_mask, int mod, char *key_name);
68  w16 key_modifiers_pressed;
69  i4_bool loaded;
70
71public:
72  i4_bool control_pressed() { return (key_modifiers_pressed & I4_MODIFIER_CTRL) ? i4_T : i4_F; }
73  i4_bool alt_pressed() { return (key_modifiers_pressed & I4_MODIFIER_ALT) ? i4_T : i4_F; }
74  i4_bool shift_pressed() { return (key_modifiers_pressed & I4_MODIFIER_SHIFT) ? i4_T : i4_F; }
75
76
77  i4_key_man_class();
78
79  char *name() { return "key manager"; }
80  i4_bool load(const i4_const_str &filename);
81  void uninit();
82
83  int get_context_id(char *context);
84  int get_command_id(char *command);
85
86  void set_context(int _context_id) { context_id=_context_id; }
87  void set_context(char *context) {   set_context(get_context_id(context)); }
88
89  int current_context() { return context_id; }
90  char *context_name(int context) { return (*context_list)[context].name; }
91
92  i4_bool get_key_for_command(int command_id, i4_key &key, w16 &mod);
93  i4_bool get_key_for_command(char *command_name, i4_key &key, w16 &mod)
94  { return get_key_for_command(get_command_id(command_name), key, mod); }
95};
96
97
98
99class i4_key_matchup_class
100{
101  struct command_matchup
102  {
103    command_matchup *left, *right;
104    w16 command_id;
105    int remap_id;
106
107    command_matchup() {}
108    command_matchup(w16 command_id, int remap) : command_id(command_id), remap_id(remap) {}
109
110    int compare(const command_matchup *b) const
111    {
112      if (command_id>b->command_id)
113        return 1;
114      else if (command_id<b->command_id)
115        return -1;
116      else return 0;
117    }
118
119  };
120
121  i4_binary_tree<command_matchup> matchup; 
122
123public:
124  void add(char *command, int remap);
125  int remap(int command_id);
126
127  ~i4_key_matchup_class() { matchup.delete_tree(); }
128};
129
130extern i4_key_man_class i4_key_man;
131
132
133#endif
Note: See TracBrowser for help on using the repository browser.