10 #include "libmpcodecs/img_format.h"
11 #include "libmpcodecs/mp_image.h"
17 #include "libvo/font_load.h"
18 #include "osdep/keycodes.h"
30 static struct menu_priv_s cfg_dflt
= {
40 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
42 static m_option_t cfg_fields
[] = {
43 { "minbor", ST_OFF(minb
), CONF_TYPE_INT
, M_OPT_MIN
, 0, 0, NULL
},
44 { "hspace", ST_OFF(hspace
), CONF_TYPE_INT
, M_OPT_MIN
, 0, 0, NULL
},
45 { "file", ST_OFF(file
), CONF_TYPE_STRING
, 0, 0, 0, NULL
},
46 { NULL
, NULL
, NULL
, 0,0,0,NULL
}
49 #define mpriv (menu->priv)
51 static void read_cmd(menu_t
* menu
,int cmd
) {
54 mpriv
->cur_line
-= mpriv
->disp_lines
/ 2;
55 if(mpriv
->cur_line
< 0)
60 mpriv
->cur_line
+= mpriv
->disp_lines
/ 2;
61 if(mpriv
->cur_line
>= mpriv
->num_lines
)
62 mpriv
->cur_line
= mpriv
->num_lines
- 1;
72 static void read_key(menu_t
* menu
,int c
) {
78 mpriv
->cur_line
= mpriv
->num_lines
- 1;
81 mpriv
->cur_line
= mpriv
->cur_line
> mpriv
->disp_lines
?
82 mpriv
->cur_line
- mpriv
->disp_lines
: 0;
85 mpriv
->cur_line
= mpriv
->cur_line
+ mpriv
->disp_lines
> mpriv
->num_lines
- 1 ? mpriv
->num_lines
- 1 : mpriv
->cur_line
+ mpriv
->disp_lines
;
88 menu_dflt_read_key(menu
,c
);
93 static void draw(menu_t
* menu
,mp_image_t
* mpi
) {
96 //int th = 2*mpriv->hspace + vo_font->height;
102 mpriv
->disp_lines
= (mpi
->h
+ mpriv
->hspace
- 2*mpriv
->minb
) / ( vo_font
->height
+ mpriv
->hspace
);
103 if(mpriv
->num_lines
- mpriv
->cur_line
< mpriv
->disp_lines
) {
104 i
= mpriv
->num_lines
- 1 - mpriv
->disp_lines
;
106 end
= mpriv
->num_lines
- 1;
109 end
= i
+ mpriv
->disp_lines
;
110 if(end
>= mpriv
->num_lines
) end
= mpriv
->num_lines
- 1;
113 for( ; i
< end
; i
++) {
114 menu_draw_text(mpi
,mpriv
->lines
[i
],x
,y
);
115 y
+= vo_font
->height
+ mpriv
->hspace
;
120 #define BUF_SIZE 1024
122 static int open_txt(menu_t
* menu
, char* args
) {
128 args
= NULL
; // Warning kill
131 menu
->read_cmd
= read_cmd
;
132 menu
->read_key
= read_key
;
135 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_MenuTxtNeedATxtFileName
);
139 fd
= fopen(mpriv
->file
,"r");
141 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_MenuTxtCantOpen
,mpriv
->file
);
146 r
= fread(buf
+pos
,1,BUF_SIZE
-pos
-1,fd
);
149 mpriv
->lines
= realloc(mpriv
->lines
,(mpriv
->num_lines
+ 1)*sizeof(char*));
150 mpriv
->lines
[mpriv
->num_lines
] = strdup(buf
);
159 while((l
= strchr(buf
,'\n')) != NULL
) {
161 mpriv
->lines
= realloc(mpriv
->lines
,(mpriv
->num_lines
+ 1)*sizeof(char*));
162 mpriv
->lines
[mpriv
->num_lines
] = malloc(s
+1);
163 memcpy(mpriv
->lines
[mpriv
->num_lines
],buf
,s
);
164 mpriv
->lines
[mpriv
->num_lines
][s
] = '\0';
167 memmove(buf
,l
+1,pos
);
171 if(pos
>= BUF_SIZE
-1) {
172 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_WarningTooLongLineSplitting
);
173 mpriv
->lines
= realloc(mpriv
->lines
,(mpriv
->num_lines
+ 1)*sizeof(char*));
174 mpriv
->lines
[mpriv
->num_lines
] = strdup(buf
);
180 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,MSGTR_LIBMENU_ParsedLines
,mpriv
->num_lines
);
185 const menu_info_t menu_info_txt
= {
192 sizeof(struct menu_priv_s
),