Qt: do not show open options in both normal and advanced UI
[vlc.git] / src / osd / osd_text.c
blobf5e47dff8400ea7eb3673a7843bc2e953c0e9234
1 /*****************************************************************************
2 * osd_text.c : text manipulation functions
3 *****************************************************************************
4 * Copyright (C) 1999-2007 the VideoLAN team
5 * $Id$
7 * Author: Sigmund Augdal Helberg <dnumgis@videolan.org>
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 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <vlc_common.h>
28 #include <vlc_vout.h>
29 #include <vlc_block.h>
30 #include <vlc_filter.h>
31 #include <vlc_osd.h>
33 /**
34 * \brief Show text on the video for some time
35 * \param p_spu pointer to the subpicture queue the text is to be showed on
36 * \param i_channel Subpicture channel
37 * \param psz_string The text to be shown
38 * \param p_style Pointer to a struct with text style info (it is duplicated)
39 * \param i_flags flags for alignment and such
40 * \param i_hmargin horizontal margin in pixels
41 * \param i_vmargin vertical margin in pixels
42 * \param i_duration Amount of time the text is to be shown.
44 int osd_ShowTextRelative( spu_t *p_spu, int i_channel,
45 const char *psz_string, const text_style_t *p_style,
46 int i_flags, int i_hmargin, int i_vmargin,
47 mtime_t i_duration )
49 mtime_t i_now = mdate();
51 return osd_ShowTextAbsolute( p_spu, i_channel, psz_string,
52 p_style, i_flags, i_hmargin, i_vmargin,
53 i_now, i_now + i_duration );
56 /**
57 * \brief Show text on the video from a given start date to a given end date
58 * \param p_spu pointer to the subpicture queue the text is to be showed on
59 * \param i_channel Subpicture channel
60 * \param psz_string The text to be shown
61 * \param p_style Pointer to a struct with text style info (it is duplicated)
62 * \param i_flags flags for alignment and such
63 * \param i_hmargin horizontal margin in pixels
64 * \param i_vmargin vertical margin in pixels
65 * \param i_start the time when this string is to appear on the video
66 * \param i_stop the time when this string should stop to be displayed
67 * if this is 0 the string will be shown untill the next string
68 * is about to be shown
70 int osd_ShowTextAbsolute( spu_t *p_spu_channel, int i_channel,
71 const char *psz_string, const text_style_t *p_style,
72 int i_flags, int i_hmargin, int i_vmargin,
73 mtime_t i_start, mtime_t i_stop )
75 subpicture_t *p_spu;
76 video_format_t fmt;
77 (void)p_style;
79 if( !psz_string ) return VLC_EGENERIC;
81 p_spu = subpicture_New( NULL );
82 if( !p_spu )
83 return VLC_EGENERIC;
85 p_spu->i_channel = i_channel;
86 p_spu->i_start = i_start;
87 p_spu->i_stop = i_stop;
88 p_spu->b_ephemer = true;
89 p_spu->b_absolute = false;
91 /* Create a new subpicture region */
92 memset( &fmt, 0, sizeof(video_format_t) );
93 fmt.i_chroma = VLC_CODEC_TEXT;
94 fmt.i_width = fmt.i_height = 0;
95 fmt.i_x_offset = fmt.i_y_offset = 0;
96 p_spu->p_region = subpicture_region_New( &fmt );
97 if( !p_spu->p_region )
99 msg_Err( p_spu_channel, "cannot allocate SPU region" );
100 subpicture_Delete( p_spu );
101 return VLC_EGENERIC;
104 p_spu->p_region->psz_text = strdup( psz_string );
105 p_spu->p_region->i_align = i_flags & SUBPICTURE_ALIGN_MASK;
106 p_spu->p_region->i_x = i_hmargin;
107 p_spu->p_region->i_y = i_vmargin;
109 spu_PutSubpicture( p_spu_channel, p_spu );
111 return VLC_SUCCESS;
116 * \brief Write an informative message at the default location,
117 * for the default duration and only if the OSD option is enabled.
118 * \param p_caller The object that called the function.
119 * \param i_channel Subpicture channel
120 * \param psz_format printf style formatting
122 void osd_Message( spu_t *p_spu, int i_channel,
123 char *psz_format, ... )
125 va_list args;
127 if( p_spu )
129 char *psz_string;
130 va_start( args, psz_format );
131 if( vasprintf( &psz_string, psz_format, args ) != -1 )
133 osd_ShowTextRelative( p_spu, i_channel, psz_string, NULL,
134 SUBPICTURE_ALIGN_TOP|SUBPICTURE_ALIGN_RIGHT, 30,20,1000000 );
136 free( psz_string );
138 va_end( args );