Mercurial > mplayer.hg
annotate libmenu/menu.c @ 9174:0333afac3a56
closing some tags in Zr section
author | gabucino |
---|---|
date | Thu, 30 Jan 2003 19:32:19 +0000 |
parents | 6c2c74adaebe |
children | 24b102dbd0fe |
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" | |
12 #include "../linux/keycodes.h" | |
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; |
6c2c74adaebe
mplayer crashes if one tries to use osd menu without having a font
arpi
parents:
8604
diff
changeset
|
120 if(vo_font == NULL) |
6c2c74adaebe
mplayer crashes if one tries to use osd menu without having a font
arpi
parents:
8604
diff
changeset
|
121 return 0; |
6c2c74adaebe
mplayer crashes if one tries to use osd menu without having a font
arpi
parents:
8604
diff
changeset
|
122 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
|
123 if(fd < 0) { |
8197 | 124 printf("Can't open menu config file: %s\n",cfg_file); |
125 return 0; | |
126 } | |
127 buffer = malloc(bl); | |
128 while(1) { | |
129 int r; | |
130 if(bl - br < BUF_MIN) { | |
131 if(bl >= BUF_MAX) { | |
132 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
|
133 close(fd); |
8197 | 134 free(buffer); |
135 return 0; | |
136 } | |
137 bl += BUF_STEP; | |
138 buffer = realloc(buffer,bl); | |
139 } | |
8604
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
140 r = read(fd,buffer+br,bl-br); |
8197 | 141 if(r == 0) break; |
142 br += r; | |
143 } | |
144 if(!br) { | |
145 printf("Menu config file is empty\n"); | |
146 return 0; | |
147 } | |
148 buffer[br-1] = '\0'; | |
149 | |
8604
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
150 close(fd); |
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
151 |
8197 | 152 f = menu_parse_config(buffer); |
153 free(buffer); | |
154 return f; | |
155 } | |
156 | |
157 // Destroy all this stuff | |
158 void menu_unint(void) { | |
159 int i; | |
160 for(i = 0 ; menu_list && menu_list[i].name ; i++) { | |
161 free(menu_list[i].name); | |
162 m_struct_free(&menu_list[i].type->priv_st,menu_list[i].cfg); | |
163 if(menu_list[i].args) free(menu_list[i].args); | |
164 } | |
165 free(menu_list); | |
166 mcount = 0; | |
167 } | |
168 | |
169 /// Default read_key function | |
170 void menu_dflt_read_key(menu_t* menu,int cmd) { | |
171 switch(cmd) { | |
172 case KEY_UP: | |
173 menu->read_cmd(menu,MENU_CMD_UP); | |
174 break; | |
175 case KEY_DOWN: | |
176 menu->read_cmd(menu,MENU_CMD_DOWN); | |
177 break; | |
178 case KEY_LEFT: | |
179 case KEY_ESC: | |
180 menu->read_cmd(menu,MENU_CMD_CANCEL); | |
181 break; | |
182 case KEY_RIGHT: | |
183 case KEY_ENTER: | |
184 menu->read_cmd(menu,MENU_CMD_OK); | |
185 break; | |
186 } | |
187 } | |
188 | |
189 menu_t* menu_open(char *name) { | |
190 menu_t* m; | |
191 int i; | |
192 | |
193 for(i = 0 ; menu_list[i].name != NULL ; i++) { | |
194 if(strcmp(name,menu_list[i].name) == 0) | |
195 break; | |
196 } | |
197 if(menu_list[i].name == NULL) { | |
198 printf("Menu %s not found\n",name); | |
199 return NULL; | |
200 } | |
201 m = calloc(1,sizeof(menu_t)); | |
202 m->priv_st = &(menu_list[i].type->priv_st); | |
203 m->priv = m_struct_copy(m->priv_st,menu_list[i].cfg); | |
204 if(menu_list[i].type->open(m,menu_list[i].args)) | |
205 return m; | |
206 if(m->priv) | |
207 m_struct_free(m->priv_st,m->priv); | |
208 free(m); | |
209 printf("Menu %s: init failed\n",name); | |
210 return NULL; | |
211 } | |
212 | |
213 void menu_draw(menu_t* menu,mp_image_t* mpi) { | |
214 if(menu->show && menu->draw) | |
215 menu->draw(menu,mpi); | |
216 } | |
217 | |
218 void menu_read_cmd(menu_t* menu,int cmd) { | |
219 if(menu->read_cmd) | |
220 menu->read_cmd(menu,cmd); | |
221 } | |
222 | |
223 void menu_close(menu_t* menu) { | |
224 if(menu->close) | |
225 menu->close(menu); | |
226 if(menu->priv) | |
227 m_struct_free(menu->priv_st,menu->priv); | |
228 free(menu); | |
229 } | |
230 | |
231 void menu_read_key(menu_t* menu,int cmd) { | |
232 if(menu->read_key) | |
233 menu->read_key(menu,cmd); | |
234 else | |
235 menu_dflt_read_key(menu,cmd); | |
236 } | |
237 | |
238 ///////////////////////////// Helpers //////////////////////////////////// | |
239 | |
240 typedef void (*draw_alpha_f)(int w,int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dstbase,int dststride); | |
241 | |
242 inline static draw_alpha_f get_draw_alpha(uint32_t fmt) { | |
243 switch(fmt) { | |
244 case IMGFMT_BGR15: | |
245 case IMGFMT_RGB15: | |
246 return vo_draw_alpha_rgb15; | |
247 case IMGFMT_BGR16: | |
248 case IMGFMT_RGB16: | |
249 return vo_draw_alpha_rgb16; | |
250 case IMGFMT_BGR24: | |
251 case IMGFMT_RGB24: | |
252 return vo_draw_alpha_rgb24; | |
253 case IMGFMT_BGR32: | |
254 case IMGFMT_RGB32: | |
255 return vo_draw_alpha_rgb32; | |
256 case IMGFMT_YV12: | |
257 case IMGFMT_I420: | |
258 case IMGFMT_IYUV: | |
259 case IMGFMT_YVU9: | |
260 case IMGFMT_IF09: | |
261 case IMGFMT_Y800: | |
262 case IMGFMT_Y8: | |
263 return vo_draw_alpha_yv12; | |
264 case IMGFMT_YUY2: | |
265 return vo_draw_alpha_yuy2; | |
266 } | |
267 | |
268 return NULL; | |
269 } | |
270 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
271 // return the real height of a char: |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
272 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
|
273 int font; |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
274 if ((font=vo_font->font[c])>=0) |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
275 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
|
276 return h; |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
277 } |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
278 |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
279 #ifdef HAVE_FREETYPE |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
280 #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
|
281 #else |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
282 #define render_txt(t) |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
283 #endif |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
284 |
8197 | 285 |
286 void menu_draw_text(mp_image_t* mpi,char* txt, int x, int y) { | |
287 draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt); | |
288 int font; | |
289 | |
290 if(!draw_alpha) { | |
291 printf("Unsupported outformat !!!!\n"); | |
292 return; | |
293 } | |
294 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
295 render_txt(txt); |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
296 |
8197 | 297 while (*txt) { |
298 unsigned char c=*txt++; | |
299 if ((font=vo_font->font[c])>=0 && (x + vo_font->width[c] <= mpi->w) && (y + vo_font->pic_a[font]->h <= mpi->h)) | |
300 draw_alpha(vo_font->width[c], vo_font->pic_a[font]->h, | |
301 vo_font->pic_b[font]->bmp+vo_font->start[c], | |
302 vo_font->pic_a[font]->bmp+vo_font->start[c], | |
303 vo_font->pic_a[font]->w, | |
304 mpi->planes[0] + y * mpi->stride[0] + x * (mpi->bpp>>3), | |
305 mpi->stride[0]); | |
306 x+=vo_font->width[c]+vo_font->charspace; | |
307 } | |
308 | |
309 } | |
310 | |
311 void menu_draw_text_full(mp_image_t* mpi,char* txt, | |
312 int x, int y,int w, int h, | |
313 int vspace, int warp, int align, int anchor) { | |
314 int need_w,need_h; | |
315 int sy, ymin, ymax; | |
316 int sx, xmin, xmax, xmid, xrmin; | |
317 int ll = 0; | |
318 int font; | |
319 draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt); | |
320 | |
321 if(!draw_alpha) { | |
322 printf("Unsupported outformat !!!!\n"); | |
323 return; | |
324 } | |
325 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
326 render_txt(txt); |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
327 |
8197 | 328 if(x > mpi->w || y > mpi->h) |
329 return; | |
330 | |
331 if(anchor & MENU_TEXT_VCENTER) { | |
332 if(h <= 0) h = mpi->h; | |
333 ymin = y - h/2; | |
334 ymax = y + h/2; | |
335 } else if(anchor & MENU_TEXT_BOT) { | |
336 if(h <= 0) h = mpi->h - y; | |
337 ymin = y - h; | |
338 ymax = y; | |
339 } else { | |
340 if(h <= 0) h = mpi->h - y; | |
341 ymin = y; | |
342 ymax = y + h; | |
343 } | |
344 | |
345 if(anchor & MENU_TEXT_HCENTER) { | |
346 if(w <= 0) w = mpi->w; | |
347 xmin = x - w/2; | |
348 xmax = x + w/2; | |
349 } else if(anchor & MENU_TEXT_RIGHT) { | |
350 if(w <= 0) w = mpi->w -x; | |
351 xmin = x - w; | |
352 xmax = x; | |
353 } else { | |
354 if(w <= 0) w = mpi->w -x; | |
355 xmin = x; | |
356 xmax = x + w; | |
357 } | |
358 | |
359 // How many space do we need to draw this ? | |
360 menu_text_size(txt,w,vspace,warp,&need_w,&need_h); | |
361 | |
362 // Find the first line | |
363 if(align & MENU_TEXT_VCENTER) | |
364 sy = ymin + ((h - need_h)/2); | |
365 else if(align & MENU_TEXT_BOT) | |
8232 | 366 sy = ymax - need_h - 1; |
8197 | 367 else |
368 sy = y; | |
369 | |
370 #if 0 | |
371 // Find the first col | |
372 if(align & MENU_TEXT_HCENTER) | |
373 sx = xmin + ((w - need_w)/2); | |
374 else if(align & MENU_TEXT_RIGHT) | |
375 sx = xmax - need_w; | |
376 #endif | |
377 | |
378 xmid = xmin + (xmax - xmin) / 2; | |
379 xrmin = xmin; | |
380 // Clamp the bb to the mpi size | |
381 if(ymin < 0) ymin = 0; | |
382 if(xmin < 0) xmin = 0; | |
383 if(ymax > mpi->h) ymax = mpi->h; | |
384 if(xmax > mpi->w) xmax = mpi->w; | |
385 | |
386 // Jump some the beginnig text if needed | |
387 while(sy < ymin && *txt) { | |
388 unsigned char c=*txt++; | |
389 if(c == '\n' || (warp && ll + vo_font->width[c] > w)) { | |
390 ll = 0; | |
391 sy += vo_font->height + vspace; | |
392 if(c == '\n') continue; | |
393 } | |
394 ll += vo_font->width[c]+vo_font->charspace; | |
395 } | |
396 if(*txt == '\0') // Nothing left to draw | |
397 return; | |
398 | |
399 while(sy < ymax && *txt) { | |
400 char* line_end = NULL; | |
401 int n; | |
402 | |
403 if(txt[0] == '\n') { // New line | |
404 sy += vo_font->height + vspace; | |
405 txt++; | |
406 continue; | |
407 } | |
408 | |
409 // Get the length and end of this line | |
410 for(n = 0, ll = 0 ; txt[n] != '\0' && txt[n] != '\n' ; n++) { | |
411 unsigned char c = txt[n]; | |
412 if(warp && ll + vo_font->width[c] > w) break; | |
413 ll += vo_font->width[c]+vo_font->charspace; | |
414 } | |
415 line_end = &txt[n]; | |
416 ll -= vo_font->charspace; | |
417 | |
418 | |
419 if(align & (MENU_TEXT_HCENTER|MENU_TEXT_RIGHT)) { | |
420 // Too long line | |
421 if(ll > xmax-xmin) { | |
422 if(align & MENU_TEXT_HCENTER) { | |
423 int mid = ll/2; | |
424 // Find the middle point | |
425 for(n--, ll = 0 ; n <= 0 ; n--) { | |
426 ll += vo_font->width[(int)txt[n]]+vo_font->charspace; | |
427 if(ll - vo_font->charspace > mid) break; | |
428 } | |
429 ll -= vo_font->charspace; | |
430 sx = xmid + mid - ll; | |
431 } else// MENU_TEXT_RIGHT) | |
432 sx = xmax + vo_font->charspace; | |
433 | |
434 // We are after the start point -> go back | |
435 if(sx > xmin) { | |
436 for(n-- ; n <= 0 ; n--) { | |
437 unsigned char c = txt[n]; | |
438 if(sx - vo_font->width[c] - vo_font->charspace < xmin) break; | |
439 sx -= vo_font->width[c]+vo_font->charspace; | |
440 } | |
441 } else { // We are before the start point -> go forward | |
442 for( ; sx < xmin && (&txt[n]) != line_end ; n++) { | |
443 unsigned char c = txt[n]; | |
444 sx += vo_font->width[c]+vo_font->charspace; | |
445 } | |
446 } | |
447 txt = &txt[n]; // Jump to the new start char | |
448 } else { | |
449 if(align & MENU_TEXT_HCENTER) | |
450 sx = xmid - ll/2; | |
451 else | |
8232 | 452 sx = xmax - 1 - ll; |
8197 | 453 } |
454 } else { | |
455 for(sx = xrmin ; sx < xmin && txt != line_end ; txt++) { | |
456 unsigned char c = txt[n]; | |
457 sx += vo_font->width[c]+vo_font->charspace; | |
458 } | |
459 } | |
460 | |
461 while(sx < xmax && txt != line_end) { | |
462 unsigned char c = *txt++; | |
463 font = vo_font->font[c]; | |
8232 | 464 if(font >= 0) { |
465 int cs = (vo_font->pic_a[font]->h - vo_font->height) / 2; | |
466 if ((sx + vo_font->width[c] < xmax) && (sy + vo_font->height < ymax) ) | |
467 draw_alpha(vo_font->width[c], vo_font->height, | |
468 vo_font->pic_b[font]->bmp+vo_font->start[c] + | |
469 cs * vo_font->pic_a[font]->w, | |
470 vo_font->pic_a[font]->bmp+vo_font->start[c] + | |
471 cs * vo_font->pic_a[font]->w, | |
472 vo_font->pic_a[font]->w, | |
473 mpi->planes[0] + sy * mpi->stride[0] + sx * (mpi->bpp>>3), | |
474 mpi->stride[0]); | |
475 // else | |
476 //printf("Can't draw '%c'\n",c); | |
477 } | |
8197 | 478 sx+=vo_font->width[c]+vo_font->charspace; |
479 } | |
480 txt = line_end; | |
481 if(txt[0] == '\0') break; | |
482 sy += vo_font->height + vspace; | |
483 } | |
484 } | |
485 | |
486 int menu_text_length(char* txt) { | |
487 int l = 0; | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
488 render_txt(txt); |
8197 | 489 while (*txt) { |
490 unsigned char c=*txt++; | |
491 l += vo_font->width[c]+vo_font->charspace; | |
492 } | |
493 return l - vo_font->charspace; | |
494 } | |
495 | |
496 void menu_text_size(char* txt,int max_width, int vspace, int warp, int* _w, int* _h) { | |
497 int l = 1, i = 0; | |
498 int w = 0; | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
499 |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
500 render_txt(txt); |
8197 | 501 while (*txt) { |
502 unsigned char c=*txt++; | |
503 if(c == '\n' || (warp && i + vo_font->width[c] >= max_width)) { | |
504 if(*txt) | |
505 l++; | |
506 i = 0; | |
507 if(c == '\n') continue; | |
508 } | |
509 i += vo_font->width[c]+vo_font->charspace; | |
510 if(i > w) w = i; | |
511 } | |
512 | |
513 *_w = w; | |
514 *_h = (l-1) * (vo_font->height + vspace) + vo_font->height; | |
515 } | |
516 | |
517 | |
518 int menu_text_num_lines(char* txt, int max_width) { | |
519 int l = 1, i = 0; | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
520 render_txt(txt); |
8197 | 521 while (*txt) { |
522 unsigned char c=*txt++; | |
523 if(c == '\n' || i + vo_font->width[c] > max_width) { | |
524 l++; | |
525 i = 0; | |
526 if(c == '\n') continue; | |
527 } | |
528 i += vo_font->width[c]+vo_font->charspace; | |
529 } | |
530 return l; | |
531 } | |
532 | |
533 char* menu_text_get_next_line(char* txt, int max_width) { | |
534 int i = 0; | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
535 render_txt(txt); |
8197 | 536 while (*txt) { |
537 unsigned char c=*txt; | |
538 if(c == '\n') { | |
539 txt++; | |
540 break; | |
541 } | |
542 i += vo_font->width[c]; | |
543 if(i >= max_width) | |
544 break; | |
545 i += vo_font->charspace; | |
546 } | |
547 return txt; | |
548 } |