[MPlayer-cvslog] CVS: main/libmenu menu_list.c, 1.6, 1.7 menu_list.h, 1.1, 1.2

Alban Bedel CVS syncmail at mplayerhq.hu
Sat Mar 25 19:15:40 CET 2006


CVS change done by Alban Bedel CVS

Update of /cvsroot/mplayer/main/libmenu
In directory mail:/var2/tmp/cvs-serv1663/libmenu

Modified Files:
	menu_list.c menu_list.h 
Log Message:
Allow hiding list elements and disableing the pointer.


Index: menu_list.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmenu/menu_list.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- menu_list.c	25 Mar 2006 17:32:10 -0000	1.6
+++ menu_list.c	25 Mar 2006 18:15:37 -0000	1.7
@@ -28,8 +28,8 @@
   int w = mpriv->w;
   int dh = 0,dw =  0;
   int dy = 0;
-  int need_h = 0,need_w = 0,ptr_l = menu_text_length(mpriv->ptr) + 10,sidx = 0;
-  int th;
+  int need_h = 0,need_w = 0,ptr_l,sidx = 0;
+  int th,count = 0;
   list_entry_t* m;
 
   if(mpriv->count < 1)
@@ -39,17 +39,32 @@
   if(w <= 0) w = mpi->width;
   dh = h - 2*mpriv->minb;
   dw = w - 2*mpriv->minb;
-  ptr_l = menu_text_length(mpriv->ptr);
+  ptr_l = mpriv->ptr ? menu_text_length(mpriv->ptr) : 0;
   // mpi is too small
   if(h - vo_font->height <= 0 || w - ptr_l <= 0 || dw <= 0 || dh <= 0)
     return;
 
   th = menu_text_num_lines(mpriv->title,dw) * (mpriv->vspace + vo_font->height) + mpriv->vspace;
 
+  // the selected item is hidden, find a visible one
+  if(mpriv->current->hide) {
+    // try the next
+    for(m = mpriv->current->next ; m ; m = m->next)
+      if(!m->hide) break;
+    if(!m) // or the previous
+      for(m = mpriv->current->prev ; m ; m = m->prev)
+        if(!m->hide) break;
+    if(m) mpriv->current = m;
+    else ptr_l = 0;
+  }
+  
   for(i = 0, m = mpriv->menu ; m ; m = m->next, i++) {
-    int ll = menu_text_length(m->txt);
+    int ll;
+    if(m->hide) continue;
+    ll = menu_text_length(m->txt);
     if(ptr_l + ll > need_w) need_w = ptr_l + ll;
     if(m == mpriv->current) sidx = i;
+    count++;
   }
   if(need_w > dw) need_w = dw;
   if(x > 0)
@@ -59,7 +74,7 @@
   else 
     y = mpriv->minb;
 
-  need_h = mpriv->count * (mpriv->vspace + vo_font->height) - mpriv->vspace;
+  need_h = count * (mpriv->vspace + vo_font->height) - mpriv->vspace;
   if( need_h + th > dh) {
     int start,end;
     int maxl = (dh + mpriv->vspace - th) / (mpriv->vspace + vo_font->height);
@@ -74,14 +89,16 @@
     start = sidx - (maxl/2);
     if(start < 0) start = 0;
     end = start + maxl;
-    if(end > mpriv->count) {
-      end = mpriv->count;
+    if(end > count) {
+      end = count;
       if(end - start < maxl)
 	start = end - maxl < 0 ? 0 : end - maxl;
     }
     m = mpriv->menu;
-    for(i = 0 ; m->next && i < start ; i++)
+    for(i = 0 ; m->next && i < start ; ) {
+      if(!m->hide) i++;
       m = m->next;
+    }
   } else
     m = mpriv->menu;
 
@@ -96,7 +113,8 @@
   }
   
   for( ; m != NULL && dy + vo_font->height < dh ; m = m->next ) {
-    if(m == mpriv->current)
+    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,
@@ -117,18 +135,26 @@
 void menu_list_read_cmd(menu_t* menu,int cmd) {
   switch(cmd) {
   case MENU_CMD_UP:
-    if(mpriv->current->prev) {
-      mpriv->current = mpriv->current->prev;
-    } else {
+    if(!mpriv->current->prev) {
       for( ; mpriv->current->next != NULL ; mpriv->current = mpriv->current->next)
 	/* NOTHING */;
-    } break;
+      if(!mpriv->current->hide) return;
+    }
+    while(mpriv->current->prev) {
+      mpriv->current = mpriv->current->prev;
+      if(!mpriv->current->hide) return;
+    }
+    break;
   case MENU_CMD_DOWN:
-    if(mpriv->current->next) {
+    if(!mpriv->current->next) {
+      mpriv->current = mpriv->menu;
+      if(!mpriv->current->hide) return;
+    }
+    while(mpriv->current->next) {
       mpriv->current = mpriv->current->next;
-   } else {
-     mpriv->current = mpriv->menu;
-   } break;
+      if(!mpriv->current->hide) return;
+    }
+    break;
   case MENU_CMD_LEFT:
   case MENU_CMD_CANCEL:
     menu->show = 0;

Index: menu_list.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmenu/menu_list.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- menu_list.h	14 Nov 2002 23:47:11 -0000	1.1
+++ menu_list.h	25 Mar 2006 18:15:37 -0000	1.2
@@ -11,6 +11,7 @@
   list_entry_t* next;
 
   char* txt;
+  char hide;
 };
 
 




More information about the MPlayer-cvslog mailing list