annotate libmenu/menu.c @ 30752:abec4bb780e5

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