2008-12-13 18:40:19 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2002-11-14 23:47:11 +00:00
|
|
|
|
2005-10-26 00:07:43 +00:00
|
|
|
#include "config.h"
|
2006-03-30 06:40:58 +00:00
|
|
|
#include "mp_msg.h"
|
2002-11-14 23:47:11 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2006-08-18 13:58:03 +00:00
|
|
|
#include "libmpcodecs/img_format.h"
|
|
|
|
#include "libmpcodecs/mp_image.h"
|
2002-11-14 23:47:11 +00:00
|
|
|
|
2005-10-26 00:07:43 +00:00
|
|
|
#include "m_struct.h"
|
|
|
|
#include "m_option.h"
|
2002-11-14 23:47:11 +00:00
|
|
|
#include "menu.h"
|
|
|
|
|
2005-10-26 00:07:43 +00:00
|
|
|
#include "libvo/font_load.h"
|
|
|
|
#include "osdep/keycodes.h"
|
2002-11-14 23:47:11 +00:00
|
|
|
|
|
|
|
struct menu_priv_s {
|
|
|
|
char** lines;
|
|
|
|
int num_lines;
|
|
|
|
int cur_line;
|
|
|
|
int disp_lines;
|
|
|
|
int minb;
|
|
|
|
int hspace;
|
|
|
|
char* file;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct menu_priv_s cfg_dflt = {
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
3,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
|
|
|
|
|
2010-04-04 16:11:20 +00:00
|
|
|
static const m_option_t cfg_fields[] = {
|
2002-11-14 23:47:11 +00:00
|
|
|
{ "minbor", ST_OFF(minb), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL },
|
|
|
|
{ "hspace", ST_OFF(hspace), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL },
|
|
|
|
{ "file", ST_OFF(file), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
|
|
|
{ NULL, NULL, NULL, 0,0,0,NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
#define mpriv (menu->priv)
|
|
|
|
|
|
|
|
static void read_cmd(menu_t* menu,int cmd) {
|
|
|
|
switch(cmd) {
|
|
|
|
case MENU_CMD_UP:
|
|
|
|
mpriv->cur_line -= mpriv->disp_lines / 2;
|
|
|
|
if(mpriv->cur_line < 0)
|
|
|
|
mpriv->cur_line = 0;
|
|
|
|
break;
|
|
|
|
case MENU_CMD_DOWN:
|
|
|
|
case MENU_CMD_OK:
|
|
|
|
mpriv->cur_line += mpriv->disp_lines / 2;
|
|
|
|
if(mpriv->cur_line >= mpriv->num_lines)
|
|
|
|
mpriv->cur_line = mpriv->num_lines - 1;
|
|
|
|
break;
|
2007-05-25 16:31:16 +00:00
|
|
|
case MENU_CMD_LEFT:
|
2002-11-14 23:47:11 +00:00
|
|
|
case MENU_CMD_CANCEL:
|
|
|
|
menu->show = 0;
|
|
|
|
menu->cl = 1;
|
|
|
|
break;
|
2007-12-04 10:42:59 +00:00
|
|
|
case MENU_CMD_HOME:
|
2002-11-14 23:47:11 +00:00
|
|
|
mpriv->cur_line = 0;
|
|
|
|
break;
|
2007-12-04 10:42:59 +00:00
|
|
|
case MENU_CMD_END:
|
2002-11-14 23:47:11 +00:00
|
|
|
mpriv->cur_line = mpriv->num_lines - 1;
|
|
|
|
break;
|
2007-12-04 10:42:59 +00:00
|
|
|
case MENU_CMD_PAGE_UP:
|
2002-11-14 23:47:11 +00:00
|
|
|
mpriv->cur_line = mpriv->cur_line > mpriv->disp_lines ?
|
|
|
|
mpriv->cur_line - mpriv->disp_lines : 0;
|
|
|
|
break;
|
2007-12-04 10:42:59 +00:00
|
|
|
case MENU_CMD_PAGE_DOWN:
|
2002-11-14 23:47:11 +00:00
|
|
|
mpriv->cur_line = mpriv->cur_line + mpriv->disp_lines > mpriv->num_lines - 1 ? mpriv->num_lines - 1 : mpriv->cur_line + mpriv->disp_lines;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void draw(menu_t* menu,mp_image_t* mpi) {
|
|
|
|
int x = mpriv->minb;
|
|
|
|
int y = mpriv->minb;
|
|
|
|
//int th = 2*mpriv->hspace + vo_font->height;
|
|
|
|
int i,end;
|
|
|
|
|
|
|
|
if(x < 0) x = 8;
|
|
|
|
if(y < 0) y = 8;
|
|
|
|
|
|
|
|
mpriv->disp_lines = (mpi->h + mpriv->hspace - 2*mpriv->minb) / ( vo_font->height + mpriv->hspace);
|
|
|
|
if(mpriv->num_lines - mpriv->cur_line < mpriv->disp_lines) {
|
|
|
|
i = mpriv->num_lines - 1 - mpriv->disp_lines;
|
|
|
|
if(i < 0) i = 0;
|
|
|
|
end = mpriv->num_lines - 1;
|
|
|
|
} else {
|
|
|
|
i = mpriv->cur_line;
|
|
|
|
end = i + mpriv->disp_lines;
|
|
|
|
if(end >= mpriv->num_lines) end = mpriv->num_lines - 1;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-11-14 23:47:11 +00:00
|
|
|
for( ; i < end ; i++) {
|
|
|
|
menu_draw_text(mpi,mpriv->lines[i],x,y);
|
|
|
|
y += vo_font->height + mpriv->hspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-11-14 23:47:11 +00:00
|
|
|
#define BUF_SIZE 1024
|
|
|
|
|
2007-05-25 10:26:39 +00:00
|
|
|
static int open_txt(menu_t* menu, char* args) {
|
2002-11-14 23:47:11 +00:00
|
|
|
FILE* fd;
|
|
|
|
char buf[BUF_SIZE];
|
|
|
|
char *l;
|
|
|
|
int s;
|
|
|
|
int pos = 0, r = 0;
|
|
|
|
args = NULL; // Warning kill
|
|
|
|
|
|
|
|
menu->draw = draw;
|
|
|
|
menu->read_cmd = read_cmd;
|
|
|
|
|
|
|
|
if(!mpriv->file) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Text menu needs a textfile name (parameter file).\n");
|
2002-11-14 23:47:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = fopen(mpriv->file,"r");
|
|
|
|
if(!fd) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Can't open %s.\n",mpriv->file);
|
2002-11-14 23:47:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
r = fread(buf+pos,1,BUF_SIZE-pos-1,fd);
|
|
|
|
if(r <= 0) {
|
|
|
|
if(pos > 0) {
|
|
|
|
mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*));
|
|
|
|
mpriv->lines[mpriv->num_lines] = strdup(buf);
|
|
|
|
mpriv->num_lines++;
|
|
|
|
}
|
|
|
|
fclose(fd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos += r;
|
|
|
|
buf[pos] = '\0';
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-11-14 23:47:11 +00:00
|
|
|
while((l = strchr(buf,'\n')) != NULL) {
|
|
|
|
s = l-buf;
|
|
|
|
mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*));
|
|
|
|
mpriv->lines[mpriv->num_lines] = malloc(s+1);
|
|
|
|
memcpy(mpriv->lines[mpriv->num_lines],buf,s);
|
|
|
|
mpriv->lines[mpriv->num_lines][s] = '\0';
|
|
|
|
pos -= s + 1;
|
|
|
|
if(pos > 0)
|
|
|
|
memmove(buf,l+1,pos);
|
|
|
|
buf[pos] = '\0';
|
|
|
|
mpriv->num_lines++;
|
|
|
|
}
|
|
|
|
if(pos >= BUF_SIZE-1) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_GLOBAL,MSGL_WARN,"[MENU] Warning, line too long. Splitting it.\n");
|
2002-11-14 23:47:11 +00:00
|
|
|
mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*));
|
|
|
|
mpriv->lines[mpriv->num_lines] = strdup(buf);
|
|
|
|
mpriv->num_lines++;
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_GLOBAL,MSGL_INFO,"[MENU] Parsed %d lines.\n",mpriv->num_lines);
|
2002-11-14 23:47:11 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const menu_info_t menu_info_txt = {
|
|
|
|
"Text file viewer",
|
|
|
|
"txt",
|
|
|
|
"Albeu",
|
|
|
|
"",
|
|
|
|
{
|
|
|
|
"txt_cfg",
|
|
|
|
sizeof(struct menu_priv_s),
|
|
|
|
&cfg_dflt,
|
|
|
|
cfg_fields
|
|
|
|
},
|
2007-05-25 10:26:39 +00:00
|
|
|
open_txt,
|
2002-11-14 23:47:11 +00:00
|
|
|
};
|