Mercurial > mplayer.hg
annotate libmenu/vf_menu.c @ 27279:6d8527aeeebb
Rewrite translation handling in the build system.
author | diego |
---|---|
date | Thu, 17 Jul 2008 12:36:54 +0000 |
parents | 8eff880f638c |
children | 4876c89bafdd |
rev | line source |
---|---|
8197 | 1 |
16862 | 2 #include "config.h" |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
3 #include "mp_msg.h" |
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
4 #include "help_mp.h" |
8197 | 5 |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 | |
8623
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8251
diff
changeset
|
10 #ifdef HAVE_MALLOC_H |
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8251
diff
changeset
|
11 #include <malloc.h> |
440301fef3fe
Added/reordered #includes to silence warnings about "implicit declaration".
rathann
parents:
8251
diff
changeset
|
12 #endif |
8197 | 13 |
23338
2a66d95355f0
add new -subfont option, that allows having a different font for OSD (controls and menu) and subtitles
ben
parents:
22284
diff
changeset
|
14 #include "mplayer.h" |
16862 | 15 #include "mp_msg.h" |
8197 | 16 |
16862 | 17 #include "libmpcodecs/img_format.h" |
18 #include "libmpcodecs/mp_image.h" | |
19 #include "libmpcodecs/vf.h" | |
8197 | 20 |
16862 | 21 #include "libvo/fastmemcpy.h" |
22 #include "libvo/video_out.h" | |
23 #include "libvo/font_load.h" | |
25026
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
24 #include "libvo/sub.h" |
16862 | 25 #include "input/input.h" |
26 #include "m_struct.h" | |
8197 | 27 #include "menu.h" |
22284 | 28 #include "access_mpcontext.h" |
8197 | 29 |
30 | |
31 static struct vf_priv_s* st_priv = NULL; | |
32 | |
33 static mp_image_t* pause_mpi = NULL; | |
34 static int go2pause = 0; | |
13344
0d96af97ec00
option to display menu at startup, patch by Aurelien Jacobs <aurel at gnuage.org>
faust3
parents:
10397
diff
changeset
|
35 /// if nonzero display menu at startup |
13528 | 36 int attribute_used menu_startup = 0; |
8197 | 37 |
38 struct vf_priv_s { | |
39 menu_t* root; | |
40 menu_t* current; | |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
41 int passthrough; |
8197 | 42 }; |
43 | |
17908 | 44 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts); |
8197 | 45 |
46 void vf_menu_pause_update(struct vf_instance_s* vf) { | |
25219
e82ecde2cbd4
Mark several uses of vo_functions_t as const to stop some of the current
reimar
parents:
25026
diff
changeset
|
47 const vo_functions_t *video_out = mpctx_get_video_out(vf->priv->current->ctx); |
8197 | 48 if(pause_mpi) { |
17908 | 49 put_image(vf,pause_mpi, MP_NOPTS_VALUE); |
8197 | 50 // Don't draw the osd atm |
51 //vf->control(vf,VFCTRL_DRAW_OSD,NULL); | |
52 video_out->flip_page(); | |
53 } | |
54 } | |
55 | |
56 static int cmd_filter(mp_cmd_t* cmd, int paused, struct vf_priv_s * priv) { | |
57 | |
58 switch(cmd->id) { | |
59 case MP_CMD_MENU : { // Convert txt cmd from the users into libmenu stuff | |
60 char* arg = cmd->args[0].v.s; | |
61 | |
25496 | 62 if (!priv->current->show && strcmp(arg,"hide")) |
8197 | 63 priv->current->show = 1; |
64 else if(strcmp(arg,"up") == 0) | |
65 menu_read_cmd(priv->current,MENU_CMD_UP); | |
66 else if(strcmp(arg,"down") == 0) | |
67 menu_read_cmd(priv->current,MENU_CMD_DOWN); | |
17945
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
68 else if(strcmp(arg,"left") == 0) |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
69 menu_read_cmd(priv->current,MENU_CMD_LEFT); |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
70 else if(strcmp(arg,"right") == 0) |
98f4e3704a76
Allow 6 ways (up/down/left/right/ok/cancel) navigation.
albeu
parents:
17908
diff
changeset
|
71 menu_read_cmd(priv->current,MENU_CMD_RIGHT); |
8197 | 72 else if(strcmp(arg,"ok") == 0) |
73 menu_read_cmd(priv->current,MENU_CMD_OK); | |
74 else if(strcmp(arg,"cancel") == 0) | |
75 menu_read_cmd(priv->current,MENU_CMD_CANCEL); | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
76 else if(strcmp(arg,"home") == 0) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
77 menu_read_cmd(priv->current,MENU_CMD_HOME); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
78 else if(strcmp(arg,"end") == 0) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
79 menu_read_cmd(priv->current,MENU_CMD_END); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
80 else if(strcmp(arg,"pageup") == 0) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
81 menu_read_cmd(priv->current,MENU_CMD_PAGE_UP); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
82 else if(strcmp(arg,"pagedown") == 0) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25219
diff
changeset
|
83 menu_read_cmd(priv->current,MENU_CMD_PAGE_DOWN); |
25461 | 84 else if(strcmp(arg,"click") == 0) |
85 menu_read_cmd(priv->current,MENU_CMD_CLICK); | |
19489 | 86 else if(strcmp(arg,"hide") == 0 || strcmp(arg,"toggle") == 0) |
8197 | 87 priv->current->show = 0; |
88 else | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
89 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnknownMenuCommand,arg); |
8197 | 90 return 1; |
91 } | |
92 case MP_CMD_SET_MENU : { | |
93 char* menu = cmd->args[0].v.s; | |
94 menu_t* l = priv->current; | |
95 priv->current = menu_open(menu); | |
96 if(!priv->current) { | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17945
diff
changeset
|
97 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_FailedToOpenMenu,menu); |
8197 | 98 priv->current = l; |
99 priv->current->show = 0; | |
100 } else { | |
101 priv->current->show = 1; | |
102 priv->current->parent = l; | |
103 } | |
104 return 1; | |
105 } | |
106 } | |
107 return 0; | |
108 } | |
109 | |
110 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
111 mp_image_t *dmpi; | |
112 | |
113 if(mpi->type == MP_IMGTYPE_TEMP && (!(mpi->flags&MP_IMGFLAG_PRESERVE)) ) { | |
114 dmpi = vf_get_image(vf->next,mpi->imgfmt,mpi->type, mpi->flags, mpi->w, mpi->h); | |
23458
973e53dc7df5
Do not use fast_memcpy for small size copy, esp. when the size is constant
reimar
parents:
23457
diff
changeset
|
115 memcpy(mpi->planes,dmpi->planes,MP_MAX_PLANES*sizeof(unsigned char*)); |
973e53dc7df5
Do not use fast_memcpy for small size copy, esp. when the size is constant
reimar
parents:
23457
diff
changeset
|
116 memcpy(mpi->stride,dmpi->stride,MP_MAX_PLANES*sizeof(unsigned int)); |
8197 | 117 mpi->flags|=MP_IMGFLAG_DIRECT; |
118 mpi->priv=(void*)dmpi; | |
119 return; | |
120 } | |
121 } | |
122 | |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25496
diff
changeset
|
123 static int key_cb(int code) { |
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25496
diff
changeset
|
124 return menu_read_key(st_priv->current,code); |
8197 | 125 } |
126 | |
17908 | 127 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
8197 | 128 mp_image_t *dmpi = NULL; |
129 | |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
130 if (vf->priv->passthrough) { |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
131 dmpi=vf_get_image(vf->next, IMGFMT_MPEGPES, MP_IMGTYPE_EXPORT, |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
132 0, mpi->w, mpi->h); |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
133 dmpi->planes[0]=mpi->planes[0]; |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
134 return vf_next_put_image(vf,dmpi, pts); |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
135 } |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
136 |
8197 | 137 // Close all menu who requested it |
138 while(vf->priv->current->cl && vf->priv->current != vf->priv->root) { | |
139 menu_t* m = vf->priv->current; | |
140 vf->priv->current = m->parent ? m->parent : vf->priv->root; | |
141 menu_close(m); | |
142 } | |
143 | |
25026
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
144 // Try to capture the last frame before pause, or fallback to use |
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
145 // last captured frame. |
8197 | 146 if(pause_mpi && (mpi->w != pause_mpi->w || mpi->h != pause_mpi->h || |
147 mpi->imgfmt != pause_mpi->imgfmt)) { | |
148 free_mp_image(pause_mpi); | |
149 pause_mpi = NULL; | |
150 } | |
25026
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
151 if (!pause_mpi) { |
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
152 pause_mpi = alloc_mpi(mpi->w,mpi->h,mpi->imgfmt); |
8197 | 153 copy_mpi(pause_mpi,mpi); |
154 } | |
25026
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
155 else if (mpctx_get_osd_function(vf->priv->root->ctx) == OSD_PAUSE) |
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
156 copy_mpi(pause_mpi,mpi); |
8197 | 157 |
25026
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
158 if (vf->priv->current->show) { |
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
159 if (!mp_input_key_cb) |
afead6ecb8ba
Remove the pause filter and the cmd queue hack, to know the mplayer going to
ulion
parents:
24960
diff
changeset
|
160 mp_input_key_cb = key_cb; |
8197 | 161 |
162 if(mpi->flags&MP_IMGFLAG_DIRECT) | |
163 dmpi = mpi->priv; | |
164 else { | |
165 dmpi = vf_get_image(vf->next,mpi->imgfmt, | |
166 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
167 mpi->w,mpi->h); | |
168 copy_mpi(dmpi,mpi); | |
169 } | |
170 menu_draw(vf->priv->current,dmpi); | |
171 | |
8244
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
172 } else { |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
173 if(mp_input_key_cb) |
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
174 mp_input_key_cb = NULL; |
21924
422eef67d14a
speeds up mplayer execution by over FIVE times when all of the of the following apply:
gpoirier
parents:
21818
diff
changeset
|
175 |
422eef67d14a
speeds up mplayer execution by over FIVE times when all of the of the following apply:
gpoirier
parents:
21818
diff
changeset
|
176 if(mpi->flags&MP_IMGFLAG_DIRECT) |
422eef67d14a
speeds up mplayer execution by over FIVE times when all of the of the following apply:
gpoirier
parents:
21818
diff
changeset
|
177 dmpi = mpi->priv; |
422eef67d14a
speeds up mplayer execution by over FIVE times when all of the of the following apply:
gpoirier
parents:
21818
diff
changeset
|
178 else { |
21925 | 179 dmpi = vf_get_image(vf->next,mpi->imgfmt, |
180 MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE, | |
181 mpi->w,mpi->h); | |
8244
64352fb332b6
don't fully-copy the planes if the menu doesn't show (faster)
colin
parents:
8224
diff
changeset
|
182 |
21925 | 183 dmpi->stride[0] = mpi->stride[0]; |
184 dmpi->stride[1] = mpi->stride[1]; | |
185 dmpi->stride[2] = mpi->stride[2]; | |
186 dmpi->planes[0] = mpi->planes[0]; | |
187 dmpi->planes[1] = mpi->planes[1]; | |
188 dmpi->planes[2] = mpi->planes[2]; | |
189 dmpi->priv = mpi->priv; | |
190 } | |
21924
422eef67d14a
speeds up mplayer execution by over FIVE times when all of the of the following apply:
gpoirier
parents:
21818
diff
changeset
|
191 } |
17908 | 192 return vf_next_put_image(vf,dmpi, pts); |
8197 | 193 } |
194 | |
195 static void uninit(vf_instance_t *vf) { | |
196 vf->priv=NULL; | |
197 if(pause_mpi) { | |
198 free_mp_image(pause_mpi); | |
199 pause_mpi = NULL; | |
200 } | |
201 } | |
202 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
203 static int config(struct vf_instance_s* vf, int width, int height, int d_width, int d_height, |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
204 unsigned int flags, unsigned int outfmt) { |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
205 #ifdef HAVE_FREETYPE |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
206 // here is the right place to get screen dimensions |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
207 if (force_load_font) { |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
208 force_load_font = 0; |
25851
9ebd00825df2
Allow independent scaling of vo_font and sub_font.
reimar
parents:
25502
diff
changeset
|
209 load_font_ft(width,height,&vo_font,font_name,osd_font_scale_factor); |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
210 } |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
211 #endif |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
212 if(outfmt == IMGFMT_MPEGPES) |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
213 vf->priv->passthrough = 1; |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
214 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
215 } |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
216 |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
217 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ |
26759
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
25851
diff
changeset
|
218 return vf_next_query_format(vf,fmt); |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
219 } |
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
220 |
23366
b344b6520518
rename some menu open functions, to avoid confusion with libc native open()
ben
parents:
23338
diff
changeset
|
221 static int open_vf(vf_instance_t *vf, char* args){ |
8197 | 222 if(!st_priv) { |
223 st_priv = calloc(1,sizeof(struct vf_priv_s)); | |
224 st_priv->root = st_priv->current = menu_open(args); | |
225 if(!st_priv->current) { | |
226 free(st_priv); | |
227 st_priv = NULL; | |
228 return 0; | |
229 } | |
13344
0d96af97ec00
option to display menu at startup, patch by Aurelien Jacobs <aurel at gnuage.org>
faust3
parents:
10397
diff
changeset
|
230 st_priv->root->show = menu_startup; |
8197 | 231 mp_input_add_cmd_filter((mp_input_cmd_filter)cmd_filter,st_priv); |
232 } | |
233 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
234 vf->config = config; |
21803
3acc4b00bcc6
allows OSD menu to be displayed when using MPEG PES video out
ben
parents:
19489
diff
changeset
|
235 vf->query_format=query_format; |
8197 | 236 vf->put_image = put_image; |
237 vf->get_image = get_image; | |
238 vf->uninit=uninit; | |
239 vf->priv=st_priv; | |
240 go2pause=0; | |
241 | |
242 return 1; | |
243 } | |
244 | |
245 | |
246 vf_info_t vf_info_menu = { | |
247 "Internal filter for libmenu", | |
248 "menu", | |
249 "Albeu", | |
250 "", | |
23366
b344b6520518
rename some menu open functions, to avoid confusion with libc native open()
ben
parents:
23338
diff
changeset
|
251 open_vf, |
9755 | 252 NULL |
8197 | 253 }; |
254 | |
255 | |
256 |