mirror of
https://github.com/mpv-player/mpv
synced 2024-12-24 15:52:25 +00:00
Add a function to draw flat boxes and use it to make the list
menu and console look much cooler. Idea take from Otvos Atilla's patches (oattila_At_chello--.--hu). git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@17994 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
22e18ebe85
commit
9c301c3e16
@ -559,3 +559,31 @@ char* menu_text_get_next_line(char* txt, int max_width) {
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
|
||||
|
||||
void menu_draw_box(mp_image_t* mpi, char grey, char alpha, int x, int y, int w, int h) {
|
||||
draw_alpha_f draw_alpha = get_draw_alpha(mpi->imgfmt);
|
||||
|
||||
if(!draw_alpha) {
|
||||
printf("Unsupported outformat !!!!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(x > mpi->w || y > mpi->h) return;
|
||||
|
||||
if(x < 0) w += x, x = 0;
|
||||
if(x+w > mpi->w) w = mpi->w-x;
|
||||
if(y < 0) h += y, y = 0;
|
||||
if(y+h > mpi->h) h = mpi->h-y;
|
||||
|
||||
{
|
||||
int stride = (w+7)&(~7); // round to 8
|
||||
char pic[stride*h],pic_alpha[stride*h];
|
||||
memset(pic,grey,stride*h);
|
||||
memset(pic_alpha,alpha,stride*h);
|
||||
draw_alpha(w,h,pic,pic_alpha,stride,
|
||||
mpi->planes[0] + y * mpi->stride[0] + x * (mpi->bpp>>3),
|
||||
mpi->stride[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -72,3 +72,5 @@ void menu_text_size(char* txt,int max_width,
|
||||
void menu_draw_text_full(mp_image_t* mpi,char* txt,
|
||||
int x, int y,int w, int h,
|
||||
int vspace, int warp, int align, int anchor);
|
||||
|
||||
void menu_draw_box(mp_image_t* mpi, char grey, char alpha, int x, int y, int w, int h);
|
||||
|
@ -55,6 +55,7 @@ struct menu_priv_s {
|
||||
int height; // Display size in %
|
||||
int minb;
|
||||
int vspace;
|
||||
int bg,bg_alpha;
|
||||
unsigned int hide_time;
|
||||
unsigned int show_time;
|
||||
int history_max;
|
||||
@ -81,6 +82,7 @@ static struct menu_priv_s cfg_dflt = {
|
||||
33, // %
|
||||
3,
|
||||
3,
|
||||
0x80,0x40,
|
||||
500,
|
||||
500,
|
||||
10,
|
||||
@ -96,6 +98,8 @@ static m_option_t cfg_fields[] = {
|
||||
{ "height", ST_OFF(height), CONF_TYPE_INT, M_OPT_RANGE, 1, 100, NULL },
|
||||
{ "minbor", ST_OFF(minb), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL },
|
||||
{ "vspace", ST_OFF(vspace), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL },
|
||||
{ "bg", ST_OFF(bg), CONF_TYPE_INT, M_OPT_RANGE, -1, 255, NULL },
|
||||
{ "bg-alpha", ST_OFF(bg_alpha), CONF_TYPE_INT, M_OPT_RANGE, 0, 255, NULL },
|
||||
{ "show-time",ST_OFF(show_time), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL },
|
||||
{ "hide-time",ST_OFF(hide_time), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL },
|
||||
{ "history-size",ST_OFF(history_max), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL },
|
||||
@ -190,6 +194,9 @@ static void draw(menu_t* menu, mp_image_t* mpi) {
|
||||
if(x < 0 || y < 0 || w <= 0 || h <= 0 )
|
||||
return;
|
||||
|
||||
if(mpriv->bg >= 0)
|
||||
menu_draw_box(mpi,mpriv->bg,mpriv->bg_alpha,0,0,mpi->w,h);
|
||||
|
||||
if(!mpriv->child || !mpriv->raw_child){
|
||||
char input[strlen(mpriv->cur_history->buffer) + strlen(mpriv->prompt) + 1];
|
||||
sprintf(input,"%s%s",mpriv->prompt,mpriv->cur_history->buffer);
|
||||
|
@ -30,6 +30,7 @@ void menu_list_draw(menu_t* menu,mp_image_t* mpi) {
|
||||
int dy = 0;
|
||||
int need_h = 0,need_w = 0,ptr_l,sidx = 0;
|
||||
int th,count = 0;
|
||||
int bg_w;
|
||||
list_entry_t* m;
|
||||
|
||||
if(mpriv->count < 1)
|
||||
@ -102,7 +103,15 @@ void menu_list_draw(menu_t* menu,mp_image_t* mpi) {
|
||||
} else
|
||||
m = mpriv->menu;
|
||||
|
||||
bg_w = need_w+2*mpriv->minb;
|
||||
if(th > 0) {
|
||||
if(mpriv->title_bg >= 0) {
|
||||
int tw,th2;
|
||||
menu_text_size(mpriv->title,dw,mpriv->vspace,1,&tw,&th2);
|
||||
if(tw+2*mpriv->minb > bg_w) bg_w = tw+2*mpriv->minb;
|
||||
menu_draw_box(mpi,mpriv->title_bg,mpriv->title_bg_alpha,
|
||||
x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace,bg_w,th);
|
||||
}
|
||||
menu_draw_text_full(mpi,mpriv->title,
|
||||
x < 0 ? mpi->w / 2 : x,
|
||||
dy+y,dw,0,
|
||||
@ -114,13 +123,22 @@ void menu_list_draw(menu_t* menu,mp_image_t* mpi) {
|
||||
|
||||
for( ; m != NULL && dy + vo_font->height < dh ; m = m->next ) {
|
||||
if(m->hide) continue;
|
||||
if(ptr_l > 0 && m == mpriv->current)
|
||||
menu_draw_text_full(mpi,mpriv->ptr,
|
||||
x < 0 ? (mpi->w - need_w) / 2 + ptr_l : x,
|
||||
dy+y,dw,dh - dy,
|
||||
mpriv->vspace,0,
|
||||
MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_RIGHT :MENU_TEXT_LEFT) ,
|
||||
MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_RIGHT :MENU_TEXT_LEFT));
|
||||
if(m == mpriv->current) {
|
||||
if(mpriv->ptr_bg >= 0)
|
||||
menu_draw_box(mpi,mpriv->ptr_bg,mpriv->ptr_bg_alpha,
|
||||
x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace,
|
||||
bg_w,vo_font->height + mpriv->vspace);
|
||||
if(ptr_l > 0)
|
||||
menu_draw_text_full(mpi,mpriv->ptr,
|
||||
x < 0 ? (mpi->w - need_w) / 2 + ptr_l : x,
|
||||
dy+y,dw,dh - dy,
|
||||
mpriv->vspace,0,
|
||||
MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_RIGHT :MENU_TEXT_LEFT) ,
|
||||
MENU_TEXT_TOP|(x < 0 ? MENU_TEXT_RIGHT :MENU_TEXT_LEFT));
|
||||
} else if(mpriv->item_bg >= 0)
|
||||
menu_draw_box(mpi,mpriv->item_bg,mpriv->item_bg_alpha,
|
||||
x < 0 ? (mpi->w-bg_w)/2 : x-mpriv->minb,dy+y-mpriv->vspace,
|
||||
bg_w,vo_font->height + mpriv->vspace);
|
||||
menu_draw_text_full(mpi,m->txt,
|
||||
x < 0 ? (mpi->w - need_w) / 2 + ptr_l : x + ptr_l,
|
||||
dy+y,dw-ptr_l,dh - dy,
|
||||
|
@ -29,6 +29,9 @@ typedef struct menu_priv_s {
|
||||
int w,h;
|
||||
int vspace, minb;
|
||||
char* ptr;
|
||||
int title_bg,title_bg_alpha;
|
||||
int item_bg,item_bg_alpha;
|
||||
int ptr_bg,ptr_bg_alpha;
|
||||
} menu_list_priv_t;
|
||||
|
||||
typedef void (*free_entry_t)(list_entry_t* entry);
|
||||
@ -52,7 +55,10 @@ extern const menu_list_priv_t menu_list_priv_dflt;
|
||||
-1,-1, \
|
||||
0,0, \
|
||||
5, 3, \
|
||||
">" \
|
||||
NULL, \
|
||||
0x80, 0x80, \
|
||||
0x40, 0x80, \
|
||||
0x70, 0x80 \
|
||||
}
|
||||
|
||||
|
||||
@ -63,5 +69,15 @@ extern const menu_list_priv_t menu_list_priv_dflt;
|
||||
{ "y", M_ST_OFF(menu_list_priv_t,y), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, \
|
||||
{ "w", M_ST_OFF(menu_list_priv_t,w), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, \
|
||||
{ "h", M_ST_OFF(menu_list_priv_t,h), CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, \
|
||||
{ "ptr", M_ST_OFF(menu_list_priv_t,ptr), CONF_TYPE_STRING, 0, 0, 0, NULL }
|
||||
{ "ptr", M_ST_OFF(menu_list_priv_t,ptr), CONF_TYPE_STRING, 0, 0, 0, NULL }, \
|
||||
{ "title-bg", M_ST_OFF(menu_list_priv_t,title_bg), CONF_TYPE_INT, M_OPT_RANGE, -1, 255, NULL }, \
|
||||
{ "title-bg-alpha", M_ST_OFF(menu_list_priv_t,title_bg_alpha), \
|
||||
CONF_TYPE_INT, M_OPT_RANGE, 0, 255, NULL }, \
|
||||
{ "item-bg", M_ST_OFF(menu_list_priv_t,item_bg), CONF_TYPE_INT, M_OPT_RANGE, -1, 255, NULL }, \
|
||||
{ "item-bg-alpha", M_ST_OFF(menu_list_priv_t,item_bg_alpha), \
|
||||
CONF_TYPE_INT, M_OPT_RANGE, 0, 255, NULL }, \
|
||||
{ "ptr-bg", M_ST_OFF(menu_list_priv_t,ptr_bg), CONF_TYPE_INT, M_OPT_RANGE, -1, 255, NULL }, \
|
||||
{ "ptr-bg-alpha", M_ST_OFF(menu_list_priv_t,ptr_bg_alpha), \
|
||||
CONF_TYPE_INT, M_OPT_RANGE, 0, 255, NULL } \
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user