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;
71 static void read_key(menu_t
* menu
,int c
) {
77 mpriv
->cur_line
= mpriv
->num_lines
- 1;
80 mpriv
->cur_line
= mpriv
->cur_line
> mpriv
->disp_lines
?
81 mpriv
->cur_line
- mpriv
->disp_lines
: 0;
84 mpriv
->cur_line
= mpriv
->cur_line
+ mpriv
->disp_lines
> mpriv
->num_lines
- 1 ? mpriv
->num_lines
- 1 : mpriv
->cur_line
+ mpriv
->disp_lines
;
87 menu_dflt_read_key(menu
,c
);
92 static void draw(menu_t
* menu
,mp_image_t
* mpi
) {
95 //int th = 2*mpriv->hspace + vo_font->height;
101 mpriv
->disp_lines
= (mpi
->h
+ mpriv
->hspace
- 2*mpriv
->minb
) / ( vo_font
->height
+ mpriv
->hspace
);
102 if(mpriv
->num_lines
- mpriv
->cur_line
< mpriv
->disp_lines
) {
103 i
= mpriv
->num_lines
- 1 - mpriv
->disp_lines
;
105 end
= mpriv
->num_lines
- 1;
108 end
= i
+ mpriv
->disp_lines
;
109 if(end
>= mpriv
->num_lines
) end
= mpriv
->num_lines
- 1;
112 for( ; i
< end
; i
++) {
113 menu_draw_text(mpi
,mpriv
->lines
[i
],x
,y
);
114 y
+= vo_font
->height
+ mpriv
->hspace
;
119 #define BUF_SIZE 1024
121 static int open(menu_t
* menu
, char* args
) {
127 args
= NULL
; // Warning kill
130 menu
->read_cmd
= read_cmd
;
131 menu
->read_key
= read_key
;
134 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_MenuTxtNeedATxtFileName
);
138 fd
= fopen(mpriv
->file
,"r");
140 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_MenuTxtCantOpen
,mpriv
->file
);
145 r
= fread(buf
+pos
,1,BUF_SIZE
-pos
-1,fd
);
148 mpriv
->lines
= realloc(mpriv
->lines
,(mpriv
->num_lines
+ 1)*sizeof(char*));
149 mpriv
->lines
[mpriv
->num_lines
] = strdup(buf
);
158 while((l
= strchr(buf
,'\n')) != NULL
) {
160 mpriv
->lines
= realloc(mpriv
->lines
,(mpriv
->num_lines
+ 1)*sizeof(char*));
161 mpriv
->lines
[mpriv
->num_lines
] = malloc(s
+1);
162 memcpy(mpriv
->lines
[mpriv
->num_lines
],buf
,s
);
163 mpriv
->lines
[mpriv
->num_lines
][s
] = '\0';
166 memmove(buf
,l
+1,pos
);
170 if(pos
>= BUF_SIZE
-1) {
171 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_LIBMENU_WarningTooLongLineSplitting
);
172 mpriv
->lines
= realloc(mpriv
->lines
,(mpriv
->num_lines
+ 1)*sizeof(char*));
173 mpriv
->lines
[mpriv
->num_lines
] = strdup(buf
);
179 mp_msg(MSGT_GLOBAL
,MSGL_INFO
,MSGTR_LIBMENU_ParsedLines
,mpriv
->num_lines
);
184 const menu_info_t menu_info_txt
= {
191 sizeof(struct menu_priv_s
),