1 /*****************************************************************************
2 * osd.c - The OSD Menu core code.
3 *****************************************************************************
4 * Copyright (C) 2005-2007 M2X
7 * Authors: Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
35 #include <vlc_image.h>
42 static const char *ppsz_button_states[] = { "unselect", "select", "pressed" };
45 /*****************************************************************************
47 *****************************************************************************/
49 static void osd_UpdateState( osd_menu_state_t *, int, int, int, int, picture_t * );
50 static inline osd_state_t *osd_VolumeStateChange( osd_state_t *, int );
51 static int osd_VolumeStep( vlc_object_t *, int, int );
52 static vlc_bool_t osd_isVisible( osd_menu_t *p_osd );
53 static osd_menu_t *osd_ParserLoad( vlc_object_t *, const char * );
54 static void osd_ParserUnload( osd_menu_t * );
56 static vlc_bool_t osd_isVisible( osd_menu_t *p_osd )
60 var_Get( p_osd, "osd-menu-visible", &val );
64 /*****************************************************************************
65 * Wrappers for loading and unloading osd parser modules.
66 *****************************************************************************/
67 static osd_menu_t *osd_ParserLoad( vlc_object_t *p_this, const char *psz_file )
71 p_menu = vlc_object_create( p_this, VLC_OBJECT_OSDMENU );
74 msg_Err( p_this, "out of memory" );
77 vlc_object_yield( p_menu );
78 vlc_object_attach( p_menu, p_this->p_libvlc );
80 /* Stuff needed for Parser */
81 p_menu->psz_file = strdup( psz_file );
82 p_menu->p_image = image_HandlerCreate( p_this );
83 if( !p_menu->p_image || !p_menu->psz_file )
85 msg_Err( p_this, "unable to load images, aborting .." );
86 osd_ParserUnload( p_menu );
92 char *psz_ext = strrchr( p_menu->psz_file, '.' );
94 if( psz_ext && !strcmp( psz_ext, ".cfg") )
95 psz_type = (char*)"import-osd";
97 psz_type = (char*)"import-osd-xml";
99 p_menu->p_parser = module_Need( p_menu, "osd parser",
100 psz_type, VLC_TRUE );
101 if( !p_menu->p_parser )
103 osd_ParserUnload( p_menu );
110 static void osd_ParserUnload( osd_menu_t *p_menu )
112 if( p_menu->p_image )
113 image_HandlerDelete( p_menu->p_image );
114 if( p_menu->psz_file )
115 free( p_menu->psz_file );
117 if( p_menu->p_parser )
118 module_Unneed( p_menu, p_menu->p_parser );
120 vlc_object_detach( p_menu );
121 vlc_object_release( p_menu );
125 * Change state on an osd_button_t.
127 * This function selects the specified state and returns a pointer to it. The
128 * following states are currently supported:
129 * \see OSD_BUTTON_UNSELECT
130 * \see OSD_BUTTON_SELECT
131 * \see OSD_BUTTON_PRESSED
133 static osd_state_t *osd_StateChange( osd_button_t *p_button, const int i_state )
135 osd_state_t *p_current = p_button->p_states;
136 osd_state_t *p_temp = NULL;
139 for( i=0; p_current != NULL; i++ )
141 if( p_current->i_state == i_state )
143 p_button->i_x = p_current->i_x;
144 p_button->i_y = p_current->i_y;
145 p_button->i_width = p_current->i_width;
146 p_button->i_height = p_current->i_height;
149 p_temp = p_current->p_next;
152 return p_button->p_states;
155 /*****************************************************************************
157 *****************************************************************************/
158 osd_menu_t *__osd_MenuCreate( vlc_object_t *p_this, const char *psz_file )
160 osd_menu_t *p_osd = NULL;
165 /* to be sure to avoid multiple creation */
166 var_Create( p_this->p_libvlc, "osd_mutex", VLC_VAR_MUTEX );
167 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
168 vlc_mutex_lock( lockval.p_address );
170 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
175 /* Parse configuration file */
176 p_osd = osd_ParserLoad( p_this, psz_file );
180 /* Setup default button (first button) */
181 p_osd->p_state->p_visible = p_osd->p_button;
182 p_osd->p_state->p_visible->p_current_state =
183 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
184 p_osd->i_width = p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch;
185 p_osd->i_height = p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines;
187 if( p_osd->p_state->p_volume )
189 /* Update the volume state images to match the current volume */
190 i_volume = config_GetInt( p_this, "volume" );
191 i_steps = osd_VolumeStep( p_this, i_volume, p_osd->p_state->p_volume->i_ranges );
192 p_osd->p_state->p_volume->p_current_state = osd_VolumeStateChange(
193 p_osd->p_state->p_volume->p_states, i_steps );
195 /* Initialize OSD state */
196 osd_UpdateState( p_osd->p_state, p_osd->i_x, p_osd->i_y,
197 p_osd->i_width, p_osd->i_height, NULL );
199 /* Signal when an update of OSD menu is needed */
200 var_Create( p_osd, "osd-menu-update", VLC_VAR_BOOL );
201 var_Create( p_osd, "osd-menu-visible", VLC_VAR_BOOL );
203 val.b_bool = VLC_FALSE;
204 var_Set( p_osd, "osd-menu-update", val );
205 var_Set( p_osd, "osd-menu-visible", val );
207 vlc_mutex_unlock( lockval.p_address );
211 msg_Err( p_this, "creating OSD menu object failed" );
214 image_HandlerDelete( p_osd->p_image );
215 if( p_osd->psz_file )
216 free( p_osd->psz_file );
218 vlc_object_detach( p_osd );
219 vlc_object_release( p_osd );
220 vlc_mutex_unlock( lockval.p_address );
224 void __osd_MenuDelete( vlc_object_t *p_this, osd_menu_t *p_osd )
228 if( !p_osd || !p_this ) return;
230 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
231 vlc_mutex_lock( lockval.p_address );
233 vlc_object_release( p_osd );
234 if( p_osd->p_internals->i_refcount > 0 )
236 vlc_mutex_unlock( lockval.p_address );
240 var_Destroy( p_osd, "osd-menu-visible" );
241 var_Destroy( p_osd, "osd-menu-update" );
243 osd_ParserUnload( p_osd );
245 vlc_mutex_unlock( lockval.p_address );
248 /* The volume can be modified in another interface while the OSD Menu
249 * has not been instantiated yet. This routines updates the "volume OSD menu item"
250 * to reflect the current state of the GUI.
252 static inline osd_state_t *osd_VolumeStateChange( osd_state_t *p_current, int i_steps )
254 osd_state_t *p_temp = NULL;
257 if( i_steps < 0 ) i_steps = 0;
259 for( i=0; (i < i_steps) && (p_current != NULL); i++ )
261 p_temp = p_current->p_next;
262 if( !p_temp ) return p_current;
265 return (!p_temp) ? p_current : p_temp;
268 /* Update the state of the OSD Menu */
269 static void osd_UpdateState( osd_menu_state_t *p_state, int i_x, int i_y,
270 int i_width, int i_height, picture_t *p_pic )
274 p_state->i_width = i_width;
275 p_state->i_height = i_height;
276 p_state->p_pic = p_pic;
279 void __osd_MenuShow( vlc_object_t *p_this )
281 osd_menu_t *p_osd = NULL;
282 osd_button_t *p_button = NULL;
285 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
288 msg_Err( p_this, "osd_MenuNext failed" );
292 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
293 vlc_mutex_lock( lockval.p_address );
295 #if defined(OSD_MENU_DEBUG)
296 msg_Dbg( p_osd, "menu on" );
298 p_button = p_osd->p_state->p_visible;
301 if( !p_button->b_range )
302 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_UNSELECT );
303 p_osd->p_state->p_visible = p_osd->p_button;
305 if( !p_osd->p_state->p_visible->b_range )
306 p_osd->p_state->p_visible->p_current_state =
307 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
309 osd_UpdateState( p_osd->p_state,
310 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
311 p_osd->p_state->p_visible->p_current_state->i_width,
312 p_osd->p_state->p_visible->p_current_state->i_height,
313 p_osd->p_state->p_visible->p_current_state->p_pic );
314 osd_SetMenuUpdate( p_osd, VLC_TRUE );
316 osd_SetMenuVisible( p_osd, VLC_TRUE );
318 vlc_object_release( (vlc_object_t*) p_osd );
319 vlc_mutex_unlock( lockval.p_address );
322 void __osd_MenuHide( vlc_object_t *p_this )
324 osd_menu_t *p_osd = NULL;
327 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
330 msg_Err( p_this, "osd_MenuNext failed" );
334 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
335 vlc_mutex_lock( lockval.p_address );
337 #if defined(OSD_MENU_DEBUG)
338 msg_Dbg( p_osd, "menu off" );
340 osd_UpdateState( p_osd->p_state,
341 p_osd->p_state->i_x, p_osd->p_state->i_y,
343 osd_SetMenuUpdate( p_osd, VLC_TRUE );
345 vlc_object_release( (vlc_object_t*) p_osd );
346 vlc_mutex_unlock( lockval.p_address );
349 void __osd_MenuActivate( vlc_object_t *p_this )
351 osd_menu_t *p_osd = NULL;
352 osd_button_t *p_button = NULL;
355 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
358 msg_Err( p_this, "osd_MenuNext failed" );
362 if( osd_isVisible( p_osd ) == VLC_FALSE )
364 vlc_object_release( (vlc_object_t*) p_osd );
368 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
369 vlc_mutex_lock( lockval.p_address );
371 #if defined(OSD_MENU_DEBUG)
372 msg_Dbg( p_osd, "select" );
374 p_button = p_osd->p_state->p_visible;
376 * Is there a menu item above or below? If so, then select it.
378 if( p_button && p_button->p_up )
380 vlc_object_release( (vlc_object_t*) p_osd );
381 vlc_mutex_unlock( lockval.p_address );
382 __osd_MenuUp( p_this ); /* "menu select" means go to menu item above. */
385 if( p_button && p_button->p_down )
387 vlc_object_release( (vlc_object_t*) p_osd );
388 vlc_mutex_unlock( lockval.p_address );
389 __osd_MenuDown( p_this ); /* "menu select" means go to menu item below. */
393 if( p_button && !p_button->b_range )
395 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_PRESSED );
396 osd_UpdateState( p_osd->p_state,
397 p_button->i_x, p_button->i_y,
398 p_osd->p_state->p_visible->p_current_state->i_width,
399 p_osd->p_state->p_visible->p_current_state->i_height,
400 p_button->p_current_state->p_pic );
401 osd_SetMenuUpdate( p_osd, VLC_TRUE );
402 osd_SetMenuVisible( p_osd, VLC_TRUE );
403 osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt( p_osd, p_button->psz_action ) );
404 #if defined(OSD_MENU_DEBUG)
405 msg_Dbg( p_osd, "select (%d, %s)", config_GetInt( p_osd, p_button->psz_action ), p_button->psz_action );
408 vlc_object_release( (vlc_object_t*) p_osd );
409 vlc_mutex_unlock( lockval.p_address );
412 void __osd_MenuNext( vlc_object_t *p_this )
414 osd_menu_t *p_osd = NULL;
415 osd_button_t *p_button = NULL;
418 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
421 msg_Err( p_this, "osd_MenuNext failed" );
425 if( osd_isVisible( p_osd ) == VLC_FALSE )
427 vlc_object_release( (vlc_object_t*) p_osd );
431 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
432 vlc_mutex_lock( lockval.p_address );
434 p_button = p_osd->p_state->p_visible;
437 if( !p_button->b_range )
438 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_UNSELECT );
439 if( p_button->p_next )
440 p_osd->p_state->p_visible = p_button->p_next;
442 p_osd->p_state->p_visible = p_osd->p_button;
444 if( !p_osd->p_state->p_visible->b_range )
445 p_osd->p_state->p_visible->p_current_state =
446 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
448 osd_UpdateState( p_osd->p_state,
449 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
450 p_osd->p_state->p_visible->p_current_state->i_width,
451 p_osd->p_state->p_visible->p_current_state->i_height,
452 p_osd->p_state->p_visible->p_current_state->p_pic );
453 osd_SetMenuUpdate( p_osd, VLC_TRUE );
455 #if defined(OSD_MENU_DEBUG)
456 msg_Dbg( p_osd, "direction right [button %s]", p_osd->p_state->p_visible->psz_action );
459 vlc_object_release( (vlc_object_t*) p_osd );
460 vlc_mutex_unlock( lockval.p_address );
463 void __osd_MenuPrev( vlc_object_t *p_this )
465 osd_menu_t *p_osd = NULL;
466 osd_button_t *p_button = NULL;
469 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
472 msg_Err( p_this, "osd_MenuPrev failed" );
476 if( osd_isVisible( p_osd ) == VLC_FALSE )
478 vlc_object_release( (vlc_object_t*) p_osd );
482 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
483 vlc_mutex_lock( lockval.p_address );
485 p_button = p_osd->p_state->p_visible;
488 if( !p_button->b_range )
489 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_UNSELECT );
490 if( p_button->p_prev )
491 p_osd->p_state->p_visible = p_button->p_prev;
493 p_osd->p_state->p_visible = p_osd->p_last_button;
495 if( !p_osd->p_state->p_visible->b_range )
496 p_osd->p_state->p_visible->p_current_state =
497 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
499 osd_UpdateState( p_osd->p_state,
500 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
501 p_osd->p_state->p_visible->p_current_state->i_width,
502 p_osd->p_state->p_visible->p_current_state->i_height,
503 p_osd->p_state->p_visible->p_current_state->p_pic );
504 osd_SetMenuUpdate( p_osd, VLC_TRUE );
506 #if defined(OSD_MENU_DEBUG)
507 msg_Dbg( p_osd, "direction left [button %s]", p_osd->p_state->p_visible->psz_action );
510 vlc_object_release( (vlc_object_t*) p_osd );
511 vlc_mutex_unlock( lockval.p_address );
514 void __osd_MenuUp( vlc_object_t *p_this )
516 osd_menu_t *p_osd = NULL;
517 osd_button_t *p_button = NULL;
519 #if defined(OSD_MENU_DEBUG)
522 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
525 msg_Err( p_this, "osd_MenuDown failed" );
529 if( osd_isVisible( p_osd ) == VLC_FALSE )
531 vlc_object_release( (vlc_object_t*) p_osd );
535 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
536 vlc_mutex_lock( lockval.p_address );
538 p_button = p_osd->p_state->p_visible;
541 if( !p_button->b_range )
543 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_SELECT );
545 p_osd->p_state->p_visible = p_button->p_up;
548 if( p_button->b_range && p_osd->p_state->p_visible->b_range )
550 osd_state_t *p_temp = p_osd->p_state->p_visible->p_current_state;
551 if( p_temp && p_temp->p_next )
552 p_osd->p_state->p_visible->p_current_state = p_temp->p_next;
554 else if( !p_osd->p_state->p_visible->b_range )
556 p_osd->p_state->p_visible->p_current_state =
557 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
560 osd_UpdateState( p_osd->p_state,
561 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
562 p_osd->p_state->p_visible->p_current_state->i_width,
563 p_osd->p_state->p_visible->p_current_state->i_height,
564 p_osd->p_state->p_visible->p_current_state->p_pic );
565 osd_SetMenuUpdate( p_osd, VLC_TRUE );
566 /* If this is a range style action with associated images of only one state,
567 * then perform "menu select" on every menu navigation
569 if( p_button->b_range )
571 osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt(p_osd, p_button->psz_action) );
572 #if defined(OSD_MENU_DEBUG)
573 msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action );
577 #if defined(OSD_MENU_DEBUG)
578 msg_Dbg( p_osd, "direction up [button %s]", p_osd->p_state->p_visible->psz_action );
581 vlc_object_release( (vlc_object_t*) p_osd );
582 vlc_mutex_unlock( lockval.p_address );
585 void __osd_MenuDown( vlc_object_t *p_this )
587 osd_menu_t *p_osd = NULL;
588 osd_button_t *p_button = NULL;
590 #if defined(OSD_MENU_DEBUG)
594 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
597 msg_Err( p_this, "osd_MenuDown failed" );
601 if( osd_isVisible( p_osd ) == VLC_FALSE )
603 vlc_object_release( (vlc_object_t*) p_osd );
607 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
608 vlc_mutex_lock( lockval.p_address );
610 p_button = p_osd->p_state->p_visible;
613 if( !p_button->b_range )
615 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_SELECT );
616 if( p_button->p_down )
617 p_osd->p_state->p_visible = p_button->p_down;
620 if( p_button->b_range && p_osd->p_state->p_visible->b_range )
622 osd_state_t *p_temp = p_osd->p_state->p_visible->p_current_state;
623 if( p_temp && p_temp->p_prev )
624 p_osd->p_state->p_visible->p_current_state = p_temp->p_prev;
626 else if( !p_osd->p_state->p_visible->b_range )
628 p_osd->p_state->p_visible->p_current_state =
629 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
632 osd_UpdateState( p_osd->p_state,
633 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
634 p_osd->p_state->p_visible->p_current_state->i_width,
635 p_osd->p_state->p_visible->p_current_state->i_height,
636 p_osd->p_state->p_visible->p_current_state->p_pic );
637 osd_SetMenuUpdate( p_osd, VLC_TRUE );
638 /* If this is a range style action with associated images of only one state,
639 * then perform "menu select" on every menu navigation
641 if( p_button->b_range )
643 osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt(p_osd, p_button->psz_action_down) );
644 #if defined(OSD_MENU_DEBUG)
645 msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action_down );
649 #if defined(OSD_MENU_DEBUG)
650 msg_Dbg( p_osd, "direction down [button %s]", p_osd->p_state->p_visible->psz_action );
653 vlc_object_release( (vlc_object_t*) p_osd );
654 vlc_mutex_unlock( lockval.p_address );
657 static int osd_VolumeStep( vlc_object_t *p_this, int i_volume, int i_steps )
659 int i_volume_step = 0;
662 i_volume_step = config_GetInt( p_this->p_libvlc, "volume-step" );
663 return (i_volume/i_volume_step);
667 * Display current audio volume bitmap
669 * The OSD Menu audio volume bar is updated to reflect the new audio volume. Call this function
670 * when the audio volume is updated outside the OSD menu command "menu up", "menu down" or "menu select".
672 void __osd_Volume( vlc_object_t *p_this )
674 osd_menu_t *p_osd = NULL;
675 osd_button_t *p_button = NULL;
680 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
683 msg_Err( p_this, "OSD menu volume update failed" );
687 if( p_osd->p_state && p_osd->p_state->p_volume )
689 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
690 vlc_mutex_lock( lockval.p_address );
692 p_button = p_osd->p_state->p_volume;
693 if( p_osd->p_state->p_volume )
694 p_osd->p_state->p_visible = p_osd->p_state->p_volume;
695 if( p_button && p_button->b_range )
697 /* Update the volume state images to match the current volume */
698 i_volume = config_GetInt( p_this, "volume" );
699 i_steps = osd_VolumeStep( p_this, i_volume, p_button->i_ranges );
700 p_button->p_current_state = osd_VolumeStateChange( p_button->p_states, i_steps );
702 osd_UpdateState( p_osd->p_state,
703 p_button->i_x, p_button->i_y,
704 p_button->p_current_state->i_width,
705 p_button->p_current_state->i_height,
706 p_button->p_current_state->p_pic );
707 osd_SetMenuUpdate( p_osd, VLC_TRUE );
708 osd_SetMenuVisible( p_osd, VLC_TRUE );
710 vlc_object_release( (vlc_object_t*) p_osd );
711 vlc_mutex_unlock( lockval.p_address );
715 osd_button_t *__osd_ButtonFind( vlc_object_t *p_this, int i_x, int i_y,
716 int i_window_height, int i_window_width,
717 int i_scale_width, int i_scale_height )
720 osd_button_t *p_button;
723 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
726 msg_Err( p_this, "OSD menu button find failed" );
730 if( osd_isVisible( p_osd ) == VLC_FALSE )
732 vlc_object_release( (vlc_object_t*) p_osd );
736 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
737 vlc_mutex_lock( lockval.p_address );
739 p_button = p_osd->p_button;
740 for( ; p_button != NULL; p_button = p_button->p_next )
742 int i_source_video_width = ( i_window_width * 1000 ) / i_scale_width;
743 int i_source_video_height = ( i_window_height * 1000 ) / i_scale_height;
744 int i_y_offset = p_button->i_y;
745 int i_x_offset = p_button->i_x;
746 int i_width = p_button->i_width;
747 int i_height = p_button->i_height;
749 if( p_osd->i_position > 0 )
751 int i_inv_scale_y = i_source_video_height;
752 int i_inv_scale_x = i_source_video_width;
755 if( p_osd->i_position & SUBPICTURE_ALIGN_BOTTOM )
757 i_y_offset = i_window_height - p_button->i_height -
758 (p_osd->i_y + p_button->i_y) * i_inv_scale_y / 1000;
760 else if ( !(p_osd->i_position & SUBPICTURE_ALIGN_TOP) )
762 i_y_offset = i_window_height / 2 - p_button->i_height / 2;
765 if( p_osd->i_position & SUBPICTURE_ALIGN_RIGHT )
767 i_x_offset = i_window_width - p_button->i_width -
768 (pi_x + p_button->i_x)
769 * i_inv_scale_x / 1000;
771 else if ( !(p_osd->i_position & SUBPICTURE_ALIGN_LEFT) )
773 i_x_offset = i_window_width / 2 - p_button->i_width / 2;
776 i_width = i_window_width - p_button->i_width - i_inv_scale_x / 1000;
777 i_height = i_window_height - p_button->i_height - i_inv_scale_y / 1000;
780 // TODO: write for Up / Down case too.
781 // TODO: handle absolute positioning case
782 if( ( i_x >= i_x_offset ) && ( i_x <= i_x_offset + i_width ) &&
783 ( i_y >= i_y_offset ) && ( i_y <= i_y_offset + i_height ) )
785 vlc_object_release( (vlc_object_t*) p_osd );
786 vlc_mutex_unlock( lockval.p_address );
791 vlc_object_release( (vlc_object_t*) p_osd );
792 vlc_mutex_unlock( lockval.p_address );
797 * Select the button provided as the new active button
799 void __osd_ButtonSelect( vlc_object_t *p_this, osd_button_t *p_button )
805 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
808 msg_Err( p_this, "OSD menu button select failed" );
812 if( osd_isVisible( p_osd ) == VLC_FALSE )
814 vlc_object_release( (vlc_object_t*) p_osd );
818 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
819 vlc_mutex_lock( lockval.p_address );
821 p_old = p_osd->p_state->p_visible;
824 if( !p_old->b_range )
825 p_old->p_current_state = osd_StateChange( p_old, OSD_BUTTON_UNSELECT );
826 p_osd->p_state->p_visible = p_button;
828 if( !p_osd->p_state->p_visible->b_range )
829 p_osd->p_state->p_visible->p_current_state =
830 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
832 osd_UpdateState( p_osd->p_state,
833 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
834 p_osd->p_state->p_visible->p_current_state->i_width,
835 p_osd->p_state->p_visible->p_current_state->i_height,
836 p_osd->p_state->p_visible->p_current_state->p_pic );
837 osd_SetMenuUpdate( p_osd, VLC_TRUE );
839 #if defined(OSD_MENU_DEBUG)
840 msg_Dbg( p_osd, "button selected is [button %s]", p_osd->p_state->p_visible->psz_action );
843 vlc_object_release( (vlc_object_t*) p_osd );
844 vlc_mutex_unlock( lockval.p_address );