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