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

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 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: 4.6 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 __DEVICE_HPP_
10#define __DEVICE_HPP_
11
12#include "arch.hh"
13#include "error/error.hh"
14
15/*
16 
17  Creating and sending events :
18  -------------------
19  See event/event.hh
20
21 */
22
23class i4_event_handler_class;
24class i4_event;
25
26class i4_event_handler_class;
27
28
29// this class cannot be used directly, you must derive off of it with
30// the i4_event_handler_reference_class template (used to ensure type convience)
31class i4_event_handler_private_reference_class
32{
33protected:
34  friend class i4_event_handler_class;
35  i4_event_handler_class *ref;
36  i4_event_handler_private_reference_class *next;
37  void reference(i4_event_handler_class *who);      // if who is 0, then reference is destroyed 
38  void destroy_ref();
39public:
40  i4_event_handler_private_reference_class() { ref=0; }
41  ~i4_event_handler_private_reference_class() { destroy_ref(); }
42};
43
44template <class T>
45class i4_event_handler_reference_class : public i4_event_handler_private_reference_class
46{
47public:
48  T *get() { return (T *)ref; }
49  void reference(T *r)
50  {
51    i4_event_handler_private_reference_class::reference((i4_event_handler_class *)r);
52  }
53
54  T& operator*() const { return *((T *)ref); }
55  T* operator->() const { return (T *)ref; }
56  i4_event_handler_reference_class<T>& operator=(const i4_event_handler_reference_class<T> &r)
57  {
58    i4_event_handler_private_reference_class::reference((i4_event_handler_class *)r.ref);
59    return *this;
60  }
61
62  i4_event_handler_reference_class<T>& operator=(const T *ref)
63  {
64    i4_event_handler_private_reference_class::reference((i4_event_handler_class *)ref);
65    return *this;
66  }
67};
68
69// anything that wishes to receive events, must be derived from this
70// event handlers should be destroyed through the kernel (i4_kernel.delete_handler())
71// this will ensure that a referenced object is not destroyed.
72class i4_event_handler_class 
73{
74  friend class i4_event_handler_private_reference_class;
75  i4_event_handler_private_reference_class *first;
76public:
77  w16 call_stack_counter;                   // this ensures we are not deleted while running
78
79  i4_bool thinking() { return (i4_bool)(call_stack_counter!=0); }
80  i4_event_handler_class() { call_stack_counter=0; first=0; }
81  virtual void receive_event(i4_event *ev) { ; }
82  virtual ~i4_event_handler_class();
83
84  virtual char *name() = 0;
85};
86
87
88// this class is used to pass around an event handler/event pair
89// most gui objects use this to signal changes to other objects
90class i4_event_reaction_class
91{
92public:
93  i4_event_handler_reference_class<i4_event_handler_class> handler_reference;
94  i4_event                                                *event;
95
96  i4_event_reaction_class() { event=0; }
97
98  i4_event_reaction_class(i4_event_handler_class *handler,
99                          i4_event               *event);
100
101  i4_event_reaction_class(i4_event_handler_class *handler, w32 user_message_id);
102
103  i4_event_reaction_class *copy();
104  ~i4_event_reaction_class();
105
106};
107
108
109// anything that generates events should be derived from this
110class i4_device_class : public i4_event_handler_class   
111{
112protected:
113  i4_device_class *dev_list;
114
115  public:
116  void receive_event(i4_event *ev) {; }
117  enum
118  {
119    FLAG_MOUSE_MOVE          = 1,
120    FLAG_MOUSE_BUTTON_DOWN   = 2,
121    FLAG_MOUSE_BUTTON_UP     = 4,
122    FLAG_KEY_PRESS           = 8,
123    FLAG_KEY_RELEASE         = 16,
124    FLAG_DISPLAY_CHANGE      = 32,   // when display screen changes (size, location, etc).
125    FLAG_DISPLAY_CLOSE       = 64,
126    FLAG_SYSTEM_SIGNAL       = 128,
127    FLAG_IDLE                = 256,  // when no mouse or keyboard input sent after set interval
128    FLAG_DO_COMMAND          = 512,
129    FLAG_END_COMMAND         = 1024,
130    FLAG_DRAG_DROP_EVENTS    = 2048
131  };
132  typedef w32 device_flags;
133  i4_device_class *next;
134 
135  void send_event_to_agents(i4_event *ev, device_flags receive_types);
136  i4_device_class();
137
138  // ************* Implement these functions for each device *******************
139  virtual i4_bool process_events() = 0;       // returns true if an event was dispatched
140};
141
142#endif
Note: See TracBrowser for help on using the repository browser.