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