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.
27 #include "libmpcodecs/img_format.h"
28 #include "libmpcodecs/mp_image.h"
34 #include "libvo/font_load.h"
35 #include "osdep/keycodes.h"
47 static struct menu_priv_s cfg_dflt
= {
57 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
59 static const m_option_t cfg_fields
[] = {
60 { "minbor", ST_OFF(minb
), CONF_TYPE_INT
, M_OPT_MIN
, 0, 0, NULL
},
61 { "hspace", ST_OFF(hspace
), CONF_TYPE_INT
, M_OPT_MIN
, 0, 0, NULL
},
62 { "file", ST_OFF(file
), CONF_TYPE_STRING
, 0, 0, 0, NULL
},
63 { NULL
, NULL
, NULL
, 0,0,0,NULL
}
66 #define mpriv (menu->priv)
68 static void read_cmd(menu_t
* menu
,int cmd
) {
71 mpriv
->cur_line
-= mpriv
->disp_lines
/ 2;
72 if(mpriv
->cur_line
< 0)
77 mpriv
->cur_line
+= mpriv
->disp_lines
/ 2;
78 if(mpriv
->cur_line
>= mpriv
->num_lines
)
79 mpriv
->cur_line
= mpriv
->num_lines
- 1;
90 mpriv
->cur_line
= mpriv
->num_lines
- 1;
92 case MENU_CMD_PAGE_UP
:
93 mpriv
->cur_line
= mpriv
->cur_line
> mpriv
->disp_lines
?
94 mpriv
->cur_line
- mpriv
->disp_lines
: 0;
96 case MENU_CMD_PAGE_DOWN
:
97 mpriv
->cur_line
= mpriv
->cur_line
+ mpriv
->disp_lines
> mpriv
->num_lines
- 1 ? mpriv
->num_lines
- 1 : mpriv
->cur_line
+ mpriv
->disp_lines
;
103 static void draw(menu_t
* menu
,mp_image_t
* mpi
) {
106 //int th = 2*mpriv->hspace + vo_font->height;
112 mpriv
->disp_lines
= (mpi
->h
+ mpriv
->hspace
- 2*mpriv
->minb
) / ( vo_font
->height
+ mpriv
->hspace
);
113 if(mpriv
->num_lines
- mpriv
->cur_line
< mpriv
->disp_lines
) {
114 i
= mpriv
->num_lines
- 1 - mpriv
->disp_lines
;
116 end
= mpriv
->num_lines
- 1;
119 end
= i
+ mpriv
->disp_lines
;
120 if(end
>= mpriv
->num_lines
) end
= mpriv
->num_lines
- 1;
123 for( ; i
< end
; i
++) {
124 menu_draw_text(mpi
,mpriv
->lines
[i
],x
,y
);
125 y
+= vo_font
->height
+ mpriv
->hspace
;
130 #define BUF_SIZE 1024
132 static int open_txt(menu_t
* menu
, char* args
) {
138 args
= NULL
; // Warning kill
141 menu
->read_cmd
= read_cmd
;
144 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_MenuTxtNeedATxtFileName
);
148 fd
= fopen(mpriv
->file
,"r");
150 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_MenuTxtCantOpen
,mpriv
->file
);
155 r
= fread(buf
+pos
,1,BUF_SIZE
-pos
-1,fd
);
158 mpriv
->lines
= realloc(mpriv
->lines
,(mpriv
->num_lines
+ 1)*sizeof(char*));
159 mpriv
->lines
[mpriv
->num_lines
] = strdup(buf
);
168 while((l
= strchr(buf
,'\n')) != NULL
) {
170 mpriv
->lines
= realloc(mpriv
->lines
,(mpriv
->num_lines
+ 1)*sizeof(char*));
171 mpriv
->lines
[mpriv
->num_lines
] = malloc(s
+1);
172 memcpy(mpriv
->lines
[mpriv
->num_lines
],buf
,s
);
173 mpriv
->lines
[mpriv
->num_lines
][s
] = '\0';
176 memmove(buf
,l
+1,pos
);
180 if(pos
>= BUF_SIZE
-1) {
181 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_WarningTooLongLineSplitting
);
182 mpriv
->lines
= realloc(mpriv
->lines
,(mpriv
->num_lines
+ 1)*sizeof(char*));
183 mpriv
->lines
[mpriv
->num_lines
] = strdup(buf
);
189 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,MSGTR_LIBMENU_ParsedLines
,mpriv
->num_lines
);
194 const menu_info_t menu_info_txt
= {
201 sizeof(struct menu_priv_s
),