]> git.sesse.net Git - vlc/blob - src/osd/osd.c
remove trailing whitespace
[vlc] / src / osd / osd.c
1 /*****************************************************************************\r
2  * osd.c - The OSD Menu core code.\r
3  *****************************************************************************\r
4  * Copyright (C) 2005 M2X\r
5  * $Id: osd.c 9451 2004-12-01 01:07:08Z jpsaman $\r
6  *\r
7  * Authors: Jean-Paul Saman <jpsaman #_at_# m2x dot nl>\r
8  *\r
9  * This program is free software; you can redistribute it and/or modify\r
10  * it under the terms of the GNU General Public License as published by\r
11  * the Free Software Foundation; either version 2 of the License, or\r
12  * (at your option) any later version.\r
13  *\r
14  * This program is distributed in the hope that it will be useful,\r
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17  * GNU General Public License for more details.\r
18  *\r
19  * You should have received a copy of the GNU General Public License\r
20  * along with this program; if not, write to the Free Software\r
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.\r
22  *****************************************************************************/\r
23 \r
24 /*****************************************************************************\r
25  * Preamble\r
26  *****************************************************************************/\r
27 #include <stdlib.h>\r
28 #include <string.h>\r
29 \r
30 #include <vlc/vlc.h>\r
31 #include <vlc_keys.h>\r
32 #include <vlc_osd.h>\r
33 \r
34 #undef OSD_MENU_DEBUG\r
35 \r
36 /*****************************************************************************\r
37  * Local prototypes\r
38  *****************************************************************************/\r
39 \r
40 static void osd_UpdateState( osd_menu_state_t *, int, int, int, int, picture_t * );\r
41 static inline osd_state_t *osd_VolumeStateChange( osd_state_t *, int );\r
42 static int osd_VolumeStep( vlc_object_t *, int, int );\r
43 static vlc_bool_t osd_isVisible( osd_menu_t *p_osd );\r
44 \r
45 static vlc_bool_t osd_isVisible( osd_menu_t *p_osd )\r
46 {\r
47     vlc_value_t val;\r
48 \r
49     var_Get( p_osd, "osd-menu-visible", &val );\r
50     return val.b_bool;\r
51 }\r
52 \r
53 /*****************************************************************************\r
54  * OSD menu Funtions\r
55  *****************************************************************************/\r
56 osd_menu_t *__osd_MenuCreate( vlc_object_t *p_this, const char *psz_file )\r
57 {\r
58     osd_menu_t  *p_osd = NULL;\r
59     vlc_value_t lockval;\r
60     int         i_volume = 0;\r
61     int         i_steps = 0;\r
62 \r
63     /* to be sure to avoid multiple creation */\r
64     var_Create( p_this->p_libvlc, "osd_mutex", VLC_VAR_MUTEX );\r
65     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );\r
66     vlc_mutex_lock( lockval.p_address );\r
67 \r
68     if( ( p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE ) ) == NULL )\r
69     {\r
70         vlc_value_t val;\r
71 \r
72         msg_Dbg( p_this, "creating osd menu object" );\r
73         if( ( p_osd = vlc_object_create( p_this, VLC_OBJECT_OSDMENU ) ) == NULL )\r
74         {\r
75             msg_Err( p_this, "out of memory" );\r
76             vlc_mutex_unlock( lockval.p_address );\r
77             return NULL;\r
78         }\r
79 \r
80         /* Parse configuration file */\r
81         if( osd_ConfigLoader( p_this, psz_file, &p_osd ) )\r
82             goto error;\r
83 \r
84         /* Setup default button (first button) */\r
85         p_osd->p_state->p_visible = p_osd->p_button;\r
86         p_osd->p_state->p_visible->p_current_state =\r
87             osd_StateChange( p_osd->p_state->p_visible->p_states, OSD_BUTTON_SELECT );\r
88         p_osd->i_width  = p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch;\r
89         p_osd->i_height = p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines;\r
90 \r
91         /* Update the volume state images to match the current volume */\r
92         i_volume = config_GetInt( p_this, "volume" );\r
93         i_steps = osd_VolumeStep( p_this, i_volume, p_osd->p_state->p_volume->i_ranges );\r
94         p_osd->p_state->p_volume->p_current_state = osd_VolumeStateChange( p_osd->p_state->p_volume->p_states, i_steps );\r
95 \r
96         /* Initialize OSD state */\r
97         osd_UpdateState( p_osd->p_state, p_osd->i_x, p_osd->i_y,\r
98                          p_osd->i_width, p_osd->i_height, NULL );\r
99 \r
100         vlc_object_yield( p_osd );\r
101         vlc_object_attach( p_osd, p_this->p_vlc );\r
102 \r
103         /* Signal when an update of OSD menu is needed */\r
104         var_Create( p_osd, "osd-menu-update", VLC_VAR_BOOL );\r
105         var_Create( p_osd, "osd-menu-visible", VLC_VAR_BOOL );\r
106 \r
107         val.b_bool = VLC_FALSE;\r
108         var_Set( p_osd, "osd-menu-update", val );\r
109         var_Set( p_osd, "osd-menu-visible", val );\r
110     }\r
111     vlc_mutex_unlock( lockval.p_address );\r
112     return p_osd;\r
113 \r
114 error:\r
115     msg_Err( p_this, "creating osd menu object failed" );\r
116     vlc_mutex_unlock( lockval.p_address );\r
117     vlc_object_destroy( p_osd );\r
118     return NULL;\r
119 }\r
120 \r
121 void __osd_MenuDelete( vlc_object_t *p_this, osd_menu_t *p_osd )\r
122 {\r
123     vlc_value_t lockval;\r
124 \r
125     if( !p_osd || !p_this ) return;\r
126 \r
127     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );\r
128     vlc_mutex_lock( lockval.p_address );\r
129 \r
130     vlc_object_release( p_osd );\r
131     if( p_osd->i_refcount > 0 )\r
132     {\r
133         vlc_mutex_unlock( lockval.p_address );\r
134         return;\r
135     }\r
136 \r
137     var_Destroy( p_osd, "osd-menu-visible" );\r
138     var_Destroy( p_osd, "osd-menu-update" );\r
139 \r
140     osd_ConfigUnload( p_this, &p_osd );\r
141     vlc_object_detach( p_osd );\r
142     vlc_object_destroy( p_osd );\r
143     p_osd = NULL;\r
144 \r
145     vlc_mutex_unlock( lockval.p_address );\r
146 }\r
147 \r
148 osd_state_t *__osd_StateChange( osd_state_t *p_states, const int i_state )\r
149 {\r
150     osd_state_t *p_current = p_states;\r
151     osd_state_t *p_temp = NULL;\r
152     int i = 0;\r
153 \r
154     for( i=0; p_current != NULL; i++ )\r
155     {\r
156         if( p_current->i_state == i_state )\r
157             return p_current;\r
158         p_temp = p_current->p_next;\r
159         p_current = p_temp;\r
160     }\r
161     return p_states;\r
162 }\r
163 \r
164 /* The volume can be modified in another interface while the OSD Menu \r
165  * has not been instantiated yet. This routines updates the "volume OSD menu item"\r
166  * to reflect the current state of the GUI.\r
167  */\r
168 static inline osd_state_t *osd_VolumeStateChange( osd_state_t *p_current, int i_steps )\r
169 {\r
170     osd_state_t *p_temp = NULL;\r
171     int i;\r
172 \r
173     if( i_steps < 0 ) i_steps = 0;\r
174 \r
175     for( i=0; (i < i_steps) && (p_current != NULL); i++ )\r
176     {\r
177         p_temp = p_current->p_next;\r
178         if( !p_temp ) return p_current;\r
179         p_current = p_temp;\r
180     }\r
181     return (!p_temp) ? p_current : p_temp;\r
182 }\r
183 \r
184 /* Update the state of the OSD Menu */\r
185 static void osd_UpdateState( osd_menu_state_t *p_state, int i_x, int i_y,\r
186         int i_width, int i_height, picture_t *p_pic )\r
187 {\r
188     p_state->i_x = i_x;\r
189     p_state->i_y = i_y;\r
190     p_state->i_width = i_width;\r
191     p_state->i_height = i_height;\r
192     p_state->p_pic = p_pic;\r
193 }\r
194 \r
195 void __osd_MenuShow( vlc_object_t *p_this )\r
196 {\r
197     osd_menu_t *p_osd = NULL;\r
198     osd_button_t *p_button = NULL;\r
199     vlc_value_t lockval;\r
200 \r
201     if( ( p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE ) ) == NULL )\r
202     {\r
203         msg_Err( p_this, "osd_MenuNext failed" );\r
204         return;\r
205     }\r
206 \r
207     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );\r
208     vlc_mutex_lock( lockval.p_address );\r
209 \r
210 #if defined(OSD_MENU_DEBUG)\r
211     msg_Dbg( p_osd, "menu on" );\r
212 #endif\r
213     p_button = p_osd->p_state->p_visible;\r
214     if( p_button )\r
215     {\r
216         if( !p_button->b_range ) \r
217             p_button->p_current_state = osd_StateChange( p_button->p_states, OSD_BUTTON_UNSELECT );\r
218         p_osd->p_state->p_visible = p_osd->p_button;\r
219 \r
220         if( !p_osd->p_state->p_visible->b_range ) \r
221             p_osd->p_state->p_visible->p_current_state =\r
222                 osd_StateChange( p_osd->p_state->p_visible->p_states, OSD_BUTTON_SELECT );\r
223 \r
224         osd_UpdateState( p_osd->p_state,\r
225                 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,\r
226                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,\r
227                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,\r
228                 p_osd->p_state->p_visible->p_current_state->p_pic );\r
229         osd_SetMenuUpdate( p_osd, VLC_TRUE );\r
230     }\r
231     osd_SetMenuVisible( p_osd, VLC_TRUE );\r
232 \r
233     vlc_object_release( (vlc_object_t*) p_osd );\r
234     vlc_mutex_unlock( lockval.p_address );\r
235 }\r
236 \r
237 void __osd_MenuHide( vlc_object_t *p_this )\r
238 {\r
239     osd_menu_t *p_osd = NULL;\r
240     vlc_value_t lockval;\r
241 \r
242     if( ( p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE ) ) == NULL )\r
243     {\r
244         msg_Err( p_this, "osd_MenuNext failed" );\r
245         return;\r
246     }\r
247 \r
248     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );\r
249     vlc_mutex_lock( lockval.p_address );\r
250 \r
251 #if defined(OSD_MENU_DEBUG)\r
252     msg_Dbg( p_osd, "menu off" );\r
253 #endif\r
254     osd_UpdateState( p_osd->p_state,\r
255                 p_osd->p_state->i_x, p_osd->p_state->i_y,\r
256                 0, 0, NULL );\r
257     osd_SetMenuUpdate( p_osd, VLC_TRUE );\r
258 \r
259     vlc_object_release( (vlc_object_t*) p_osd );\r
260     vlc_mutex_unlock( lockval.p_address );\r
261 }\r
262 \r
263 void __osd_MenuActivate( vlc_object_t *p_this )\r
264 {\r
265     osd_menu_t *p_osd = NULL;\r
266     osd_button_t *p_button = NULL;\r
267     vlc_value_t lockval;\r
268 \r
269     if( ( p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE ) ) == NULL )\r
270     {\r
271         msg_Err( p_this, "osd_MenuNext failed" );\r
272         return;\r
273     }\r
274 \r
275     if( osd_isVisible( p_osd ) == VLC_FALSE )\r
276     {\r
277         vlc_object_release( (vlc_object_t*) p_osd );\r
278         return;\r
279     }\r
280 \r
281     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );\r
282     vlc_mutex_lock( lockval.p_address );\r
283 \r
284 #if defined(OSD_MENU_DEBUG)\r
285     msg_Dbg( p_osd, "select" );\r
286 #endif\r
287     p_button = p_osd->p_state->p_visible;\r
288     /*\r
289      * Is there a menu item above or below? If so, then select it.\r
290      */\r
291     if( p_button && p_button->p_up)\r
292     {\r
293         vlc_object_release( (vlc_object_t*) p_osd );\r
294         vlc_mutex_unlock( lockval.p_address );\r
295         __osd_MenuUp( p_this );   /* "menu select" means go to menu item above. */\r
296         return;\r
297     }\r
298     if( p_button && p_button->p_down)\r
299     {\r
300         vlc_object_release( (vlc_object_t*) p_osd );\r
301         vlc_mutex_unlock( lockval.p_address );\r
302         __osd_MenuDown( p_this ); /* "menu select" means go to menu item below. */\r
303         return;\r
304     }\r
305 \r
306     if( p_button && !p_button->b_range )\r
307     {\r
308         p_button->p_current_state = osd_StateChange( p_button->p_states, OSD_BUTTON_PRESSED );\r
309         osd_UpdateState( p_osd->p_state,\r
310                 p_button->i_x, p_button->i_y,\r
311                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,\r
312                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,\r
313                 p_button->p_current_state->p_pic );\r
314         osd_SetMenuUpdate( p_osd, VLC_TRUE );\r
315         osd_SetMenuVisible( p_osd, VLC_TRUE );\r
316         osd_SetKeyPressed( VLC_OBJECT(p_osd->p_vlc), config_GetInt( p_osd, p_button->psz_action ) );\r
317 #if defined(OSD_MENU_DEBUG)\r
318         msg_Dbg( p_osd, "select (%d, %s)", config_GetInt( p_osd, p_button->psz_action ), p_button->psz_action );\r
319 #endif\r
320     }\r
321     vlc_object_release( (vlc_object_t*) p_osd );\r
322     vlc_mutex_unlock( lockval.p_address );\r
323 }\r
324 \r
325 void __osd_MenuNext( vlc_object_t *p_this )\r
326 {\r
327     osd_menu_t *p_osd = NULL;\r
328     osd_button_t *p_button = NULL;\r
329     vlc_value_t lockval;\r
330 \r
331     if( ( p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE ) ) == NULL )\r
332     {\r
333         msg_Err( p_this, "osd_MenuNext failed" );\r
334         return;\r
335     }\r
336 \r
337     if( osd_isVisible( p_osd ) == VLC_FALSE )\r
338     {\r
339         vlc_object_release( (vlc_object_t*) p_osd );\r
340         return;\r
341     }\r
342 \r
343     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );\r
344     vlc_mutex_lock( lockval.p_address );\r
345 \r
346     p_button = p_osd->p_state->p_visible;\r
347     if( p_button )\r
348     {\r
349         if( !p_button->b_range ) \r
350             p_button->p_current_state = osd_StateChange( p_button->p_states, OSD_BUTTON_UNSELECT );\r
351         if( p_button->p_next )\r
352             p_osd->p_state->p_visible = p_button->p_next;\r
353         else\r
354             p_osd->p_state->p_visible = p_osd->p_button;\r
355 \r
356         if( !p_osd->p_state->p_visible->b_range ) \r
357             p_osd->p_state->p_visible->p_current_state =\r
358                 osd_StateChange( p_osd->p_state->p_visible->p_states, OSD_BUTTON_SELECT );\r
359 \r
360         osd_UpdateState( p_osd->p_state, \r
361                 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,\r
362                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,\r
363                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,\r
364                 p_osd->p_state->p_visible->p_current_state->p_pic );\r
365         osd_SetMenuUpdate( p_osd, VLC_TRUE );\r
366     }\r
367 #if defined(OSD_MENU_DEBUG)\r
368     msg_Dbg( p_osd, "direction right [button %s]", p_osd->p_state->p_visible->psz_action );\r
369 #endif\r
370 \r
371     vlc_object_release( (vlc_object_t*) p_osd );\r
372     vlc_mutex_unlock( lockval.p_address );\r
373 }\r
374 \r
375 void __osd_MenuPrev( vlc_object_t *p_this )\r
376 {\r
377     osd_menu_t *p_osd = NULL;\r
378     osd_button_t *p_button = NULL;\r
379     vlc_value_t lockval;\r
380 \r
381     if( ( p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE ) ) == NULL )\r
382     {\r
383         msg_Err( p_this, "osd_MenuPrev failed" );\r
384         return;\r
385     }\r
386 \r
387     if( osd_isVisible( p_osd ) == VLC_FALSE )\r
388     {\r
389         vlc_object_release( (vlc_object_t*) p_osd );\r
390         return;\r
391     }\r
392 \r
393     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );\r
394     vlc_mutex_lock( lockval.p_address );\r
395 \r
396     p_button = p_osd->p_state->p_visible;\r
397     if( p_button )\r
398     {\r
399         if( !p_button->b_range ) \r
400             p_button->p_current_state = osd_StateChange( p_button->p_states, OSD_BUTTON_UNSELECT );\r
401         if( p_button->p_prev )\r
402             p_osd->p_state->p_visible = p_button->p_prev;\r
403         else\r
404             p_osd->p_state->p_visible = p_osd->p_last_button;\r
405 \r
406         if( !p_osd->p_state->p_visible->b_range ) \r
407             p_osd->p_state->p_visible->p_current_state =\r
408                 osd_StateChange( p_osd->p_state->p_visible->p_states, OSD_BUTTON_SELECT );\r
409 \r
410         osd_UpdateState( p_osd->p_state, \r
411                 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,\r
412                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,\r
413                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,\r
414                 p_osd->p_state->p_visible->p_current_state->p_pic );\r
415         osd_SetMenuUpdate( p_osd, VLC_TRUE );\r
416     }\r
417 #if defined(OSD_MENU_DEBUG)\r
418     msg_Dbg( p_osd, "direction left [button %s]", p_osd->p_state->p_visible->psz_action );\r
419 #endif\r
420 \r
421     vlc_object_release( (vlc_object_t*) p_osd );\r
422     vlc_mutex_unlock( lockval.p_address );\r
423 }\r
424 \r
425 void __osd_MenuUp( vlc_object_t *p_this )\r
426 {\r
427     osd_menu_t *p_osd = NULL;\r
428     osd_button_t *p_button = NULL;\r
429     vlc_value_t lockval;\r
430 #if defined(OSD_MENU_DEBUG)\r
431     vlc_value_t val;\r
432 #endif\r
433 \r
434     if( ( p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE ) ) == NULL )\r
435     {\r
436         msg_Err( p_this, "osd_MenuDown failed" );\r
437         return;\r
438     }\r
439 \r
440     if( osd_isVisible( p_osd ) == VLC_FALSE )\r
441     {\r
442         vlc_object_release( (vlc_object_t*) p_osd );\r
443         return;\r
444     }\r
445 \r
446     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );\r
447     vlc_mutex_lock( lockval.p_address );\r
448 \r
449     p_button = p_osd->p_state->p_visible;\r
450     if( p_button )\r
451     {\r
452         if( !p_button->b_range ) \r
453         {\r
454             p_button->p_current_state = osd_StateChange( p_button->p_states, OSD_BUTTON_SELECT );\r
455             if( p_button->p_up )\r
456                 p_osd->p_state->p_visible = p_button->p_up;\r
457         }\r
458 \r
459         if( p_button->b_range && p_osd->p_state->p_visible->b_range ) \r
460         {\r
461             osd_state_t *p_temp = p_osd->p_state->p_visible->p_current_state;\r
462             if( p_temp && p_temp->p_next )\r
463                 p_osd->p_state->p_visible->p_current_state = p_temp->p_next;\r
464         }\r
465         else if( !p_osd->p_state->p_visible->b_range )\r
466         {\r
467             p_osd->p_state->p_visible->p_current_state =\r
468                 osd_StateChange( p_osd->p_state->p_visible->p_states, OSD_BUTTON_SELECT );\r
469         }\r
470 \r
471         osd_UpdateState( p_osd->p_state, \r
472                 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,\r
473                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,\r
474                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,\r
475                 p_osd->p_state->p_visible->p_current_state->p_pic );\r
476         osd_SetMenuUpdate( p_osd, VLC_TRUE );\r
477         /* If this is a range style action with associated images of only one state, \r
478             * then perform "menu select" on every menu navigation\r
479             */\r
480         if( p_button->b_range ) \r
481         {\r
482             osd_SetKeyPressed( VLC_OBJECT(p_osd->p_vlc), config_GetInt(p_osd, p_button->psz_action) );\r
483 #if defined(OSD_MENU_DEBUG)\r
484             msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action );\r
485 #endif\r
486         }\r
487     }\r
488 #if defined(OSD_MENU_DEBUG)\r
489     msg_Dbg( p_osd, "direction up [button %s]", p_osd->p_state->p_visible->psz_action );\r
490 #endif\r
491 \r
492     vlc_object_release( (vlc_object_t*) p_osd );\r
493     vlc_mutex_unlock( lockval.p_address );\r
494 }\r
495 \r
496 void __osd_MenuDown( vlc_object_t *p_this )\r
497 {\r
498     osd_menu_t *p_osd = NULL;\r
499     osd_button_t *p_button = NULL;\r
500     vlc_value_t lockval;\r
501 #if defined(OSD_MENU_DEBUG)\r
502     vlc_value_t val;\r
503 #endif\r
504 \r
505     if( ( p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE ) ) == NULL )\r
506     {\r
507         msg_Err( p_this, "osd_MenuDown failed" );\r
508         return;\r
509     }\r
510 \r
511     if( osd_isVisible( p_osd ) == VLC_FALSE )\r
512     {\r
513         vlc_object_release( (vlc_object_t*) p_osd );\r
514         return;\r
515     }\r
516 \r
517     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );\r
518     vlc_mutex_lock( lockval.p_address );\r
519 \r
520     p_button = p_osd->p_state->p_visible;\r
521     if( p_button )\r
522     {\r
523         if( !p_button->b_range ) \r
524         {\r
525             p_button->p_current_state = osd_StateChange( p_button->p_states, OSD_BUTTON_SELECT );\r
526             if( p_button->p_down )\r
527                 p_osd->p_state->p_visible = p_button->p_down;\r
528         }\r
529 \r
530         if( p_button->b_range && p_osd->p_state->p_visible->b_range ) \r
531         {\r
532             osd_state_t *p_temp = p_osd->p_state->p_visible->p_current_state;\r
533             if( p_temp && p_temp->p_prev )\r
534                 p_osd->p_state->p_visible->p_current_state = p_temp->p_prev;\r
535         }\r
536         else if( !p_osd->p_state->p_visible->b_range )\r
537         {\r
538             p_osd->p_state->p_visible->p_current_state =\r
539                 osd_StateChange( p_osd->p_state->p_visible->p_states, OSD_BUTTON_SELECT );\r
540         }\r
541 \r
542         osd_UpdateState( p_osd->p_state, \r
543                 p_osd->p_state->p_visible->i_x, p_osd->p_state->p_visible->i_y,\r
544                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,\r
545                 p_osd->p_state->p_visible->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,\r
546                 p_osd->p_state->p_visible->p_current_state->p_pic );\r
547         osd_SetMenuUpdate( p_osd, VLC_TRUE );\r
548         /* If this is a range style action with associated images of only one state,\r
549          * then perform "menu select" on every menu navigation\r
550          */\r
551         if( p_button->b_range ) \r
552         {\r
553             osd_SetKeyPressed( VLC_OBJECT(p_osd->p_vlc), config_GetInt(p_osd, p_button->psz_action_down) );\r
554 #if defined(OSD_MENU_DEBUG)\r
555             msg_Dbg( p_osd, "select (%d, %s)", val.i_int, p_button->psz_action_down );\r
556 #endif\r
557         }\r
558     }\r
559 #if defined(OSD_MENU_DEBUG)\r
560     msg_Dbg( p_osd, "direction down [button %s]", p_osd->p_state->p_visible->psz_action ); \r
561 #endif\r
562 \r
563     vlc_object_release( (vlc_object_t*) p_osd );\r
564     vlc_mutex_unlock( lockval.p_address );\r
565 }\r
566 \r
567 static int osd_VolumeStep( vlc_object_t *p_this, int i_volume, int i_steps )\r
568 {\r
569     int i_volume_step = 0;\r
570 \r
571     i_volume_step = config_GetInt( p_this->p_vlc, "volume-step" );\r
572     return (i_volume/i_volume_step);\r
573 }\r
574 \r
575 /**\r
576  * Display current audio volume bitmap\r
577  *\r
578  * The OSD Menu audio volume bar is updated to reflect the new audio volume. Call this function\r
579  * when the audio volume is updated outside the OSD menu command "menu up", "menu down" or "menu select".\r
580  */\r
581 void __osd_Volume( vlc_object_t *p_this )\r
582 {\r
583     osd_menu_t *p_osd = NULL;\r
584     osd_button_t *p_button = NULL;\r
585     vlc_value_t lockval;\r
586     int i_volume = 0;\r
587     int i_steps = 0;\r
588 \r
589     if( ( p_osd = vlc_object_find( p_this, VLC_OBJECT_OSDMENU, FIND_ANYWHERE ) ) == NULL )\r
590     {\r
591         msg_Err( p_this, "OSD menu volume update failed" );\r
592         return;\r
593     }\r
594 \r
595     var_Get( p_this->p_libvlc, "osd_mutex", &lockval );\r
596     vlc_mutex_lock( lockval.p_address );\r
597 \r
598     p_button = p_osd->p_state->p_volume;\r
599     if( p_osd->p_state->p_volume ) \r
600         p_osd->p_state->p_visible = p_osd->p_state->p_volume;\r
601     if( p_button && p_button->b_range )\r
602     {\r
603         /* Update the volume state images to match the current volume */\r
604         i_volume = config_GetInt( p_this, "volume" );\r
605         i_steps = osd_VolumeStep( p_this, i_volume, p_button->i_ranges );\r
606         p_button->p_current_state = osd_VolumeStateChange( p_button->p_states, i_steps );\r
607 \r
608         osd_UpdateState( p_osd->p_state,\r
609                 p_button->i_x, p_button->i_y,\r
610                 p_button->p_current_state->p_pic->p[Y_PLANE].i_visible_pitch,\r
611                 p_button->p_current_state->p_pic->p[Y_PLANE].i_visible_lines,\r
612                 p_button->p_current_state->p_pic );\r
613         osd_SetMenuUpdate( p_osd, VLC_TRUE );\r
614         osd_SetMenuVisible( p_osd, VLC_TRUE );\r
615     }\r
616     vlc_object_release( (vlc_object_t*) p_osd );\r
617     vlc_mutex_unlock( lockval.p_address );\r
618 }\r