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>
41 static const char *ppsz_button_states[] = { "unselect", "select", "pressed" };
43 /*****************************************************************************
45 *****************************************************************************/
47 static void osd_UpdateState( osd_menu_state_t *, int, int, int, int, picture_t * );
48 static inline osd_state_t *osd_VolumeStateChange( osd_state_t *, int );
49 static int osd_VolumeStep( vlc_object_t *, int, int );
50 static vlc_bool_t osd_isVisible( osd_menu_t *p_osd );
51 static osd_menu_t *osd_ParserLoad( vlc_object_t *, const char * );
52 static void osd_ParserUnload( vlc_object_t *, osd_menu_t * );
54 static vlc_bool_t osd_isVisible( osd_menu_t *p_osd )
58 var_Get( p_osd, "osd-menu-visible", &val );
62 /*****************************************************************************
63 * Wrappers for loading and unloading osd parser modules.
64 *****************************************************************************/
65 static osd_menu_t *osd_ParserLoad( vlc_object_t *p_this, const char *psz_file )
69 p_menu = vlc_object_create( p_this, VLC_OBJECT_OSDMENU );
72 msg_Err( p_this, "out of memory" );
75 vlc_object_yield( p_menu );
76 vlc_object_attach( p_menu, p_this->p_libvlc );
78 /* Stuff needed for Parser */
79 p_menu->psz_file = strdup( psz_file );
80 p_menu->p_image = image_HandlerCreate( p_this );
81 if( !p_menu->p_image || !p_menu->psz_file )
83 msg_Err( p_this, "unable to load images, aborting .." );
84 osd_ParserUnload( p_this, p_menu );
90 char *psz_ext = strrchr( p_menu->psz_file, '.' );
92 if( psz_ext && !strcmp( psz_ext, ".cfg") )
93 psz_type = "import-osd";
95 psz_type = "import-osd-xml";
97 p_menu->p_parser = module_Need( p_menu, "osd parser",
99 if( !p_menu->p_parser )
101 osd_ParserUnload( p_this, p_menu );
108 static void osd_ParserUnload( vlc_object_t *p_this, osd_menu_t *p_menu )
110 if( p_menu->p_image )
111 image_HandlerDelete( p_menu->p_image );
112 if( p_menu->psz_file )
113 free( p_menu->psz_file );
115 if( p_menu->p_parser )
116 module_Unneed( p_menu, p_menu->p_parser );
118 vlc_object_detach( p_menu );
119 vlc_object_destroy( p_menu );
123 * Change state on an osd_button_t.
125 * This function selects the specified state and returns a pointer to it. The
126 * following states are currently supported:
127 * \see OSD_BUTTON_UNSELECT
128 * \see OSD_BUTTON_SELECT
129 * \see OSD_BUTTON_PRESSED
131 static osd_state_t *osd_StateChange( osd_button_t *p_button, const int i_state )
133 osd_state_t *p_current = p_button->p_states;
134 osd_state_t *p_temp = NULL;
137 for( i=0; p_current != NULL; i++ )
139 if( p_current->i_state == i_state )
141 p_button->i_x = p_current->i_x;
142 p_button->i_y = p_current->i_y;
143 p_button->i_width = p_current->i_width;
144 p_button->i_height = p_current->i_height;
147 p_temp = p_current->p_next;
150 return p_button->p_states;
153 /*****************************************************************************
155 *****************************************************************************/
156 osd_menu_t *__osd_MenuCreate( vlc_object_t *p_this, const char *psz_file )
158 osd_menu_t *p_osd = NULL;
163 /* to be sure to avoid multiple creation */
164 var_Create( p_this->p_libvlc, "osd_mutex", VLC_VAR_MUTEX );
165 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
166 vlc_mutex_lock( lockval.p_address );
168 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
173 /* Parse configuration file */
174 p_osd = osd_ParserLoad( p_this, psz_file );
178 /* Setup default button (first button) */
179 p_osd->p_state->p_visible = p_osd->p_button;
180 p_osd->p_state->p_visible->p_current_state =
181 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
182 p_osd->i_width = p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch;
183 p_osd->i_height = p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines;
185 if( p_osd->p_state->p_volume )
187 /* Update the volume state images to match the current volume */
188 i_volume = config_GetInt( p_this, "volume" );
189 i_steps = osd_VolumeStep( p_this, i_volume, p_osd->p_state->p_volume->i_ranges );
190 p_osd->p_state->p_volume->p_current_state = osd_VolumeStateChange(
191 p_osd->p_state->p_volume->p_states, i_steps );
193 /* Initialize OSD state */
194 osd_UpdateState( p_osd->p_state, p_osd->i_x, p_osd->i_y,
195 p_osd->i_width, p_osd->i_height, NULL );
197 /* Signal when an update of OSD menu is needed */
198 var_Create( p_osd, "osd-menu-update", VLC_VAR_BOOL );
199 var_Create( p_osd, "osd-menu-visible", VLC_VAR_BOOL );
201 val.b_bool = VLC_FALSE;
202 var_Set( p_osd, "osd-menu-update", val );
203 var_Set( p_osd, "osd-menu-visible", val );
205 vlc_mutex_unlock( lockval.p_address );
209 msg_Err( p_this, "creating OSD menu object failed" );
212 image_HandlerDelete( p_osd->p_image );
213 if( p_osd->psz_file )
214 free( p_osd->psz_file );
216 vlc_object_detach( p_osd );
217 vlc_object_destroy( p_osd );
218 vlc_mutex_unlock( lockval.p_address );
222 void __osd_MenuDelete( vlc_object_t *p_this, osd_menu_t *p_osd )
226 if( !p_osd || !p_this ) return;
228 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
229 vlc_mutex_lock( lockval.p_address );
231 vlc_object_release( p_osd );
232 if( p_osd->p_internals->i_refcount > 0 )
234 vlc_mutex_unlock( lockval.p_address );
238 var_Destroy( p_osd, "osd-menu-visible" );
239 var_Destroy( p_osd, "osd-menu-update" );
241 osd_ParserUnload( p_this, p_osd );
243 vlc_mutex_unlock( lockval.p_address );
246 /* The volume can be modified in another interface while the OSD Menu
247 * has not been instantiated yet. This routines updates the "volume OSD menu item"
248 * to reflect the current state of the GUI.
250 static inline osd_state_t *osd_VolumeStateChange( osd_state_t *p_current, int i_steps )
252 osd_state_t *p_temp = NULL;
255 if( i_steps < 0 ) i_steps = 0;
257 for( i=0; (i < i_steps) && (p_current != NULL); i++ )
259 p_temp = p_current->p_next;
260 if( !p_temp ) return p_current;
263 return (!p_temp) ? p_current : p_temp;
266 /* Update the state of the OSD Menu */
267 static void osd_UpdateState( osd_menu_state_t *p_state, int i_x, int i_y,
268 int i_width, int i_height, picture_t *p_pic )
272 p_state->i_width = i_width;
273 p_state->i_height = i_height;
274 p_state->p_pic = p_pic;
277 void __osd_MenuShow( vlc_object_t *p_this )
279 osd_menu_t *p_osd = NULL;
280 osd_button_t *p_button = NULL;
283 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
286 msg_Err( p_this, "osd_MenuNext failed" );
290 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
291 vlc_mutex_lock( lockval.p_address );
293 #if defined(OSD_MENU_DEBUG)
294 msg_Dbg( p_osd, "menu on" );
296 p_button = p_osd->p_state->p_visible;
299 if( !p_button->b_range )
300 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_UNSELECT );
301 p_osd->p_state->p_visible = p_osd->p_button;
303 if( !p_osd->p_state->p_visible->b_range )
304 p_osd->p_state->p_visible->p_current_state =
305 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
307 osd_UpdateState( p_osd->p_state,
308 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
309 p_osd->p_state->p_visible->p_current_state->i_width,
310 p_osd->p_state->p_visible->p_current_state->i_height,
311 p_osd->p_state->p_visible->p_current_state->p_pic );
312 osd_SetMenuUpdate( p_osd, VLC_TRUE );
314 osd_SetMenuVisible( p_osd, VLC_TRUE );
316 vlc_object_release( (vlc_object_t*) p_osd );
317 vlc_mutex_unlock( lockval.p_address );
320 void __osd_MenuHide( vlc_object_t *p_this )
322 osd_menu_t *p_osd = NULL;
325 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
328 msg_Err( p_this, "osd_MenuNext failed" );
332 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
333 vlc_mutex_lock( lockval.p_address );
335 #if defined(OSD_MENU_DEBUG)
336 msg_Dbg( p_osd, "menu off" );
338 osd_UpdateState( p_osd->p_state,
339 p_osd->p_state->i_x, p_osd->p_state->i_y,
341 osd_SetMenuUpdate( p_osd, VLC_TRUE );
343 vlc_object_release( (vlc_object_t*) p_osd );
344 vlc_mutex_unlock( lockval.p_address );
347 void __osd_MenuActivate( vlc_object_t *p_this )
349 osd_menu_t *p_osd = NULL;
350 osd_button_t *p_button = NULL;
353 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
356 msg_Err( p_this, "osd_MenuNext failed" );
360 if( osd_isVisible( p_osd ) == VLC_FALSE )
362 vlc_object_release( (vlc_object_t*) p_osd );
366 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
367 vlc_mutex_lock( lockval.p_address );
369 #if defined(OSD_MENU_DEBUG)
370 msg_Dbg( p_osd, "select" );
372 p_button = p_osd->p_state->p_visible;
374 * Is there a menu item above or below? If so, then select it.
376 if( p_button && p_button->p_up )
378 vlc_object_release( (vlc_object_t*) p_osd );
379 vlc_mutex_unlock( lockval.p_address );
380 __osd_MenuUp( p_this ); /* "menu select" means go to menu item above. */
383 if( p_button && p_button->p_down )
385 vlc_object_release( (vlc_object_t*) p_osd );
386 vlc_mutex_unlock( lockval.p_address );
387 __osd_MenuDown( p_this ); /* "menu select" means go to menu item below. */
391 if( p_button && !p_button->b_range )
393 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_PRESSED );
394 osd_UpdateState( p_osd->p_state,
395 p_button->i_x, p_button->i_y,
396 p_osd->p_state->p_visible->p_current_state->i_width,
397 p_osd->p_state->p_visible->p_current_state->i_height,
398 p_button->p_current_state->p_pic );
399 osd_SetMenuUpdate( p_osd, VLC_TRUE );
400 osd_SetMenuVisible( p_osd, VLC_TRUE );
401 osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt( p_osd, p_button->psz_action ) );
402 #if defined(OSD_MENU_DEBUG)
403 msg_Dbg( p_osd, "select (%d, %s)", config_GetInt( p_osd, p_button->psz_action ), p_button->psz_action );
406 vlc_object_release( (vlc_object_t*) p_osd );
407 vlc_mutex_unlock( lockval.p_address );
410 void __osd_MenuNext( vlc_object_t *p_this )
412 osd_menu_t *p_osd = NULL;
413 osd_button_t *p_button = NULL;
416 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
419 msg_Err( p_this, "osd_MenuNext failed" );
423 if( osd_isVisible( p_osd ) == VLC_FALSE )
425 vlc_object_release( (vlc_object_t*) p_osd );
429 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
430 vlc_mutex_lock( lockval.p_address );
432 p_button = p_osd->p_state->p_visible;
435 if( !p_button->b_range )
436 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_UNSELECT );
437 if( p_button->p_next )
438 p_osd->p_state->p_visible = p_button->p_next;
440 p_osd->p_state->p_visible = p_osd->p_button;
442 if( !p_osd->p_state->p_visible->b_range )
443 p_osd->p_state->p_visible->p_current_state =
444 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
446 osd_UpdateState( p_osd->p_state,
447 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
448 p_osd->p_state->p_visible->p_current_state->i_width,
449 p_osd->p_state->p_visible->p_current_state->i_height,
450 p_osd->p_state->p_visible->p_current_state->p_pic );
451 osd_SetMenuUpdate( p_osd, VLC_TRUE );
453 #if defined(OSD_MENU_DEBUG)
454 msg_Dbg( p_osd, "direction right [button %s]", p_osd->p_state->p_visible->psz_action );
457 vlc_object_release( (vlc_object_t*) p_osd );
458 vlc_mutex_unlock( lockval.p_address );
461 void __osd_MenuPrev( vlc_object_t *p_this )
463 osd_menu_t *p_osd = NULL;
464 osd_button_t *p_button = NULL;
467 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
470 msg_Err( p_this, "osd_MenuPrev failed" );
474 if( osd_isVisible( p_osd ) == VLC_FALSE )
476 vlc_object_release( (vlc_object_t*) p_osd );
480 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
481 vlc_mutex_lock( lockval.p_address );
483 p_button = p_osd->p_state->p_visible;
486 if( !p_button->b_range )
487 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_UNSELECT );
488 if( p_button->p_prev )
489 p_osd->p_state->p_visible = p_button->p_prev;
491 p_osd->p_state->p_visible = p_osd->p_last_button;
493 if( !p_osd->p_state->p_visible->b_range )
494 p_osd->p_state->p_visible->p_current_state =
495 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
497 osd_UpdateState( p_osd->p_state,
498 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
499 p_osd->p_state->p_visible->p_current_state->i_width,
500 p_osd->p_state->p_visible->p_current_state->i_height,
501 p_osd->p_state->p_visible->p_current_state->p_pic );
502 osd_SetMenuUpdate( p_osd, VLC_TRUE );
504 #if defined(OSD_MENU_DEBUG)
505 msg_Dbg( p_osd, "direction left [button %s]", p_osd->p_state->p_visible->psz_action );
508 vlc_object_release( (vlc_object_t*) p_osd );
509 vlc_mutex_unlock( lockval.p_address );
512 void __osd_MenuUp( vlc_object_t *p_this )
514 osd_menu_t *p_osd = NULL;
515 osd_button_t *p_button = NULL;
517 #if defined(OSD_MENU_DEBUG)
520 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
523 msg_Err( p_this, "osd_MenuDown failed" );
527 if( osd_isVisible( p_osd ) == VLC_FALSE )
529 vlc_object_release( (vlc_object_t*) p_osd );
533 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
534 vlc_mutex_lock( lockval.p_address );
536 p_button = p_osd->p_state->p_visible;
539 if( !p_button->b_range )
541 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_SELECT );
543 p_osd->p_state->p_visible = p_button->p_up;
546 if( p_button->b_range && p_osd->p_state->p_visible->b_range )
548 osd_state_t *p_temp = p_osd->p_state->p_visible->p_current_state;
549 if( p_temp && p_temp->p_next )
550 p_osd->p_state->p_visible->p_current_state = p_temp->p_next;
552 else if( !p_osd->p_state->p_visible->b_range )
554 p_osd->p_state->p_visible->p_current_state =
555 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
558 osd_UpdateState( p_osd->p_state,
559 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
560 p_osd->p_state->p_visible->p_current_state->i_width,
561 p_osd->p_state->p_visible->p_current_state->i_height,
562 p_osd->p_state->p_visible->p_current_state->p_pic );
563 osd_SetMenuUpdate( p_osd, VLC_TRUE );
564 /* If this is a range style action with associated images of only one state,
565 * then perform "menu select" on every menu navigation
567 if( p_button->b_range )
569 osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt(p_osd, p_button->psz_action) );
570 #if defined(OSD_MENU_DEBUG)
571 msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action );
575 #if defined(OSD_MENU_DEBUG)
576 msg_Dbg( p_osd, "direction up [button %s]", p_osd->p_state->p_visible->psz_action );
579 vlc_object_release( (vlc_object_t*) p_osd );
580 vlc_mutex_unlock( lockval.p_address );
583 void __osd_MenuDown( vlc_object_t *p_this )
585 osd_menu_t *p_osd = NULL;
586 osd_button_t *p_button = NULL;
588 #if defined(OSD_MENU_DEBUG)
592 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
595 msg_Err( p_this, "osd_MenuDown failed" );
599 if( osd_isVisible( p_osd ) == VLC_FALSE )
601 vlc_object_release( (vlc_object_t*) p_osd );
605 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
606 vlc_mutex_lock( lockval.p_address );
608 p_button = p_osd->p_state->p_visible;
611 if( !p_button->b_range )
613 p_button->p_current_state = osd_StateChange( p_button, OSD_BUTTON_SELECT );
614 if( p_button->p_down )
615 p_osd->p_state->p_visible = p_button->p_down;
618 if( p_button->b_range && p_osd->p_state->p_visible->b_range )
620 osd_state_t *p_temp = p_osd->p_state->p_visible->p_current_state;
621 if( p_temp && p_temp->p_prev )
622 p_osd->p_state->p_visible->p_current_state = p_temp->p_prev;
624 else if( !p_osd->p_state->p_visible->b_range )
626 p_osd->p_state->p_visible->p_current_state =
627 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
630 osd_UpdateState( p_osd->p_state,
631 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
632 p_osd->p_state->p_visible->p_current_state->i_width,
633 p_osd->p_state->p_visible->p_current_state->i_height,
634 p_osd->p_state->p_visible->p_current_state->p_pic );
635 osd_SetMenuUpdate( p_osd, VLC_TRUE );
636 /* If this is a range style action with associated images of only one state,
637 * then perform "menu select" on every menu navigation
639 if( p_button->b_range )
641 osd_SetKeyPressed( VLC_OBJECT(p_osd->p_libvlc), config_GetInt(p_osd, p_button->psz_action_down) );
642 #if defined(OSD_MENU_DEBUG)
643 msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action_down );
647 #if defined(OSD_MENU_DEBUG)
648 msg_Dbg( p_osd, "direction down [button %s]", p_osd->p_state->p_visible->psz_action );
651 vlc_object_release( (vlc_object_t*) p_osd );
652 vlc_mutex_unlock( lockval.p_address );
655 static int osd_VolumeStep( vlc_object_t *p_this, int i_volume, int i_steps )
657 int i_volume_step = 0;
660 i_volume_step = config_GetInt( p_this->p_libvlc, "volume-step" );
661 return (i_volume/i_volume_step);
665 * Display current audio volume bitmap
667 * The OSD Menu audio volume bar is updated to reflect the new audio volume. Call this function
668 * when the audio volume is updated outside the OSD menu command "menu up", "menu down" or "menu select".
670 void __osd_Volume( vlc_object_t *p_this )
672 osd_menu_t *p_osd = NULL;
673 osd_button_t *p_button = NULL;
678 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
681 msg_Err( p_this, "OSD menu volume update failed" );
685 if( p_osd->p_state && p_osd->p_state->p_volume )
687 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
688 vlc_mutex_lock( lockval.p_address );
690 p_button = p_osd->p_state->p_volume;
691 if( p_osd->p_state->p_volume )
692 p_osd->p_state->p_visible = p_osd->p_state->p_volume;
693 if( p_button && p_button->b_range )
695 /* Update the volume state images to match the current volume */
696 i_volume = config_GetInt( p_this, "volume" );
697 i_steps = osd_VolumeStep( p_this, i_volume, p_button->i_ranges );
698 p_button->p_current_state = osd_VolumeStateChange( p_button->p_states, i_steps );
700 osd_UpdateState( p_osd->p_state,
701 p_button->i_x, p_button->i_y,
702 p_button->p_current_state->i_width,
703 p_button->p_current_state->i_height,
704 p_button->p_current_state->p_pic );
705 osd_SetMenuUpdate( p_osd, VLC_TRUE );
706 osd_SetMenuVisible( p_osd, VLC_TRUE );
708 vlc_object_release( (vlc_object_t*) p_osd );
709 vlc_mutex_unlock( lockval.p_address );
713 osd_button_t *__osd_ButtonFind( vlc_object_t *p_this, int i_x, int i_y,
714 int i_window_height, int i_window_width,
715 int i_scale_width, int i_scale_height )
718 osd_button_t *p_button;
721 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
724 msg_Err( p_this, "OSD menu button find failed" );
728 if( osd_isVisible( p_osd ) == VLC_FALSE )
730 vlc_object_release( (vlc_object_t*) p_osd );
734 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
735 vlc_mutex_lock( lockval.p_address );
737 p_button = p_osd->p_button;
738 for( ; p_button != NULL; p_button = p_button->p_next )
740 int i_source_video_width = ( i_window_width * 1000 ) / i_scale_width;
741 int i_source_video_height = ( i_window_height * 1000 ) / i_scale_height;
742 int i_y_offset = p_button->i_y;
743 int i_x_offset = p_button->i_x;
744 int i_width = p_button->i_width;
745 int i_height = p_button->i_height;
747 if( p_osd->i_position > 0 )
749 int i_inv_scale_y = i_source_video_height;
750 int i_inv_scale_x = i_source_video_width;
753 if( p_osd->i_position & SUBPICTURE_ALIGN_BOTTOM )
755 i_y_offset = i_window_height - p_button->i_height -
756 (p_osd->i_y + p_button->i_y) * i_inv_scale_y / 1000;
758 else if ( !(p_osd->i_position & SUBPICTURE_ALIGN_TOP) )
760 i_y_offset = i_window_height / 2 - p_button->i_height / 2;
763 if( p_osd->i_position & SUBPICTURE_ALIGN_RIGHT )
765 i_x_offset = i_window_width - p_button->i_width -
766 (pi_x + p_button->i_x)
767 * i_inv_scale_x / 1000;
769 else if ( !(p_osd->i_position & SUBPICTURE_ALIGN_LEFT) )
771 i_x_offset = i_window_width / 2 - p_button->i_width / 2;
774 i_width = i_window_width - p_button->i_width - i_inv_scale_x / 1000;
775 i_height = i_window_height - p_button->i_height - i_inv_scale_y / 1000;
778 // TODO: write for Up / Down case too.
779 // TODO: handle absolute positioning case
780 if( ( i_x >= i_x_offset ) && ( i_x <= i_x_offset + i_width ) &&
781 ( i_y >= i_y_offset ) && ( i_y <= i_y_offset + i_height ) )
783 vlc_object_release( (vlc_object_t*) p_osd );
784 vlc_mutex_unlock( lockval.p_address );
789 vlc_object_release( (vlc_object_t*) p_osd );
790 vlc_mutex_unlock( lockval.p_address );
795 * Select the button provided as the new active button
797 void __osd_ButtonSelect( vlc_object_t *p_this, osd_button_t *p_button )
803 p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE );
806 msg_Err( p_this, "OSD menu button select failed" );
810 if( osd_isVisible( p_osd ) == VLC_FALSE )
812 vlc_object_release( (vlc_object_t*) p_osd );
816 var_Get( p_this->p_libvlc, "osd_mutex", &lockval );
817 vlc_mutex_lock( lockval.p_address );
819 p_old = p_osd->p_state->p_visible;
822 if( !p_old->b_range )
823 p_old->p_current_state = osd_StateChange( p_old, OSD_BUTTON_UNSELECT );
824 p_osd->p_state->p_visible = p_button;
826 if( !p_osd->p_state->p_visible->b_range )
827 p_osd->p_state->p_visible->p_current_state =
828 osd_StateChange( p_osd->p_state->p_visible, OSD_BUTTON_SELECT );
830 osd_UpdateState( p_osd->p_state,
831 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,
832 p_osd->p_state->p_visible->p_current_state->i_width,
833 p_osd->p_state->p_visible->p_current_state->i_height,
834 p_osd->p_state->p_visible->p_current_state->p_pic );
835 osd_SetMenuUpdate( p_osd, VLC_TRUE );
837 #if defined(OSD_MENU_DEBUG)
838 msg_Dbg( p_osd, "button selected is [button %s]", p_osd->p_state->p_visible->psz_action );
841 vlc_object_release( (vlc_object_t*) p_osd );
842 vlc_mutex_unlock( lockval.p_address );