Mercurial > mplayer.hg
annotate libmenu/menu_txt.c @ 26521:4bcaa9a8a860
Remove unnecessary compilation command that shadows GNU Make builtin command.
author | diego |
---|---|
date | Sun, 27 Apr 2008 11:00:06 +0000 |
parents | 96d0992c7920 |
children | f8b6c7045cf8 |
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; | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23367
diff
changeset
|
69 case MENU_CMD_HOME: |
8197 | 70 mpriv->cur_line = 0; |
71 break; | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23367
diff
changeset
|
72 case MENU_CMD_END: |
8197 | 73 mpriv->cur_line = mpriv->num_lines - 1; |
74 break; | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23367
diff
changeset
|
75 case MENU_CMD_PAGE_UP: |
8197 | 76 mpriv->cur_line = mpriv->cur_line > mpriv->disp_lines ? |
77 mpriv->cur_line - mpriv->disp_lines : 0; | |
78 break; | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
23367
diff
changeset
|
79 case MENU_CMD_PAGE_DOWN: |
8197 | 80 mpriv->cur_line = mpriv->cur_line + mpriv->disp_lines > mpriv->num_lines - 1 ? mpriv->num_lines - 1 : mpriv->cur_line + mpriv->disp_lines; |
81 break; | |
82 } | |
83 } | |
84 | |
85 | |
86 static void draw(menu_t* menu,mp_image_t* mpi) { | |
87 int x = mpriv->minb; | |
88 int y = mpriv->minb; | |
89 //int th = 2*mpriv->hspace + vo_font->height; | |
90 int i,end; | |
91 | |
92 if(x < 0) x = 8; | |
93 if(y < 0) y = 8; | |
94 | |
95 mpriv->disp_lines = (mpi->h + mpriv->hspace - 2*mpriv->minb) / ( vo_font->height + mpriv->hspace); | |
96 if(mpriv->num_lines - mpriv->cur_line < mpriv->disp_lines) { | |
97 i = mpriv->num_lines - 1 - mpriv->disp_lines; | |
98 if(i < 0) i = 0; | |
99 end = mpriv->num_lines - 1; | |
100 } else { | |
101 i = mpriv->cur_line; | |
102 end = i + mpriv->disp_lines; | |
103 if(end >= mpriv->num_lines) end = mpriv->num_lines - 1; | |
104 } | |
105 | |
106 for( ; i < end ; i++) { | |
107 menu_draw_text(mpi,mpriv->lines[i],x,y); | |
108 y += vo_font->height + mpriv->hspace; | |
109 } | |
110 | |
111 } | |
112 | |
113 #define BUF_SIZE 1024 | |
114 | |
23366
b344b6520518
rename some menu open functions, to avoid confusion with libc native open()
ben
parents:
19431
diff
changeset
|
115 static int open_txt(menu_t* menu, char* args) { |
8197 | 116 FILE* fd; |
117 char buf[BUF_SIZE]; | |
118 char *l; | |
119 int s; | |
120 int pos = 0, r = 0; | |
121 args = NULL; // Warning kill | |
122 | |
123 menu->draw = draw; | |
124 menu->read_cmd = read_cmd; | |
125 | |
126 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
|
127 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuTxtNeedATxtFileName); |
8197 | 128 return 0; |
129 } | |
130 | |
131 fd = fopen(mpriv->file,"r"); | |
132 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
|
133 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuTxtCantOpen,mpriv->file); |
8197 | 134 return 0; |
135 } | |
136 | |
137 while(1) { | |
138 r = fread(buf+pos,1,BUF_SIZE-pos-1,fd); | |
139 if(r <= 0) { | |
140 if(pos > 0) { | |
141 mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*)); | |
142 mpriv->lines[mpriv->num_lines] = strdup(buf); | |
143 mpriv->num_lines++; | |
144 } | |
145 fclose(fd); | |
146 break; | |
147 } | |
148 pos += r; | |
149 buf[pos] = '\0'; | |
150 | |
151 while((l = strchr(buf,'\n')) != NULL) { | |
152 s = l-buf; | |
153 mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*)); | |
154 mpriv->lines[mpriv->num_lines] = malloc(s+1); | |
155 memcpy(mpriv->lines[mpriv->num_lines],buf,s); | |
156 mpriv->lines[mpriv->num_lines][s] = '\0'; | |
157 pos -= s + 1; | |
158 if(pos > 0) | |
159 memmove(buf,l+1,pos); | |
160 buf[pos] = '\0'; | |
161 mpriv->num_lines++; | |
162 } | |
163 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
|
164 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_WarningTooLongLineSplitting); |
8197 | 165 mpriv->lines = realloc(mpriv->lines,(mpriv->num_lines + 1)*sizeof(char*)); |
166 mpriv->lines[mpriv->num_lines] = strdup(buf); | |
167 mpriv->num_lines++; | |
168 pos = 0; | |
169 } | |
170 } | |
171 | |
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_INFO,MSGTR_LIBMENU_ParsedLines,mpriv->num_lines); |
8197 | 173 |
174 return 1; | |
175 } | |
176 | |
177 const menu_info_t menu_info_txt = { | |
178 "Text file viewer", | |
179 "txt", | |
180 "Albeu", | |
181 "", | |
182 { | |
183 "txt_cfg", | |
184 sizeof(struct menu_priv_s), | |
185 &cfg_dflt, | |
186 cfg_fields | |
187 }, | |
23366
b344b6520518
rename some menu open functions, to avoid confusion with libc native open()
ben
parents:
19431
diff
changeset
|
188 open_txt, |
8197 | 189 }; |