Mercurial > mplayer.hg
annotate libmenu/menu.c @ 9716:72f795ef6bf3
-audiofile-cache documented, bytes --> Bytes, typo.
author | diego |
---|---|
date | Sat, 29 Mar 2003 00:44:45 +0000 |
parents | edfe34c5405d |
children | 6180d7558f75 |
rev | line source |
---|---|
8197 | 1 |
2 #include "../config.h" | |
3 | |
4 #include <stdlib.h> | |
5 #include <stdio.h> | |
6 #include <string.h> | |
8604
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
7 #include <fcntl.h> |
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
8 #include <unistd.h> |
8197 | 9 |
10 #include "../libvo/osd.h" | |
11 #include "../libvo/font_load.h" | |
9380 | 12 #include "../osdep/keycodes.h" |
8197 | 13 #include "../asxparser.h" |
14 #include "../libmpdemux/stream.h" | |
15 | |
16 #include "img_format.h" | |
17 #include "mp_image.h" | |
18 #include "../m_option.h" | |
19 #include "../m_struct.h" | |
20 #include "menu.h" | |
21 | |
22 extern menu_info_t menu_info_cmdlist; | |
23 extern menu_info_t menu_info_pt; | |
24 extern menu_info_t menu_info_filesel; | |
25 extern menu_info_t menu_info_txt; | |
26 extern menu_info_t menu_info_console; | |
27 extern menu_info_t menu_info_pref; | |
28 | |
29 menu_info_t* menu_info_list[] = { | |
30 &menu_info_pt, | |
31 &menu_info_cmdlist, | |
32 &menu_info_filesel, | |
33 &menu_info_txt, | |
34 &menu_info_console, | |
35 &menu_info_pref, | |
36 NULL | |
37 }; | |
38 | |
39 typedef struct menu_def_st { | |
40 char* name; | |
41 menu_info_t* type; | |
42 void* cfg; | |
43 char* args; | |
44 } menu_def_t; | |
45 | |
46 static menu_def_t* menu_list = NULL; | |
47 static int mcount = 0; | |
48 | |
49 | |
50 static int menu_parse_config(char* buffer) { | |
51 char *element,*body, **attribs, *name; | |
52 menu_info_t* minfo = NULL; | |
53 int r,i; | |
54 ASX_Parser_t* parser = asx_parser_new(); | |
55 | |
56 while(1) { | |
57 r = asx_get_element(parser,&buffer,&element,&body,&attribs); | |
58 if(r < 0) { | |
59 printf("Syntax error at line %d\n",parser->line); | |
60 asx_parser_free(parser); | |
61 return 0; | |
62 } else if(r == 0) { | |
63 asx_parser_free(parser); | |
64 return 1; | |
65 } | |
66 // Has it a name ? | |
67 name = asx_get_attrib("name",attribs); | |
68 if(!name) { | |
69 printf("Menu definitions need a name attrib (line %d)\n",parser->line); | |
70 free(element); | |
71 if(body) free(body); | |
72 asx_free_attribs(attribs); | |
73 continue; | |
74 } | |
75 | |
76 // Try to find this menu type in our list | |
77 for(i = 0, minfo = NULL ; menu_info_list[i] ; i++) { | |
78 if(strcasecmp(element,menu_info_list[i]->name) == 0) { | |
79 minfo = menu_info_list[i]; | |
80 break; | |
81 } | |
82 } | |
83 // Got it : add this to our list | |
84 if(minfo) { | |
85 menu_list = realloc(menu_list,(mcount+2)*sizeof(menu_def_t)); | |
86 menu_list[mcount].name = name; | |
87 menu_list[mcount].type = minfo; | |
88 menu_list[mcount].cfg = m_struct_alloc(&minfo->priv_st); | |
89 menu_list[mcount].args = body; | |
90 // Setup the attribs | |
91 for(i = 0 ; attribs[2*i] ; i++) { | |
92 if(strcasecmp(attribs[2*i],"name") == 0) continue; | |
93 if(!m_struct_set(&minfo->priv_st,menu_list[mcount].cfg,attribs[2*i], attribs[2*i+1])) | |
94 printf("Bad attrib %s=%s in menu %s at line %d\n",attribs[2*i],attribs[2*i+1], | |
95 name,parser->line); | |
96 } | |
97 mcount++; | |
98 memset(&menu_list[mcount],0,sizeof(menu_def_t)); | |
99 } else { | |
100 printf("Unknow menu type %s at line %d\n",element,parser->line); | |
101 free(name); | |
102 if(body) free(body); | |
103 } | |
104 | |
105 free(element); | |
106 asx_free_attribs(attribs); | |
107 } | |
108 | |
109 } | |
110 | |
111 | |
112 /// This will build the menu_defs list from the cfg file | |
113 #define BUF_STEP 1024 | |
114 #define BUF_MIN 128 | |
115 #define BUF_MAX BUF_STEP*1024 | |
116 int menu_init(char* cfg_file) { | |
117 char* buffer = NULL; | |
118 int bl = BUF_STEP, br = 0; | |
9103
6c2c74adaebe
mplayer crashes if one tries to use osd menu without having a font
arpi
parents:
8604
diff
changeset
|
119 int f, fd; |
9212
24b102dbd0fe
Fixes a problem where the menu won't work, if you just use freetype fonts
arpi
parents:
9103
diff
changeset
|
120 #ifndef HAVE_FREETYPE |
9103
6c2c74adaebe
mplayer crashes if one tries to use osd menu without having a font
arpi
parents:
8604
diff
changeset
|
121 if(vo_font == NULL) |
6c2c74adaebe
mplayer crashes if one tries to use osd menu without having a font
arpi
parents:
8604
diff
changeset
|
122 return 0; |
9212
24b102dbd0fe
Fixes a problem where the menu won't work, if you just use freetype fonts
arpi
parents:
9103
diff
changeset
|
123 #endif |
9103
6c2c74adaebe
mplayer crashes if one tries to use osd menu without having a font
arpi
parents:
8604
diff
changeset
|
124 fd = open(cfg_file, O_RDONLY); |
8604
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
125 if(fd < 0) { |
8197 | 126 printf("Can't open menu config file: %s\n",cfg_file); |
127 return 0; | |
128 } | |
129 buffer = malloc(bl); | |
130 while(1) { | |
131 int r; | |
132 if(bl - br < BUF_MIN) { | |
133 if(bl >= BUF_MAX) { | |
134 printf("Menu config file is too big (> %d KB)\n",BUF_MAX/1024); | |
8604
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
135 close(fd); |
8197 | 136 free(buffer); |
137 return 0; | |
138 } | |
139 bl += BUF_STEP; | |
140 buffer = realloc(buffer,bl); | |
141 } | |
8604
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
142 r = read(fd,buffer+br,bl-br); |
8197 | 143 if(r == 0) break; |
144 br += r; | |
145 } | |
146 if(!br) { | |
147 printf("Menu config file is empty\n"); | |
148 return 0; | |
149 } | |
150 buffer[br-1] = '\0'; | |
151 | |
8604
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
152 close(fd); |
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
153 |
8197 | 154 f = menu_parse_config(buffer); |
155 free(buffer); | |
156 return f; | |
157 } | |
158 | |
159 // Destroy all this stuff | |
160 void menu_unint(void) { | |
161 int i; | |
162 for(i = 0 ; menu_list && menu_list[i].name ; i++) { | |
163 free(menu_list[i].name); | |
164 m_struct_free(&menu_list[i].type->priv_st,menu_list[i].cfg); | |
165 if(menu_list[i].args) free(menu_list[i].args); | |
166 } | |
167 free(menu_list); | |
168 mcount = 0; | |
169 } | |
170 | |
171 /// Default read_key function | |
172 void menu_dflt_read_key(menu_t* menu,int cmd) { | |
173 switch(cmd) { | |
174 case KEY_UP: | |
175 menu->read_cmd(menu,MENU_CMD_UP); | |
176 break; | |
177 case KEY_DOWN: | |
178 menu->read_cmd(menu,MENU_CMD_DOWN); | |
179 break; | |
180 case KEY_LEFT: | |
181 case KEY_ESC: | |
182 menu->read_cmd(menu,MENU_CMD_CANCEL); | |
183 break; | |
184 case KEY_RIGHT: | |
185 case KEY_ENTER: | |
186 menu->read_cmd(menu,MENU_CMD_OK); | |
187 break; | |
188 } | |
189 } | |
190 | |
191 menu_t* menu_open(char *name) { | |
192 menu_t* m; | |
193 int i; | |
194 | |
195 for(i = 0 ; menu_list[i].name != NULL ; i++) { | |
196 if(strcmp(name,menu_list[i].name) == 0) | |
197 break; | |
198 } | |
199 if(menu_list[i].name == NULL) { | |
200 printf("Menu %s not found\n",name); | |
201 return NULL; | |
202 } | |
203 m = calloc(1,sizeof(menu_t)); | |
204 m->priv_st = &(menu_list[i].type->priv_st); | |
205 m->priv = m_struct_copy(m->priv_st,menu_list[i].cfg); | |
206 if(menu_list[i].type->open(m,menu_list[i].args)) | |
207 return m; | |
208 if(m->priv) | |
209 m_struct_free(m->priv_st,m->priv); | |
210 free(m); | |
211 printf("Menu %s: init failed\n",name); | |
212 return NULL; | |
213 } | |
214 | |
215 void menu_draw(menu_t* menu,mp_image_t* mpi) { | |
216 if(menu->show && menu->draw) | |
217 menu->draw(menu,mpi); | |
218 } | |
219 | |
220 void menu_read_cmd(menu_t* menu,int cmd) { | |
221 if(menu->read_cmd) | |
222 menu->read_cmd(menu,cmd); | |
223 } | |
224 | |
225 void menu_close(menu_t* menu) { | |
226 if(menu->close) | |
227 menu->close(menu); | |
228 if(menu->priv) | |
229 m_struct_free(menu->priv_st,menu->priv); | |
230 free(menu); | |
231 } | |
232 | |
233 void menu_read_key(menu_t* menu,int cmd) { | |
234 if(menu->read_key) | |
235 menu->read_key(menu,cmd); | |
236 else | |
237 menu_dflt_read_key(menu,cmd); | |
238 } | |
239 | |
240 ///////////////////////////// Helpers //////////////////////////////////// | |
241 | |
242 typedef void (*draw_alpha_f)(int w,int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dstbase,int dststride); | |
243 | |
244 inline static draw_alpha_f get_draw_alpha(uint32_t fmt) { | |
245 switch(fmt) { | |
246 case IMGFMT_BGR15: | |
247 case IMGFMT_RGB15: | |
248 return vo_draw_alpha_rgb15; | |
249 case IMGFMT_BGR16: | |
250 case IMGFMT_RGB16: | |
251 return vo_draw_alpha_rgb16; | |
252 case IMGFMT_BGR24: | |
253 case IMGFMT_RGB24: | |
254 return vo_draw_alpha_rgb24; | |
255 case IMGFMT_BGR32: | |
256 case IMGFMT_RGB32: | |
257 return vo_draw_alpha_rgb32; | |
258 case IMGFMT_YV12: | |
259 case IMGFMT_I420: | |
260 case IMGFMT_IYUV: | |
261 case IMGFMT_YVU9: | |
262 case IMGFMT_IF09: | |
263 case IMGFMT_Y800: | |
264 case IMGFMT_Y8: | |
265 return vo_draw_alpha_yv12; | |
266 case IMGFMT_YUY2: | |
267 return vo_draw_alpha_yuy2; | |
268 } | |
269 | |
270 return NULL; | |
271 } | |
272 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
273 // return the real height of a char: |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
274 static inline int get_height(int c,int h){ |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
275 int font; |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
276 if ((font=vo_font->font[c])>=0) |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
277 if(h<vo_font->pic_a[font]->h) h=vo_font->pic_a[font]->h; |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
278 return h; |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
279 } |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
280 |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
281 #ifdef HAVE_FREETYPE |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
282 #define render_txt(t) { char* p = t; while(*p) render_one_glyph(vo_font,*p++); } |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
283 #else |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
284 #define render_txt(t) |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
285 #endif |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
286 |
8197 | 287 |
288 void menu_draw_text(mp_image_t* mpi,char* txt, int x, int y) { | |
289 draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt); | |
290 int font; | |
291 | |
292 if(!draw_alpha) { | |
293 printf("Unsupported outformat !!!!\n"); | |
294 return; | |
295 } | |
296 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
297 render_txt(txt); |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
298 |
8197 | 299 while (*txt) { |
300 unsigned char c=*txt++; | |
301 if ((font=vo_font->font[c])>=0 && (x + vo_font->width[c] <= mpi->w) && (y + vo_font->pic_a[font]->h <= mpi->h)) | |
302 draw_alpha(vo_font->width[c], vo_font->pic_a[font]->h, | |
303 vo_font->pic_b[font]->bmp+vo_font->start[c], | |
304 vo_font->pic_a[font]->bmp+vo_font->start[c], | |
305 vo_font->pic_a[font]->w, | |
306 mpi->planes[0] + y * mpi->stride[0] + x * (mpi->bpp>>3), | |
307 mpi->stride[0]); | |
308 x+=vo_font->width[c]+vo_font->charspace; | |
309 } | |
310 | |
311 } | |
312 | |
313 void menu_draw_text_full(mp_image_t* mpi,char* txt, | |
314 int x, int y,int w, int h, | |
315 int vspace, int warp, int align, int anchor) { | |
316 int need_w,need_h; | |
317 int sy, ymin, ymax; | |
318 int sx, xmin, xmax, xmid, xrmin; | |
319 int ll = 0; | |
320 int font; | |
321 draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt); | |
322 | |
323 if(!draw_alpha) { | |
324 printf("Unsupported outformat !!!!\n"); | |
325 return; | |
326 } | |
327 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
328 render_txt(txt); |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
329 |
8197 | 330 if(x > mpi->w || y > mpi->h) |
331 return; | |
332 | |
333 if(anchor & MENU_TEXT_VCENTER) { | |
334 if(h <= 0) h = mpi->h; | |
335 ymin = y - h/2; | |
336 ymax = y + h/2; | |
337 } else if(anchor & MENU_TEXT_BOT) { | |
338 if(h <= 0) h = mpi->h - y; | |
339 ymin = y - h; | |
340 ymax = y; | |
341 } else { | |
342 if(h <= 0) h = mpi->h - y; | |
343 ymin = y; | |
344 ymax = y + h; | |
345 } | |
346 | |
347 if(anchor & MENU_TEXT_HCENTER) { | |
348 if(w <= 0) w = mpi->w; | |
349 xmin = x - w/2; | |
350 xmax = x + w/2; | |
351 } else if(anchor & MENU_TEXT_RIGHT) { | |
352 if(w <= 0) w = mpi->w -x; | |
353 xmin = x - w; | |
354 xmax = x; | |
355 } else { | |
356 if(w <= 0) w = mpi->w -x; | |
357 xmin = x; | |
358 xmax = x + w; | |
359 } | |
360 | |
361 // How many space do we need to draw this ? | |
362 menu_text_size(txt,w,vspace,warp,&need_w,&need_h); | |
363 | |
364 // Find the first line | |
365 if(align & MENU_TEXT_VCENTER) | |
366 sy = ymin + ((h - need_h)/2); | |
367 else if(align & MENU_TEXT_BOT) | |
8232 | 368 sy = ymax - need_h - 1; |
8197 | 369 else |
370 sy = y; | |
371 | |
372 #if 0 | |
373 // Find the first col | |
374 if(align & MENU_TEXT_HCENTER) | |
375 sx = xmin + ((w - need_w)/2); | |
376 else if(align & MENU_TEXT_RIGHT) | |
377 sx = xmax - need_w; | |
378 #endif | |
379 | |
380 xmid = xmin + (xmax - xmin) / 2; | |
381 xrmin = xmin; | |
382 // Clamp the bb to the mpi size | |
383 if(ymin < 0) ymin = 0; | |
384 if(xmin < 0) xmin = 0; | |
385 if(ymax > mpi->h) ymax = mpi->h; | |
386 if(xmax > mpi->w) xmax = mpi->w; | |
387 | |
388 // Jump some the beginnig text if needed | |
389 while(sy < ymin && *txt) { | |
390 unsigned char c=*txt++; | |
391 if(c == '\n' || (warp && ll + vo_font->width[c] > w)) { | |
392 ll = 0; | |
393 sy += vo_font->height + vspace; | |
394 if(c == '\n') continue; | |
395 } | |
396 ll += vo_font->width[c]+vo_font->charspace; | |
397 } | |
398 if(*txt == '\0') // Nothing left to draw | |
399 return; | |
400 | |
401 while(sy < ymax && *txt) { | |
402 char* line_end = NULL; | |
403 int n; | |
404 | |
405 if(txt[0] == '\n') { // New line | |
406 sy += vo_font->height + vspace; | |
407 txt++; | |
408 continue; | |
409 } | |
410 | |
411 // Get the length and end of this line | |
412 for(n = 0, ll = 0 ; txt[n] != '\0' && txt[n] != '\n' ; n++) { | |
413 unsigned char c = txt[n]; | |
414 if(warp && ll + vo_font->width[c] > w) break; | |
415 ll += vo_font->width[c]+vo_font->charspace; | |
416 } | |
417 line_end = &txt[n]; | |
418 ll -= vo_font->charspace; | |
419 | |
420 | |
421 if(align & (MENU_TEXT_HCENTER|MENU_TEXT_RIGHT)) { | |
422 // Too long line | |
423 if(ll > xmax-xmin) { | |
424 if(align & MENU_TEXT_HCENTER) { | |
425 int mid = ll/2; | |
426 // Find the middle point | |
427 for(n--, ll = 0 ; n <= 0 ; n--) { | |
428 ll += vo_font->width[(int)txt[n]]+vo_font->charspace; | |
429 if(ll - vo_font->charspace > mid) break; | |
430 } | |
431 ll -= vo_font->charspace; | |
432 sx = xmid + mid - ll; | |
433 } else// MENU_TEXT_RIGHT) | |
434 sx = xmax + vo_font->charspace; | |
435 | |
436 // We are after the start point -> go back | |
437 if(sx > xmin) { | |
438 for(n-- ; n <= 0 ; n--) { | |
439 unsigned char c = txt[n]; | |
440 if(sx - vo_font->width[c] - vo_font->charspace < xmin) break; | |
441 sx -= vo_font->width[c]+vo_font->charspace; | |
442 } | |
443 } else { // We are before the start point -> go forward | |
444 for( ; sx < xmin && (&txt[n]) != line_end ; n++) { | |
445 unsigned char c = txt[n]; | |
446 sx += vo_font->width[c]+vo_font->charspace; | |
447 } | |
448 } | |
449 txt = &txt[n]; // Jump to the new start char | |
450 } else { | |
451 if(align & MENU_TEXT_HCENTER) | |
452 sx = xmid - ll/2; | |
453 else | |
8232 | 454 sx = xmax - 1 - ll; |
8197 | 455 } |
456 } else { | |
457 for(sx = xrmin ; sx < xmin && txt != line_end ; txt++) { | |
458 unsigned char c = txt[n]; | |
459 sx += vo_font->width[c]+vo_font->charspace; | |
460 } | |
461 } | |
462 | |
463 while(sx < xmax && txt != line_end) { | |
464 unsigned char c = *txt++; | |
465 font = vo_font->font[c]; | |
8232 | 466 if(font >= 0) { |
467 int cs = (vo_font->pic_a[font]->h - vo_font->height) / 2; | |
468 if ((sx + vo_font->width[c] < xmax) && (sy + vo_font->height < ymax) ) | |
469 draw_alpha(vo_font->width[c], vo_font->height, | |
470 vo_font->pic_b[font]->bmp+vo_font->start[c] + | |
471 cs * vo_font->pic_a[font]->w, | |
472 vo_font->pic_a[font]->bmp+vo_font->start[c] + | |
473 cs * vo_font->pic_a[font]->w, | |
474 vo_font->pic_a[font]->w, | |
475 mpi->planes[0] + sy * mpi->stride[0] + sx * (mpi->bpp>>3), | |
476 mpi->stride[0]); | |
477 // else | |
478 //printf("Can't draw '%c'\n",c); | |
479 } | |
8197 | 480 sx+=vo_font->width[c]+vo_font->charspace; |
481 } | |
482 txt = line_end; | |
483 if(txt[0] == '\0') break; | |
484 sy += vo_font->height + vspace; | |
485 } | |
486 } | |
487 | |
488 int menu_text_length(char* txt) { | |
489 int l = 0; | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
490 render_txt(txt); |
8197 | 491 while (*txt) { |
492 unsigned char c=*txt++; | |
493 l += vo_font->width[c]+vo_font->charspace; | |
494 } | |
495 return l - vo_font->charspace; | |
496 } | |
497 | |
498 void menu_text_size(char* txt,int max_width, int vspace, int warp, int* _w, int* _h) { | |
499 int l = 1, i = 0; | |
500 int w = 0; | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
501 |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
502 render_txt(txt); |
8197 | 503 while (*txt) { |
504 unsigned char c=*txt++; | |
505 if(c == '\n' || (warp && i + vo_font->width[c] >= max_width)) { | |
506 if(*txt) | |
507 l++; | |
508 i = 0; | |
509 if(c == '\n') continue; | |
510 } | |
511 i += vo_font->width[c]+vo_font->charspace; | |
512 if(i > w) w = i; | |
513 } | |
514 | |
515 *_w = w; | |
516 *_h = (l-1) * (vo_font->height + vspace) + vo_font->height; | |
517 } | |
518 | |
519 | |
520 int menu_text_num_lines(char* txt, int max_width) { | |
521 int l = 1, i = 0; | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
522 render_txt(txt); |
8197 | 523 while (*txt) { |
524 unsigned char c=*txt++; | |
525 if(c == '\n' || i + vo_font->width[c] > max_width) { | |
526 l++; | |
527 i = 0; | |
528 if(c == '\n') continue; | |
529 } | |
530 i += vo_font->width[c]+vo_font->charspace; | |
531 } | |
532 return l; | |
533 } | |
534 | |
535 char* menu_text_get_next_line(char* txt, int max_width) { | |
536 int i = 0; | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
537 render_txt(txt); |
8197 | 538 while (*txt) { |
539 unsigned char c=*txt; | |
540 if(c == '\n') { | |
541 txt++; | |
542 break; | |
543 } | |
544 i += vo_font->width[c]; | |
545 if(i >= max_width) | |
546 break; | |
547 i += vo_font->charspace; | |
548 } | |
549 return txt; | |
550 } |