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