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 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,
76 msg_Err( p_this, "out of memory" );
79 vlc_object_yield( p_menu );
80 vlc_object_attach( p_menu, p_this->p_libvlc );
82 /* Stuff needed for Parser */
83 p_menu->psz_file = strdup( psz_file );
84 p_menu->p_image = image_HandlerCreate( p_this );
85 if( !p_menu->p_image || !p_menu->psz_file )
87 msg_Err( p_this, "unable to load images, aborting .." );
88 osd_ParserUnload( p_menu );
94 char *psz_ext = strrchr( p_menu->psz_file, '.' );
96 if( psz_ext && !strcmp( psz_ext, ".cfg") )
97 psz_type = (char*)"import-osd";
99 psz_type = (char*)"import-osd-xml";
101 p_menu->p_parser = module_Need( p_menu, "osd parser",
103 if( !p_menu->p_parser )
105 osd_ParserUnload( p_menu );
112 static void osd_ParserUnload( osd_menu_t *p_menu )
114 if( p_menu->p_image )
115 image_HandlerDelete( p_menu->p_image );
116 if( p_menu->psz_file )
117 free( p_menu->psz_file );
119 if( p_menu->p_parser )
120 module_Unneed( p_menu, p_menu->p_parser );
122 vlc_object_detach( p_menu );
123 vlc_object_release( p_menu );
127 * Change state on an osd_button_t.
129 * This function selects the specified state and returns a pointer to it. The
130 * following states are currently supported:
131 * \see OSD_BUTTON_UNSELECT
132 * \see OSD_BUTTON_SELECT
133 * \see OSD_BUTTON_PRESSED
135 static osd_state_t *osd_StateChange( osd_button_t *p_button, const int i_state )
137 osd_state_t *p_current = p_button->p_states;
138 osd_state_t *p_temp = NULL;
141 for( i=0; p_current != NULL; i++ )
143 if( p_current->i_state == i_state )
145 p_button->i_x = p_current->i_x;
146 p_button->i_y = p_current->i_y;
147 p_button->i_width = p_current->i_width;
148 p_button->i_height = p_current->i_height;
151 p_temp = p_current->p_next;
154 return p_button->p_states;
157 /*****************************************************************************
159 *****************************************************************************/
160 osd_menu_t *__osd_MenuCreate( vlc_object_t *p_this, const char *psz_file )
162 osd_menu_t *p_osd = NULL;
167 /* to be sure to avoid multiple creation */
168 var_Create( p_this->p_libvlc, "osd_mutex", VLC_VAR_MUTEX );
169 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
170 vlc_mutex_lock( lockval.p_address );
172 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
177 /* Parse configuration file */
178 p_osd = osd_ParserLoad( p_this, psz_file );
182 /* Setup default button (first button) */
183 p_osd->p_state->p_visible = p_osd->p_button;
184 p_osd->p_state->p_visible->p_current_state =
185 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
186 p_osd->i_width = p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch;
187 p_osd->i_height = p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines;
189 if( p_osd->p_state->p_volume )
191 /* Update the volume state images to match the current volume */
192 i_volume = config_GetInt( p_this, "volume" );
193 i_steps = osd_VolumeStep( p_this, i_volume, p_osd->p_state->p_volume->i_ranges );
194 p_osd->p_state->p_volume->p_current_state = osd_VolumeStateChange(
195 p_osd->p_state->p_volume->p_states, i_steps );
197 /* Initialize OSD state */
198 osd_UpdateState( p_osd->p_state, p_osd->i_x, p_osd->i_y,
199 p_osd->i_width, p_osd->i_height, NULL );
201 /* Signal when an update of OSD menu is needed */
202 var_Create( p_osd, "osd-menu-update", VLC_VAR_BOOL );
203 var_Create( p_osd, "osd-menu-visible", VLC_VAR_BOOL );
206 var_Set( p_osd, "osd-menu-update", val );
207 var_Set( p_osd, "osd-menu-visible", val );
209 vlc_mutex_unlock( lockval.p_address );
213 msg_Err( p_this, "creating OSD menu object failed" );
216 image_HandlerDelete( p_osd->p_image );
217 if( p_osd->psz_file )
218 free( p_osd->psz_file );
220 vlc_object_detach( p_osd );
221 vlc_object_release( p_osd );
222 vlc_mutex_unlock( lockval.p_address );
226 void __osd_MenuDelete( vlc_object_t *p_this, osd_menu_t *p_osd )
230 if( !p_osd || !p_this ) return;
232 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
233 vlc_mutex_lock( lockval.p_address );
235 vlc_object_release( p_osd );
236 if( p_osd->p_internals->i_refcount > 0 )
238 vlc_mutex_unlock( lockval.p_address );
242 var_Destroy( p_osd, "osd-menu-visible" );
243 var_Destroy( p_osd, "osd-menu-update" );
245 osd_ParserUnload( p_osd );
247 vlc_mutex_unlock( lockval.p_address );
250 /* The volume can be modified in another interface while the OSD Menu
251 * has not been instantiated yet. This routines updates the "volume OSD menu item"
252 * to reflect the current state of the GUI.
254 static inline osd_state_t *osd_VolumeStateChange( osd_state_t *p_current, int i_steps )
256 osd_state_t *p_temp = NULL;
259 if( i_steps < 0 ) i_steps = 0;
261 for( i=0; (i < i_steps) && (p_current != NULL); i++ )
263 p_temp = p_current->p_next;
264 if( !p_temp ) return p_current;
267 return (!p_temp) ? p_current : p_temp;
270 /* Update the state of the OSD Menu */
271 static void osd_UpdateState( osd_menu_state_t *p_state, int i_x, int i_y,
272 int i_width, int i_height, picture_t *p_pic )
276 p_state->i_width = i_width;
277 p_state->i_height = i_height;
278 p_state->p_pic = p_pic;
281 void __osd_MenuShow( vlc_object_t *p_this )
283 osd_menu_t *p_osd = NULL;
284 osd_button_t *p_button = NULL;
287 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
290 msg_Err( p_this, "osd_MenuNext failed" );
294 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
295 vlc_mutex_lock( lockval.p_address );
297 #if defined(OSD_MENU_DEBUG)
298 msg_Dbg( p_osd, "menu on" );
300 p_button = p_osd->p_state->p_visible;
303 if( !p_button->b_range )
304 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_UNSELECT );
305 p_osd->p_state->p_visible = p_osd->p_button;
307 if( !p_osd->p_state->p_visible->b_range )
308 p_osd->p_state->p_visible->p_current_state =
309 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
311 osd_UpdateState( p_osd->p_state,
312 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
313 p_osd->p_state->p_visible->p_current_state->i_width,
314 p_osd->p_state->p_visible->p_current_state->i_height,
315 p_osd->p_state->p_visible->p_current_state->p_pic );
316 osd_SetMenuUpdate( p_osd, true );
318 osd_SetMenuVisible( p_osd, true );
320 vlc_object_release( (vlc_object_t*) p_osd );
321 vlc_mutex_unlock( lockval.p_address );
324 void __osd_MenuHide( vlc_object_t *p_this )
326 osd_menu_t *p_osd = NULL;
329 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
332 msg_Err( p_this, "osd_MenuNext failed" );
336 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
337 vlc_mutex_lock( lockval.p_address );
339 #if defined(OSD_MENU_DEBUG)
340 msg_Dbg( p_osd, "menu off" );
342 osd_UpdateState( p_osd->p_state,
343 p_osd->p_state->i_x, p_osd->p_state->i_y,
345 osd_SetMenuUpdate( p_osd, true );
347 vlc_object_release( (vlc_object_t*) p_osd );
348 vlc_mutex_unlock( lockval.p_address );
351 void __osd_MenuActivate( vlc_object_t *p_this )
353 osd_menu_t *p_osd = NULL;
354 osd_button_t *p_button = NULL;
357 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
360 msg_Err( p_this, "osd_MenuNext failed" );
364 if( osd_isVisible( p_osd ) == false )
366 vlc_object_release( (vlc_object_t*) p_osd );
370 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
371 vlc_mutex_lock( lockval.p_address );
373 #if defined(OSD_MENU_DEBUG)
374 msg_Dbg( p_osd, "select" );
376 p_button = p_osd->p_state->p_visible;
378 * Is there a menu item above or below? If so, then select it.
380 if( p_button && p_button->p_up )
382 vlc_object_release( (vlc_object_t*) p_osd );
383 vlc_mutex_unlock( lockval.p_address );
384 __osd_MenuUp( p_this ); /* "menu select" means go to menu item above. */
387 if( p_button && p_button->p_down )
389 vlc_object_release( (vlc_object_t*) p_osd );
390 vlc_mutex_unlock( lockval.p_address );
391 __osd_MenuDown( p_this ); /* "menu select" means go to menu item below. */
395 if( p_button && !p_button->b_range )
397 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_PRESSED );
398 osd_UpdateState( p_osd->p_state,
399 p_button->i_x, p_button->i_y,
400 p_osd->p_state->p_visible->p_current_state->i_width,
401 p_osd->p_state->p_visible->p_current_state->i_height,
402 p_button->p_current_state->p_pic );
403 osd_SetMenuUpdate( p_osd, true );
404 osd_SetMenuVisible( p_osd, true );
405 osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt( p_osd, p_button->psz_action ) );
406 #if defined(OSD_MENU_DEBUG)
407 msg_Dbg( p_osd, "select (%d, %s)", config_GetInt( p_osd, p_button->psz_action ), p_button->psz_action );
410 vlc_object_release( (vlc_object_t*) p_osd );
411 vlc_mutex_unlock( lockval.p_address );
414 void __osd_MenuNext( vlc_object_t *p_this )
416 osd_menu_t *p_osd = NULL;
417 osd_button_t *p_button = NULL;
420 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
423 msg_Err( p_this, "osd_MenuNext failed" );
427 if( osd_isVisible( p_osd ) == false )
429 vlc_object_release( (vlc_object_t*) p_osd );
433 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
434 vlc_mutex_lock( lockval.p_address );
436 p_button = p_osd->p_state->p_visible;
439 if( !p_button->b_range )
440 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_UNSELECT );
441 if( p_button->p_next )
442 p_osd->p_state->p_visible = p_button->p_next;
444 p_osd->p_state->p_visible = p_osd->p_button;
446 if( !p_osd->p_state->p_visible->b_range )
447 p_osd->p_state->p_visible->p_current_state =
448 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
450 osd_UpdateState( p_osd->p_state,
451 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
452 p_osd->p_state->p_visible->p_current_state->i_width,
453 p_osd->p_state->p_visible->p_current_state->i_height,
454 p_osd->p_state->p_visible->p_current_state->p_pic );
455 osd_SetMenuUpdate( p_osd, true );
457 #if defined(OSD_MENU_DEBUG)
458 msg_Dbg( p_osd, "direction right [button %s]", p_osd->p_state->p_visible->psz_action );
461 vlc_object_release( (vlc_object_t*) p_osd );
462 vlc_mutex_unlock( lockval.p_address );
465 void __osd_MenuPrev( vlc_object_t *p_this )
467 osd_menu_t *p_osd = NULL;
468 osd_button_t *p_button = NULL;
471 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
474 msg_Err( p_this, "osd_MenuPrev failed" );
478 if( osd_isVisible( p_osd ) == false )
480 vlc_object_release( (vlc_object_t*) p_osd );
484 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
485 vlc_mutex_lock( lockval.p_address );
487 p_button = p_osd->p_state->p_visible;
490 if( !p_button->b_range )
491 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_UNSELECT );
492 if( p_button->p_prev )
493 p_osd->p_state->p_visible = p_button->p_prev;
495 p_osd->p_state->p_visible = p_osd->p_last_button;
497 if( !p_osd->p_state->p_visible->b_range )
498 p_osd->p_state->p_visible->p_current_state =
499 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
501 osd_UpdateState( p_osd->p_state,
502 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
503 p_osd->p_state->p_visible->p_current_state->i_width,
504 p_osd->p_state->p_visible->p_current_state->i_height,
505 p_osd->p_state->p_visible->p_current_state->p_pic );
506 osd_SetMenuUpdate( p_osd, true );
508 #if defined(OSD_MENU_DEBUG)
509 msg_Dbg( p_osd, "direction left [button %s]", p_osd->p_state->p_visible->psz_action );
512 vlc_object_release( (vlc_object_t*) p_osd );
513 vlc_mutex_unlock( lockval.p_address );
516 void __osd_MenuUp( vlc_object_t *p_this )
518 osd_menu_t *p_osd = NULL;
519 osd_button_t *p_button = NULL;
521 #if defined(OSD_MENU_DEBUG)
524 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
527 msg_Err( p_this, "osd_MenuDown failed" );
531 if( osd_isVisible( p_osd ) == false )
533 vlc_object_release( (vlc_object_t*) p_osd );
537 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
538 vlc_mutex_lock( lockval.p_address );
540 p_button = p_osd->p_state->p_visible;
543 if( !p_button->b_range )
545 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_SELECT );
547 p_osd->p_state->p_visible = p_button->p_up;
550 if( p_button->b_range && p_osd->p_state->p_visible->b_range )
552 osd_state_t *p_temp = p_osd->p_state->p_visible->p_current_state;
553 if( p_temp && p_temp->p_next )
554 p_osd->p_state->p_visible->p_current_state = p_temp->p_next;
556 else if( !p_osd->p_state->p_visible->b_range )
558 p_osd->p_state->p_visible->p_current_state =
559 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
562 osd_UpdateState( p_osd->p_state,
563 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
564 p_osd->p_state->p_visible->p_current_state->i_width,
565 p_osd->p_state->p_visible->p_current_state->i_height,
566 p_osd->p_state->p_visible->p_current_state->p_pic );
567 osd_SetMenuUpdate( p_osd, true );
568 /* If this is a range style action with associated images of only one state,
569 * then perform "menu select" on every menu navigation
571 if( p_button->b_range )
573 osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt(p_osd, p_button->psz_action) );
574 #if defined(OSD_MENU_DEBUG)
575 msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action );
579 #if defined(OSD_MENU_DEBUG)
580 msg_Dbg( p_osd, "direction up [button %s]", p_osd->p_state->p_visible->psz_action );
583 vlc_object_release( (vlc_object_t*) p_osd );
584 vlc_mutex_unlock( lockval.p_address );
587 void __osd_MenuDown( vlc_object_t *p_this )
589 osd_menu_t *p_osd = NULL;
590 osd_button_t *p_button = NULL;
592 #if defined(OSD_MENU_DEBUG)
596 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
599 msg_Err( p_this, "osd_MenuDown failed" );
603 if( osd_isVisible( p_osd ) == false )
605 vlc_object_release( (vlc_object_t*) p_osd );
609 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
610 vlc_mutex_lock( lockval.p_address );
612 p_button = p_osd->p_state->p_visible;
615 if( !p_button->b_range )
617 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_SELECT );
618 if( p_button->p_down )
619 p_osd->p_state->p_visible = p_button->p_down;
622 if( p_button->b_range && p_osd->p_state->p_visible->b_range )
624 osd_state_t *p_temp = p_osd->p_state->p_visible->p_current_state;
625 if( p_temp && p_temp->p_prev )
626 p_osd->p_state->p_visible->p_current_state = p_temp->p_prev;
628 else if( !p_osd->p_state->p_visible->b_range )
630 p_osd->p_state->p_visible->p_current_state =
631 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
634 osd_UpdateState( p_osd->p_state,
635 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
636 p_osd->p_state->p_visible->p_current_state->i_width,
637 p_osd->p_state->p_visible->p_current_state->i_height,
638 p_osd->p_state->p_visible->p_current_state->p_pic );
639 osd_SetMenuUpdate( p_osd, true );
640 /* If this is a range style action with associated images of only one state,
641 * then perform "menu select" on every menu navigation
643 if( p_button->b_range )
645 osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt(p_osd, p_button->psz_action_down) );
646 #if defined(OSD_MENU_DEBUG)
647 msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action_down );
651 #if defined(OSD_MENU_DEBUG)
652 msg_Dbg( p_osd, "direction down [button %s]", p_osd->p_state->p_visible->psz_action );
655 vlc_object_release( (vlc_object_t*) p_osd );
656 vlc_mutex_unlock( lockval.p_address );
659 static int osd_VolumeStep( vlc_object_t *p_this, int i_volume, int i_steps )
661 int i_volume_step = 0;
664 i_volume_step = config_GetInt( p_this->p_libvlc, "volume-step" );
665 return (i_volume/i_volume_step);
669 * Display current audio volume bitmap
671 * The OSD Menu audio volume bar is updated to reflect the new audio volume. Call this function
672 * when the audio volume is updated outside the OSD menu command "menu up", "menu down" or "menu select".
674 void __osd_Volume( vlc_object_t *p_this )
676 osd_menu_t *p_osd = NULL;
677 osd_button_t *p_button = NULL;
682 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
685 msg_Err( p_this, "OSD menu volume update failed" );
689 if( p_osd->p_state && p_osd->p_state->p_volume )
691 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
692 vlc_mutex_lock( lockval.p_address );
694 p_button = p_osd->p_state->p_volume;
695 if( p_osd->p_state->p_volume )
696 p_osd->p_state->p_visible = p_osd->p_state->p_volume;
697 if( p_button && p_button->b_range )
699 /* Update the volume state images to match the current volume */
700 i_volume = config_GetInt( p_this, "volume" );
701 i_steps = osd_VolumeStep( p_this, i_volume, p_button->i_ranges );
702 p_button->p_current_state = osd_VolumeStateChange( p_button->p_states, i_steps );
704 osd_UpdateState( p_osd->p_state,
705 p_button->i_x, p_button->i_y,
706 p_button->p_current_state->i_width,
707 p_button->p_current_state->i_height,
708 p_button->p_current_state->p_pic );
709 osd_SetMenuUpdate( p_osd, true );
710 osd_SetMenuVisible( p_osd, true );
712 vlc_object_release( (vlc_object_t*) p_osd );
713 vlc_mutex_unlock( lockval.p_address );
717 osd_button_t *__osd_ButtonFind( vlc_object_t *p_this, int i_x, int i_y,
718 int i_window_height, int i_window_width,
719 int i_scale_width, int i_scale_height )
722 osd_button_t *p_button;
725 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
728 msg_Err( p_this, "OSD menu button find failed" );
732 if( osd_isVisible( p_osd ) == false )
734 vlc_object_release( (vlc_object_t*) p_osd );
738 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
739 vlc_mutex_lock( lockval.p_address );
741 p_button = p_osd->p_button;
742 for( ; p_button != NULL; p_button = p_button->p_next )
744 int i_source_video_width = ( i_window_width * 1000 ) / i_scale_width;
745 int i_source_video_height = ( i_window_height * 1000 ) / i_scale_height;
746 int i_y_offset = p_button->i_y;
747 int i_x_offset = p_button->i_x;
748 int i_width = p_button->i_width;
749 int i_height = p_button->i_height;
751 if( p_osd->i_position > 0 )
753 int i_inv_scale_y = i_source_video_height;
754 int i_inv_scale_x = i_source_video_width;
757 if( p_osd->i_position & SUBPICTURE_ALIGN_BOTTOM )
759 i_y_offset = i_window_height - p_button->i_height -
760 (p_osd->i_y + p_button->i_y) * i_inv_scale_y / 1000;
762 else if ( !(p_osd->i_position & SUBPICTURE_ALIGN_TOP) )
764 i_y_offset = i_window_height / 2 - p_button->i_height / 2;
767 if( p_osd->i_position & SUBPICTURE_ALIGN_RIGHT )
769 i_x_offset = i_window_width - p_button->i_width -
770 (pi_x + p_button->i_x)
771 * i_inv_scale_x / 1000;
773 else if ( !(p_osd->i_position & SUBPICTURE_ALIGN_LEFT) )
775 i_x_offset = i_window_width / 2 - p_button->i_width / 2;
778 i_width = i_window_width - p_button->i_width - i_inv_scale_x / 1000;
779 i_height = i_window_height - p_button->i_height - i_inv_scale_y / 1000;
782 // TODO: write for Up / Down case too.
783 // TODO: handle absolute positioning case
784 if( ( i_x >= i_x_offset ) && ( i_x <= i_x_offset + i_width ) &&
785 ( i_y >= i_y_offset ) && ( i_y <= i_y_offset + i_height ) )
787 vlc_object_release( (vlc_object_t*) p_osd );
788 vlc_mutex_unlock( lockval.p_address );
793 vlc_object_release( (vlc_object_t*) p_osd );
794 vlc_mutex_unlock( lockval.p_address );
799 * Select the button provided as the new active button
801 void __osd_ButtonSelect( vlc_object_t *p_this, osd_button_t *p_button )
807 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
810 msg_Err( p_this, "OSD menu button select failed" );
814 if( osd_isVisible( p_osd ) == false )
816 vlc_object_release( (vlc_object_t*) p_osd );
820 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
821 vlc_mutex_lock( lockval.p_address );
823 p_old = p_osd->p_state->p_visible;
826 if( !p_old->b_range )
827 p_old->p_current_state = osd_StateChange( p_old, OSD_BUTTON_UNSELECT );
828 p_osd->p_state->p_visible = p_button;
830 if( !p_osd->p_state->p_visible->b_range )
831 p_osd->p_state->p_visible->p_current_state =
832 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
834 osd_UpdateState( p_osd->p_state,
835 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
836 p_osd->p_state->p_visible->p_current_state->i_width,
837 p_osd->p_state->p_visible->p_current_state->i_height,
838 p_osd->p_state->p_visible->p_current_state->p_pic );
839 osd_SetMenuUpdate( p_osd, true );
841 #if defined(OSD_MENU_DEBUG)
842 msg_Dbg( p_osd, "button selected is [button %s]", p_osd->p_state->p_visible->psz_action );
845 vlc_object_release( (vlc_object_t*) p_osd );
846 vlc_mutex_unlock( lockval.p_address );