Tscope5
mouse_internal.c
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // __ ______
4 // / /_______________ ____ ___ / ____/
5 // / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
6 // / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
7 // \__/____/\___/\____/ .___/\___/ /_____/
8 // /_/
9 //
10 /// \file mouse_internal.c
11 /// Definitions of internal mouse functions.
12 ////////////////////////////////////////////////////////////////////////////////
13 
14 #include "../include/tscope5/mouse_internal.h"
15 #include "../include/tscope5/system_internal.h"
16 #include "../include/tscope5/timer_internal.h"
17 #include "../include/tscope5/graphics_internal.h"
18 
19 /// Is the mouse subsystem installed?
21 
22 
23 ////////////////////////////////////////////////////////////////////////////////
24 /// Do some checks at the start of each mouse function.
25 ///
26 /// \param calling_function Name the function that calls for
27 /// this check or installation.
28 ///
29 /// Checks whether tscope5 is installed. If not, the program is aborted.
30 ///
31 /// Checks whether a is display installed. If not, the program is aborted.
32 ///
33 /// Checks whether the mouse subsystem installed.
34 /// If not, the mouse subsystem is installed.
35 ////////////////////////////////////////////////////////////////////////////////
36 void ts5_check_mouse(char *calling_function)
37 {
38  ts5_log(TS5_LOGLEVEL_6, "%s: ts5_check_mouse\n", calling_function);
39 
41  ts5_fatal("%s: Tscope5 not installed\n", calling_function);
42  }
43 
44  if (_ts5_status.active_display == -1) {
45  ts5_fatal("%s: no active display available\n", calling_function);
46  }
47 
49  ts5_install_mouse(calling_function);
50  }
51 }
52 
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// Install the mouse subsystem.
56 ///
57 /// \param calling_function Name the function that calls for
58 /// this check or installation.
59 ///
60 /// This function is called automatically if necessary.
61 ////////////////////////////////////////////////////////////////////////////////
62 void ts5_install_mouse(char *calling_function)
63 {
65  ts5_install_timer(calling_function);
66  }
67 
69 
71  ts5_log(TS5_LOGLEVEL_1, "%s: Installing Tscope5 mouse\n",
72  calling_function);
73 
74  if (!al_install_mouse()) {
75  ts5_fatal("%s: could not install Tscope5 mouse\n",
76  calling_function);
77  }
78 
79  al_register_event_source(_ts5_data.timer.response_queue,
80  al_get_mouse_event_source());
81 
82  _ts5_status.timer.mouse.num_buttons = al_get_mouse_num_buttons();
83  _ts5_status.timer.mouse.num_defined_buttons = 0;
84  _ts5_status.timer.mouse.num_active_buttons = 0;
85 
86  _ts5_status.timer.mouse.button_press_defined =
87  (int *)al_malloc(sizeof(int)*_ts5_status.timer.mouse.num_buttons);
88 
89  _ts5_status.timer.mouse.button_press_active =
90  (int *)al_malloc(sizeof(int)*_ts5_status.timer.mouse.num_buttons);
91 
92  _ts5_status.timer.mouse.button_release_defined =
93  (int *)al_malloc(sizeof(int)*_ts5_status.timer.mouse.num_buttons);
94 
95  _ts5_status.timer.mouse.button_release_active =
96  (int *)al_malloc(sizeof(int)*_ts5_status.timer.mouse.num_buttons);
97 
98  int i;
99  for (i=0; i<_ts5_status.timer.mouse.num_buttons; i++) {
100  _ts5_status.timer.mouse.button_press_defined[i] = 0;
101  _ts5_status.timer.mouse.button_press_active[i] = 0;
102  _ts5_status.timer.mouse.button_release_defined[i] = 0;
103  _ts5_status.timer.mouse.button_release_active[i] = 0;
104  }
105 
106  atexit(ts5_uninstall_mouse);
107  }
108 }
109 
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Uninstall the mouse subsystem.
113 ///
114 /// This function is called automatically at the end of the program.
115 ////////////////////////////////////////////////////////////////////////////////
117 {
119 
120  ts5_log(TS5_LOGLEVEL_1, "Uninstalling Tscope5 mouse\n");
121 
122  _ts5_status.timer.mouse.num_buttons = 0;
123  _ts5_status.timer.mouse.num_defined_buttons = 0;
124  _ts5_status.timer.mouse.num_active_buttons = 0;
125 
126  al_free(_ts5_status.timer.mouse.button_press_defined);
127  _ts5_status.timer.mouse.button_press_defined = NULL;
128 
129  al_free(_ts5_status.timer.mouse.button_press_active);
130  _ts5_status.timer.mouse.button_press_active = NULL;
131 
132  al_free(_ts5_status.timer.mouse.button_release_defined);
133  _ts5_status.timer.mouse.button_release_defined = NULL;
134 
135  al_free(_ts5_status.timer.mouse.button_release_active);
136  _ts5_status.timer.mouse.button_release_active = NULL;
137 
138  _ts5_status.timer.mouse_is_response_device = 0;
139 
140  al_unregister_event_source(_ts5_data.timer.response_queue,
141  al_get_mouse_event_source());
142 
143  al_uninstall_mouse();
144 
146  }
147 }
148 
int _ts5_is_tscope5_installed
Is Tscope5 installed?
int _ts5_is_timer_installed
Is the timer subsystem installed?
void ts5_install_mouse(char *calling_function)
Install the mouse subsystem.
int _ts5_is_mouse_installed
Is the mouse subsystem installed?
void ts5_install_timer(char *calling_function)
Install the timer subsystem.
void ts5_log(const unsigned int level, const char *format,...)
Send info to a logging window.
Definition: system.c:45
void ts5_check_mouse(char *calling_function)
Do some checks at the start of each mouse function.
void ts5_fatal(const char *format,...)
Exit safely with an error message.
Definition: system.c:533
void ts5_uninstall_mouse()
Uninstall the mouse subsystem.