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