Remove unnecessary CLEANFILES declaration. Test programs do not require it.
[mplayer/glamo.git] / libmenu / vf_menu.c
blob7f93b1a84009e2baf4ccba01cc20d136caa49a70
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "config.h"
20 #include "mp_msg.h"
21 #include "help_mp.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #if HAVE_MALLOC_H
28 #include <malloc.h>
29 #endif
31 #include "mplayer.h"
32 #include "mp_msg.h"
34 #include "libmpcodecs/img_format.h"
35 #include "libmpcodecs/mp_image.h"
36 #include "libmpcodecs/vf.h"
38 #include "libvo/fastmemcpy.h"
39 #include "libvo/video_out.h"
40 #include "libvo/font_load.h"
41 #include "libvo/sub.h"
42 #include "input/input.h"
43 #include "m_struct.h"
44 #include "menu.h"
45 #include "access_mpcontext.h"
48 static struct vf_priv_s* st_priv = NULL;
50 static mp_image_t* pause_mpi = NULL;
51 static int go2pause = 0;
52 /// if nonzero display menu at startup
53 int menu_startup = 0;
55 struct vf_priv_s {
56 menu_t* root;
57 menu_t* current;
58 int passthrough;
61 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts);
63 void vf_menu_pause_update(struct vf_instance_s* vf) {
64 const vo_functions_t *video_out = mpctx_get_video_out(vf->priv->current->ctx);
65 if(pause_mpi) {
66 put_image(vf,pause_mpi, MP_NOPTS_VALUE);
67 // Don't draw the osd atm
68 //vf->control(vf,VFCTRL_DRAW_OSD,NULL);
69 video_out->flip_page();
73 static int cmd_filter(mp_cmd_t* cmd, int paused, struct vf_priv_s * priv) {
75 switch(cmd->id) {
76 case MP_CMD_MENU : { // Convert txt cmd from the users into libmenu stuff
77 char* arg = cmd->args[0].v.s;
79 if (!priv->current->show && strcmp(arg,"hide"))
80 priv->current->show = 1;
81 else if(strcmp(arg,"up") == 0)
82 menu_read_cmd(priv->current,MENU_CMD_UP);
83 else if(strcmp(arg,"down") == 0)
84 menu_read_cmd(priv->current,MENU_CMD_DOWN);
85 else if(strcmp(arg,"left") == 0)
86 menu_read_cmd(priv->current,MENU_CMD_LEFT);
87 else if(strcmp(arg,"right") == 0)
88 menu_read_cmd(priv->current,MENU_CMD_RIGHT);
89 else if(strcmp(arg,"ok") == 0)
90 menu_read_cmd(priv->current,MENU_CMD_OK);
91 else if(strcmp(arg,"cancel") == 0)
92 menu_read_cmd(priv->current,MENU_CMD_CANCEL);
93 else if(strcmp(arg,"home") == 0)
94 menu_read_cmd(priv->current,MENU_CMD_HOME);
95 else if(strcmp(arg,"end") == 0)
96 menu_read_cmd(priv->current,MENU_CMD_END);
97 else if(strcmp(arg,"pageup") == 0)
98 menu_read_cmd(priv->current,MENU_CMD_PAGE_UP);
99 else if(strcmp(arg,"pagedown") == 0)
100 menu_read_cmd(priv->current,MENU_CMD_PAGE_DOWN);
101 else if(strcmp(arg,"click") == 0)
102 menu_read_cmd(priv->current,MENU_CMD_CLICK);
103 else if(strcmp(arg,"hide") == 0 || strcmp(arg,"toggle") == 0)
104 priv->current->show = 0;
105 else
106 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnknownMenuCommand,arg);
107 return 1;
109 case MP_CMD_SET_MENU : {
110 char* menu = cmd->args[0].v.s;
111 menu_t* l = priv->current;
112 priv->current = menu_open(menu);
113 if(!priv->current) {
114 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_FailedToOpenMenu,menu);
115 priv->current = l;
116 priv->current->show = 0;
117 } else {
118 priv->current->show = 1;
119 priv->current->parent = l;
121 return 1;
124 return 0;
127 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){
128 mp_image_t *dmpi;
130 if(mpi->type == MP_IMGTYPE_TEMP && (!(mpi->flags&MP_IMGFLAG_PRESERVE)) ) {
131 dmpi = vf_get_image(vf->next,mpi->imgfmt,mpi->type, mpi->flags, mpi->w, mpi->h);
132 memcpy(mpi->planes,dmpi->planes,MP_MAX_PLANES*sizeof(unsigned char*));
133 memcpy(mpi->stride,dmpi->stride,MP_MAX_PLANES*sizeof(unsigned int));
134 mpi->flags|=MP_IMGFLAG_DIRECT;
135 mpi->priv=(void*)dmpi;
136 return;
140 static int key_cb(int code) {
141 return menu_read_key(st_priv->current,code);
144 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
145 mp_image_t *dmpi = NULL;
147 if (vf->priv->passthrough) {
148 dmpi=vf_get_image(vf->next, IMGFMT_MPEGPES, MP_IMGTYPE_EXPORT,
149 0, mpi->w, mpi->h);
150 dmpi->planes[0]=mpi->planes[0];
151 return vf_next_put_image(vf,dmpi, pts);
154 // Close all menu who requested it
155 while(vf->priv->current->cl && vf->priv->current != vf->priv->root) {
156 menu_t* m = vf->priv->current;
157 vf->priv->current = m->parent ? m->parent : vf->priv->root;
158 menu_close(m);
161 // Try to capture the last frame before pause, or fallback to use
162 // last captured frame.
163 if(pause_mpi && (mpi->w != pause_mpi->w || mpi->h != pause_mpi->h ||
164 mpi->imgfmt != pause_mpi->imgfmt)) {
165 free_mp_image(pause_mpi);
166 pause_mpi = NULL;
168 if (!pause_mpi) {
169 pause_mpi = alloc_mpi(mpi->w,mpi->h,mpi->imgfmt);
170 copy_mpi(pause_mpi,mpi);
172 else if (mpctx_get_osd_function(vf->priv->root->ctx) == OSD_PAUSE)
173 copy_mpi(pause_mpi,mpi);
175 if (vf->priv->current->show) {
176 if (!mp_input_key_cb)
177 mp_input_key_cb = key_cb;
179 if(mpi->flags&MP_IMGFLAG_DIRECT)
180 dmpi = mpi->priv;
181 else {
182 dmpi = vf_get_image(vf->next,mpi->imgfmt,
183 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
184 mpi->w,mpi->h);
185 copy_mpi(dmpi,mpi);
187 menu_draw(vf->priv->current,dmpi);
189 } else {
190 if(mp_input_key_cb)
191 mp_input_key_cb = NULL;
193 if(mpi->flags&MP_IMGFLAG_DIRECT)
194 dmpi = mpi->priv;
195 else {
196 dmpi = vf_get_image(vf->next,mpi->imgfmt,
197 MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE,
198 mpi->w,mpi->h);
200 dmpi->stride[0] = mpi->stride[0];
201 dmpi->stride[1] = mpi->stride[1];
202 dmpi->stride[2] = mpi->stride[2];
203 dmpi->planes[0] = mpi->planes[0];
204 dmpi->planes[1] = mpi->planes[1];
205 dmpi->planes[2] = mpi->planes[2];
206 dmpi->priv = mpi->priv;
209 return vf_next_put_image(vf,dmpi, pts);
212 static void uninit(vf_instance_t *vf) {
213 vf->priv=NULL;
214 if(pause_mpi) {
215 free_mp_image(pause_mpi);
216 pause_mpi = NULL;
220 static int config(struct vf_instance_s* vf, int width, int height, int d_width, int d_height,
221 unsigned int flags, unsigned int outfmt) {
222 #ifdef CONFIG_FREETYPE
223 // here is the right place to get screen dimensions
224 if (force_load_font) {
225 force_load_font = 0;
226 load_font_ft(width,height,&vo_font,font_name,osd_font_scale_factor);
228 #endif
229 if(outfmt == IMGFMT_MPEGPES)
230 vf->priv->passthrough = 1;
231 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
234 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
235 return vf_next_query_format(vf,fmt);
238 static int open_vf(vf_instance_t *vf, char* args){
239 if(!st_priv) {
240 st_priv = calloc(1,sizeof(struct vf_priv_s));
241 st_priv->root = st_priv->current = menu_open(args);
242 if(!st_priv->current) {
243 free(st_priv);
244 st_priv = NULL;
245 return 0;
247 st_priv->root->show = menu_startup;
248 mp_input_add_cmd_filter((mp_input_cmd_filter)cmd_filter,st_priv);
251 vf->config = config;
252 vf->query_format=query_format;
253 vf->put_image = put_image;
254 vf->get_image = get_image;
255 vf->uninit=uninit;
256 vf->priv=st_priv;
257 go2pause=0;
259 return 1;
263 vf_info_t vf_info_menu = {
264 "Internal filter for libmenu",
265 "menu",
266 "Albeu",
268 open_vf,
269 NULL