1 // Copyright (c) <2012> <Leif Asbrink>
2 //
3 // Permission is hereby granted, free of charge, to any person
4 // obtaining a copy of this software and associated documentation
5 // files (the "Software"), to deal in the Software without restriction,
6 // including without limitation the rights to use, copy, modify,
7 // merge, publish, distribute, sublicense, and/or sell copies of
8 // the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
22
23
24 #include "globdef.h"
25 #include "uidef.h"
26 #include "screendef.h"
27 #include "keyboard_def.h"
28 #include "rusage.h"
29 #include "thrdef.h"
30
31
check_mouse_actions(void)32 void check_mouse_actions(void)
33 {
34 int i, task_info;
35 if(kill_all_flag) return;
36 if(mouse_inhibit || mouse_task != -1)return;
37 if( rbutton_state == new_rbutton_state &&
38 lbutton_state == new_lbutton_state )return;
39 task_info=0;
40 if(new_rbutton_state==1 && rbutton_state==0)
41 {
42 task_info=GRAPH_RIGHTPRESSED;
43 }
44 else
45 {
46 if(new_lbutton_state==1 && lbutton_state==0)
47 {
48 task_info=0;
49 }
50 else
51 {
52 goto mouseact_x;
53 }
54 }
55 for(i=0; i<no_of_scro; i++)
56 {
57 if(scro[i].no != METER_GRAPH || mg_flag != 0)
58 {
59 if( scro[i].x1 <= mouse_x &&
60 scro[i].x2 >= mouse_x &&
61 scro[i].y1 <= mouse_y &&
62 scro[i].y2 >= mouse_y)
63 {
64 mouse_task=scro[i].no+task_info;
65 }
66 }
67 }
68 mouseact_x:;
69 lir_sched_yield();
70 if( (mouse_task&GRAPH_MASK) > MAX_WIDEBAND_GRAPHS ||
71 (ui.network_flag&NET_RXIN_FFT1) != 0)
72 {
73 lir_set_event(EVENT_FFT1_READY);
74 }
75 else
76 {
77 lir_set_event(EVENT_TIMF1);
78 }
79 }
80
set_button_states(void)81 void set_button_states(void)
82 {
83 if( (mouse_task&GRAPH_RIGHTPRESSED) == 0)
84 {
85 if (lbutton_state==0)
86 {
87 if (leftpressed==BUTTON_IDLE)
88 {
89 leftpressed = BUTTON_PRESSED;
90 lbutton_state=1;
91 }
92 }
93 else
94 {
95 if(new_lbutton_state == 0)
96 {
97 if(leftpressed==BUTTON_PRESSED)
98 {
99 leftpressed = BUTTON_RELEASED;
100 lbutton_state=0;
101 }
102 }
103 }
104 }
105 else
106 {
107 if(rbutton_state==0)
108 {
109 if (rightpressed==BUTTON_IDLE)
110 {
111 rightpressed = BUTTON_PRESSED;
112 rbutton_state=1;
113 }
114 }
115 else
116 {
117 if(new_rbutton_state == 0)
118 {
119 if(rightpressed==BUTTON_PRESSED)
120 {
121 rightpressed = BUTTON_RELEASED;
122 rbutton_state=0;
123 }
124 }
125 }
126 }
127 }
128
129
set_button_coordinates(void)130 void set_button_coordinates(void)
131 {
132 mouse_x=new_mouse_x;
133 mouse_y=new_mouse_y;
134 if (new_lbutton_state!=0)
135 {
136 mouse_lbutton_x=new_mouse_x;
137 mouse_lbutton_y=new_mouse_y;
138 }
139 if (new_rbutton_state!=0)
140 {
141 mouse_rbutton_x=new_mouse_x;
142 mouse_rbutton_y=new_mouse_y;
143 }
144 }
145
open_mouse(void)146 void open_mouse(void)
147 {
148 mouse_task=-1;
149 mouse_hide_flag=1;
150 unconditional_hide_mouse();
151 leftpressed=0;
152 rightpressed=0;
153 mouse_active_flag=0;
154 mouse_inhibit=FALSE;
155 mouse_flag=1;
156 }
157
close_mouse(void)158 void close_mouse(void)
159 {
160 mouse_active_flag=0;
161 mouse_flag=0;
162 }
163
mouse_nothing(void)164 void mouse_nothing(void)
165 {
166 if(rightpressed == BUTTON_IDLE)
167 {
168 if(leftpressed == BUTTON_RELEASED)
169 {
170 leftpressed=BUTTON_IDLE;
171 mouse_active_flag=0;
172 }
173 }
174 else
175 {
176 if(rightpressed == BUTTON_RELEASED)
177 {
178 rightpressed=BUTTON_IDLE;
179 mouse_active_flag=0;
180 }
181 }
182 }
183
184
erase_numinput_txt(void)185 void erase_numinput_txt(void)
186 {
187 int i;
188 pause_screen_and_hide_mouse();
189 settextcolor(15);
190 numinput_txt[0]=1;
191 for(i=1; i<numinput_chars; i++)numinput_txt[i]=' ';
192 numinput_txt[numinput_chars]=0;
193 lir_pixwrite(numinput_xpix,numinput_ypix,numinput_txt);
194 numinput_curpos=0;
195 settextcolor(7);
196 resume_thread(THREAD_SCREEN);
197 }
198
get_numinput_chars(void)199 void get_numinput_chars(void)
200 {
201 int i, flag;
202 flag=0;
203 if(lir_inkey == 10 || lir_inkey == 13)
204 {
205 switch (numinput_flag)
206 {
207 case FIXED_INT_PARM:
208 sscanf(numinput_txt,"%d",&numinput_int_data);
209 break;
210
211 case FIXED_FLOAT_PARM:
212 sscanf(numinput_txt,"%f",&numinput_float_data);
213 break;
214
215 case FIXED_DOUBLE_PARM:
216 sscanf(numinput_txt,"%lf",&numinput_double_data);
217 break;
218 }
219 numinput_flag|=DATA_READY_PARM;
220 lir_inkey=0;
221 return;
222 }
223 pause_screen_and_hide_mouse();
224 settextcolor(15);
225 if(lir_inkey == 8 || lir_inkey == 127 || lir_inkey == ARROW_LEFT_KEY)
226 {
227 if(numinput_curpos==0)goto gncx;
228 numinput_curpos--;
229 numinput_txt[numinput_curpos]=1;
230 numinput_txt[numinput_curpos+1]=' ';
231 lir_pixwrite(numinput_xpix,numinput_ypix,numinput_txt);
232 goto gncx;
233 }
234 if( (lir_inkey >= '0' && lir_inkey <= '9') || numinput_flag == TEXT_PARM)
235 {
236 flag=1;
237 }
238 if(numinput_curpos == 0 && lir_inkey == '-' && numinput_flag != TEXT_PARM)
239 {
240 flag=1;
241 }
242 if( numinput_flag == FIXED_FLOAT_PARM || numinput_flag == FIXED_DOUBLE_PARM)
243 {
244 if(lir_inkey == '.' || lir_inkey == 'E')
245 {
246 for(i=0; i<numinput_curpos; i++)if(numinput_txt[i] == lir_inkey)goto gncx;
247 flag=1;
248 }
249 if(numinput_curpos > 0 && lir_inkey == '-')
250 {
251 if(numinput_txt[numinput_curpos-1] == 'E')
252 {
253 flag=1;
254 }
255 }
256 }
257 if(flag == 1)
258 {
259 numinput_txt[numinput_curpos]=lir_inkey;
260 numinput_curpos++;
261 }
262 if(numinput_curpos > numinput_chars-1)
263 {
264 numinput_curpos=numinput_chars-1;
265 }
266 else
267 {
268 numinput_txt[numinput_curpos]=1;
269 }
270 numinput_txt[numinput_curpos+1]=0;
271 lir_pixwrite(numinput_xpix,numinput_ypix,numinput_txt);
272 cursor_blink_time=current_time();
273 gncx:;
274 settextcolor(7);
275 resume_thread(THREAD_SCREEN);
276 }
277
278