| 1 |
/* |
| 2 |
* Copyright (C) 2000 Rich Wareham <[email protected]> |
| 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 along |
| 17 |
* with libdvdnav; if not, write to the Free Software Foundation, Inc., |
| 18 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifdef HAVE_CONFIG_H |
| 22 |
#include "config.h" |
| 23 |
#endif |
| 24 |
|
| 25 |
#include <assert.h> |
| 26 |
#include <inttypes.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <stdio.h> |
| 29 |
#include <limits.h> |
| 30 |
#include <string.h> |
| 31 |
#include <sys/time.h> |
| 32 |
#include <dvdread/nav_types.h> |
| 33 |
#include "dvdnav/dvdnav.h" |
| 34 |
#include "vm/decoder.h" |
| 35 |
#include "vm/vm.h" |
| 36 |
#include "vm/vmcmd.h" |
| 37 |
#include "dvdnav_internal.h" |
| 38 |
|
| 39 |
/* |
| 40 |
#define BUTTON_TESTING |
| 41 |
*/ |
| 42 |
|
| 43 |
#ifdef BUTTON_TESTING |
| 44 |
|
| 45 |
#include <dvdread/nav_print.h> |
| 46 |
|
| 47 |
static void print_time(dvd_time_t *dtime) { |
| 48 |
const char *rate; |
| 49 |
|
| 50 |
assert((dtime->hour>>4) < 0xa && (dtime->hour&0xf) < 0xa); |
| 51 |
assert((dtime->minute>>4) < 0x7 && (dtime->minute&0xf) < 0xa); |
| 52 |
assert((dtime->second>>4) < 0x7 && (dtime->second&0xf) < 0xa); |
| 53 |
assert((dtime->frame_u&0xf) < 0xa); |
| 54 |
|
| 55 |
fprintf(MSG_OUT,"%02x:%02x:%02x.%02x", |
| 56 |
dtime->hour, |
| 57 |
dtime->minute, |
| 58 |
dtime->second, |
| 59 |
dtime->frame_u & 0x3f); |
| 60 |
switch((dtime->frame_u & 0xc0) >> 6) { |
| 61 |
case 1: |
| 62 |
rate = "25.00"; |
| 63 |
break; |
| 64 |
case 3: |
| 65 |
rate = "29.97"; |
| 66 |
break; |
| 67 |
default: |
| 68 |
rate = "(please send a bug report)"; |
| 69 |
break; |
| 70 |
} |
| 71 |
fprintf(MSG_OUT," @ %s fps", rate); |
| 72 |
} |
| 73 |
|
| 74 |
static void nav_print_PCI_GI(pci_gi_t *pci_gi) { |
| 75 |
int32_t i; |
| 76 |
|
| 77 |
fprintf(MSG_OUT,"libdvdnav: pci_gi:\n"); |
| 78 |
fprintf(MSG_OUT,"libdvdnav: nv_pck_lbn 0x%08x\n", pci_gi->nv_pck_lbn); |
| 79 |
fprintf(MSG_OUT,"libdvdnav: vobu_cat 0x%04x\n", pci_gi->vobu_cat); |
| 80 |
fprintf(MSG_OUT,"libdvdnav: vobu_uop_ctl 0x%08x\n", *(uint32_t*)&pci_gi->vobu_uop_ctl); |
| 81 |
fprintf(MSG_OUT,"libdvdnav: vobu_s_ptm 0x%08x\n", pci_gi->vobu_s_ptm); |
| 82 |
fprintf(MSG_OUT,"libdvdnav: vobu_e_ptm 0x%08x\n", pci_gi->vobu_e_ptm); |
| 83 |
fprintf(MSG_OUT,"libdvdnav: vobu_se_e_ptm 0x%08x\n", pci_gi->vobu_se_e_ptm); |
| 84 |
fprintf(MSG_OUT,"libdvdnav: e_eltm "); |
| 85 |
print_time(&pci_gi->e_eltm); |
| 86 |
fprintf(MSG_OUT,"\n"); |
| 87 |
|
| 88 |
fprintf(MSG_OUT,"libdvdnav: vobu_isrc \""); |
| 89 |
for(i = 0; i < 32; i++) { |
| 90 |
char c = pci_gi->vobu_isrc[i]; |
| 91 |
if((c >= ' ') && (c <= '~')) |
| 92 |
fprintf(MSG_OUT,"%c", c); |
| 93 |
else |
| 94 |
fprintf(MSG_OUT,"."); |
| 95 |
} |
| 96 |
fprintf(MSG_OUT,"\"\n"); |
| 97 |
} |
| 98 |
|
| 99 |
static void nav_print_NSML_AGLI(nsml_agli_t *nsml_agli) { |
| 100 |
int32_t i, j = 0; |
| 101 |
|
| 102 |
for(i = 0; i < 9; i++) |
| 103 |
j |= nsml_agli->nsml_agl_dsta[i]; |
| 104 |
if(j == 0) |
| 105 |
return; |
| 106 |
|
| 107 |
fprintf(MSG_OUT,"libdvdnav: nsml_agli:\n"); |
| 108 |
for(i = 0; i < 9; i++) |
| 109 |
if(nsml_agli->nsml_agl_dsta[i]) |
| 110 |
fprintf(MSG_OUT,"libdvdnav: nsml_agl_c%d_dsta 0x%08x\n", i + 1, |
| 111 |
nsml_agli->nsml_agl_dsta[i]); |
| 112 |
} |
| 113 |
|
| 114 |
static void nav_print_HL_GI(hl_gi_t *hl_gi, int32_t *btngr_ns, int32_t *btn_ns) { |
| 115 |
|
| 116 |
if((hl_gi->hli_ss & 0x03) == 0) |
| 117 |
return; |
| 118 |
|
| 119 |
fprintf(MSG_OUT,"libdvdnav: hl_gi:\n"); |
| 120 |
fprintf(MSG_OUT,"libdvdnav: hli_ss 0x%01x\n", hl_gi->hli_ss & 0x03); |
| 121 |
fprintf(MSG_OUT,"libdvdnav: hli_s_ptm 0x%08x\n", hl_gi->hli_s_ptm); |
| 122 |
fprintf(MSG_OUT,"libdvdnav: hli_e_ptm 0x%08x\n", hl_gi->hli_e_ptm); |
| 123 |
fprintf(MSG_OUT,"libdvdnav: btn_se_e_ptm 0x%08x\n", hl_gi->btn_se_e_ptm); |
| 124 |
|
| 125 |
*btngr_ns = hl_gi->btngr_ns; |
| 126 |
fprintf(MSG_OUT,"libdvdnav: btngr_ns %d\n", hl_gi->btngr_ns); |
| 127 |
fprintf(MSG_OUT,"libdvdnav: btngr%d_dsp_ty 0x%02x\n", 1, hl_gi->btngr1_dsp_ty); |
| 128 |
fprintf(MSG_OUT,"libdvdnav: btngr%d_dsp_ty 0x%02x\n", 2, hl_gi->btngr2_dsp_ty); |
| 129 |
fprintf(MSG_OUT,"libdvdnav: btngr%d_dsp_ty 0x%02x\n", 3, hl_gi->btngr3_dsp_ty); |
| 130 |
|
| 131 |
fprintf(MSG_OUT,"libdvdnav: btn_ofn %d\n", hl_gi->btn_ofn); |
| 132 |
*btn_ns = hl_gi->btn_ns; |
| 133 |
fprintf(MSG_OUT,"libdvdnav: btn_ns %d\n", hl_gi->btn_ns); |
| 134 |
fprintf(MSG_OUT,"libdvdnav: nsl_btn_ns %d\n", hl_gi->nsl_btn_ns); |
| 135 |
fprintf(MSG_OUT,"libdvdnav: fosl_btnn %d\n", hl_gi->fosl_btnn); |
| 136 |
fprintf(MSG_OUT,"libdvdnav: foac_btnn %d\n", hl_gi->foac_btnn); |
| 137 |
} |
| 138 |
|
| 139 |
static void nav_print_BTN_COLIT(btn_colit_t *btn_colit) { |
| 140 |
int32_t i, j; |
| 141 |
|
| 142 |
j = 0; |
| 143 |
for(i = 0; i < 6; i++) |
| 144 |
j |= btn_colit->btn_coli[i/2][i&1]; |
| 145 |
if(j == 0) |
| 146 |
return; |
| 147 |
|
| 148 |
fprintf(MSG_OUT,"libdvdnav: btn_colit:\n"); |
| 149 |
for(i = 0; i < 3; i++) |
| 150 |
for(j = 0; j < 2; j++) |
| 151 |
fprintf(MSG_OUT,"libdvdnav: btn_cqoli %d %s_coli: %08x\n", |
| 152 |
i, (j == 0) ? "sl" : "ac", |
| 153 |
btn_colit->btn_coli[i][j]); |
| 154 |
} |
| 155 |
|
| 156 |
static void nav_print_BTNIT(btni_t *btni_table, int32_t btngr_ns, int32_t btn_ns) { |
| 157 |
int32_t i, j, k; |
| 158 |
|
| 159 |
fprintf(MSG_OUT,"libdvdnav: btnit:\n"); |
| 160 |
fprintf(MSG_OUT,"libdvdnav: btngr_ns: %i\n", btngr_ns); |
| 161 |
fprintf(MSG_OUT,"libdvdnav: btn_ns: %i\n", btn_ns); |
| 162 |
|
| 163 |
if(btngr_ns == 0) |
| 164 |
return; |
| 165 |
|
| 166 |
for(i = 0; i < btngr_ns; i++) { |
| 167 |
for(j = 0; j < (36 / btngr_ns); j++) { |
| 168 |
if(j < btn_ns) { |
| 169 |
btni_t *btni = &btni_table[(36 / btngr_ns) * i + j]; |
| 170 |
|
| 171 |
fprintf(MSG_OUT,"libdvdnav: group %d btni %d: ", i+1, j+1); |
| 172 |
fprintf(MSG_OUT,"btn_coln %d, auto_action_mode %d\n", |
| 173 |
btni->btn_coln, btni->auto_action_mode); |
| 174 |
fprintf(MSG_OUT,"libdvdnav: coords (%d, %d) .. (%d, %d)\n", |
| 175 |
btni->x_start, btni->y_start, btni->x_end, btni->y_end); |
| 176 |
|
| 177 |
fprintf(MSG_OUT,"libdvdnav: up %d, ", btni->up); |
| 178 |
fprintf(MSG_OUT,"down %d, ", btni->down); |
| 179 |
fprintf(MSG_OUT,"left %d, ", btni->left); |
| 180 |
fprintf(MSG_OUT,"right %d\n", btni->right); |
| 181 |
for(k = 0; k < 8; k++) { |
| 182 |
fprintf(MSG_OUT, "libdvdnav: %02x ", btni->cmd.bytes[k]); |
| 183 |
} |
| 184 |
fprintf(MSG_OUT, "| "); |
| 185 |
#ifdef TRACE |
| 186 |
vm_print_mnemonic(&btni->cmd); |
| 187 |
#endif |
| 188 |
fprintf(MSG_OUT, "\n"); |
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
static void nav_print_HLI(hli_t *hli) { |
| 195 |
int32_t btngr_ns = 0, btn_ns = 0; |
| 196 |
|
| 197 |
fprintf(MSG_OUT,"libdvdnav: hli:\n"); |
| 198 |
nav_print_HL_GI(&hli->hl_gi, & btngr_ns, & btn_ns); |
| 199 |
nav_print_BTN_COLIT(&hli->btn_colit); |
| 200 |
nav_print_BTNIT(hli->btnit, btngr_ns, btn_ns); |
| 201 |
} |
| 202 |
|
| 203 |
void nav_print_PCI(pci_t *pci) { |
| 204 |
fprintf(MSG_OUT,"libdvdnav: pci packet:\n"); |
| 205 |
nav_print_PCI_GI(&pci->pci_gi); |
| 206 |
nav_print_NSML_AGLI(&pci->nsml_agli); |
| 207 |
nav_print_HLI(&pci->hli); |
| 208 |
} |
| 209 |
|
| 210 |
#endif |
| 211 |
|
| 212 |
|
| 213 |
/* Highlighting API calls */ |
| 214 |
|
| 215 |
dvdnav_status_t dvdnav_get_current_highlight(dvdnav_t *this, int32_t *button) { |
| 216 |
/* Simply return the appropriate value based on the SPRM */ |
| 217 |
if(((*button) = this->position_current.button) == -1) |
| 218 |
(*button) = this->vm->state.HL_BTNN_REG >> 10; |
| 219 |
|
| 220 |
return DVDNAV_STATUS_OK; |
| 221 |
} |
| 222 |
|
| 223 |
static const btni_t *get_current_button(dvdnav_t *this, pci_t *pci) { |
| 224 |
int32_t button = 0; |
| 225 |
|
| 226 |
if(!pci->hli.hl_gi.hli_ss) { |
| 227 |
printerr("Not in a menu."); |
| 228 |
return NULL; |
| 229 |
} |
| 230 |
if(this->last_cmd_nav_lbn == pci->pci_gi.nv_pck_lbn) { |
| 231 |
printerr("This NAV has already been left."); |
| 232 |
return NULL; |
| 233 |
} |
| 234 |
|
| 235 |
button = this->vm->state.HL_BTNN_REG >> 10; |
| 236 |
#ifdef BUTTON_TESTING |
| 237 |
nav_print_PCI(pci); |
| 238 |
#endif |
| 239 |
|
| 240 |
return &(pci->hli.btnit[button-1]); |
| 241 |
} |
| 242 |
|
| 243 |
static dvdnav_status_t button_auto_action(dvdnav_t *this, pci_t *pci) { |
| 244 |
const btni_t *button_ptr; |
| 245 |
if ((button_ptr = get_current_button(this, pci)) == NULL) |
| 246 |
return DVDNAV_STATUS_ERR; |
| 247 |
|
| 248 |
if (button_ptr->auto_action_mode) |
| 249 |
return dvdnav_button_activate(this, pci); |
| 250 |
|
| 251 |
return DVDNAV_STATUS_OK; |
| 252 |
} |
| 253 |
|
| 254 |
dvdnav_status_t dvdnav_upper_button_select(dvdnav_t *this, pci_t *pci) { |
| 255 |
const btni_t *button_ptr; |
| 256 |
|
| 257 |
if(!(button_ptr = get_current_button(this, pci))) |
| 258 |
return DVDNAV_STATUS_ERR; |
| 259 |
|
| 260 |
dvdnav_button_select(this, pci, button_ptr->up); |
| 261 |
return button_auto_action(this, pci); |
| 262 |
} |
| 263 |
|
| 264 |
dvdnav_status_t dvdnav_lower_button_select(dvdnav_t *this, pci_t *pci) { |
| 265 |
const btni_t *button_ptr; |
| 266 |
|
| 267 |
if(!(button_ptr = get_current_button(this, pci))) |
| 268 |
return DVDNAV_STATUS_ERR; |
| 269 |
|
| 270 |
dvdnav_button_select(this, pci, button_ptr->down); |
| 271 |
return button_auto_action(this, pci); |
| 272 |
} |
| 273 |
|
| 274 |
dvdnav_status_t dvdnav_right_button_select(dvdnav_t *this, pci_t *pci) { |
| 275 |
const btni_t *button_ptr; |
| 276 |
|
| 277 |
if(!(button_ptr = get_current_button(this, pci))) |
| 278 |
return DVDNAV_STATUS_ERR; |
| 279 |
|
| 280 |
dvdnav_button_select(this, pci, button_ptr->right); |
| 281 |
return button_auto_action(this, pci); |
| 282 |
} |
| 283 |
|
| 284 |
dvdnav_status_t dvdnav_left_button_select(dvdnav_t *this, pci_t *pci) { |
| 285 |
const btni_t *button_ptr; |
| 286 |
|
| 287 |
if(!(button_ptr = get_current_button(this, pci))) |
| 288 |
return DVDNAV_STATUS_ERR; |
| 289 |
|
| 290 |
dvdnav_button_select(this, pci, button_ptr->left); |
| 291 |
return button_auto_action(this, pci); |
| 292 |
} |
| 293 |
|
| 294 |
dvdnav_status_t dvdnav_get_highlight_area(pci_t *nav_pci , int32_t button, int32_t mode, |
| 295 |
dvdnav_highlight_area_t *highlight) { |
| 296 |
const btni_t *button_ptr; |
| 297 |
|
| 298 |
#ifdef BUTTON_TESTING |
| 299 |
fprintf(MSG_OUT, "libdvdnav: Button get_highlight_area %i\n", button); |
| 300 |
#endif |
| 301 |
|
| 302 |
if(!nav_pci->hli.hl_gi.hli_ss) |
| 303 |
return DVDNAV_STATUS_ERR; |
| 304 |
if((button <= 0) || (button > nav_pci->hli.hl_gi.btn_ns)) |
| 305 |
return DVDNAV_STATUS_ERR; |
| 306 |
|
| 307 |
|
| 308 |
button_ptr = &nav_pci->hli.btnit[button-1]; |
| 309 |
|
| 310 |
highlight->sx = button_ptr->x_start; |
| 311 |
highlight->sy = button_ptr->y_start; |
| 312 |
highlight->ex = button_ptr->x_end; |
| 313 |
highlight->ey = button_ptr->y_end; |
| 314 |
if(button_ptr->btn_coln != 0) { |
| 315 |
highlight->palette = nav_pci->hli.btn_colit.btn_coli[button_ptr->btn_coln-1][mode]; |
| 316 |
} else { |
| 317 |
highlight->palette = 0; |
| 318 |
} |
| 319 |
highlight->pts = nav_pci->hli.hl_gi.hli_s_ptm; |
| 320 |
highlight->buttonN = button; |
| 321 |
#ifdef BUTTON_TESTING |
| 322 |
fprintf(MSG_OUT, "libdvdnav: highlight: Highlight area is (%u,%u)-(%u,%u), display = %i, button = %u\n", |
| 323 |
button_ptr->x_start, button_ptr->y_start, |
| 324 |
button_ptr->x_end, button_ptr->y_end, |
| 325 |
1, |
| 326 |
button); |
| 327 |
#endif |
| 328 |
|
| 329 |
return DVDNAV_STATUS_OK; |
| 330 |
} |
| 331 |
|
| 332 |
dvdnav_status_t dvdnav_button_activate(dvdnav_t *this, pci_t *pci) { |
| 333 |
int32_t button; |
| 334 |
const btni_t *button_ptr = NULL; |
| 335 |
|
| 336 |
if(!pci->hli.hl_gi.hli_ss) { |
| 337 |
printerr("Not in a menu."); |
| 338 |
return DVDNAV_STATUS_ERR; |
| 339 |
} |
| 340 |
if(this->last_cmd_nav_lbn == pci->pci_gi.nv_pck_lbn) { |
| 341 |
printerr("This NAV has already been left."); |
| 342 |
return DVDNAV_STATUS_ERR; |
| 343 |
} |
| 344 |
pthread_mutex_lock(&this->vm_lock); |
| 345 |
|
| 346 |
if(!this->vm->state.pgc) { |
| 347 |
printerr("No current PGC."); |
| 348 |
pthread_mutex_unlock(&this->vm_lock); |
| 349 |
return DVDNAV_STATUS_ERR; |
| 350 |
} |
| 351 |
|
| 352 |
button = this->vm->state.HL_BTNN_REG >> 10; |
| 353 |
|
| 354 |
if((button <= 0) || (button > pci->hli.hl_gi.btn_ns)) { |
| 355 |
/* Special code to handle still menus with no buttons. |
| 356 |
* The navigation is expected to report to the application that a STILL is |
| 357 |
* underway. In turn, the application is supposed to report to the user |
| 358 |
* that the playback is paused. The user is then expected to undo the pause, |
| 359 |
* ie: hit play. At that point, the navigation should release the still and |
| 360 |
* go to the next Cell. |
| 361 |
* Explanation by Mathieu Lacage <[email protected]> |
| 362 |
* Code added by jcdutton. |
| 363 |
*/ |
| 364 |
if (this->position_current.still != 0) { |
| 365 |
/* In still, but no buttons. */ |
| 366 |
vm_get_next_cell(this->vm); |
| 367 |
this->position_current.still = 0; |
| 368 |
this->sync_wait = 0; |
| 369 |
this->last_cmd_nav_lbn = pci->pci_gi.nv_pck_lbn; |
| 370 |
pthread_mutex_unlock(&this->vm_lock); |
| 371 |
/* clear error message */ |
| 372 |
printerr(""); |
| 373 |
return DVDNAV_STATUS_OK; |
| 374 |
} |
| 375 |
pthread_mutex_unlock(&this->vm_lock); |
| 376 |
return DVDNAV_STATUS_ERR; |
| 377 |
} |
| 378 |
|
| 379 |
if ((button_ptr = get_current_button(this, pci)) == NULL) { |
| 380 |
pthread_mutex_unlock(&this->vm_lock); |
| 381 |
return DVDNAV_STATUS_ERR; |
| 382 |
} |
| 383 |
|
| 384 |
/* Finally, make the VM execute the appropriate code and probably |
| 385 |
* schedule a jump */ |
| 386 |
#ifdef BUTTON_TESTING |
| 387 |
fprintf(MSG_OUT, "libdvdnav: Evaluating Button Activation commands.\n"); |
| 388 |
#endif |
| 389 |
if(vm_exec_cmd(this->vm, &(button_ptr->cmd)) == 1) { |
| 390 |
/* Command caused a jump */ |
| 391 |
this->vm->hop_channel++; |
| 392 |
this->position_current.still = 0; |
| 393 |
this->last_cmd_nav_lbn = pci->pci_gi.nv_pck_lbn; |
| 394 |
} |
| 395 |
|
| 396 |
pthread_mutex_unlock(&this->vm_lock); |
| 397 |
return DVDNAV_STATUS_OK; |
| 398 |
} |
| 399 |
|
| 400 |
dvdnav_status_t dvdnav_button_activate_cmd(dvdnav_t *this, int32_t button, vm_cmd_t *cmd) |
| 401 |
{ |
| 402 |
pthread_mutex_lock(&this->vm_lock); |
| 403 |
|
| 404 |
if(!this->vm->state.pgc) { |
| 405 |
printerr("No current PGC."); |
| 406 |
pthread_mutex_unlock(&this->vm_lock); |
| 407 |
return DVDNAV_STATUS_ERR; |
| 408 |
} |
| 409 |
|
| 410 |
/* make the VM execute the appropriate code and probably |
| 411 |
* schedule a jump */ |
| 412 |
#ifdef BUTTON_TESTING |
| 413 |
fprintf(MSG_OUT, "libdvdnav: dvdnav_button_activate_cmd: Evaluating Button Activation commands.\n"); |
| 414 |
#endif |
| 415 |
if(button > 0) { |
| 416 |
this->vm->state.HL_BTNN_REG = (button << 10); |
| 417 |
if(vm_exec_cmd(this->vm, cmd) == 1) { |
| 418 |
/* Command caused a jump */ |
| 419 |
this->vm->hop_channel++; |
| 420 |
} |
| 421 |
} |
| 422 |
/* Always remove still, because some still menus have no buttons. */ |
| 423 |
this->position_current.still = 0; |
| 424 |
this->sync_wait = 0; |
| 425 |
pthread_mutex_unlock(&this->vm_lock); |
| 426 |
return DVDNAV_STATUS_OK; |
| 427 |
} |
| 428 |
|
| 429 |
dvdnav_status_t dvdnav_button_select(dvdnav_t *this, pci_t *pci, int32_t button) { |
| 430 |
if(!pci->hli.hl_gi.hli_ss) { |
| 431 |
printerr("Not in a menu."); |
| 432 |
return DVDNAV_STATUS_ERR; |
| 433 |
} |
| 434 |
if(this->last_cmd_nav_lbn == pci->pci_gi.nv_pck_lbn) { |
| 435 |
printerr("This NAV has already been left."); |
| 436 |
return DVDNAV_STATUS_ERR; |
| 437 |
} |
| 438 |
|
| 439 |
#ifdef BUTTON_TESTING |
| 440 |
fprintf(MSG_OUT, "libdvdnav: Button select %i\n", button); |
| 441 |
#endif |
| 442 |
|
| 443 |
if((button <= 0) || (button > pci->hli.hl_gi.btn_ns)) { |
| 444 |
printerr("Button does not exist."); |
| 445 |
return DVDNAV_STATUS_ERR; |
| 446 |
} |
| 447 |
|
| 448 |
this->vm->state.HL_BTNN_REG = (button << 10); |
| 449 |
this->position_current.button = -1; /* Force Highlight change */ |
| 450 |
|
| 451 |
return DVDNAV_STATUS_OK; |
| 452 |
} |
| 453 |
|
| 454 |
dvdnav_status_t dvdnav_button_select_and_activate(dvdnav_t *this, pci_t *pci, |
| 455 |
int32_t button) { |
| 456 |
/* A trivial function */ |
| 457 |
if(dvdnav_button_select(this, pci, button) != DVDNAV_STATUS_ERR) |
| 458 |
return dvdnav_button_activate(this, pci); |
| 459 |
return DVDNAV_STATUS_ERR; |
| 460 |
} |
| 461 |
|
| 462 |
dvdnav_status_t dvdnav_mouse_select(dvdnav_t *this, pci_t *pci, int32_t x, int32_t y) { |
| 463 |
int32_t button, cur_button; |
| 464 |
int32_t best,dist,d; |
| 465 |
int32_t mx,my,dx,dy; |
| 466 |
|
| 467 |
if(!pci->hli.hl_gi.hli_ss) { |
| 468 |
printerr("Not in a menu."); |
| 469 |
return DVDNAV_STATUS_ERR; |
| 470 |
} |
| 471 |
if(this->last_cmd_nav_lbn == pci->pci_gi.nv_pck_lbn) { |
| 472 |
printerr("This NAV has already been left."); |
| 473 |
return DVDNAV_STATUS_ERR; |
| 474 |
} |
| 475 |
|
| 476 |
cur_button = this->vm->state.HL_BTNN_REG >> 10; |
| 477 |
|
| 478 |
best = 0; |
| 479 |
dist = 0x08000000; /* >> than (720*720)+(567*567); */ |
| 480 |
|
| 481 |
/* Loop through all buttons */ |
| 482 |
for(button = 1; button <= pci->hli.hl_gi.btn_ns; button++) { |
| 483 |
const btni_t *button_ptr = &(pci->hli.btnit[button-1]); |
| 484 |
|
| 485 |
if((x >= button_ptr->x_start) && (x <= button_ptr->x_end) && |
| 486 |
(y >= button_ptr->y_start) && (y <= button_ptr->y_end)) { |
| 487 |
mx = (button_ptr->x_start + button_ptr->x_end)/2; |
| 488 |
my = (button_ptr->y_start + button_ptr->y_end)/2; |
| 489 |
dx = mx - x; |
| 490 |
dy = my - y; |
| 491 |
d = (dx*dx) + (dy*dy); |
| 492 |
/* If the mouse is within the button and the mouse is closer |
| 493 |
* to the center of this button then it is the best choice. */ |
| 494 |
if(d < dist) { |
| 495 |
dist = d; |
| 496 |
best = button; |
| 497 |
} |
| 498 |
} |
| 499 |
} |
| 500 |
/* As an efficiency measure, only re-select the button |
| 501 |
* if it is different to the previously selected one. */ |
| 502 |
if (best != 0 && best != cur_button) |
| 503 |
dvdnav_button_select(this, pci, best); |
| 504 |
|
| 505 |
/* return DVDNAV_STATUS_OK only if we actually found a matching button */ |
| 506 |
return best ? DVDNAV_STATUS_OK : DVDNAV_STATUS_ERR; |
| 507 |
} |
| 508 |
|
| 509 |
dvdnav_status_t dvdnav_mouse_activate(dvdnav_t *this, pci_t *pci, int32_t x, int32_t y) { |
| 510 |
/* A trivial function */ |
| 511 |
if(dvdnav_mouse_select(this, pci, x,y) != DVDNAV_STATUS_ERR) |
| 512 |
return dvdnav_button_activate(this, pci); |
| 513 |
return DVDNAV_STATUS_ERR; |
| 514 |
} |