]> git.sesse.net Git - vlc/blob - include/vlc_osd.h
Forward port of branches/0.8.1-jpsaman-thedj revision 12070. The OSD menu subsystem...
[vlc] / include / vlc_osd.h
1 /*****************************************************************************\r
2  * osd.h - OSD menu definitions and function prototypes\r
3  *****************************************************************************\r
4  * Copyright (C) 2004-2005 M2X\r
5  * $Id: osd.h 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  * \file\r
26  * The OSD menu core creates the OSD menu structure in memory. It parses a \r
27  * configuration file that defines all elements that are part of the menu. The \r
28  * core also handles all actions and menu structure updates on behalf of video \r
29  * subpicture filters.\r
30  *\r
31  * The file modules/video_filters/osdmenu.c implements a subpicture filter that\r
32  * specifies the final information on positioning of the current state image. \r
33  * A subpicture filter is called each time a video picture has to be rendered, it\r
34  * also gives a start and end date to the subpicture. The subpicture can be streamed\r
35  * if used inside a transcoding command. For example:\r
36  *\r
37  *  vlc dvdsimple:///dev/dvd --extraintf rc\r
38  *  --sout='#transcode{osdenc=dvbsub,osdcoded=YUVP,sfilter=osdmenu} \r
39  *  --osdmenu-file share/osdmenu/dvd.cfg\r
40  *\r
41  * Each OSD menu element, called "action", defines a hotkey action. Each action \r
42  * can have several states (unselect, select, pressed). Each state has an image \r
43  * that represents the state visually. The commands "menu right", "menu left", \r
44  * "menu up" and "menu down" are used to navigate through the OSD menu structure.\r
45  * The commands "menu on" or "menu show" and "menu off" or "menu hide" respectively\r
46  * show and hide the OSD menu subpictures.\r
47  *\r
48  * There is one special element called "range". A range is an arbritary range\r
49  * of state images that can be browsed using "menu up" and "menu down" commands\r
50  * on the rc interface. \r
51  *  \r
52  * The OSD menu configuration file uses a very simple syntax and basic parser. \r
53  * A configuration file has the ".cfg". An example is "share/osdmenu/dvd256.cfg".\r
54  */\r
55   \r
56 #ifndef _VLC_OSD_H\r
57 #define _VLC_OSD_H 1\r
58 \r
59 #include "vlc_video.h"\r
60 \r
61 # ifdef __cplusplus\r
62 extern "C" {\r
63 # endif\r
64 \r
65 /**\r
66  * The OSD Menu configuration file format.\r
67  *\r
68  * The configuration file syntax is very basic and so is its parser. See the\r
69  * BNF formal representation below:\r
70  *\r
71  * The keywords FILENAME and PATHNAME represent the filename and pathname specification\r
72  * that is valid for the Operating System VLC is compiled for. \r
73  *\r
74  * The hotkey actions that are supported by VLC are documented in the file src/libvlc. The\r
75  * file include/vlc_keys.h defines some hotkey internals.\r
76  *\r
77  * CONFIG_FILE = FILENAME '.cfg'\r
78  * WS = [ ' ' | '\t' ]+\r
79  * OSDMEN_PATH = PATHNAME\r
80  * DIR = 'dir' WS OSDMENU_PATH '\n'\r
81  * STATE = [ 'unselect' | 'select' | 'pressed' ]\r
82  * HOTKEY_ACTION = 'key-' [ 'a' .. 'z', 'A' .. 'Z', '-' ]+\r
83  * \r
84  * ACTION_TYPE        = 'type' 'volume' '\n'\r
85  * ACTION_BLOCK_START = 'action' WS HOTKEY_ACTION WS '('POS','POS')' '\n'\r
86  * ACTION_BLOCK_END   = 'end' '\n'\r
87  * ACTION_STATE       = STATE WS FILENAME '\n'\r
88  * ACTION_RANGE_START = 'range' WS HOTKEY_ACTION WS DEFAULT_INDEX '\n'\r
89  * ACTION_RANGE_END   = 'end' '\n'\r
90  * ACTION_RANGE_STATE = FILENAME '\n'\r
91  *\r
92  * ACTION_BLOCK_RANGE = ACTION_RANGE_START [WS ACTION_RANGE_STATE]+ WS ACTION_RANGE_END\r
93  * ACTION_BLOCK = ACTION_BLOCK_START [WS ACTION_TYPE*] [ [WS ACTION_STATE]+3 | [WS ACTION_BLOCK_RANGE]+1 ] ACTION_BLOCK_END\r
94  * CONFIG_FILE_CONTENTS = DIR [ACTION_BLOCK]+\r
95  *\r
96  */ \r
97 \r
98 /**\r
99  * OSD menu button states\r
100  *\r
101  * Every button has three states, either it is unselected, selected or pressed.\r
102  * An OSD menu skin can associate images with each state.\r
103  *\r
104  *  OSD_BUTTON_UNSELECT 0\r
105  *  OSD_BUTTON_SELECT   1\r
106  *  OSD_BUTTON_PRESSED  2\r
107  */\r
108 #define OSD_BUTTON_UNSELECT 0\r
109 #define OSD_BUTTON_SELECT   1\r
110 #define OSD_BUTTON_PRESSED  2\r
111 \r
112 /**\r
113  * OSD State object\r
114  *\r
115  * The OSD state object holds the state and associated images for a particular state\r
116  * on the screen. The picture is displayed when this state is the active state.\r
117  */\r
118 struct osd_state_t\r
119 {\r
120     osd_state_t *p_next;    /*< pointer to next state */\r
121     osd_state_t *p_prev;    /*< pointer to previous state */\r
122     picture_t   *p_pic;     /*< picture of state */\r
123     \r
124     char        *psz_state; /*< state name */\r
125     int          i_state;   /*< state index */ \r
126 };\r
127 \r
128 /** \r
129  * OSD Button object\r
130  *\r
131  * An OSD Button has different states. Each state has an image for display. \r
132  */\r
133 struct osd_button_t\r
134 {\r
135     osd_button_t *p_next;   /*< pointer to next button */\r
136     osd_button_t *p_prev;   /*< pointer to previous button */\r
137     osd_button_t *p_up;     /*< pointer to up button */\r
138     osd_button_t *p_down;   /*< pointer to down button */\r
139     \r
140     osd_state_t *p_current_state; /*< pointer to current state image */\r
141     osd_state_t *p_states; /*< doubly linked list of states */\r
142     picture_t   *p_feedback; /*< feedback picture */\r
143         \r
144     char    *psz_name;     /*< name of button */\r
145     \r
146     /* These member should probably be a struct hotkey */\r
147     char    *psz_action;      /*< hotkey action name on button*/\r
148     char    *psz_action_down; /*< hotkey action name on range buttons for command "menu down" */\r
149     /* end of hotkey specifics */\r
150     \r
151     int     i_x;            /*< x-position of button visible state image */\r
152     int     i_y;            /*< y-position of button visible state image */ \r
153     \r
154     /* range style button */    \r
155     vlc_bool_t   b_range;    /*< button should be interpreted as range */\r
156     int          i_ranges;   /*< number of states */\r
157 };\r
158 \r
159 /** \r
160  * OSD Menu State object\r
161  *\r
162  * Represents the current state as displayed. \r
163  */\r
164 /* Represent the menu state */\r
165 struct osd_menu_state_t\r
166 {\r
167     int     i_x;        /*< x position of spu region */\r
168     int     i_y;        /*< y position of spu region */\r
169     int     i_width;    /*< width of spu region */\r
170     int     i_height;   /*< height of spu region */    \r
171     \r
172     picture_t    *p_pic;  /*< pointer to picture to display */\r
173     osd_button_t *p_visible; /*< shortcut to visible button */\r
174     \r
175     vlc_bool_t b_menu_visible; /*< menu currently visible? */\r
176     vlc_bool_t b_update;       /*< update OSD Menu when VLC_TRUE */\r
177     \r
178     /* quick hack to volume state. */\r
179     osd_button_t *p_volume; /*< pointer to volume range object. */\r
180 };\r
181 \r
182 /**\r
183  * OSD Menu object\r
184  *\r
185  * The main OSD Menu object, which holds a linked list to all buttons\r
186  * and images that defines the menu. The p_state variable represents the\r
187  * current state of the OSD Menu.\r
188  */\r
189 struct osd_menu_t\r
190 {\r
191     VLC_COMMON_MEMBERS\r
192     \r
193     int     i_x;        /*< x-position of OSD Menu on the video screen */ \r
194     int     i_y;        /*< y-position of OSD Menu on the video screen */ \r
195     int     i_width;    /*< width of OSD Menu on the video screen */ \r
196     int     i_height;   /*< height of OSD Menu on the video screen */ \r
197     \r
198     char             *psz_path;  /*< directory where OSD menu images are stored */\r
199     osd_button_t     *p_button;  /*< doubly linked list of buttons */\r
200     osd_menu_state_t *p_state;   /*< current state of OSD menu */\r
201         \r
202     /* quick link in the linked list. */\r
203     osd_button_t  *p_last_button; /*< pointer to last button in the list */\r
204 };\r
205 \r
206 /**\r
207  * Initialize an osd_menu_t object\r
208  *\r
209  * This functions has to be called before any call to other osd_menu_t* functions.\r
210  * It creates the osd_menu object and holds a pointer to it during its lifetime.\r
211  */\r
212 VLC_EXPORT( osd_menu_t *, __osd_MenuCreate, ( vlc_object_t *, const char * ) );\r
213 \r
214 /**\r
215  * Delete the osd_menu_t object\r
216  *\r
217  * This functions has to be called to release the associated module and memory\r
218  * for the osdmenu. After return of this function the pointer to osd_menu_t* is invalid.\r
219  */\r
220 VLC_EXPORT( void, __osd_MenuDelete, ( vlc_object_t *, osd_menu_t * ) );\r
221 \r
222 /**\r
223  * Change state on an osd_button_t.\r
224  *\r
225  * This function selects the specified state and returns a pointer to it. The \r
226  * following states are currently supported: \r
227  * \see OSD_BUTTON_UNSELECT\r
228  * \see OSD_BUTTON_SELECT   \r
229  * \see OSD_BUTTON_PRESSED  \r
230  */\r
231 VLC_EXPORT( osd_state_t *, __osd_StateChange, ( osd_state_t *, const int ) );\r
232 \r
233 #define osd_MenuCreate(object,file) __osd_MenuCreate( VLC_OBJECT(object), file )\r
234 #define osd_MenuDelete(object,osd)  __osd_MenuDelete( VLC_OBJECT(object), osd )\r
235 #define osd_StateChange(object,value) __osd_StateChange( object, value )\r
236 \r
237 /**\r
238  * Show the OSD menu.\r
239  *\r
240  * Show the OSD menu on the video output or mux it into the stream. \r
241  * Every change to the OSD menu will now be visible in the output. An output \r
242  * can be a video output window or a stream (\see stream output)\r
243  */\r
244 VLC_EXPORT( void, __osd_MenuShow, ( vlc_object_t * ) ); \r
245 \r
246 /**\r
247  * Hide the OSD menu.\r
248  *\r
249  * Stop showing the OSD menu on the video output or mux it into the stream.\r
250  */\r
251 VLC_EXPORT( void, __osd_MenuHide, ( vlc_object_t * ) );\r
252 \r
253 /**\r
254  * Activate the action of this OSD menu item.\r
255  *\r
256  * The rc interface command "menu select" triggers the sending of an hotkey action\r
257  * to the hotkey interface. The hotkey that belongs to the current highlighted \r
258  * OSD menu item will be used.\r
259  */\r
260 VLC_EXPORT( void, __osd_MenuActivate,   ( vlc_object_t * ) );\r
261 \r
262 #define osd_MenuShow(object) __osd_MenuShow( VLC_OBJECT(object) )\r
263 #define osd_MenuHide(object) __osd_MenuHide( VLC_OBJECT(object) )\r
264 #define osd_MenuActivate(object)   __osd_MenuActivate( VLC_OBJECT(object) )\r
265 \r
266 /**\r
267  * Next OSD menu item\r
268  *\r
269  * Select the next OSD menu item to be highlighted.\r
270  * Note: The actual position on screen of the menu item is determined by the the\r
271  * OSD menu configuration file.\r
272  */\r
273 VLC_EXPORT( void, __osd_MenuNext, ( vlc_object_t * ) ); \r
274 \r
275 /**\r
276  * Previous OSD menu item\r
277  *\r
278  * Select the previous OSD menu item to be highlighted.\r
279  * Note: The actual position on screen of the menu item is determined by the the\r
280  * OSD menu configuration file.\r
281  */\r
282 VLC_EXPORT( void, __osd_MenuPrev, ( vlc_object_t * ) );\r
283 \r
284 /**\r
285  * OSD menu item above\r
286  *\r
287  * Select the OSD menu item above the current item to be highlighted. \r
288  * Note: The actual position on screen of the menu item is determined by the the\r
289  * OSD menu configuration file.\r
290  */\r
291 VLC_EXPORT( void, __osd_MenuUp,   ( vlc_object_t * ) );\r
292 \r
293 /**\r
294  * OSD menu item below\r
295  *\r
296  * Select the next OSD menu item below the current item to be highlighted.\r
297  * Note: The actual position on screen of the menu item is determined by the the\r
298  * OSD menu configuration file.\r
299  */\r
300 VLC_EXPORT( void, __osd_MenuDown, ( vlc_object_t * ) );\r
301 \r
302 #define osd_MenuNext(object) __osd_MenuNext( VLC_OBJECT(object) )\r
303 #define osd_MenuPrev(object) __osd_MenuPrev( VLC_OBJECT(object) )\r
304 #define osd_MenuUp(object)   __osd_MenuUp( VLC_OBJECT(object) )\r
305 #define osd_MenuDown(object) __osd_MenuDown( VLC_OBJECT(object) )\r
306 \r
307 /**\r
308  * Turn Volume Up\r
309  *\r
310  * Use the OSD menu to turn the audio volume up.\r
311  */\r
312 VLC_EXPORT( void, __osd_VolumeUp, ( vlc_object_t * ) );\r
313 \r
314 /**\r
315  * Turn Volume Down\r
316  *\r
317  * Use the OSD menu to turn the audio volume down.\r
318  */\r
319 VLC_EXPORT( void, __osd_VolumeDown, ( vlc_object_t * ) );\r
320 \r
321 #define osd_VolumeUp(object)   __osd_VolumeUp( VLC_OBJECT(object) )\r
322 #define osd_VolumeDown(object) __osd_VolumeDown( VLC_OBJECT(object) )\r
323 \r
324 /**\r
325  * Retrieve a non modifyable pointer to the OSD Menu state\r
326  *\r
327  */\r
328 static inline const osd_menu_state_t *osd_GetMenuState( osd_menu_t *p_osd )\r
329 {\r
330     return( p_osd->p_state );\r
331 }\r
332 \r
333 /**\r
334  * Get the last key press received by the OSD Menu\r
335  *\r
336  * Returns 0 when no key has been pressed or the value of the key pressed.\r
337  */\r
338 static inline vlc_bool_t osd_GetKeyPressed( osd_menu_t *p_osd )\r
339 {\r
340     return( p_osd->p_state->b_update );\r
341 }       \r
342 \r
343 /**\r
344  * Set the key pressed to a value.\r
345  *\r
346  * Assign a new key value to the last key pressed on the OSD Menu.\r
347  */\r
348 static inline void osd_SetKeyPressed( vlc_object_t *p_this, int i_value )\r
349 {\r
350     vlc_value_t val;\r
351     \r
352     val.i_int = i_value;    \r
353     var_Set( p_this, "key-pressed", val );            \r
354 }\r
355 \r
356 /**\r
357  * Update the OSD Menu visibility flag.\r
358  *\r
359  * VLC_TRUE means OSD Menu should be shown. VLC_FALSE means OSD Menu should not be shown.\r
360  */\r
361 static inline void osd_SetMenuVisible( osd_menu_t *p_osd, vlc_bool_t b_value )\r
362 {\r
363     vlc_value_t val;\r
364     \r
365     val.b_bool = p_osd->p_state->b_menu_visible = b_value; \r
366     var_Set( p_osd, "osd-menu-visible", val );\r
367 }\r
368 \r
369 /**\r
370  * Update the OSD Menu update flag\r
371  *\r
372  * If the OSD Menu should be updated then set the update flag to VLC_TRUE, else to VLC_FALSE.\r
373  */\r
374 static inline void osd_SetMenuUpdate( osd_menu_t *p_osd, vlc_bool_t b_value )\r
375 {\r
376     vlc_value_t val;\r
377     \r
378     val.b_bool = p_osd->p_state->b_update = b_value;\r
379     var_Set( p_osd, "osd-menu-update", val );\r
380\r
381 \r
382 /**\r
383  * Default feedback images\r
384  *\r
385  * Functions that provide the default OSD feedback images on hotkey commands. These feedback\r
386  * images are also part of the osd_button_t object. The types are declared in the include file\r
387  * include/osd.h\r
388  * @see osd.h \r
389  */\r
390 VLC_EXPORT( picture_t *, osd_Slider, ( int i_width, int i_height, int i_position, short i_type ) );\r
391 VLC_EXPORT( picture_t *, osd_Icon,   ( int i_width, int i_height, short i_type ) );\r
392 \r
393 /**\r
394  * Loading and parse the OSD Configuration file\r
395  *\r
396  * These functions load/unload the OSD menu configuration file and create/destroy the\r
397  * themable OSD menu structure on the OSD object.\r
398  */\r
399 VLC_EXPORT( int,  osd_ConfigLoader, ( vlc_object_t *, const char *, osd_menu_t ** ) );\r
400 VLC_EXPORT( void, osd_ConfigUnload, ( vlc_object_t *, osd_menu_t ** ) );\r
401 \r
402 # ifdef __cplusplus\r
403 }\r
404 # endif\r
405 \r
406 #endif /* _VLC_OSD_H */\r