Mercurial > mplayer.hg
annotate libmenu/menu_txt.c @ 24661:598b3c2b9e5b
Remove stray XML tags that broke compilation.
author | diego |
---|---|
date | Mon, 01 Oct 2007 20:51:09 +0000 |
parents | ee2c8684c925 |
children | 96d0992c7920 |
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; | |
23367 | 64 case MENU_CMD_LEFT: |
8197 | 65 case MENU_CMD_CANCEL: |
66 menu->show = 0; | |
67 menu->cl = 1; | |
68 break; | |
69 } | |
70 } | |
71 | |
72 static void read_key(menu_t* menu,int c) { | |
73 switch (c) { | |
74 case KEY_HOME: | |
75 mpriv->cur_line = 0; | |
76 break; | |
77 case KEY_END: | |
78 mpriv->cur_line = mpriv->num_lines - 1; | |
79 break; | |
80 case KEY_PAGE_UP: | |
81 mpriv->cur_line = mpriv->cur_line > mpriv->disp_lines ? | |
82 mpriv->cur_line - mpriv->disp_lines : 0; | |
83 break; | |
84 case KEY_PAGE_DOWN: | |
85 mpriv->cur_line = mpriv->cur_line + mpriv->disp_lines > mpriv->num_lines - 1 ? mpriv->num_lines - 1 : mpriv->cur_line + mpriv->disp_lines; | |
86 break; | |
87 default: | |
88 menu_dflt_read_key(menu,c); | |
89 } | |
90 } | |
91 | |
92 | |
93 static void draw(menu_t* menu,mp_image_t* mpi) { | |
94 int x = mpriv->minb; | |
95 int y = mpriv->minb; | |
96 //int th = 2*mpriv->hspace + vo_font->height; | |
97 int i,end; | |
98 | |
99 if(x < 0) x = 8; | |
100 if(y < 0) y = 8; | |
101 | |
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; | |
105 if(i < 0) i = 0; | |
106 end = mpriv->num_lines - 1; | |
107 } else { | |
108 i = mpriv->cur_line; | |
109 end = i + mpriv->disp_lines; | |
110 if(end >= mpriv->num_lines) end = mpriv->num_lines - 1; | |
111 } | |
112 | |
113 for( ; i < end ; i++) { | |
114 menu_draw_text(mpi,mpriv->lines[i],x,y); | |
115 y += vo_font->height + mpriv->hspace; | |
116 } | |
117 | |
118 } | |
119 | |
120 #define BUF_SIZE 1024 | |
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 | 123 FILE* fd; |
124 char buf[BUF_SIZE]; | |
125 char *l; | |
126 int s; | |
127 int pos = 0, r = 0; | |
128 args = NULL; // Warning kill | |
129 | |
130 menu->draw = draw; | |
131 menu->read_cmd = read_cmd; | |
132 menu->read_key = read_key; | |
133 | |
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 | 136 return 0; |
137 } | |
138 | |
139 fd = fopen(mpriv->file,"r"); | |
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 | 142 return 0; |
143 } | |
144 | |
145 while(1) { | |
146 r = fread(buf+pos,1,BUF_SIZE-pos-1,fd); | |
147 if(r <= 0) { | |
148 if(pos > 0) { | |
149 mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*)); | |
150 mpriv->lines[mpriv->num_lines] = strdup(buf); | |
151 mpriv->num_lines++; | |
152 } | |
153 fclose(fd); | |
154 break; | |
155 } | |
156 pos += r; | |
157 buf[pos] = '\0'; | |
158 | |
159 while((l = strchr(buf,'\n')) != NULL) { | |
160 s = l-buf; | |
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'; | |
165 pos -= s + 1; | |
166 if(pos > 0) | |
167 memmove(buf,l+1,pos); | |
168 buf[pos] = '\0'; | |
169 mpriv->num_lines++; | |
170 } | |
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 | 173 mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*)); |
174 mpriv->lines[mpriv->num_lines] = strdup(buf); | |
175 mpriv->num_lines++; | |
176 pos = 0; | |
177 } | |
178 } | |
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 | 181 |
182 return 1; | |
183 } | |
184 | |
185 const menu_info_t menu_info_txt = { | |
186 "Text file viewer", | |
187 "txt", | |
188 "Albeu", | |
189 "", | |
190 { | |
191 "txt_cfg", | |
192 sizeof(struct menu_priv_s), | |
193 &cfg_dflt, | |
194 cfg_fields | |
195 }, | |
23366
b344b6520518
rename some menu open functions, to avoid confusion with libc native open()
ben
parents:
19431
diff
changeset
|
196 open_txt, |
8197 | 197 }; |