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