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