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 *****************************************************************************/
32 #include <vlc_common.h>
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 bool 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 bool 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 )
70 static const char osdmenu_name[] = "osd menu";
72 p_menu = vlc_custom_create( p_this, sizeof( *p_menu ), VLC_OBJECT_OSDMENU,
77 vlc_object_attach( p_menu, p_this->p_libvlc );
79 /* Stuff needed for Parser */
80 p_menu->psz_file = strdup( psz_file );
81 p_menu->p_image = image_HandlerCreate( p_this );
82 if( !p_menu->p_image || !p_menu->psz_file )
84 msg_Err( p_this, "unable to load images, aborting .." );
85 osd_ParserUnload( p_menu );
91 char *psz_ext = strrchr( p_menu->psz_file, '.' );
93 if( psz_ext && !strcmp( psz_ext, ".cfg") )
94 psz_type = (char*)"import-osd";
96 psz_type = (char*)"import-osd-xml";
98 p_menu->p_parser = module_Need( p_menu, "osd parser",
100 if( !p_menu->p_parser )
102 osd_ParserUnload( p_menu );
109 static void osd_ParserUnload( osd_menu_t *p_menu )
111 if( p_menu->p_image )
112 image_HandlerDelete( p_menu->p_image );
113 if( p_menu->psz_file )
114 free( p_menu->psz_file );
116 if( p_menu->p_parser )
117 module_Unneed( p_menu, p_menu->p_parser );
119 vlc_object_detach( p_menu );
120 vlc_object_release( p_menu );
124 * Change state on an osd_button_t.
126 * This function selects the specified state and returns a pointer to it. The
127 * following states are currently supported:
128 * \see OSD_BUTTON_UNSELECT
129 * \see OSD_BUTTON_SELECT
130 * \see OSD_BUTTON_PRESSED
132 static osd_state_t *osd_StateChange( osd_button_t *p_button, const int i_state )
134 osd_state_t *p_current = p_button->p_states;
135 osd_state_t *p_temp = NULL;
138 for( i=0; p_current != NULL; i++ )
140 if( p_current->i_state == i_state )
142 p_button->i_x = p_current->i_x;
143 p_button->i_y = p_current->i_y;
144 p_button->i_width = p_current->i_width;
145 p_button->i_height = p_current->i_height;
148 p_temp = p_current->p_next;
151 return p_button->p_states;
154 /*****************************************************************************
156 *****************************************************************************/
157 osd_menu_t *__osd_MenuCreate( vlc_object_t *p_this, const char *psz_file )
159 osd_menu_t *p_osd = NULL;
164 /* to be sure to avoid multiple creation */
165 var_Create( p_this->p_libvlc, "osd_mutex", VLC_VAR_MUTEX );
166 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
167 vlc_mutex_lock( lockval.p_address );
169 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
174 /* Parse configuration file */
175 p_osd = osd_ParserLoad( p_this, psz_file );
179 /* Setup default button (first button) */
180 p_osd->p_state->p_visible = p_osd->p_button;
181 p_osd->p_state->p_visible->p_current_state =
182 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
183 p_osd->i_width = p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch;
184 p_osd->i_height = p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines;
186 if( p_osd->p_state->p_volume )
188 /* Update the volume state images to match the current volume */
189 i_volume = config_GetInt( p_this, "volume" );
190 i_steps = osd_VolumeStep( p_this, i_volume, p_osd->p_state->p_volume->i_ranges );
191 p_osd->p_state->p_volume->p_current_state = osd_VolumeStateChange(
192 p_osd->p_state->p_volume->p_states, i_steps );
194 /* Initialize OSD state */
195 osd_UpdateState( p_osd->p_state, p_osd->i_x, p_osd->i_y,
196 p_osd->i_width, p_osd->i_height, NULL );
198 /* Signal when an update of OSD menu is needed */
199 var_Create( p_osd, "osd-menu-update", VLC_VAR_BOOL );
200 var_Create( p_osd, "osd-menu-visible", VLC_VAR_BOOL );
203 var_Set( p_osd, "osd-menu-update", val );
204 var_Set( p_osd, "osd-menu-visible", val );
206 vlc_mutex_unlock( lockval.p_address );
210 msg_Err( p_this, "creating OSD menu object failed" );
213 image_HandlerDelete( p_osd->p_image );
214 if( p_osd->psz_file )
215 free( p_osd->psz_file );
217 vlc_object_detach( p_osd );
218 vlc_object_release( p_osd );
219 vlc_mutex_unlock( lockval.p_address );
223 void __osd_MenuDelete( vlc_object_t *p_this, osd_menu_t *p_osd )
227 if( !p_osd || !p_this ) return;
229 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
230 vlc_mutex_lock( lockval.p_address );
232 vlc_object_release( p_osd );
233 if( vlc_internals( VLC_OBJECT(p_osd) )->i_refcount > 0 )
235 vlc_mutex_unlock( lockval.p_address );
239 var_Destroy( p_osd, "osd-menu-visible" );
240 var_Destroy( p_osd, "osd-menu-update" );
242 osd_ParserUnload( p_osd );
244 vlc_mutex_unlock( lockval.p_address );
247 /* The volume can be modified in another interface while the OSD Menu
248 * has not been instantiated yet. This routines updates the "volume OSD menu item"
249 * to reflect the current state of the GUI.
251 static inline osd_state_t *osd_VolumeStateChange( osd_state_t *p_current, int i_steps )
253 osd_state_t *p_temp = NULL;
256 if( i_steps < 0 ) i_steps = 0;
258 for( i=0; (i < i_steps) && (p_current != NULL); i++ )
260 p_temp = p_current->p_next;
261 if( !p_temp ) return p_current;
264 return (!p_temp) ? p_current : p_temp;
267 /* Update the state of the OSD Menu */
268 static void osd_UpdateState( osd_menu_state_t *p_state, int i_x, int i_y,
269 int i_width, int i_height, picture_t *p_pic )
273 p_state->i_width = i_width;
274 p_state->i_height = i_height;
275 p_state->p_pic = p_pic;
278 void __osd_MenuShow( vlc_object_t *p_this )
280 osd_menu_t *p_osd = NULL;
281 osd_button_t *p_button = NULL;
284 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
287 msg_Err( p_this, "osd_MenuNext failed" );
291 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
292 vlc_mutex_lock( lockval.p_address );
294 #if defined(OSD_MENU_DEBUG)
295 msg_Dbg( p_osd, "menu on" );
297 p_button = p_osd->p_state->p_visible;
300 if( !p_button->b_range )
301 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_UNSELECT );
302 p_osd->p_state->p_visible = p_osd->p_button;
304 if( !p_osd->p_state->p_visible->b_range )
305 p_osd->p_state->p_visible->p_current_state =
306 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
308 osd_UpdateState( p_osd->p_state,
309 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
310 p_osd->p_state->p_visible->p_current_state->i_width,
311 p_osd->p_state->p_visible->p_current_state->i_height,
312 p_osd->p_state->p_visible->p_current_state->p_pic );
313 osd_SetMenuUpdate( p_osd, true );
315 osd_SetMenuVisible( p_osd, true );
317 vlc_object_release( (vlc_object_t*) p_osd );
318 vlc_mutex_unlock( lockval.p_address );
321 void __osd_MenuHide( vlc_object_t *p_this )
323 osd_menu_t *p_osd = NULL;
326 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
329 msg_Err( p_this, "osd_MenuNext failed" );
333 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
334 vlc_mutex_lock( lockval.p_address );
336 #if defined(OSD_MENU_DEBUG)
337 msg_Dbg( p_osd, "menu off" );
339 osd_UpdateState( p_osd->p_state,
340 p_osd->p_state->i_x, p_osd->p_state->i_y,
342 osd_SetMenuUpdate( p_osd, true );
344 vlc_object_release( (vlc_object_t*) p_osd );
345 vlc_mutex_unlock( lockval.p_address );
348 void __osd_MenuActivate( vlc_object_t *p_this )
350 osd_menu_t *p_osd = NULL;
351 osd_button_t *p_button = NULL;
354 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
357 msg_Err( p_this, "osd_MenuNext failed" );
361 if( osd_isVisible( p_osd ) == false )
363 vlc_object_release( (vlc_object_t*) p_osd );
367 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
368 vlc_mutex_lock( lockval.p_address );
370 #if defined(OSD_MENU_DEBUG)
371 msg_Dbg( p_osd, "select" );
373 p_button = p_osd->p_state->p_visible;
375 * Is there a menu item above or below? If so, then select it.
377 if( p_button && p_button->p_up )
379 vlc_object_release( (vlc_object_t*) p_osd );
380 vlc_mutex_unlock( lockval.p_address );
381 __osd_MenuUp( p_this ); /* "menu select" means go to menu item above. */
384 if( p_button && p_button->p_down )
386 vlc_object_release( (vlc_object_t*) p_osd );
387 vlc_mutex_unlock( lockval.p_address );
388 __osd_MenuDown( p_this ); /* "menu select" means go to menu item below. */
392 if( p_button && !p_button->b_range )
394 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_PRESSED );
395 osd_UpdateState( p_osd->p_state,
396 p_button->i_x, p_button->i_y,
397 p_osd->p_state->p_visible->p_current_state->i_width,
398 p_osd->p_state->p_visible->p_current_state->i_height,
399 p_button->p_current_state->p_pic );
400 osd_SetMenuUpdate( p_osd, true );
401 osd_SetMenuVisible( p_osd, true );
402 osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt( p_osd, p_button->psz_action ) );
403 #if defined(OSD_MENU_DEBUG)
404 msg_Dbg( p_osd, "select (%d, %s)", config_GetInt( p_osd, p_button->psz_action ), p_button->psz_action );
407 vlc_object_release( (vlc_object_t*) p_osd );
408 vlc_mutex_unlock( lockval.p_address );
411 void __osd_MenuNext( vlc_object_t *p_this )
413 osd_menu_t *p_osd = NULL;
414 osd_button_t *p_button = NULL;
417 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
420 msg_Err( p_this, "osd_MenuNext failed" );
424 if( osd_isVisible( p_osd ) == false )
426 vlc_object_release( (vlc_object_t*) p_osd );
430 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
431 vlc_mutex_lock( lockval.p_address );
433 p_button = p_osd->p_state->p_visible;
436 if( !p_button->b_range )
437 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_UNSELECT );
438 if( p_button->p_next )
439 p_osd->p_state->p_visible = p_button->p_next;
441 p_osd->p_state->p_visible = p_osd->p_button;
443 if( !p_osd->p_state->p_visible->b_range )
444 p_osd->p_state->p_visible->p_current_state =
445 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
447 osd_UpdateState( p_osd->p_state,
448 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
449 p_osd->p_state->p_visible->p_current_state->i_width,
450 p_osd->p_state->p_visible->p_current_state->i_height,
451 p_osd->p_state->p_visible->p_current_state->p_pic );
452 osd_SetMenuUpdate( p_osd, true );
454 #if defined(OSD_MENU_DEBUG)
455 msg_Dbg( p_osd, "direction right [button %s]", p_osd->p_state->p_visible->psz_action );
458 vlc_object_release( (vlc_object_t*) p_osd );
459 vlc_mutex_unlock( lockval.p_address );
462 void __osd_MenuPrev( vlc_object_t *p_this )
464 osd_menu_t *p_osd = NULL;
465 osd_button_t *p_button = NULL;
468 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
471 msg_Err( p_this, "osd_MenuPrev failed" );
475 if( osd_isVisible( p_osd ) == false )
477 vlc_object_release( (vlc_object_t*) p_osd );
481 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
482 vlc_mutex_lock( lockval.p_address );
484 p_button = p_osd->p_state->p_visible;
487 if( !p_button->b_range )
488 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_UNSELECT );
489 if( p_button->p_prev )
490 p_osd->p_state->p_visible = p_button->p_prev;
492 p_osd->p_state->p_visible = p_osd->p_last_button;
494 if( !p_osd->p_state->p_visible->b_range )
495 p_osd->p_state->p_visible->p_current_state =
496 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
498 osd_UpdateState( p_osd->p_state,
499 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
500 p_osd->p_state->p_visible->p_current_state->i_width,
501 p_osd->p_state->p_visible->p_current_state->i_height,
502 p_osd->p_state->p_visible->p_current_state->p_pic );
503 osd_SetMenuUpdate( p_osd, true );
505 #if defined(OSD_MENU_DEBUG)
506 msg_Dbg( p_osd, "direction left [button %s]", p_osd->p_state->p_visible->psz_action );
509 vlc_object_release( (vlc_object_t*) p_osd );
510 vlc_mutex_unlock( lockval.p_address );
513 void __osd_MenuUp( vlc_object_t *p_this )
515 osd_menu_t *p_osd = NULL;
516 osd_button_t *p_button = NULL;
518 #if defined(OSD_MENU_DEBUG)
521 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
524 msg_Err( p_this, "osd_MenuDown failed" );
528 if( osd_isVisible( p_osd ) == false )
530 vlc_object_release( (vlc_object_t*) p_osd );
534 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
535 vlc_mutex_lock( lockval.p_address );
537 p_button = p_osd->p_state->p_visible;
540 if( !p_button->b_range )
542 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_SELECT );
544 p_osd->p_state->p_visible = p_button->p_up;
547 if( p_button->b_range && p_osd->p_state->p_visible->b_range )
549 osd_state_t *p_temp = p_osd->p_state->p_visible->p_current_state;
550 if( p_temp && p_temp->p_next )
551 p_osd->p_state->p_visible->p_current_state = p_temp->p_next;
553 else if( !p_osd->p_state->p_visible->b_range )
555 p_osd->p_state->p_visible->p_current_state =
556 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
559 osd_UpdateState( p_osd->p_state,
560 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
561 p_osd->p_state->p_visible->p_current_state->i_width,
562 p_osd->p_state->p_visible->p_current_state->i_height,
563 p_osd->p_state->p_visible->p_current_state->p_pic );
564 osd_SetMenuUpdate( p_osd, true );
565 /* If this is a range style action with associated images of only one state,
566 * then perform "menu select" on every menu navigation
568 if( p_button->b_range )
570 osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt(p_osd, p_button->psz_action) );
571 #if defined(OSD_MENU_DEBUG)
572 msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action );
576 #if defined(OSD_MENU_DEBUG)
577 msg_Dbg( p_osd, "direction up [button %s]", p_osd->p_state->p_visible->psz_action );
580 vlc_object_release( (vlc_object_t*) p_osd );
581 vlc_mutex_unlock( lockval.p_address );
584 void __osd_MenuDown( vlc_object_t *p_this )
586 osd_menu_t *p_osd = NULL;
587 osd_button_t *p_button = NULL;
589 #if defined(OSD_MENU_DEBUG)
593 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
596 msg_Err( p_this, "osd_MenuDown failed" );
600 if( osd_isVisible( p_osd ) == false )
602 vlc_object_release( (vlc_object_t*) p_osd );
606 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
607 vlc_mutex_lock( lockval.p_address );
609 p_button = p_osd->p_state->p_visible;
612 if( !p_button->b_range )
614 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_SELECT );
615 if( p_button->p_down )
616 p_osd->p_state->p_visible = p_button->p_down;
619 if( p_button->b_range && p_osd->p_state->p_visible->b_range )
621 osd_state_t *p_temp = p_osd->p_state->p_visible->p_current_state;
622 if( p_temp && p_temp->p_prev )
623 p_osd->p_state->p_visible->p_current_state = p_temp->p_prev;
625 else if( !p_osd->p_state->p_visible->b_range )
627 p_osd->p_state->p_visible->p_current_state =
628 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
631 osd_UpdateState( p_osd->p_state,
632 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
633 p_osd->p_state->p_visible->p_current_state->i_width,
634 p_osd->p_state->p_visible->p_current_state->i_height,
635 p_osd->p_state->p_visible->p_current_state->p_pic );
636 osd_SetMenuUpdate( p_osd, true );
637 /* If this is a range style action with associated images of only one state,
638 * then perform "menu select" on every menu navigation
640 if( p_button->b_range )
642 osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt(p_osd, p_button->psz_action_down) );
643 #if defined(OSD_MENU_DEBUG)
644 msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action_down );
648 #if defined(OSD_MENU_DEBUG)
649 msg_Dbg( p_osd, "direction down [button %s]", p_osd->p_state->p_visible->psz_action );
652 vlc_object_release( (vlc_object_t*) p_osd );
653 vlc_mutex_unlock( lockval.p_address );
656 static int osd_VolumeStep( vlc_object_t *p_this, int i_volume, int i_steps )
658 int i_volume_step = 0;
661 i_volume_step = config_GetInt( p_this->p_libvlc, "volume-step" );
662 return (i_volume/i_volume_step);
666 * Display current audio volume bitmap
668 * The OSD Menu audio volume bar is updated to reflect the new audio volume. Call this function
669 * when the audio volume is updated outside the OSD menu command "menu up", "menu down" or "menu select".
671 void __osd_Volume( vlc_object_t *p_this )
673 osd_menu_t *p_osd = NULL;
674 osd_button_t *p_button = NULL;
679 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
682 msg_Err( p_this, "OSD menu volume update failed" );
686 if( p_osd->p_state && p_osd->p_state->p_volume )
688 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
689 vlc_mutex_lock( lockval.p_address );
691 p_button = p_osd->p_state->p_volume;
692 if( p_osd->p_state->p_volume )
693 p_osd->p_state->p_visible = p_osd->p_state->p_volume;
694 if( p_button && p_button->b_range )
696 /* Update the volume state images to match the current volume */
697 i_volume = config_GetInt( p_this, "volume" );
698 i_steps = osd_VolumeStep( p_this, i_volume, p_button->i_ranges );
699 p_button->p_current_state = osd_VolumeStateChange( p_button->p_states, i_steps );
701 osd_UpdateState( p_osd->p_state,
702 p_button->i_x, p_button->i_y,
703 p_button->p_current_state->i_width,
704 p_button->p_current_state->i_height,
705 p_button->p_current_state->p_pic );
706 osd_SetMenuUpdate( p_osd, true );
707 osd_SetMenuVisible( p_osd, true );
709 vlc_mutex_unlock( lockval.p_address );
711 vlc_object_release( p_osd );
714 osd_button_t *__osd_ButtonFind( vlc_object_t *p_this, int i_x, int i_y,
715 int i_window_height, int i_window_width,
716 int i_scale_width, int i_scale_height )
719 osd_button_t *p_button;
722 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
725 msg_Err( p_this, "OSD menu button find failed" );
729 if( osd_isVisible( p_osd ) == false )
731 vlc_object_release( p_osd );
735 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
736 vlc_mutex_lock( lockval.p_address );
738 p_button = p_osd->p_button;
739 for( ; p_button != NULL; p_button = p_button->p_next )
741 int i_source_video_width = ( i_window_width * 1000 ) / i_scale_width;
742 int i_source_video_height = ( i_window_height * 1000 ) / i_scale_height;
743 int i_y_offset = p_button->i_y;
744 int i_x_offset = p_button->i_x;
745 int i_width = p_button->i_width;
746 int i_height = p_button->i_height;
748 if( p_osd->i_position > 0 )
750 int i_inv_scale_y = i_source_video_height;
751 int i_inv_scale_x = i_source_video_width;
754 if( p_osd->i_position & SUBPICTURE_ALIGN_BOTTOM )
756 i_y_offset = i_window_height - p_button->i_height -
757 (p_osd->i_y + p_button->i_y) * i_inv_scale_y / 1000;
759 else if ( !(p_osd->i_position & SUBPICTURE_ALIGN_TOP) )
761 i_y_offset = i_window_height / 2 - p_button->i_height / 2;
764 if( p_osd->i_position & SUBPICTURE_ALIGN_RIGHT )
766 i_x_offset = i_window_width - p_button->i_width -
767 (pi_x + p_button->i_x)
768 * i_inv_scale_x / 1000;
770 else if ( !(p_osd->i_position & SUBPICTURE_ALIGN_LEFT) )
772 i_x_offset = i_window_width / 2 - p_button->i_width / 2;
775 i_width = i_window_width - p_button->i_width - i_inv_scale_x / 1000;
776 i_height = i_window_height - p_button->i_height - i_inv_scale_y / 1000;
779 // TODO: write for Up / Down case too.
780 // TODO: handle absolute positioning case
781 if( ( i_x >= i_x_offset ) && ( i_x <= i_x_offset + i_width ) &&
782 ( i_y >= i_y_offset ) && ( i_y <= i_y_offset + i_height ) )
784 vlc_object_release( p_osd );
785 vlc_mutex_unlock( lockval.p_address );
790 vlc_object_release( p_osd );
791 vlc_mutex_unlock( lockval.p_address );
796 * Select the button provided as the new active button
798 void __osd_ButtonSelect( vlc_object_t *p_this, osd_button_t *p_button )
804 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
807 msg_Err( p_this, "OSD menu button select failed" );
811 if( osd_isVisible( p_osd ) == false )
813 vlc_object_release( (vlc_object_t*) p_osd );
817 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
818 vlc_mutex_lock( lockval.p_address );
820 p_old = p_osd->p_state->p_visible;
823 if( !p_old->b_range )
824 p_old->p_current_state = osd_StateChange( p_old, OSD_BUTTON_UNSELECT );
825 p_osd->p_state->p_visible = p_button;
827 if( !p_osd->p_state->p_visible->b_range )
828 p_osd->p_state->p_visible->p_current_state =
829 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
831 osd_UpdateState( p_osd->p_state,
832 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
833 p_osd->p_state->p_visible->p_current_state->i_width,
834 p_osd->p_state->p_visible->p_current_state->i_height,
835 p_osd->p_state->p_visible->p_current_state->p_pic );
836 osd_SetMenuUpdate( p_osd, true );
838 #if defined(OSD_MENU_DEBUG)
839 msg_Dbg( p_osd, "button selected is [button %s]", p_osd->p_state->p_visible->psz_action );
842 vlc_object_release( p_osd );
843 vlc_mutex_unlock( lockval.p_address );