Mercurial > libdvdnav.hg
comparison highlight.c @ 98:457f35f43ba6 src
Improved DVD menu selection.
The application using libdvdnav has to supply the nav_pci info.
The nav_pci info in libdvdnav is not parsed correctly, and is also not insync with the
display.
author | jcdutton |
---|---|
date | Wed, 18 Sep 2002 04:21:45 +0000 |
parents | df9712507b30 |
children | b6834e6359cf |
comparison
equal
deleted
inserted
replaced
97:c1dff1899bda | 98:457f35f43ba6 |
---|---|
215 (*button) = (this->vm->state.HL_BTNN_REG) >> 10; | 215 (*button) = (this->vm->state.HL_BTNN_REG) >> 10; |
216 | 216 |
217 return S_OK; | 217 return S_OK; |
218 } | 218 } |
219 | 219 |
220 btni_t *__get_current_button(dvdnav_t *this) { | 220 btni_t *__get_current_button(dvdnav_t *this, pci_t *pci) { |
221 int button = 0; | 221 int button = 0; |
222 | 222 |
223 if(dvdnav_get_current_highlight(this, &button) != S_OK) { | 223 if(dvdnav_get_current_highlight(this, &button) != S_OK) { |
224 printerr("Unable to get information on current highlight."); | 224 printerr("Unable to get information on current highlight."); |
225 return NULL; | 225 return NULL; |
226 } | 226 } |
227 #ifdef BUTTON_TESTING | 227 #ifdef BUTTON_TESTING |
228 nav_print_PCI(&(this->pci)); | 228 nav_print_PCI(&(this->pci)); |
229 #endif | 229 #endif |
230 | 230 |
231 return &(this->pci.hli.btnit[button-1]); | 231 return &(pci->hli.btnit[button-1]); |
232 } | 232 } |
233 | 233 |
234 dvdnav_status_t dvdnav_button_auto_action(dvdnav_t *this) { | 234 dvdnav_status_t dvdnav_button_auto_action(dvdnav_t *this, pci_t *pci) { |
235 btni_t *button_ptr; | 235 btni_t *button_ptr; |
236 | 236 |
237 if(!this) | 237 if(!this) |
238 return S_ERR; | 238 return S_ERR; |
239 | 239 |
240 if((button_ptr = __get_current_button(this)) == NULL) { | 240 if((button_ptr = __get_current_button(this, pci)) == NULL) { |
241 return S_ERR; | 241 return S_ERR; |
242 } | 242 } |
243 if (button_ptr->auto_action_mode == 1) { | 243 if (button_ptr->auto_action_mode == 1) { |
244 return S_OK; | 244 return S_OK; |
245 } | 245 } |
246 return S_ERR; | 246 return S_ERR; |
247 } | 247 } |
248 | 248 |
249 | 249 |
250 dvdnav_status_t dvdnav_upper_button_select(dvdnav_t *this) { | 250 dvdnav_status_t dvdnav_upper_button_select(dvdnav_t *this, pci_t *pci) { |
251 btni_t *button_ptr; | 251 btni_t *button_ptr; |
252 | 252 |
253 if(!this) | 253 if(!this) |
254 return S_ERR; | 254 return S_ERR; |
255 | 255 |
256 if((button_ptr = __get_current_button(this)) == NULL) { | 256 if((button_ptr = __get_current_button(this, pci)) == NULL) { |
257 return S_ERR; | 257 return S_ERR; |
258 } | 258 } |
259 | 259 |
260 dvdnav_button_select(this, button_ptr->up); | 260 dvdnav_button_select(this, pci, button_ptr->up); |
261 if (dvdnav_button_auto_action(this) ) { | 261 if (dvdnav_button_auto_action(this, pci) ) { |
262 dvdnav_button_activate(this); | 262 dvdnav_button_activate(this, pci); |
263 } | 263 } |
264 | 264 |
265 return S_OK; | 265 return S_OK; |
266 } | 266 } |
267 | 267 |
268 dvdnav_status_t dvdnav_lower_button_select(dvdnav_t *this) { | 268 dvdnav_status_t dvdnav_lower_button_select(dvdnav_t *this, pci_t *pci) { |
269 btni_t *button_ptr; | 269 btni_t *button_ptr; |
270 | 270 |
271 if(!this) | 271 if(!this) |
272 return S_ERR; | 272 return S_ERR; |
273 | 273 |
274 if((button_ptr = __get_current_button(this)) == NULL) { | 274 if((button_ptr = __get_current_button(this, pci)) == NULL) { |
275 return S_ERR; | 275 return S_ERR; |
276 } | 276 } |
277 | 277 |
278 dvdnav_button_select(this, button_ptr->down); | 278 dvdnav_button_select(this, pci, button_ptr->down); |
279 if (dvdnav_button_auto_action(this) ) { | 279 if (dvdnav_button_auto_action(this, pci) ) { |
280 dvdnav_button_activate(this); | 280 dvdnav_button_activate(this, pci); |
281 } | 281 } |
282 | 282 |
283 return S_OK; | 283 return S_OK; |
284 } | 284 } |
285 | 285 |
286 dvdnav_status_t dvdnav_right_button_select(dvdnav_t *this) { | 286 dvdnav_status_t dvdnav_right_button_select(dvdnav_t *this, pci_t *pci) { |
287 btni_t *button_ptr; | 287 btni_t *button_ptr; |
288 | 288 |
289 if(!this) | 289 if(!this) |
290 return S_ERR; | 290 return S_ERR; |
291 | 291 |
292 if((button_ptr = __get_current_button(this)) == NULL) { | 292 if((button_ptr = __get_current_button(this, pci)) == NULL) { |
293 printerr("Error fetching information on current button."); | 293 printerr("Error fetching information on current button."); |
294 return S_ERR; | 294 return S_ERR; |
295 } | 295 } |
296 | 296 |
297 dvdnav_button_select(this, button_ptr->right); | 297 dvdnav_button_select(this, pci, button_ptr->right); |
298 if (dvdnav_button_auto_action(this) ) { | 298 if (dvdnav_button_auto_action(this, pci) ) { |
299 dvdnav_button_activate(this); | 299 dvdnav_button_activate(this, pci); |
300 } | 300 } |
301 | 301 |
302 return S_OK; | 302 return S_OK; |
303 } | 303 } |
304 | 304 |
305 dvdnav_status_t dvdnav_left_button_select(dvdnav_t *this) { | 305 dvdnav_status_t dvdnav_left_button_select(dvdnav_t *this, pci_t *pci) { |
306 btni_t *button_ptr; | 306 btni_t *button_ptr; |
307 | 307 |
308 if(!this) | 308 if(!this) |
309 return S_ERR; | 309 return S_ERR; |
310 | 310 |
311 if((button_ptr = __get_current_button(this)) == NULL) { | 311 if((button_ptr = __get_current_button(this, pci)) == NULL) { |
312 return S_ERR; | 312 return S_ERR; |
313 } | 313 } |
314 | 314 |
315 dvdnav_button_select(this, button_ptr->left); | 315 dvdnav_button_select(this, pci, button_ptr->left); |
316 if (dvdnav_button_auto_action(this) ) { | 316 if (dvdnav_button_auto_action(this, pci) ) { |
317 dvdnav_button_activate(this); | 317 dvdnav_button_activate(this, pci); |
318 } | 318 } |
319 | 319 |
320 return S_OK; | 320 return S_OK; |
321 } | 321 } |
322 | 322 |
355 #endif | 355 #endif |
356 | 356 |
357 return S_OK; | 357 return S_OK; |
358 } | 358 } |
359 | 359 |
360 dvdnav_status_t dvdnav_button_activate(dvdnav_t *this) { | 360 dvdnav_status_t dvdnav_button_activate(dvdnav_t *this, pci_t *pci) { |
361 int button; | 361 int button; |
362 btni_t *button_ptr = NULL; | 362 btni_t *button_ptr = NULL; |
363 | 363 |
364 if(!this) | 364 if(!this) |
365 return S_ERR; | 365 return S_ERR; |
372 return S_ERR; | 372 return S_ERR; |
373 } | 373 } |
374 /* FIXME: dvdnav_button_select should really return a | 374 /* FIXME: dvdnav_button_select should really return a |
375 * special case for explicit NO-BUTTONS. | 375 * special case for explicit NO-BUTTONS. |
376 */ | 376 */ |
377 if(dvdnav_button_select(this, button) != S_OK) { | 377 if(dvdnav_button_select(this, pci, button) != S_OK) { |
378 /* Special code to handle still menus with no buttons. | 378 /* Special code to handle still menus with no buttons. |
379 * the navigation is expected to report to the appicatino that a STILL is | 379 * the navigation is expected to report to the appicatino that a STILL is |
380 * underway. In turn, the application is supposed to report to the user | 380 * underway. In turn, the application is supposed to report to the user |
381 * that the playback is pause. The user is then expected to undo the pause. | 381 * that the playback is pause. The user is then expected to undo the pause. |
382 * ie: hit play. At that point, the navigation should release the still and | 382 * ie: hit play. At that point, the navigation should release the still and |
393 } | 393 } |
394 pthread_mutex_unlock(&this->vm_lock); | 394 pthread_mutex_unlock(&this->vm_lock); |
395 return S_ERR; | 395 return S_ERR; |
396 } | 396 } |
397 /* FIXME: The button command should really be passed in the API instead. */ | 397 /* FIXME: The button command should really be passed in the API instead. */ |
398 button_ptr = __get_current_button(this); | 398 button_ptr = __get_current_button(this, pci); |
399 /* Finally, make the VM execute the appropriate code and | 399 /* Finally, make the VM execute the appropriate code and |
400 * scedule a jump */ | 400 * scedule a jump */ |
401 #ifdef BUTTON_TESTING | 401 #ifdef BUTTON_TESTING |
402 fprintf(MSG_OUT, "libdvdnav: Evaluating Button Activation commands.\n"); | 402 fprintf(MSG_OUT, "libdvdnav: Evaluating Button Activation commands.\n"); |
403 #endif | 403 #endif |
433 this->position_current.still = 0; | 433 this->position_current.still = 0; |
434 pthread_mutex_unlock(&this->vm_lock); | 434 pthread_mutex_unlock(&this->vm_lock); |
435 return S_OK; | 435 return S_OK; |
436 } | 436 } |
437 | 437 |
438 dvdnav_status_t dvdnav_button_select(dvdnav_t *this, int button) { | 438 dvdnav_status_t dvdnav_button_select(dvdnav_t *this, pci_t *pci, int button) { |
439 | 439 |
440 if(!this) { | 440 if(!this) { |
441 printerrf("Unable to select button number %i as this state bad", | 441 printerrf("Unable to select button number %i as this state bad", |
442 button); | 442 button); |
443 return S_ERR; | 443 return S_ERR; |
447 fprintf(MSG_OUT, "libdvdnav: Button select %i\n", button); | 447 fprintf(MSG_OUT, "libdvdnav: Button select %i\n", button); |
448 #endif | 448 #endif |
449 | 449 |
450 /* Set the highlight SPRM if the passed button was valid*/ | 450 /* Set the highlight SPRM if the passed button was valid*/ |
451 /* FIXME: this->pci should be provided by the application. */ | 451 /* FIXME: this->pci should be provided by the application. */ |
452 if((button <= 0) || (button > this->pci.hli.hl_gi.btn_ns)) { | 452 if((button <= 0) || (button > pci->hli.hl_gi.btn_ns)) { |
453 printerrf("Unable to select button number %i as it doesn't exist", | 453 printerrf("Unable to select button number %i as it doesn't exist", |
454 button); | 454 button); |
455 return S_ERR; | 455 return S_ERR; |
456 } | 456 } |
457 this->vm->state.HL_BTNN_REG = (button << 10); | 457 this->vm->state.HL_BTNN_REG = (button << 10); |
461 this->position_current.button = -1; /* Force Highligh change */ | 461 this->position_current.button = -1; /* Force Highligh change */ |
462 | 462 |
463 return S_OK; | 463 return S_OK; |
464 } | 464 } |
465 | 465 |
466 dvdnav_status_t dvdnav_button_select_and_activate(dvdnav_t *this, | 466 dvdnav_status_t dvdnav_button_select_and_activate(dvdnav_t *this, pci_t *pci, |
467 int button) { | 467 int button) { |
468 /* A trivial function */ | 468 /* A trivial function */ |
469 if(dvdnav_button_select(this, button) != S_ERR) { | 469 if(dvdnav_button_select(this, pci, button) != S_ERR) { |
470 return dvdnav_button_activate(this); | 470 return dvdnav_button_activate(this, pci); |
471 } | 471 } |
472 | 472 |
473 /* Should never get here without an error */ | 473 /* Should never get here without an error */ |
474 return S_ERR; | 474 return S_ERR; |
475 } | 475 } |
476 | 476 |
477 dvdnav_status_t dvdnav_mouse_select(dvdnav_t *this, int x, int y) { | 477 dvdnav_status_t dvdnav_mouse_select(dvdnav_t *this, pci_t *pci, int x, int y) { |
478 int button, cur_button; | 478 int button, cur_button; |
479 uint32_t best,dist; | 479 uint32_t best,dist; |
480 int mx,my,dx,dy,d; | 480 int mx,my,dx,dy,d; |
481 | 481 |
482 /* FIXME: At the moment, the case of no button matchin (x,y) is | 482 /* FIXME: At the moment, the case of no button matchin (x,y) is |
490 | 490 |
491 best = 0; | 491 best = 0; |
492 dist = 0x08000000; /* >> than (720*720)+(567*567); */ | 492 dist = 0x08000000; /* >> than (720*720)+(567*567); */ |
493 | 493 |
494 /* Loop through each button */ | 494 /* Loop through each button */ |
495 for(button=1; button <= this->pci.hli.hl_gi.btn_ns; button++) { | 495 for(button=1; button <= pci->hli.hl_gi.btn_ns; button++) { |
496 btni_t *button_ptr = NULL; | 496 btni_t *button_ptr = NULL; |
497 button_ptr = &(this->pci.hli.btnit[button-1]); | 497 button_ptr = &(this->pci.hli.btnit[button-1]); |
498 if((x >= button_ptr->x_start) && (x <= button_ptr->x_end) && | 498 if((x >= button_ptr->x_start) && (x <= button_ptr->x_end) && |
499 (y >= button_ptr->y_start) && (y <= button_ptr->y_end)) { | 499 (y >= button_ptr->y_start) && (y <= button_ptr->y_end)) { |
500 mx = (button_ptr->x_start + button_ptr->x_end)/2; | 500 mx = (button_ptr->x_start + button_ptr->x_end)/2; |
512 | 512 |
513 if (best!=0) { | 513 if (best!=0) { |
514 /* As an efficiency measure, only re-select the button | 514 /* As an efficiency measure, only re-select the button |
515 * if it is different to the previously selected one. */ | 515 * if it is different to the previously selected one. */ |
516 if(best != cur_button) { | 516 if(best != cur_button) { |
517 dvdnav_button_select(this, best); | 517 dvdnav_button_select(this, pci, best); |
518 } | 518 } |
519 } | 519 } |
520 | 520 |
521 return S_OK; | 521 return S_OK; |
522 } | 522 } |
523 | 523 |
524 dvdnav_status_t dvdnav_mouse_activate(dvdnav_t *this, int x, int y) { | 524 dvdnav_status_t dvdnav_mouse_activate(dvdnav_t *this, pci_t *pci, int x, int y) { |
525 /* A trivial function */ | 525 /* A trivial function */ |
526 if(dvdnav_mouse_select(this, x,y) != S_ERR) { | 526 if(dvdnav_mouse_select(this, pci, x,y) != S_ERR) { |
527 return dvdnav_button_activate(this); | 527 return dvdnav_button_activate(this, pci); |
528 } | 528 } |
529 | 529 |
530 /* Should never get here without an error */ | 530 /* Should never get here without an error */ |
531 return S_ERR; | 531 return S_ERR; |
532 } | 532 } |