Mercurial > mplayer.hg
annotate libmenu/menu_txt.c @ 21816:fa8128898231
removed useless reporting code
author | nicodvb |
---|---|
date | Sat, 06 Jan 2007 11:59:33 +0000 |
parents | ac69ba536915 |
children | b344b6520518 |
rev | line source |
---|---|
8197 | 1 |
16862 | 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 | 5 |
6 #include <stdlib.h> | |
7 #include <stdio.h> | |
8 #include <string.h> | |
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 | 12 |
16862 | 13 #include "m_struct.h" |
14 #include "m_option.h" | |
8197 | 15 #include "menu.h" |
16 | |
16862 | 17 #include "libvo/font_load.h" |
18 #include "osdep/keycodes.h" | |
8197 | 19 |
20 struct menu_priv_s { | |
21 char** lines; | |
22 int num_lines; | |
23 int cur_line; | |
24 int disp_lines; | |
25 int minb; | |
26 int hspace; | |
27 char* file; | |
28 }; | |
29 | |
30 static struct menu_priv_s cfg_dflt = { | |
31 NULL, | |
32 0, | |
33 0, | |
34 0, | |
35 0, | |
36 3, | |
37 NULL | |
38 }; | |
39 | |
40 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m) | |
41 | |
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 } | |
47 }; | |
48 | |
49 #define mpriv (menu->priv) | |
50 | |
51 static void read_cmd(menu_t* menu,int cmd) { | |
52 switch(cmd) { | |
53 case MENU_CMD_UP: | |
54 mpriv->cur_line -= mpriv->disp_lines / 2; | |
55 if(mpriv->cur_line < 0) | |
56 mpriv->cur_line = 0; | |
57 break; | |
58 case MENU_CMD_DOWN: | |
59 case MENU_CMD_OK: | |
60 mpriv->cur_line += mpriv->disp_lines / 2; | |
61 if(mpriv->cur_line >= mpriv->num_lines) | |
62 mpriv->cur_line = mpriv->num_lines - 1; | |
63 break; | |
64 case MENU_CMD_CANCEL: | |
65 menu->show = 0; | |
66 menu->cl = 1; | |
67 break; | |
68 } | |
69 } | |
70 | |
71 static void read_key(menu_t* menu,int c) { | |
72 switch (c) { | |
73 case KEY_HOME: | |
74 mpriv->cur_line = 0; | |
75 break; | |
76 case KEY_END: | |
77 mpriv->cur_line = mpriv->num_lines - 1; | |
78 break; | |
79 case KEY_PAGE_UP: | |
80 mpriv->cur_line = mpriv->cur_line > mpriv->disp_lines ? | |
81 mpriv->cur_line - mpriv->disp_lines : 0; | |
82 break; | |
83 case KEY_PAGE_DOWN: | |
84 mpriv->cur_line = mpriv->cur_line + mpriv->disp_lines > mpriv->num_lines - 1 ? mpriv->num_lines - 1 : mpriv->cur_line + mpriv->disp_lines; | |
85 break; | |
86 default: | |
87 menu_dflt_read_key(menu,c); | |
88 } | |
89 } | |
90 | |
91 | |
92 static void draw(menu_t* menu,mp_image_t* mpi) { | |
93 int x = mpriv->minb; | |
94 int y = mpriv->minb; | |
95 //int th = 2*mpriv->hspace + vo_font->height; | |
96 int i,end; | |
97 | |
98 if(x < 0) x = 8; | |
99 if(y < 0) y = 8; | |
100 | |
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; | |
104 if(i < 0) i = 0; | |
105 end = mpriv->num_lines - 1; | |
106 } else { | |
107 i = mpriv->cur_line; | |
108 end = i + mpriv->disp_lines; | |
109 if(end >= mpriv->num_lines) end = mpriv->num_lines - 1; | |
110 } | |
111 | |
112 for( ; i < end ; i++) { | |
113 menu_draw_text(mpi,mpriv->lines[i],x,y); | |
114 y += vo_font->height + mpriv->hspace; | |
115 } | |
116 | |
117 } | |
118 | |
119 #define BUF_SIZE 1024 | |
120 | |
121 static int open(menu_t* menu, char* args) { | |
122 FILE* fd; | |
123 char buf[BUF_SIZE]; | |
124 char *l; | |
125 int s; | |
126 int pos = 0, r = 0; | |
127 args = NULL; // Warning kill | |
128 | |
129 menu->draw = draw; | |
130 menu->read_cmd = read_cmd; | |
131 menu->read_key = read_key; | |
132 | |
133 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
|
134 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuTxtNeedATxtFileName); |
8197 | 135 return 0; |
136 } | |
137 | |
138 fd = fopen(mpriv->file,"r"); | |
139 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
|
140 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuTxtCantOpen,mpriv->file); |
8197 | 141 return 0; |
142 } | |
143 | |
144 while(1) { | |
145 r = fread(buf+pos,1,BUF_SIZE-pos-1,fd); | |
146 if(r <= 0) { | |
147 if(pos > 0) { | |
148 mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*)); | |
149 mpriv->lines[mpriv->num_lines] = strdup(buf); | |
150 mpriv->num_lines++; | |
151 } | |
152 fclose(fd); | |
153 break; | |
154 } | |
155 pos += r; | |
156 buf[pos] = '\0'; | |
157 | |
158 while((l = strchr(buf,'\n')) != NULL) { | |
159 s = l-buf; | |
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'; | |
164 pos -= s + 1; | |
165 if(pos > 0) | |
166 memmove(buf,l+1,pos); | |
167 buf[pos] = '\0'; | |
168 mpriv->num_lines++; | |
169 } | |
170 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
|
171 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_WarningTooLongLineSplitting); |
8197 | 172 mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*)); |
173 mpriv->lines[mpriv->num_lines] = strdup(buf); | |
174 mpriv->num_lines++; | |
175 pos = 0; | |
176 } | |
177 } | |
178 | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
16862
diff
changeset
|
179 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_LIBMENU_ParsedLines,mpriv->num_lines); |
8197 | 180 |
181 return 1; | |
182 } | |
183 | |
184 const menu_info_t menu_info_txt = { | |
185 "Text file viewer", | |
186 "txt", | |
187 "Albeu", | |
188 "", | |
189 { | |
190 "txt_cfg", | |
191 sizeof(struct menu_priv_s), | |
192 &cfg_dflt, | |
193 cfg_fields | |
194 }, | |
195 open, | |
196 }; |