Mercurial > mplayer.hg
annotate libmenu/menu.c @ 30526:68e260df472b
Just use goto instead of reimplementing it badly with a do { } while (0) and
break.
author | reimar |
---|---|
date | Sun, 14 Feb 2010 11:17:12 +0000 |
parents | 0f1b5b68af32 |
children | d218228dc74d |
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:
17993
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:
17993
diff
changeset
|
21 #include "help_mp.h" |
8197 | 22 |
23 #include <stdlib.h> | |
24 #include <stdio.h> | |
25 #include <string.h> | |
8604
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
26 #include <fcntl.h> |
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
27 #include <unistd.h> |
8197 | 28 |
16862 | 29 #include "libvo/osd.h" |
30 #include "libvo/font_load.h" | |
23232
c5ac43d53bb1
use already existing function to get utf8 char in libmenu (thx to reimar)
ben
parents:
23231
diff
changeset
|
31 #include "libvo/sub.h" |
16862 | 32 #include "osdep/keycodes.h" |
33 #include "asxparser.h" | |
19271
64d82a45a05d
introduce new 'stream' directory for all stream layer related components and split them from libmpdemux
ben
parents:
18194
diff
changeset
|
34 #include "stream/stream.h" |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
35 #include "input/input.h" |
8197 | 36 |
19431
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
19271
diff
changeset
|
37 #include "libmpcodecs/img_format.h" |
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
19271
diff
changeset
|
38 #include "libmpcodecs/mp_image.h" |
16862 | 39 #include "m_option.h" |
40 #include "m_struct.h" | |
8197 | 41 #include "menu.h" |
42 | |
43 extern menu_info_t menu_info_cmdlist; | |
25364 | 44 extern menu_info_t menu_info_chapsel; |
8197 | 45 extern menu_info_t menu_info_pt; |
46 extern menu_info_t menu_info_filesel; | |
47 extern menu_info_t menu_info_txt; | |
48 extern menu_info_t menu_info_console; | |
49 extern menu_info_t menu_info_pref; | |
10626
fd97f3727f15
Finnaly commit Nico's dvb menu. Sorry for committing this
albeu
parents:
10397
diff
changeset
|
50 extern menu_info_t menu_info_dvbsel; |
fd97f3727f15
Finnaly commit Nico's dvb menu. Sorry for committing this
albeu
parents:
10397
diff
changeset
|
51 |
8197 | 52 |
53 menu_info_t* menu_info_list[] = { | |
54 &menu_info_pt, | |
55 &menu_info_cmdlist, | |
25364 | 56 &menu_info_chapsel, |
8197 | 57 &menu_info_filesel, |
58 &menu_info_txt, | |
59 &menu_info_console, | |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27359
diff
changeset
|
60 #ifdef CONFIG_DVBIN |
10626
fd97f3727f15
Finnaly commit Nico's dvb menu. Sorry for committing this
albeu
parents:
10397
diff
changeset
|
61 &menu_info_dvbsel, |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
62 #endif |
8197 | 63 &menu_info_pref, |
64 NULL | |
65 }; | |
66 | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
67 typedef struct key_cmd_s { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
68 int key; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
69 char *cmd; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
70 } key_cmd_t; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
71 |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
72 typedef struct menu_cmd_bindings_s { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
73 char *name; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
74 key_cmd_t *bindings; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
75 int binding_num; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
76 struct menu_cmd_bindings_s *parent; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
77 } menu_cmd_bindings_t; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
78 |
25208
1b3dabc8c2b8
Add type info to menu_t, now we can get the menu name and the type name of menu.
ulion
parents:
24940
diff
changeset
|
79 struct menu_def_st { |
8197 | 80 char* name; |
81 menu_info_t* type; | |
82 void* cfg; | |
83 char* args; | |
25208
1b3dabc8c2b8
Add type info to menu_t, now we can get the menu name and the type name of menu.
ulion
parents:
24940
diff
changeset
|
84 }; |
8197 | 85 |
25461 | 86 double menu_mouse_x = -1.0; |
87 double menu_mouse_y = -1.0; | |
88 int menu_mouse_pos_updated = 0; | |
89 | |
22284 | 90 static struct MPContext *menu_ctx = NULL; |
8197 | 91 static menu_def_t* menu_list = NULL; |
21797
14061bc22cb3
fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents:
20507
diff
changeset
|
92 static int menu_count = 0; |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
93 static menu_cmd_bindings_t *cmd_bindings = NULL; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
94 static int cmd_bindings_num = 0; |
8197 | 95 |
96 | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
97 menu_cmd_bindings_t *get_cmd_bindings(const char *name) { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
98 int i; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
99 for (i = 0; i < cmd_bindings_num; ++i) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
100 if (!strcasecmp(cmd_bindings[i].name, name)) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
101 return &cmd_bindings[i]; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
102 return NULL; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
103 } |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
104 |
8197 | 105 static int menu_parse_config(char* buffer) { |
106 char *element,*body, **attribs, *name; | |
107 menu_info_t* minfo = NULL; | |
108 int r,i; | |
109 ASX_Parser_t* parser = asx_parser_new(); | |
110 | |
111 while(1) { | |
112 r = asx_get_element(parser,&buffer,&element,&body,&attribs); | |
113 if(r < 0) { | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
114 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_SyntaxErrorAtLine,parser->line); |
8197 | 115 asx_parser_free(parser); |
116 return 0; | |
117 } else if(r == 0) { | |
118 asx_parser_free(parser); | |
119 return 1; | |
120 } | |
121 // Has it a name ? | |
122 name = asx_get_attrib("name",attribs); | |
123 if(!name) { | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
124 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuDefinitionsNeedANameAttrib,parser->line); |
8197 | 125 free(element); |
126 if(body) free(body); | |
127 asx_free_attribs(attribs); | |
128 continue; | |
129 } | |
130 | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
131 if (!strcasecmp(element, "keybindings")) { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
132 menu_cmd_bindings_t *bindings = cmd_bindings; |
25347
22e5eb039c83
Fix memory leak. I thought asx_get_attrib() return a const char *,
ulion
parents:
25320
diff
changeset
|
133 char *parent_bindings; |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
134 cmd_bindings = realloc(cmd_bindings, |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
135 (cmd_bindings_num+1)*sizeof(menu_cmd_bindings_t)); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
136 for (i = 0; i < cmd_bindings_num; ++i) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
137 if (cmd_bindings[i].parent) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
138 cmd_bindings[i].parent = cmd_bindings[i].parent-bindings+cmd_bindings; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
139 bindings = &cmd_bindings[cmd_bindings_num]; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
140 memset(bindings, 0, sizeof(menu_cmd_bindings_t)); |
25347
22e5eb039c83
Fix memory leak. I thought asx_get_attrib() return a const char *,
ulion
parents:
25320
diff
changeset
|
141 bindings->name = name; |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
142 parent_bindings = asx_get_attrib("parent",attribs); |
25347
22e5eb039c83
Fix memory leak. I thought asx_get_attrib() return a const char *,
ulion
parents:
25320
diff
changeset
|
143 if (parent_bindings) { |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
144 bindings->parent = get_cmd_bindings(parent_bindings); |
25347
22e5eb039c83
Fix memory leak. I thought asx_get_attrib() return a const char *,
ulion
parents:
25320
diff
changeset
|
145 free(parent_bindings); |
22e5eb039c83
Fix memory leak. I thought asx_get_attrib() return a const char *,
ulion
parents:
25320
diff
changeset
|
146 } |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
147 free(element); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
148 asx_free_attribs(attribs); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
149 if (body) { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
150 char *bd = body; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
151 char *b, *key, *cmd; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
152 int keycode; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
153 for(;;) { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
154 r = asx_get_element(parser,&bd,&element,&b,&attribs); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
155 if(r < 0) { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
156 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_SyntaxErrorAtLine, |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
157 parser->line); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
158 free(body); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
159 asx_parser_free(parser); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
160 return 0; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
161 } |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
162 if(r == 0) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
163 break; |
25408
f73887cc6b45
Ignore elements of keybindings other than 'binding'.
ulion
parents:
25407
diff
changeset
|
164 if (!strcasecmp(element, "binding")) { |
25409 | 165 key = asx_get_attrib("key",attribs); |
166 cmd = asx_get_attrib("cmd",attribs); | |
167 if (key && (keycode = mp_input_get_key_from_name(key)) >= 0) { | |
168 keycode &= ~MP_NO_REPEAT_KEY; | |
169 mp_msg(MSGT_GLOBAL,MSGL_V, | |
170 "[libmenu] got keybinding element %d %s=>[%s].\n", | |
171 keycode, key, cmd ? cmd : ""); | |
172 bindings->bindings = realloc(bindings->bindings, | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
173 (bindings->binding_num+1)*sizeof(key_cmd_t)); |
25409 | 174 bindings->bindings[bindings->binding_num].key = keycode; |
175 bindings->bindings[bindings->binding_num].cmd = cmd; | |
176 ++bindings->binding_num; | |
177 } | |
178 else | |
179 free(cmd); | |
180 free(key); | |
25408
f73887cc6b45
Ignore elements of keybindings other than 'binding'.
ulion
parents:
25407
diff
changeset
|
181 } |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
182 free(element); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
183 asx_free_attribs(attribs); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
184 free(b); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
185 } |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
186 free(body); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
187 } |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
188 ++cmd_bindings_num; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
189 continue; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
190 } |
8197 | 191 // Try to find this menu type in our list |
192 for(i = 0, minfo = NULL ; menu_info_list[i] ; i++) { | |
193 if(strcasecmp(element,menu_info_list[i]->name) == 0) { | |
194 minfo = menu_info_list[i]; | |
195 break; | |
196 } | |
197 } | |
198 // Got it : add this to our list | |
199 if(minfo) { | |
21797
14061bc22cb3
fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents:
20507
diff
changeset
|
200 menu_list = realloc(menu_list,(menu_count+2)*sizeof(menu_def_t)); |
14061bc22cb3
fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents:
20507
diff
changeset
|
201 menu_list[menu_count].name = name; |
14061bc22cb3
fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents:
20507
diff
changeset
|
202 menu_list[menu_count].type = minfo; |
14061bc22cb3
fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents:
20507
diff
changeset
|
203 menu_list[menu_count].cfg = m_struct_alloc(&minfo->priv_st); |
14061bc22cb3
fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents:
20507
diff
changeset
|
204 menu_list[menu_count].args = body; |
8197 | 205 // Setup the attribs |
206 for(i = 0 ; attribs[2*i] ; i++) { | |
207 if(strcasecmp(attribs[2*i],"name") == 0) continue; | |
21797
14061bc22cb3
fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents:
20507
diff
changeset
|
208 if(!m_struct_set(&minfo->priv_st,menu_list[menu_count].cfg,attribs[2*i], attribs[2*i+1])) |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
209 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_BadAttrib,attribs[2*i],attribs[2*i+1], |
8197 | 210 name,parser->line); |
211 } | |
21797
14061bc22cb3
fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents:
20507
diff
changeset
|
212 menu_count++; |
14061bc22cb3
fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents:
20507
diff
changeset
|
213 memset(&menu_list[menu_count],0,sizeof(menu_def_t)); |
8197 | 214 } else { |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
215 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnknownMenuType,element,parser->line); |
8197 | 216 free(name); |
217 if(body) free(body); | |
218 } | |
219 | |
220 free(element); | |
221 asx_free_attribs(attribs); | |
222 } | |
223 | |
224 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
225 |
8197 | 226 |
227 /// This will build the menu_defs list from the cfg file | |
228 #define BUF_STEP 1024 | |
229 #define BUF_MIN 128 | |
230 #define BUF_MAX BUF_STEP*1024 | |
22284 | 231 int menu_init(struct MPContext *mpctx, char* cfg_file) { |
8197 | 232 char* buffer = NULL; |
233 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
|
234 int f, fd; |
27393 | 235 #ifndef CONFIG_FREETYPE |
9103
6c2c74adaebe
mplayer crashes if one tries to use osd menu without having a font
arpi
parents:
8604
diff
changeset
|
236 if(vo_font == NULL) |
6c2c74adaebe
mplayer crashes if one tries to use osd menu without having a font
arpi
parents:
8604
diff
changeset
|
237 return 0; |
9212
24b102dbd0fe
Fixes a problem where the menu won't work, if you just use freetype fonts
arpi
parents:
9103
diff
changeset
|
238 #endif |
9103
6c2c74adaebe
mplayer crashes if one tries to use osd menu without having a font
arpi
parents:
8604
diff
changeset
|
239 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
|
240 if(fd < 0) { |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
241 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_CantOpenConfigFile,cfg_file); |
8197 | 242 return 0; |
243 } | |
244 buffer = malloc(bl); | |
245 while(1) { | |
246 int r; | |
247 if(bl - br < BUF_MIN) { | |
248 if(bl >= BUF_MAX) { | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
249 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ConfigFileIsTooBig,BUF_MAX/1024); |
8604
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
250 close(fd); |
8197 | 251 free(buffer); |
252 return 0; | |
253 } | |
254 bl += BUF_STEP; | |
255 buffer = realloc(buffer,bl); | |
256 } | |
8604
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
257 r = read(fd,buffer+br,bl-br); |
8197 | 258 if(r == 0) break; |
259 br += r; | |
260 } | |
261 if(!br) { | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
262 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_ConfigFileIsEmpty); |
8197 | 263 return 0; |
264 } | |
265 buffer[br-1] = '\0'; | |
266 | |
8604
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
267 close(fd); |
41a1e5dbb552
This patch fixes the reading of the menu.conf, because stream_open()
arpi
parents:
8251
diff
changeset
|
268 |
22284 | 269 menu_ctx = mpctx; |
8197 | 270 f = menu_parse_config(buffer); |
271 free(buffer); | |
272 return f; | |
273 } | |
274 | |
275 // Destroy all this stuff | |
25420 | 276 void menu_uninit(void) { |
8197 | 277 int i; |
278 for(i = 0 ; menu_list && menu_list[i].name ; i++) { | |
279 free(menu_list[i].name); | |
280 m_struct_free(&menu_list[i].type->priv_st,menu_list[i].cfg); | |
281 if(menu_list[i].args) free(menu_list[i].args); | |
282 } | |
283 free(menu_list); | |
21797
14061bc22cb3
fix gprof support (aka work around gprof's brain dead design)
gpoirier
parents:
20507
diff
changeset
|
284 menu_count = 0; |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
285 for (i = 0; i < cmd_bindings_num; ++i) { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
286 free(cmd_bindings[i].name); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
287 while(cmd_bindings[i].binding_num > 0) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
288 free(cmd_bindings[i].bindings[--cmd_bindings[i].binding_num].cmd); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
289 free(cmd_bindings[i].bindings); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
290 } |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
291 free(cmd_bindings); |
8197 | 292 } |
293 | |
294 /// Default read_key function | |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
295 int menu_dflt_read_key(menu_t* menu,int cmd) { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
296 int i; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
297 menu_cmd_bindings_t *bindings = get_cmd_bindings(menu->type->name); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
298 if (!bindings) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
299 bindings = get_cmd_bindings(menu->type->type->name); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
300 if (!bindings) |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
301 bindings = get_cmd_bindings("default"); |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
302 while (bindings) { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
303 for (i = 0; i < bindings->binding_num; ++i) { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
304 if (bindings->bindings[i].key == cmd) { |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
305 if (bindings->bindings[i].cmd) |
25320
4fbf536cc033
Support to run multiple mplayer commands set in menu.conf
ulion
parents:
25263
diff
changeset
|
306 mp_input_parse_and_queue_cmds(bindings->bindings[i].cmd); |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
307 return 1; |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
308 } |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
309 } |
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
310 bindings = bindings->parent; |
8197 | 311 } |
25263
96d0992c7920
Remove hardcoded key->cmd bindings in libmenu, support custom key bindings
ulion
parents:
25208
diff
changeset
|
312 return 0; |
8197 | 313 } |
314 | |
315 menu_t* menu_open(char *name) { | |
316 menu_t* m; | |
317 int i; | |
318 | |
319 for(i = 0 ; menu_list[i].name != NULL ; i++) { | |
320 if(strcmp(name,menu_list[i].name) == 0) | |
321 break; | |
322 } | |
323 if(menu_list[i].name == NULL) { | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
324 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuNotFound,name); |
8197 | 325 return NULL; |
326 } | |
327 m = calloc(1,sizeof(menu_t)); | |
328 m->priv_st = &(menu_list[i].type->priv_st); | |
329 m->priv = m_struct_copy(m->priv_st,menu_list[i].cfg); | |
22284 | 330 m->ctx = menu_ctx; |
25208
1b3dabc8c2b8
Add type info to menu_t, now we can get the menu name and the type name of menu.
ulion
parents:
24940
diff
changeset
|
331 m->type = &menu_list[i]; |
8197 | 332 if(menu_list[i].type->open(m,menu_list[i].args)) |
333 return m; | |
334 if(m->priv) | |
335 m_struct_free(m->priv_st,m->priv); | |
336 free(m); | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
337 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_MenuInitFailed,name); |
8197 | 338 return NULL; |
339 } | |
340 | |
341 void menu_draw(menu_t* menu,mp_image_t* mpi) { | |
342 if(menu->show && menu->draw) | |
343 menu->draw(menu,mpi); | |
344 } | |
345 | |
25461 | 346 void menu_update_mouse_pos(double x, double y) { |
347 menu_mouse_x = x; | |
348 menu_mouse_y = y; | |
349 menu_mouse_pos_updated = 1; | |
350 } | |
351 | |
8197 | 352 void menu_read_cmd(menu_t* menu,int cmd) { |
353 if(menu->read_cmd) | |
354 menu->read_cmd(menu,cmd); | |
355 } | |
356 | |
357 void menu_close(menu_t* menu) { | |
358 if(menu->close) | |
359 menu->close(menu); | |
360 if(menu->priv) | |
361 m_struct_free(menu->priv_st,menu->priv); | |
362 free(menu); | |
363 } | |
364 | |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25461
diff
changeset
|
365 int menu_read_key(menu_t* menu,int cmd) { |
8197 | 366 if(menu->read_key) |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25461
diff
changeset
|
367 return menu->read_key(menu,cmd); |
8197 | 368 else |
25502
605d4e3e403f
From now on, libmenu does not steal all input keys from input modules.
ulion
parents:
25461
diff
changeset
|
369 return menu_dflt_read_key(menu,cmd); |
8197 | 370 } |
371 | |
372 ///////////////////////////// Helpers //////////////////////////////////// | |
373 | |
374 typedef void (*draw_alpha_f)(int w,int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dstbase,int dststride); | |
375 | |
376 inline static draw_alpha_f get_draw_alpha(uint32_t fmt) { | |
377 switch(fmt) { | |
378 case IMGFMT_BGR15: | |
379 case IMGFMT_RGB15: | |
380 return vo_draw_alpha_rgb15; | |
381 case IMGFMT_BGR16: | |
382 case IMGFMT_RGB16: | |
383 return vo_draw_alpha_rgb16; | |
384 case IMGFMT_BGR24: | |
385 case IMGFMT_RGB24: | |
386 return vo_draw_alpha_rgb24; | |
387 case IMGFMT_BGR32: | |
388 case IMGFMT_RGB32: | |
389 return vo_draw_alpha_rgb32; | |
390 case IMGFMT_YV12: | |
391 case IMGFMT_I420: | |
392 case IMGFMT_IYUV: | |
393 case IMGFMT_YVU9: | |
394 case IMGFMT_IF09: | |
395 case IMGFMT_Y800: | |
396 case IMGFMT_Y8: | |
397 return vo_draw_alpha_yv12; | |
398 case IMGFMT_YUY2: | |
399 return vo_draw_alpha_yuy2; | |
18194 | 400 case IMGFMT_UYVY: |
401 return vo_draw_alpha_uyvy; | |
8197 | 402 } |
403 | |
404 return NULL; | |
405 } | |
406 | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
407 // return the real height of a char: |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
408 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
|
409 int font; |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
410 if ((font=vo_font->font[c])>=0) |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
411 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
|
412 return h; |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
413 } |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
414 |
23227
a142b048c65e
support for unicode/utf8 in libmenu (geexbox patch #545)
ben
parents:
22284
diff
changeset
|
415 static void render_txt(char *txt) |
a142b048c65e
support for unicode/utf8 in libmenu (geexbox patch #545)
ben
parents:
22284
diff
changeset
|
416 { |
a142b048c65e
support for unicode/utf8 in libmenu (geexbox patch #545)
ben
parents:
22284
diff
changeset
|
417 while (*txt) { |
24940 | 418 int c = utf8_get_char((const char**)&txt); |
23227
a142b048c65e
support for unicode/utf8 in libmenu (geexbox patch #545)
ben
parents:
22284
diff
changeset
|
419 render_one_glyph(vo_font, c); |
a142b048c65e
support for unicode/utf8 in libmenu (geexbox patch #545)
ben
parents:
22284
diff
changeset
|
420 } |
a142b048c65e
support for unicode/utf8 in libmenu (geexbox patch #545)
ben
parents:
22284
diff
changeset
|
421 } |
8197 | 422 |
27393 | 423 #ifdef CONFIG_FRIBIDI |
23228
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
424 #include <fribidi/fribidi.h> |
23231 | 425 #include "libavutil/common.h" |
23238 | 426 char *menu_fribidi_charset = NULL; |
427 int menu_flip_hebrew = 0; | |
428 int menu_fribidi_flip_commas = 0; | |
23228
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
429 |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
430 static char *menu_fribidi(char *txt) |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
431 { |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
432 static int char_set_num = -1; |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
433 static FriBidiChar *logical, *visual; |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
434 static size_t buffer_size = 1024; |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
435 static char *outputstr; |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
436 |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
437 FriBidiCharType base; |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
438 fribidi_boolean log2vis; |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
439 size_t len; |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
440 |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
441 if (menu_flip_hebrew) { |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
442 len = strlen(txt); |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
443 if (char_set_num == -1) { |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
444 fribidi_set_mirroring (1); |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
445 fribidi_set_reorder_nsm (0); |
23337
10a7279b8e56
get rid of -menu-utf8 and -menu-unicode once for all, patch by Guillaume Lecerf
ben
parents:
23238
diff
changeset
|
446 char_set_num = fribidi_parse_charset("UTF-8"); |
23231 | 447 buffer_size = FFMAX(1024,len+1); |
23230 | 448 logical = malloc(buffer_size); |
449 visual = malloc(buffer_size); | |
450 outputstr = malloc(buffer_size); | |
23228
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
451 } else if (len+1 > buffer_size) { |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
452 buffer_size = len+1; |
23230 | 453 logical = realloc(logical, buffer_size); |
454 visual = realloc(visual, buffer_size); | |
455 outputstr = realloc(outputstr, buffer_size); | |
23228
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
456 } |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
457 len = fribidi_charset_to_unicode (char_set_num, txt, len, logical); |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
458 base = menu_fribidi_flip_commas?FRIBIDI_TYPE_ON:FRIBIDI_TYPE_L; |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
459 log2vis = fribidi_log2vis (logical, len, &base, visual, NULL, NULL, NULL); |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
460 if (log2vis) { |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
461 len = fribidi_remove_bidi_marks (visual, len, NULL, NULL, NULL); |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
462 fribidi_unicode_to_charset (char_set_num, visual, len, outputstr); |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
463 return outputstr; |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
464 } |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
465 } |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
466 return txt; |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
467 } |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
468 #endif |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
469 |
8197 | 470 void menu_draw_text(mp_image_t* mpi,char* txt, int x, int y) { |
471 draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt); | |
472 int font; | |
473 | |
474 if(!draw_alpha) { | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
475 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnsupportedOutformat); |
8197 | 476 return; |
477 } | |
478 | |
27393 | 479 #ifdef CONFIG_FRIBIDI |
23228
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
480 txt = menu_fribidi(txt); |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
481 #endif |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
482 render_txt(txt); |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
483 |
8197 | 484 while (*txt) { |
24940 | 485 int c=utf8_get_char((const char**)&txt); |
8197 | 486 if ((font=vo_font->font[c])>=0 && (x + vo_font->width[c] <= mpi->w) && (y + vo_font->pic_a[font]->h <= mpi->h)) |
487 draw_alpha(vo_font->width[c], vo_font->pic_a[font]->h, | |
488 vo_font->pic_b[font]->bmp+vo_font->start[c], | |
489 vo_font->pic_a[font]->bmp+vo_font->start[c], | |
490 vo_font->pic_a[font]->w, | |
491 mpi->planes[0] + y * mpi->stride[0] + x * (mpi->bpp>>3), | |
492 mpi->stride[0]); | |
493 x+=vo_font->width[c]+vo_font->charspace; | |
494 } | |
495 | |
496 } | |
497 | |
498 void menu_draw_text_full(mp_image_t* mpi,char* txt, | |
499 int x, int y,int w, int h, | |
500 int vspace, int warp, int align, int anchor) { | |
501 int need_w,need_h; | |
502 int sy, ymin, ymax; | |
503 int sx, xmin, xmax, xmid, xrmin; | |
504 int ll = 0; | |
505 int font; | |
506 draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt); | |
507 | |
508 if(!draw_alpha) { | |
17994
6927fabaef92
Part1 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu
reynaldo
parents:
17993
diff
changeset
|
509 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnsupportedOutformat); |
8197 | 510 return; |
511 } | |
512 | |
27393 | 513 #ifdef CONFIG_FRIBIDI |
23228
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
514 txt = menu_fribidi(txt); |
2e95dcd49946
support for hebrew through fribidi in libmenu (geexbox patch #580)
ben
parents:
23227
diff
changeset
|
515 #endif |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
516 render_txt(txt); |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
517 |
8197 | 518 if(x > mpi->w || y > mpi->h) |
519 return; | |
520 | |
521 if(anchor & MENU_TEXT_VCENTER) { | |
522 if(h <= 0) h = mpi->h; | |
523 ymin = y - h/2; | |
524 ymax = y + h/2; | |
525 } else if(anchor & MENU_TEXT_BOT) { | |
526 if(h <= 0) h = mpi->h - y; | |
527 ymin = y - h; | |
528 ymax = y; | |
529 } else { | |
530 if(h <= 0) h = mpi->h - y; | |
531 ymin = y; | |
532 ymax = y + h; | |
533 } | |
534 | |
535 if(anchor & MENU_TEXT_HCENTER) { | |
536 if(w <= 0) w = mpi->w; | |
537 xmin = x - w/2; | |
538 xmax = x + w/2; | |
539 } else if(anchor & MENU_TEXT_RIGHT) { | |
540 if(w <= 0) w = mpi->w -x; | |
541 xmin = x - w; | |
542 xmax = x; | |
543 } else { | |
544 if(w <= 0) w = mpi->w -x; | |
545 xmin = x; | |
546 xmax = x + w; | |
547 } | |
548 | |
549 // How many space do we need to draw this ? | |
550 menu_text_size(txt,w,vspace,warp,&need_w,&need_h); | |
551 | |
552 // Find the first line | |
553 if(align & MENU_TEXT_VCENTER) | |
554 sy = ymin + ((h - need_h)/2); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
555 else if(align & MENU_TEXT_BOT) |
8232 | 556 sy = ymax - need_h - 1; |
8197 | 557 else |
558 sy = y; | |
559 | |
560 #if 0 | |
561 // Find the first col | |
562 if(align & MENU_TEXT_HCENTER) | |
563 sx = xmin + ((w - need_w)/2); | |
564 else if(align & MENU_TEXT_RIGHT) | |
565 sx = xmax - need_w; | |
566 #endif | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
567 |
8197 | 568 xmid = xmin + (xmax - xmin) / 2; |
569 xrmin = xmin; | |
570 // Clamp the bb to the mpi size | |
571 if(ymin < 0) ymin = 0; | |
572 if(xmin < 0) xmin = 0; | |
573 if(ymax > mpi->h) ymax = mpi->h; | |
574 if(xmax > mpi->w) xmax = mpi->w; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
575 |
8197 | 576 // Jump some the beginnig text if needed |
577 while(sy < ymin && *txt) { | |
24940 | 578 int c=utf8_get_char((const char**)&txt); |
8197 | 579 if(c == '\n' || (warp && ll + vo_font->width[c] > w)) { |
580 ll = 0; | |
581 sy += vo_font->height + vspace; | |
582 if(c == '\n') continue; | |
583 } | |
584 ll += vo_font->width[c]+vo_font->charspace; | |
585 } | |
586 if(*txt == '\0') // Nothing left to draw | |
587 return; | |
588 | |
589 while(sy < ymax && *txt) { | |
590 char* line_end = NULL; | |
591 int n; | |
592 | |
593 if(txt[0] == '\n') { // New line | |
594 sy += vo_font->height + vspace; | |
595 txt++; | |
596 continue; | |
597 } | |
598 | |
599 // Get the length and end of this line | |
600 for(n = 0, ll = 0 ; txt[n] != '\0' && txt[n] != '\n' ; n++) { | |
601 unsigned char c = txt[n]; | |
602 if(warp && ll + vo_font->width[c] > w) break; | |
603 ll += vo_font->width[c]+vo_font->charspace; | |
604 } | |
605 line_end = &txt[n]; | |
606 ll -= vo_font->charspace; | |
607 | |
608 | |
609 if(align & (MENU_TEXT_HCENTER|MENU_TEXT_RIGHT)) { | |
610 // Too long line | |
611 if(ll > xmax-xmin) { | |
612 if(align & MENU_TEXT_HCENTER) { | |
613 int mid = ll/2; | |
614 // Find the middle point | |
615 for(n--, ll = 0 ; n <= 0 ; n--) { | |
616 ll += vo_font->width[(int)txt[n]]+vo_font->charspace; | |
617 if(ll - vo_font->charspace > mid) break; | |
618 } | |
619 ll -= vo_font->charspace; | |
620 sx = xmid + mid - ll; | |
621 } else// MENU_TEXT_RIGHT) | |
622 sx = xmax + vo_font->charspace; | |
623 | |
624 // We are after the start point -> go back | |
625 if(sx > xmin) { | |
626 for(n-- ; n <= 0 ; n--) { | |
627 unsigned char c = txt[n]; | |
628 if(sx - vo_font->width[c] - vo_font->charspace < xmin) break; | |
629 sx -= vo_font->width[c]+vo_font->charspace; | |
630 } | |
631 } else { // We are before the start point -> go forward | |
632 for( ; sx < xmin && (&txt[n]) != line_end ; n++) { | |
633 unsigned char c = txt[n]; | |
634 sx += vo_font->width[c]+vo_font->charspace; | |
635 } | |
636 } | |
637 txt = &txt[n]; // Jump to the new start char | |
638 } else { | |
639 if(align & MENU_TEXT_HCENTER) | |
640 sx = xmid - ll/2; | |
641 else | |
8232 | 642 sx = xmax - 1 - ll; |
8197 | 643 } |
644 } else { | |
645 for(sx = xrmin ; sx < xmin && txt != line_end ; txt++) { | |
646 unsigned char c = txt[n]; | |
647 sx += vo_font->width[c]+vo_font->charspace; | |
648 } | |
649 } | |
650 | |
651 while(sx < xmax && txt != line_end) { | |
24940 | 652 int c=utf8_get_char((const char**)&txt); |
8197 | 653 font = vo_font->font[c]; |
8232 | 654 if(font >= 0) { |
655 int cs = (vo_font->pic_a[font]->h - vo_font->height) / 2; | |
25434 | 656 if ((sx + vo_font->width[c] <= xmax) && (sy + vo_font->height <= ymax) ) |
8232 | 657 draw_alpha(vo_font->width[c], vo_font->height, |
658 vo_font->pic_b[font]->bmp+vo_font->start[c] + | |
659 cs * vo_font->pic_a[font]->w, | |
660 vo_font->pic_a[font]->bmp+vo_font->start[c] + | |
661 cs * vo_font->pic_a[font]->w, | |
662 vo_font->pic_a[font]->w, | |
663 mpi->planes[0] + sy * mpi->stride[0] + sx * (mpi->bpp>>3), | |
664 mpi->stride[0]); | |
665 // else | |
666 //printf("Can't draw '%c'\n",c); | |
667 } | |
8197 | 668 sx+=vo_font->width[c]+vo_font->charspace; |
669 } | |
670 txt = line_end; | |
671 if(txt[0] == '\0') break; | |
672 sy += vo_font->height + vspace; | |
673 } | |
674 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
675 |
8197 | 676 int menu_text_length(char* txt) { |
677 int l = 0; | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
678 render_txt(txt); |
8197 | 679 while (*txt) { |
24940 | 680 int c=utf8_get_char((const char**)&txt); |
8197 | 681 l += vo_font->width[c]+vo_font->charspace; |
682 } | |
683 return l - vo_font->charspace; | |
684 } | |
685 | |
686 void menu_text_size(char* txt,int max_width, int vspace, int warp, int* _w, int* _h) { | |
687 int l = 1, i = 0; | |
688 int w = 0; | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
689 |
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
690 render_txt(txt); |
8197 | 691 while (*txt) { |
24940 | 692 int c=utf8_get_char((const char**)&txt); |
8197 | 693 if(c == '\n' || (warp && i + vo_font->width[c] >= max_width)) { |
25434 | 694 i -= vo_font->charspace; |
695 if (i > w) w = i; | |
8197 | 696 if(*txt) |
697 l++; | |
698 i = 0; | |
699 if(c == '\n') continue; | |
700 } | |
701 i += vo_font->width[c]+vo_font->charspace; | |
25434 | 702 } |
703 if (i > 0) { | |
704 i -= vo_font->charspace; | |
705 if (i > w) w = i; | |
8197 | 706 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
707 |
8197 | 708 *_w = w; |
709 *_h = (l-1) * (vo_font->height + vspace) + vo_font->height; | |
710 } | |
711 | |
712 | |
713 int menu_text_num_lines(char* txt, int max_width) { | |
714 int l = 1, i = 0; | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
715 render_txt(txt); |
8197 | 716 while (*txt) { |
24940 | 717 int c=utf8_get_char((const char**)&txt); |
8197 | 718 if(c == '\n' || i + vo_font->width[c] > max_width) { |
719 l++; | |
720 i = 0; | |
721 if(c == '\n') continue; | |
722 } | |
723 i += vo_font->width[c]+vo_font->charspace; | |
724 } | |
725 return l; | |
726 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
727 |
8197 | 728 char* menu_text_get_next_line(char* txt, int max_width) { |
729 int i = 0; | |
8224
fefc56153615
Fix freetype. Freetype is highly recommended for a nice output ;)
albeu
parents:
8197
diff
changeset
|
730 render_txt(txt); |
8197 | 731 while (*txt) { |
24940 | 732 int c=utf8_get_char((const char**)&txt); |
8197 | 733 if(c == '\n') { |
734 txt++; | |
735 break; | |
736 } | |
737 i += vo_font->width[c]; | |
738 if(i >= max_width) | |
739 break; | |
740 i += vo_font->charspace; | |
741 } | |
742 return txt; | |
743 } | |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
744 |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
745 |
18193 | 746 void menu_draw_box(mp_image_t* mpi,unsigned char grey,unsigned char alpha, int x, int y, int w, int h) { |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
747 draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt); |
18193 | 748 int g; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
749 |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
750 if(!draw_alpha) { |
18193 | 751 mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_UnsupportedOutformat); |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
752 return; |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
753 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
754 |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
755 if(x > mpi->w || y > mpi->h) return; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
756 |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
757 if(x < 0) w += x, x = 0; |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
758 if(x+w > mpi->w) w = mpi->w-x; |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
759 if(y < 0) h += y, y = 0; |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
760 if(y+h > mpi->h) h = mpi->h-y; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
761 |
18193 | 762 g = ((256-alpha)*grey)>>8; |
763 if(g < 1) g = 1; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
764 |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
765 { |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
766 int stride = (w+7)&(~7); // round to 8 |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
767 char pic[stride*h],pic_alpha[stride*h]; |
18193 | 768 memset(pic,g,stride*h); |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
769 memset(pic_alpha,alpha,stride*h); |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
770 draw_alpha(w,h,pic,pic_alpha,stride, |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
771 mpi->planes[0] + y * mpi->stride[0] + x * (mpi->bpp>>3), |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
772 mpi->stride[0]); |
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
773 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28113
diff
changeset
|
774 |
17993
98eb966a4024
Add a function to draw flat boxes and use it to make the list
albeu
parents:
17945
diff
changeset
|
775 } |