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.
26 #include "libmpcodecs/img_format.h"
27 #include "libmpcodecs/mp_image.h"
33 #include "libvo/font_load.h"
34 #include "osdep/keycodes.h"
46 static struct menu_priv_s cfg_dflt
= {
56 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
58 static const m_option_t cfg_fields
[] = {
59 { "minbor", ST_OFF(minb
), CONF_TYPE_INT
, M_OPT_MIN
, 0, 0, NULL
},
60 { "hspace", ST_OFF(hspace
), CONF_TYPE_INT
, M_OPT_MIN
, 0, 0, NULL
},
61 { "file", ST_OFF(file
), CONF_TYPE_STRING
, 0, 0, 0, NULL
},
62 { NULL
, NULL
, NULL
, 0,0,0,NULL
}
65 #define mpriv (menu->priv)
67 static void read_cmd(menu_t
* menu
,int cmd
) {
70 mpriv
->cur_line
-= mpriv
->disp_lines
/ 2;
71 if(mpriv
->cur_line
< 0)
76 mpriv
->cur_line
+= mpriv
->disp_lines
/ 2;
77 if(mpriv
->cur_line
>= mpriv
->num_lines
)
78 mpriv
->cur_line
= mpriv
->num_lines
- 1;
89 mpriv
->cur_line
= mpriv
->num_lines
- 1;
91 case MENU_CMD_PAGE_UP
:
92 mpriv
->cur_line
= mpriv
->cur_line
> mpriv
->disp_lines
?
93 mpriv
->cur_line
- mpriv
->disp_lines
: 0;
95 case MENU_CMD_PAGE_DOWN
:
96 mpriv
->cur_line
= mpriv
->cur_line
+ mpriv
->disp_lines
> mpriv
->num_lines
- 1 ? mpriv
->num_lines
- 1 : mpriv
->cur_line
+ mpriv
->disp_lines
;
102 static void draw(menu_t
* menu
,mp_image_t
* mpi
) {
105 //int th = 2*mpriv->hspace + vo_font->height;
111 mpriv
->disp_lines
= (mpi
->h
+ mpriv
->hspace
- 2*mpriv
->minb
) / ( vo_font
->height
+ mpriv
->hspace
);
112 if(mpriv
->num_lines
- mpriv
->cur_line
< mpriv
->disp_lines
) {
113 i
= mpriv
->num_lines
- 1 - mpriv
->disp_lines
;
115 end
= mpriv
->num_lines
- 1;
118 end
= i
+ mpriv
->disp_lines
;
119 if(end
>= mpriv
->num_lines
) end
= mpriv
->num_lines
- 1;
122 for( ; i
< end
; i
++) {
123 menu_draw_text(mpi
,mpriv
->lines
[i
],x
,y
);
124 y
+= vo_font
->height
+ mpriv
->hspace
;
129 #define BUF_SIZE 1024
131 static int open_txt(menu_t
* menu
, char* args
) {
137 args
= NULL
; // Warning kill
140 menu
->read_cmd
= read_cmd
;
143 mp_tmsg(MSGT_GLOBAL
,MSGL_WARN
,"[MENU] Text menu needs a textfile name (parameter file).\n");
147 fd
= fopen(mpriv
->file
,"r");
149 mp_tmsg(MSGT_GLOBAL
,MSGL_WARN
,"[MENU] Can't open %s.\n",mpriv
->file
);
154 r
= fread(buf
+pos
,1,BUF_SIZE
-pos
-1,fd
);
157 mpriv
->lines
= realloc(mpriv
->lines
,(mpriv
->num_lines
+ 1)*sizeof(char*));
158 mpriv
->lines
[mpriv
->num_lines
] = strdup(buf
);
167 while((l
= strchr(buf
,'\n')) != NULL
) {
169 mpriv
->lines
= realloc(mpriv
->lines
,(mpriv
->num_lines
+ 1)*sizeof(char*));
170 mpriv
->lines
[mpriv
->num_lines
] = malloc(s
+1);
171 memcpy(mpriv
->lines
[mpriv
->num_lines
],buf
,s
);
172 mpriv
->lines
[mpriv
->num_lines
][s
] = '\0';
175 memmove(buf
,l
+1,pos
);
179 if(pos
>= BUF_SIZE
-1) {
180 mp_tmsg(MSGT_GLOBAL
,MSGL_WARN
,"[MENU] Warning, line too long. Splitting it.\n");
181 mpriv
->lines
= realloc(mpriv
->lines
,(mpriv
->num_lines
+ 1)*sizeof(char*));
182 mpriv
->lines
[mpriv
->num_lines
] = strdup(buf
);
188 mp_tmsg(MSGT_GLOBAL
,MSGL_INFO
,"[MENU] Parsed %d lines.\n",mpriv
->num_lines
);
193 const menu_info_t menu_info_txt
= {
200 sizeof(struct menu_priv_s
),