1
2 /*
3 * Diverse Bristol audio routines.
4 * Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2012
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22 #include "brightoninternals.h"
23
24 brightonILocations *
brightonDeviceLocator(register brightonIResource * panel,register int x,register int y)25 brightonDeviceLocator(register brightonIResource *panel,
26 register int x, register int y)
27 {
28 register int index;
29 register brightonILocations *locn;
30
31 //printf("brightonDeviceLocator(%i, %i)\n", x, y);
32
33 if (((panel->flags & BRIGHTON_ACTIVE) == 0)
34 || (panel->flags & BRIGHTON_WITHDRAWN))
35 return(0);
36
37 for (index = 0; index < panel->ndevices; index++)
38 {
39 locn = &panel->devlocn[index];
40
41 //printf("dev location %i %i %i %i\n", locn->ax, locn->ay, locn->aw, locn->ah);
42 if ((locn->ax <= x) && ((locn->ax + locn->aw) > x)
43 && (locn->ay <= y) && ((locn->ay + locn->ah) > y))
44 {
45 //printf("found device %i\n", index);
46 return(locn);
47 }
48 }
49 return(0);
50 }
51
52 brightonIResource *
brightonPanelLocator(brightonWindow * bwin,int x,int y)53 brightonPanelLocator(brightonWindow *bwin, int x, int y)
54 {
55 register int index;
56 register brightonIResource *locn;
57
58 /* printf("brightonLocator(%i, %i)\n", x, y); */
59
60 for (index = 0; index < bwin->app->nresources; index++)
61 {
62 locn = &bwin->app->resources[index];
63
64 if (((locn->flags & BRIGHTON_ACTIVE) == 0)
65 || (locn->flags & BRIGHTON_WITHDRAWN))
66 continue;
67
68 if ((locn->sx <= x) && ((locn->sx + locn->sw) > x)
69 && (locn->sy <= y) && ((locn->sy + locn->sh) > y))
70 {
71 /*printf("found panel %i\n", index); */
72 /*
73 * Found the panel. Now go look for the device
74 */
75 return(locn);
76 }
77 }
78 return(0);
79 }
80
81 /*
82 * This will be called typically on button press, and attempts to locate
83 * which device is under the given x/y co-ord. May have other uses.
84 */
85 brightonILocations *
brightonLocator(brightonWindow * bwin,int x,int y)86 brightonLocator(brightonWindow *bwin, int x, int y)
87 {
88 register int index;
89 register brightonIResource *locn;
90
91 /* printf("brightonLocator(%i, %i)\n", x, y); */
92
93 for (index = 0; index < bwin->app->nresources; index++)
94 {
95 locn = &bwin->app->resources[index];
96
97 if (((locn->flags & BRIGHTON_ACTIVE) == 0)
98 || (locn->flags & BRIGHTON_WITHDRAWN))
99 continue;
100
101 if ((locn->sx <= x) && ((locn->sx + locn->sw) > x)
102 && (locn->sy <= y) && ((locn->sy + locn->sh) > y))
103 {
104 /*printf("found panel %i\n", index); */
105 /*
106 * Found the panel. Now go look for the device
107 */
108 return(brightonDeviceLocator(locn, x - locn->sx, y - locn->sy));
109 }
110 }
111 return(0);
112 }
113
114