Mercurial > mplayer.hg
annotate libmenu/menu_txt.c @ 35622:59456592c6d1
Add a message indicating start of initialization of X.
author | ib |
---|---|
date | Thu, 10 Jan 2013 09:52:50 +0000 |
parents | 9e627a1793b1 |
children | 63bc09af21f4 |
rev | line source |
---|---|
28113 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 */ | |
8197 | 18 |
16862 | 19 #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
|
20 #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
|
21 #include "help_mp.h" |
8197 | 22 |
23 #include <stdlib.h> | |
24 #include <stdio.h> | |
25 #include <string.h> | |
26 | |
19431
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
17994
diff
changeset
|
27 #include "libmpcodecs/img_format.h" |
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
17994
diff
changeset
|
28 #include "libmpcodecs/mp_image.h" |
8197 | 29 |
16862 | 30 #include "m_struct.h" |
31 #include "m_option.h" | |
8197 | 32 #include "menu.h" |
33 | |
32466
9e627a1793b1
Move font_load.[ch], font_load_ft.c and osd_font.h from libvo to sub.
cigaes
parents:
30957
diff
changeset
|
34 #include "sub/font_load.h" |
16862 | 35 #include "osdep/keycodes.h" |
8197 | 36 |
37 struct menu_priv_s { | |
38 char** lines; | |
39 int num_lines; | |
40 int cur_line; | |
41 int disp_lines; | |
42 int minb; | |
43 int hspace; | |
44 char* file; | |
45 }; | |
46 | |
47 static struct menu_priv_s cfg_dflt = { | |
48 NULL, | |
49 0, | |
50 0, | |
51 0, | |
52 0, | |
53 3, | |
54 NULL | |
55 }; | |
56 | |
57 #define ST_OFF(m) M_ST_OFF(struct menu_priv_s,m) | |
58 | |
30957 | 59 static const m_option_t cfg_fields[] = { |
8197 | 60 { "minbor", ST_OFF(minb), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, |
61 { "hspace", ST_OFF(hspace), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, | |
62 { "file", ST_OFF(file), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
63 { NULL, NULL, NULL, 0,0,0,NULL } | |
64 }; | |
65 | |
66 #define mpriv (menu->priv) | |
67 | |
68 static void read_cmd(menu_t* menu,int cmd) { | |
69 switch(cmd) { | |
70 case MENU_CMD_UP: | |
71 mpriv->cur_line -= mpriv->disp_lines / 2; | |
72 if(mpriv->cur_line < 0) | |
73 mpriv->cur_line = 0; | |
74 break; | |
75 case MENU_CMD_DOWN: | |
76 case MENU_CMD_OK: | |
77 mpriv->cur_line += mpriv->disp_lines / 2; | |
78 if(mpriv->cur_line >= mpriv->num_lines) | |
79 mpriv->cur_line = mpriv->num_lines - 1; | |
80 break; | |
23367 | 81 case MENU_CMD_LEFT: |
8197 | 82 case MENU_CMD_CANCEL: |
83 menu->show = 0; | |
84 menu->cl = 1; | |
85 break; | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23367
diff
changeset
|
86 case MENU_CMD_HOME: |
8197 | 87 mpriv->cur_line = 0; |
88 break; | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23367
diff
changeset
|
89 case MENU_CMD_END: |
8197 | 90 mpriv->cur_line = mpriv->num_lines - 1; |
91 break; | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23367
diff
changeset
|
92 case MENU_CMD_PAGE_UP: |
8197 | 93 mpriv->cur_line = mpriv->cur_line > mpriv->disp_lines ? |
94 mpriv->cur_line - mpriv->disp_lines : 0; | |
95 break; | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23367
diff
changeset
|
96 case MENU_CMD_PAGE_DOWN: |
8197 | 97 mpriv->cur_line = mpriv->cur_line + mpriv->disp_lines > mpriv->num_lines - 1 ? mpriv->num_lines - 1 : mpriv->cur_line + mpriv->disp_lines; |
98 break; | |
99 } | |
100 } | |
101 | |
102 | |
103 static void draw(menu_t* menu,mp_image_t* mpi) { | |
104 int x = mpriv->minb; | |
105 int y = mpriv->minb; | |
106 //int th = 2*mpriv->hspace + vo_font->height; | |
107 int i,end; | |
108 | |
109 if(x < 0) x = 8; | |
110 if(y < 0) y = 8; | |
111 | |
112 mpriv->disp_lines = (mpi->h + mpriv->hspace - 2*mpriv->minb) / ( vo_font->height + mpriv->hspace); | |
113 if(mpriv->num_lines - mpriv->cur_line < mpriv->disp_lines) { | |
114 i = mpriv->num_lines - 1 - mpriv->disp_lines; | |
115 if(i < 0) i = 0; | |
116 end = mpriv->num_lines - 1; | |
117 } else { | |
118 i = mpriv->cur_line; | |
119 end = i + mpriv->disp_lines; | |
120 if(end >= mpriv->num_lines) end = mpriv->num_lines - 1; | |
121 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
122 |
8197 | 123 for( ; i < end ; i++) { |
124 menu_draw_text(mpi,mpriv->lines[i],x,y); | |
125 y += vo_font->height + mpriv->hspace; | |
126 } | |
127 | |
128 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
129 |
8197 | 130 #define BUF_SIZE 1024 |
131 | |
23366
b344b6520518
rename some menu open functions, to avoid confusion with libc native open()
ben
parents:
19431
diff
changeset
|
132 static int open_txt(menu_t* menu, char* args) { |
8197 | 133 FILE* fd; |
134 char buf[BUF_SIZE]; | |
135 char *l; | |
136 int s; | |
137 int pos = 0, r = 0; | |
138 args = NULL; // Warning kill | |
139 | |
140 menu->draw = draw; | |
141 menu->read_cmd = read_cmd; | |
142 | |
143 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
|
144 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuTxtNeedATxtFileName); |
8197 | 145 return 0; |
146 } | |
147 | |
148 fd = fopen(mpriv->file,"r"); | |
149 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
|
150 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuTxtCantOpen,mpriv->file); |
8197 | 151 return 0; |
152 } | |
153 | |
154 while(1) { | |
155 r = fread(buf+pos,1,BUF_SIZE-pos-1,fd); | |
156 if(r <= 0) { | |
157 if(pos > 0) { | |
158 mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*)); | |
159 mpriv->lines[mpriv->num_lines] = strdup(buf); | |
160 mpriv->num_lines++; | |
161 } | |
162 fclose(fd); | |
163 break; | |
164 } | |
165 pos += r; | |
166 buf[pos] = '\0'; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
167 |
8197 | 168 while((l = strchr(buf,'\n')) != NULL) { |
169 s = l-buf; | |
170 mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*)); | |
171 mpriv->lines[mpriv->num_lines] = malloc(s+1); | |
172 memcpy(mpriv->lines[mpriv->num_lines],buf,s); | |
173 mpriv->lines[mpriv->num_lines][s] = '\0'; | |
174 pos -= s + 1; | |
175 if(pos > 0) | |
176 memmove(buf,l+1,pos); | |
177 buf[pos] = '\0'; | |
178 mpriv->num_lines++; | |
179 } | |
180 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
|
181 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_WarningTooLongLineSplitting); |
8197 | 182 mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*)); |
183 mpriv->lines[mpriv->num_lines] = strdup(buf); | |
184 mpriv->num_lines++; | |
185 pos = 0; | |
186 } | |
187 } | |
188 | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
16862
diff
changeset
|
189 mp_msg(MSGT_GLOBAL,MSGL_INFO,MSGTR_LIBMENU_ParsedLines,mpriv->num_lines); |
8197 | 190 |
191 return 1; | |
192 } | |
193 | |
194 const menu_info_t menu_info_txt = { | |
195 "Text file viewer", | |
196 "txt", | |
197 "Albeu", | |
198 "", | |
199 { | |
200 "txt_cfg", | |
201 sizeof(struct menu_priv_s), | |
202 &cfg_dflt, | |
203 cfg_fields | |
204 }, | |
23366
b344b6520518
rename some menu open functions, to avoid confusion with libc native open()
ben
parents:
19431
diff
changeset
|
205 open_txt, |
8197 | 206 }; |