annotate libmenu/menu_txt.c @ 24565:a5255ffdcfaf

rivatv_lock_nv04 is actually an extended version of rivatv_lock_nv03 (patch by Guillaume LECERF <foxcore at gmail.com>)
author faust3
date Wed, 19 Sep 2007 21:47:35 +0000
parents ee2c8684c925
children 96d0992c7920
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
1
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 9380
diff changeset
2 #include "config.h"
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 16862
diff changeset
3 #include "mp_msg.h"
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 16862
diff changeset
4 #include "help_mp.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
5
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
6 #include <stdlib.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
7 #include <stdio.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
8 #include <string.h>
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
9
19431
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 17994
diff changeset
10 #include "libmpcodecs/img_format.h"
ac69ba536915 Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents: 17994
diff changeset
11 #include "libmpcodecs/mp_image.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
12
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 9380
diff changeset
13 #include "m_struct.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 9380
diff changeset
14 #include "m_option.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
15 #include "menu.h"
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
16
16862
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 9380
diff changeset
17 #include "libvo/font_load.h"
931bdbc37ee0 Unify include paths, -I.. is in CFLAGS.
diego
parents: 9380
diff changeset
18 #include "osdep/keycodes.h"
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
19
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
20 struct menu_priv_s {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
21 char** lines;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
22 int num_lines;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
23 int cur_line;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
24 int disp_lines;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
25 int minb;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
26 int hspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
27 char* file;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
28 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
29
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
30 static struct menu_priv_s cfg_dflt = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
31 NULL,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
32 0,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
33 0,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
34 0,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
35 0,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
36 3,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
37 NULL
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
38 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
39
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
40 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
41
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
42 static m_option_t cfg_fields[] = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
43 { "minbor", ST_OFF(minb), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
44 { "hspace", ST_OFF(hspace), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
45 { "file", ST_OFF(file), CONF_TYPE_STRING, 0, 0, 0, NULL },
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
46 { NULL, NULL, NULL, 0,0,0,NULL }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
47 };
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
48
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
49 #define mpriv (menu->priv)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
50
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
51 static void read_cmd(menu_t* menu,int cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
52 switch(cmd) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
53 case MENU_CMD_UP:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
54 mpriv->cur_line -= mpriv->disp_lines / 2;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
55 if(mpriv->cur_line < 0)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
56 mpriv->cur_line = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
57 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
58 case MENU_CMD_DOWN:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
59 case MENU_CMD_OK:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
60 mpriv->cur_line += mpriv->disp_lines / 2;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
61 if(mpriv->cur_line >= mpriv->num_lines)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
62 mpriv->cur_line = mpriv->num_lines - 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
63 break;
23367
ee2c8684c925 allow left key command to close text menus too
ben
parents: 23366
diff changeset
64 case MENU_CMD_LEFT:
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
65 case MENU_CMD_CANCEL:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
66 menu->show = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
67 menu->cl = 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
68 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
69 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
70 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
71
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
72 static void read_key(menu_t* menu,int c) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
73 switch (c) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
74 case KEY_HOME:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
75 mpriv->cur_line = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
76 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
77 case KEY_END:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
78 mpriv->cur_line = mpriv->num_lines - 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
79 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
80 case KEY_PAGE_UP:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
81 mpriv->cur_line = mpriv->cur_line > mpriv->disp_lines ?
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
82 mpriv->cur_line - mpriv->disp_lines : 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
83 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
84 case KEY_PAGE_DOWN:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
85 mpriv->cur_line = mpriv->cur_line + mpriv->disp_lines > mpriv->num_lines - 1 ? mpriv->num_lines - 1 : mpriv->cur_line + mpriv->disp_lines;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
86 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
87 default:
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
88 menu_dflt_read_key(menu,c);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
89 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
90 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
91
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
92
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
93 static void draw(menu_t* menu,mp_image_t* mpi) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
94 int x = mpriv->minb;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
95 int y = mpriv->minb;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
96 //int th = 2*mpriv->hspace + vo_font->height;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
97 int i,end;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
98
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
99 if(x < 0) x = 8;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
100 if(y < 0) y = 8;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
101
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
102 mpriv->disp_lines = (mpi->h + mpriv->hspace - 2*mpriv->minb) / ( vo_font->height + mpriv->hspace);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
103 if(mpriv->num_lines - mpriv->cur_line < mpriv->disp_lines) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
104 i = mpriv->num_lines - 1 - mpriv->disp_lines;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
105 if(i < 0) i = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
106 end = mpriv->num_lines - 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
107 } else {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
108 i = mpriv->cur_line;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
109 end = i + mpriv->disp_lines;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
110 if(end >= mpriv->num_lines) end = mpriv->num_lines - 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
111 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
112
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
113 for( ; i < end ; i++) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
114 menu_draw_text(mpi,mpriv->lines[i],x,y);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
115 y += vo_font->height + mpriv->hspace;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
116 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
117
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
118 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
119
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
120 #define BUF_SIZE 1024
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
121
23366
b344b6520518 rename some menu open functions, to avoid confusion with libc native open()
ben
parents: 19431
diff changeset
122 static int open_txt(menu_t* menu, char* args) {
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
123 FILE* fd;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
124 char buf[BUF_SIZE];
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
125 char *l;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
126 int s;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
127 int pos = 0, r = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
128 args = NULL; // Warning kill
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
129
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
130 menu->draw = draw;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
131 menu->read_cmd = read_cmd;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
132 menu->read_key = read_key;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
133
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
134 if(!mpriv->file) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 16862
diff changeset
135 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuTxtNeedATxtFileName);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
136 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
137 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
138
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
139 fd = fopen(mpriv->file,"r");
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
140 if(!fd) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 16862
diff changeset
141 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuTxtCantOpen,mpriv->file);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
142 return 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
143 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
144
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
145 while(1) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
146 r = fread(buf+pos,1,BUF_SIZE-pos-1,fd);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
147 if(r <= 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
148 if(pos > 0) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
149 mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
150 mpriv->lines[mpriv->num_lines] = strdup(buf);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
151 mpriv->num_lines++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
152 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
153 fclose(fd);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
154 break;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
155 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
156 pos += r;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
157 buf[pos] = '\0';
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
158
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
159 while((l = strchr(buf,'\n')) != NULL) {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
160 s = l-buf;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
161 mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
162 mpriv->lines[mpriv->num_lines] = malloc(s+1);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
163 memcpy(mpriv->lines[mpriv->num_lines],buf,s);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
164 mpriv->lines[mpriv->num_lines][s] = '\0';
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
165 pos -= s + 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
166 if(pos > 0)
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
167 memmove(buf,l+1,pos);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
168 buf[pos] = '\0';
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
169 mpriv->num_lines++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
170 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
171 if(pos >= BUF_SIZE-1) {
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 16862
diff changeset
172 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_WarningTooLongLineSplitting);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
173 mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*));
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
174 mpriv->lines[mpriv->num_lines] = strdup(buf);
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
175 mpriv->num_lines++;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
176 pos = 0;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
177 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
178 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
179
17994
6927fabaef92 Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents: 16862
diff changeset
180 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_LIBMENU_ParsedLines,mpriv->num_lines);
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
181
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
182 return 1;
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
183 }
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
184
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
185 const menu_info_t menu_info_txt = {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
186 "Text file viewer",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
187 "txt",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
188 "Albeu",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
189 "",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
190 {
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
191 "txt_cfg",
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
192 sizeof(struct menu_priv_s),
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
193 &cfg_dflt,
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
194 cfg_fields
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
195 },
23366
b344b6520518 rename some menu open functions, to avoid confusion with libc native open()
ben
parents: 19431
diff changeset
196 open_txt,
8197
b31caec933e9 OSD menus initial version
albeu
parents:
diff changeset
197 };