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