9 #include "img_format.h"
15 #include "../libvo/font_load.h"
16 #include "../osdep/keycodes.h"
19 #include "menu_list.h"
21 #define mpriv (menu->priv)
23 void menu_list_draw(menu_t
* menu
,mp_image_t
* mpi
) {
31 int need_h
= 0,need_w
= 0,ptr_l
= menu_text_length(mpriv
->ptr
) + 10,sidx
= 0;
38 if(h
<= 0) h
= mpi
->height
;
39 if(w
<= 0) w
= mpi
->width
;
40 dh
= h
- 2*mpriv
->minb
;
41 dw
= w
- 2*mpriv
->minb
;
42 ptr_l
= menu_text_length(mpriv
->ptr
);
44 if(h
- vo_font
->height
<= 0 || w
- ptr_l
<= 0 || dw
<= 0 || dh
<= 0)
47 th
= menu_text_num_lines(mpriv
->title
,dw
) * (mpriv
->vspace
+ vo_font
->height
) + mpriv
->vspace
;
49 for(i
= 0, m
= mpriv
->menu
; m
; m
= m
->next
, i
++) {
50 int ll
= menu_text_length(m
->txt
);
51 if(ptr_l
+ ll
> need_w
) need_w
= ptr_l
+ ll
;
52 if(m
== mpriv
->current
) sidx
= i
;
54 if(need_w
> dw
) need_w
= dw
;
62 need_h
= mpriv
->count
* (mpriv
->vspace
+ vo_font
->height
) - mpriv
->vspace
;
63 if( need_h
+ th
> dh
) {
65 int maxl
= (dh
+ mpriv
->vspace
- th
) / (mpriv
->vspace
+ vo_font
->height
);
68 maxl
= (dh
+ mpriv
->vspace
) / ( vo_font
->height
+ mpriv
->vspace
);
72 need_h
= maxl
*(mpriv
->vspace
+ vo_font
->height
) - mpriv
->vspace
;
74 start
= sidx
- (maxl
/2);
75 if(start
< 0) start
= 0;
77 if(end
> mpriv
->count
) {
79 if(end
- start
< maxl
)
80 start
= end
- maxl
< 0 ? 0 : end
- maxl
;
83 for(i
= 0 ; m
->next
&& i
< start
; i
++)
89 menu_draw_text_full(mpi
,mpriv
->title
,
90 x
< 0 ? mpi
->w
/ 2 : x
,
93 MENU_TEXT_TOP
|MENU_TEXT_HCENTER
,
94 MENU_TEXT_TOP
|(x
< 0 ? MENU_TEXT_HCENTER
:MENU_TEXT_LEFT
));
98 for( ; m
!= NULL
&& dy
+ vo_font
->height
< dh
; m
= m
->next
) {
99 if(m
== mpriv
->current
)
100 menu_draw_text_full(mpi
,mpriv
->ptr
,
101 x
< 0 ? (mpi
->w
- need_w
) / 2 + ptr_l
: x
,
104 MENU_TEXT_TOP
|(x
< 0 ? MENU_TEXT_RIGHT
:MENU_TEXT_LEFT
) ,
105 MENU_TEXT_TOP
|(x
< 0 ? MENU_TEXT_RIGHT
:MENU_TEXT_LEFT
));
106 menu_draw_text_full(mpi
,m
->txt
,
107 x
< 0 ? (mpi
->w
- need_w
) / 2 + ptr_l
: x
+ ptr_l
,
108 dy
+y
,dw
-ptr_l
,dh
- dy
,
110 MENU_TEXT_TOP
|MENU_TEXT_LEFT
,
111 MENU_TEXT_TOP
|MENU_TEXT_LEFT
);
112 dy
+= vo_font
->height
+ mpriv
->vspace
;
117 void menu_list_read_cmd(menu_t
* menu
,int cmd
) {
120 if(mpriv
->current
->prev
) {
121 mpriv
->current
= mpriv
->current
->prev
;
123 for( ; mpriv
->current
->next
!= NULL
; mpriv
->current
= mpriv
->current
->next
)
127 if(mpriv
->current
->next
) {
128 mpriv
->current
= mpriv
->current
->next
;
130 mpriv
->current
= mpriv
->menu
;
132 case MENU_CMD_CANCEL
:
139 void menu_list_jump_to_key(menu_t
* menu
,int c
) {
140 if(c
< 256 && isalnum(c
)) {
141 list_entry_t
* e
= mpriv
->current
;
142 if(e
->txt
[0] == c
) e
= e
->next
;
143 for( ; e
; e
= e
->next
) {
149 for(e
= mpriv
->menu
; e
; e
= e
->next
) {
156 menu_dflt_read_key(menu
,c
);
159 void menu_list_read_key(menu_t
* menu
,int c
,int jump_to
) {
164 mpriv
->current
= mpriv
->menu
;
167 for(m
= mpriv
->current
; m
&& m
->next
; m
= m
->next
)
173 for(i
= 0, m
= mpriv
->current
; m
&& m
->prev
&& i
< 10 ; m
= m
->prev
, i
++)
179 for(i
= 0, m
= mpriv
->current
; m
&& m
->next
&& i
< 10 ; m
= m
->next
, i
++)
186 menu_list_jump_to_key(menu
,c
);
188 menu_dflt_read_key(menu
,c
);
192 void menu_list_add_entry(menu_t
* menu
,list_entry_t
* entry
) {
196 if(mpriv
->menu
== NULL
) {
197 mpriv
->menu
= mpriv
->current
= entry
;
201 for(l
= mpriv
->menu
; l
->next
!= NULL
; l
= l
->next
)
207 void menu_list_init(menu_t
* menu
) {
209 mpriv
= calloc(1,sizeof(struct menu_priv_s
));
213 void menu_list_uninit(menu_t
* menu
,free_entry_t free_func
) {
216 if(!free_func
) free_func
= (free_entry_t
)free
;
218 for(i
= mpriv
->menu
; i
!= NULL
; ) {
224 mpriv
->menu
= mpriv
->current
= NULL
;