changeset 17993:98eb966a4024

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).
author albeu
date Thu, 30 Mar 2006 02:52:54 +0000
parents 2545bbd91450
children 6927fabaef92
files libmenu/menu.c libmenu/menu.h libmenu/menu_console.c libmenu/menu_list.c libmenu/menu_list.h
diffstat 5 files changed, 80 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/libmenu/menu.c	Wed Mar 29 23:25:09 2006 +0000
+++ b/libmenu/menu.c	Thu Mar 30 02:52:54 2006 +0000
@@ -559,3 +559,31 @@
   }
   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]);
+  }
+  
+}
--- a/libmenu/menu.h	Wed Mar 29 23:25:09 2006 +0000
+++ b/libmenu/menu.h	Thu Mar 30 02:52:54 2006 +0000
@@ -72,3 +72,5 @@
 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);
--- a/libmenu/menu_console.c	Wed Mar 29 23:25:09 2006 +0000
+++ b/libmenu/menu_console.c	Thu Mar 30 02:52:54 2006 +0000
@@ -55,6 +55,7 @@
   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 @@
   33, // %
   3,
   3,
+  0x80,0x40,
   500,
   500,
   10,
@@ -96,6 +98,8 @@
   { "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 @@
   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);
--- a/libmenu/menu_list.c	Wed Mar 29 23:25:09 2006 +0000
+++ b/libmenu/menu_list.c	Thu Mar 30 02:52:54 2006 +0000
@@ -30,6 +30,7 @@
   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 @@
   } 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 @@
   
   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,
--- a/libmenu/menu_list.h	Wed Mar 29 23:25:09 2006 +0000
+++ b/libmenu/menu_list.h	Thu Mar 30 02:52:54 2006 +0000
@@ -29,6 +29,9 @@
   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 @@
   -1,-1, \
   0,0, \
   5, 3, \
-  ">" \
+  NULL, \
+  0x80, 0x80, \
+  0x40, 0x80, \
+  0x70, 0x80 \
 }
   
 
@@ -63,5 +69,15 @@
   { "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 } \
+