0
|
1 /*
|
|
2 * Copyright (C) 2000 Rich Wareham <richwareham@users.sourceforge.net>
|
|
3 *
|
|
4 * This file is part of libdvdnav, a DVD navigation library.
|
|
5 *
|
|
6 * libdvdnav is free software; you can redistribute it and/or modify
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
8 * the Free Software Foundation; either version 2 of the License, or
|
|
9 * (at your option) any later version.
|
|
10 *
|
|
11 * libdvdnav is distributed in the hope that it will be useful,
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 * GNU General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program; if not, write to the Free Software
|
|
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
19 *
|
|
20 * $Id$
|
|
21 *
|
|
22 */
|
|
23
|
|
24 #ifdef HAVE_CONFIG_H
|
|
25 #include "config.h"
|
|
26 #endif
|
|
27
|
|
28 /*
|
|
29 #define BUTTON_TESTING
|
|
30 */
|
|
31
|
|
32 #include <dvdnav.h>
|
|
33 #include "dvdnav_internal.h"
|
|
34
|
|
35 #include "vm.h"
|
|
36 #
|
|
37 #include <dvdread/nav_types.h>
|
|
38
|
|
39 #ifdef BUTTON_TESTING
|
|
40 #include <dvdread/nav_print.h>
|
|
41 #endif
|
|
42
|
|
43 /* Highlighting API calls */
|
|
44
|
|
45 dvdnav_status_t dvdnav_get_current_highlight(dvdnav_t *self, int* button) {
|
|
46 if(!self)
|
|
47 return S_ERR;
|
|
48
|
|
49 /* Simply return the appropriate value based on the SPRM */
|
|
50 (*button) = (self->vm->state.HL_BTNN_REG) >> 10;
|
|
51
|
|
52 return S_OK;
|
|
53 }
|
|
54
|
|
55 btni_t *__get_current_button(dvdnav_t *self) {
|
|
56 int button = 0;
|
|
57
|
|
58 if(dvdnav_get_current_highlight(self, &button) != S_OK) {
|
|
59 printerrf("Unable to get information on current highlight.");
|
|
60 return NULL;
|
|
61 }
|
|
62 #ifdef BUTTON_TESTING
|
|
63 navPrint_PCI(&(self->pci));
|
|
64 #endif
|
|
65
|
|
66 return &(self->pci.hli.btnit[button-1]);
|
|
67 }
|
|
68
|
|
69 dvdnav_status_t dvdnav_upper_button_select(dvdnav_t *self) {
|
|
70 btni_t *button_ptr;
|
|
71
|
|
72 if(!self)
|
|
73 return S_ERR;
|
|
74
|
|
75 if((button_ptr = __get_current_button(self)) == NULL) {
|
|
76 return S_ERR;
|
|
77 }
|
|
78
|
|
79 dvdnav_button_select(self, button_ptr->up);
|
|
80
|
|
81 return S_OK;
|
|
82 }
|
|
83
|
|
84 dvdnav_status_t dvdnav_lower_button_select(dvdnav_t *self) {
|
|
85 btni_t *button_ptr;
|
|
86
|
|
87 if(!self)
|
|
88 return S_ERR;
|
|
89
|
|
90 if((button_ptr = __get_current_button(self)) == NULL) {
|
|
91 return S_ERR;
|
|
92 }
|
|
93
|
|
94 dvdnav_button_select(self, button_ptr->down);
|
|
95
|
|
96 return S_OK;
|
|
97 }
|
|
98
|
|
99 dvdnav_status_t dvdnav_right_button_select(dvdnav_t *self) {
|
|
100 btni_t *button_ptr;
|
|
101
|
|
102 if(!self)
|
|
103 return S_ERR;
|
|
104
|
|
105 if((button_ptr = __get_current_button(self)) == NULL) {
|
|
106 printerr("Error fetching information on current button.");
|
|
107 return S_ERR;
|
|
108 }
|
|
109
|
|
110 dvdnav_button_select(self, button_ptr->right);
|
|
111
|
|
112 return S_OK;
|
|
113 }
|
|
114
|
|
115 dvdnav_status_t dvdnav_left_button_select(dvdnav_t *self) {
|
|
116 btni_t *button_ptr;
|
|
117
|
|
118 if(!self)
|
|
119 return S_ERR;
|
|
120
|
|
121 if((button_ptr = __get_current_button(self)) == NULL) {
|
|
122 return S_ERR;
|
|
123 }
|
|
124
|
|
125 dvdnav_button_select(self, button_ptr->left);
|
|
126
|
|
127 return S_OK;
|
|
128 }
|
|
129
|
|
130 dvdnav_status_t dvdnav_button_activate(dvdnav_t *self) {
|
|
131 int button;
|
|
132 btni_t *button_ptr;
|
|
133
|
|
134 if(!self)
|
|
135 return S_ERR;
|
|
136 pthread_mutex_lock(&self->vm_lock);
|
|
137
|
|
138 /* Precisely the same as selecting a button except we want
|
|
139 * a different palette */
|
|
140 if(dvdnav_get_current_highlight(self, &button) != S_OK) {
|
|
141 pthread_mutex_unlock(&self->vm_lock);
|
|
142 return S_ERR;
|
|
143 }
|
|
144 if(dvdnav_button_select(self, button) != S_OK) {
|
|
145 pthread_mutex_unlock(&self->vm_lock);
|
|
146 return S_ERR;
|
|
147 }
|
|
148
|
|
149 /* Now get the current button's info */
|
|
150 if((button_ptr = __get_current_button(self)) == NULL) {
|
|
151 printerr("Error fetching information on current button.");
|
|
152 pthread_mutex_unlock(&self->vm_lock);
|
|
153 return S_ERR;
|
|
154 }
|
|
155
|
|
156 /* And set the palette */
|
|
157 if(button_ptr->btn_coln != 0) {
|
|
158 self->hli_clut =
|
|
159 self->pci.hli.btn_colit.btn_coli[button_ptr->btn_coln-1][1];
|
|
160 } else {
|
|
161 self->hli_clut = 0;
|
|
162 }
|
|
163
|
|
164 /* Finally, make the VM execute the appropriate code and
|
|
165 * scedule a jump */
|
|
166
|
|
167 if(vm_eval_cmd(self->vm, &(button_ptr->cmd)) == 1) {
|
|
168 /* Cammand caused a jump */
|
|
169 dvdnav_do_post_jump(self);
|
|
170 }
|
|
171
|
|
172 pthread_mutex_unlock(&self->vm_lock);
|
|
173 return S_OK;
|
|
174 }
|
|
175
|
|
176 dvdnav_status_t dvdnav_button_select(dvdnav_t *self, int button) {
|
|
177 btni_t *button_ptr;
|
|
178
|
|
179 if(!self) {
|
|
180 printerrf("Unable to select button number %i as self state bad",
|
|
181 button);
|
|
182 return S_ERR;
|
|
183 }
|
|
184
|
|
185 printf("Button select %i\n", button);
|
|
186
|
|
187 /* Set the highlight SPRM if the passed button was valid*/
|
|
188 if((button <= 0) || (button > self->pci.hli.hl_gi.btn_ns)) {
|
|
189 printerrf("Unable to select button number %i as it doesn't exist",
|
|
190 button);
|
|
191 return S_ERR;
|
|
192 }
|
|
193 self->vm->state.HL_BTNN_REG = (button << 10);
|
|
194
|
|
195 /* Now get the current button's info */
|
|
196 if((button_ptr = __get_current_button(self)) == NULL) {
|
|
197 printerr("Error fetching information on current button.");
|
|
198 return S_ERR;
|
|
199 }
|
|
200
|
|
201 self->hli_bbox[0] = button_ptr->x_start;
|
|
202 self->hli_bbox[1] = button_ptr->y_start;
|
|
203 self->hli_bbox[2] = button_ptr->x_end;
|
|
204 self->hli_bbox[3] = button_ptr->y_end;
|
|
205 self->hli_state = 1; /* Selected */
|
|
206
|
|
207 if(button_ptr->btn_coln != 0) {
|
|
208 self->hli_clut =
|
|
209 self->pci.hli.btn_colit.btn_coli[button_ptr->btn_coln-1][0];
|
|
210 } else {
|
|
211 self->hli_clut = 0;
|
|
212 }
|
|
213 self->hli_pts = self->pci.hli.hl_gi.hli_s_ptm;
|
|
214 self->hli_buttonN = button;
|
|
215 self->highlight_changed = 1;
|
|
216 #ifdef BUTTON_TESTING
|
|
217 printf("highlight.c:Highlight area is (%u,%u)-(%u,%u), display = %i, button = %u\n",
|
|
218 button_ptr->x_start, button_ptr->y_start,
|
|
219 button_ptr->x_end, button_ptr->y_end,
|
|
220 1,
|
|
221 button);
|
|
222 #endif
|
|
223
|
|
224 return S_OK;
|
|
225 }
|
|
226
|
|
227 dvdnav_status_t dvdnav_button_select_and_activate(dvdnav_t *self,
|
|
228 int button) {
|
|
229 /* A trivial function */
|
|
230 if(dvdnav_button_select(self, button) != S_ERR) {
|
|
231 return dvdnav_button_activate(self);
|
|
232 }
|
|
233
|
|
234 /* Should never get here without an error */
|
|
235 return S_ERR;
|
|
236 }
|
|
237
|
|
238 dvdnav_status_t dvdnav_mouse_select(dvdnav_t *self, int x, int y) {
|
|
239 int button, cur_button;
|
|
240
|
|
241 /* FIXME: At the moment, the case of no button matchin (x,y) is
|
|
242 * silently ignored, is this OK? */
|
|
243 if(!self)
|
|
244 return S_ERR;
|
|
245
|
|
246 if(dvdnav_get_current_highlight(self, &cur_button) != S_OK) {
|
|
247 return S_ERR;
|
|
248 }
|
|
249
|
|
250 /* Loop through each button */
|
|
251 for(button=1; button <= self->pci.hli.hl_gi.btn_ns; button++) {
|
|
252 btni_t *button_ptr = NULL;
|
|
253
|
|
254 button_ptr = &(self->pci.hli.btnit[button-1]);
|
|
255 if((x >= button_ptr->x_start) && (x <= button_ptr->x_end) &&
|
|
256 (y >= button_ptr->y_start) && (y <= button_ptr->y_end)) {
|
|
257 /* As an efficiency measure, only re-select the button
|
|
258 * if it is different to the previously selected one. */
|
|
259 if(button != cur_button) {
|
|
260 dvdnav_button_select(self, button);
|
|
261 }
|
|
262 }
|
|
263 }
|
|
264
|
|
265 return S_OK;
|
|
266 }
|
|
267
|
|
268 dvdnav_status_t dvdnav_mouse_activate(dvdnav_t *self, int x, int y) {
|
|
269 /* A trivial function */
|
|
270 if(dvdnav_mouse_select(self, x,y) != S_ERR) {
|
|
271 return dvdnav_button_activate(self);
|
|
272 }
|
|
273
|
|
274 /* Should never get here without an error */
|
|
275 return S_ERR;
|
|
276 }
|
|
277
|