1 /*****************************************************************************
2 * parser.c : OSD import module
3 *****************************************************************************
4 * Copyright (C) 2007-2008 M2X
7 * Authors: Jean-Paul Saman
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>
33 #include <vlc_image.h>
40 const char * const ppsz_button_states[] = { "unselect", "select", "pressed" };
42 /*****************************************************************************
44 *****************************************************************************/
46 /*****************************************************************************
47 * Create a new Menu structure
48 *****************************************************************************/
49 osd_menu_t *osd_MenuNew( osd_menu_t *p_menu, const char *psz_path,
52 if( !p_menu ) return NULL;
54 p_menu->p_state = calloc( 1, sizeof( osd_menu_state_t ) );
55 if( !p_menu->p_state )
58 p_menu->psz_path = psz_path ? strdup( psz_path ) : NULL;
61 p_menu->i_style = OSD_MENU_STYLE_SIMPLE;
66 /*****************************************************************************
68 *****************************************************************************/
69 void osd_MenuFree( osd_menu_t *p_menu )
71 msg_Dbg( p_menu, "freeing menu" );
72 osd_ButtonFree( p_menu, p_menu->p_button );
74 free( p_menu->psz_path );
75 free( p_menu->p_state );
77 p_menu->p_button = NULL;
78 p_menu->p_last_button = NULL;
79 p_menu->psz_path = NULL;
80 p_menu->p_state = NULL;
83 /*****************************************************************************
85 *****************************************************************************/
86 osd_button_t *osd_ButtonNew( const char *psz_action, int i_x, int i_y )
88 osd_button_t *p_button = NULL;
89 p_button = calloc( 1, sizeof(osd_button_t) );
93 p_button->psz_action = strdup(psz_action);
94 p_button->psz_action_down = NULL;
101 /*****************************************************************************
103 *****************************************************************************/
104 void osd_ButtonFree( osd_menu_t *p_menu, osd_button_t *p_button )
106 osd_button_t *p_current = p_button;
107 osd_button_t *p_next = NULL;
108 osd_button_t *p_prev = NULL;
110 if( !p_current ) return;
112 /* First walk to the end. */
113 while( p_current->p_next )
115 p_next = p_current->p_next;
118 /* Then free end first and walk to the start. */
119 while( p_current->p_prev )
121 msg_Dbg( p_menu, "+ freeing button %s [%p]",
122 p_current->psz_action, p_current );
123 p_prev = p_current->p_prev;
125 if( p_current->p_next )
127 free( p_current->p_next->psz_name );
128 free( p_current->p_next->psz_action );
129 free( p_current->p_next->psz_action_down );
131 /* Free all states first */
132 if( p_current->p_next->p_states )
133 osd_StatesFree( p_menu, p_current->p_next->p_states );
135 free( p_current->p_next );
136 p_current->p_next = NULL;
139 if( p_current->p_up )
141 free( p_current->p_up->psz_name );
142 free( p_current->p_up->psz_action );
143 free( p_current->p_up->psz_action_down );
145 /* Free all states first */
146 if( p_current->p_up->p_states )
147 osd_StatesFree( p_menu, p_current->p_up->p_states );
148 free( p_current->p_up );
149 p_current->p_up = NULL;
152 /* Free the last one. */
155 msg_Dbg( p_menu, "+ freeing button %s [%p]",
156 p_button->psz_action, p_button );
157 free( p_button->psz_name );
158 free( p_button->psz_action );
159 free( p_button->psz_action_down );
161 if( p_button->p_states )
162 osd_StatesFree( p_menu, p_button->p_states );
168 /*****************************************************************************
169 * Create a new state image
170 *****************************************************************************/
171 osd_state_t *osd_StateNew( osd_menu_t *p_menu, const char *psz_file,
172 const char *psz_state )
174 osd_state_t *p_state = NULL;
175 video_format_t fmt_in, fmt_out;
177 p_state = calloc( 1, sizeof(osd_state_t) );
181 memset( &fmt_in, 0, sizeof(video_format_t) );
182 memset( &fmt_out, 0, sizeof(video_format_t) );
184 fmt_out.i_chroma = VLC_CODEC_YUVA;
185 if( p_menu->p_image )
187 p_state->p_pic = image_ReadUrl( p_menu->p_image, psz_file,
191 p_state->i_width = p_state->p_pic->p[Y_PLANE].i_visible_pitch;
192 p_state->i_height = p_state->p_pic->p[Y_PLANE].i_visible_lines;
198 p_state->psz_state = strdup( psz_state );
199 if( strncmp( ppsz_button_states[0], psz_state,
200 strlen(ppsz_button_states[0]) ) == 0 )
201 p_state->i_state = OSD_BUTTON_UNSELECT;
202 else if( strncmp( ppsz_button_states[1], psz_state,
203 strlen(ppsz_button_states[1]) ) == 0 )
204 p_state->i_state = OSD_BUTTON_SELECT;
205 else if( strncmp( ppsz_button_states[2], psz_state,
206 strlen(ppsz_button_states[2]) ) == 0 )
207 p_state->i_state = OSD_BUTTON_PRESSED;
212 /*****************************************************************************
214 *****************************************************************************/
215 void osd_StatesFree( osd_menu_t *p_menu, osd_state_t *p_states )
217 osd_state_t *p_state = p_states;
218 osd_state_t *p_next = NULL;
219 osd_state_t *p_prev = NULL;
221 if( !p_state ) return;
223 while( p_state->p_next )
225 p_next = p_state->p_next;
228 /* Then free end first and walk to the start. */
229 while( p_state->p_prev )
231 msg_Dbg( p_menu, " |- freeing state %s [%p]",
232 p_state->psz_state, p_state );
233 p_prev = p_state->p_prev;
235 if( p_state->p_next )
237 if( p_state->p_next->p_pic )
238 picture_Release( p_state->p_next->p_pic );
239 free( p_state->p_next->psz_state );
240 free( p_state->p_next );
241 p_state->p_next = NULL;
244 /* Free the last one. */
247 msg_Dbg( p_menu, " |- freeing state %s [%p]",
248 p_state->psz_state, p_states );
249 if( p_states->p_pic )
250 picture_Release( p_state->p_next->p_pic );
251 free( p_state->psz_state );