⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listb.cpp

📁 Yet another mp3 player, but this time using SVGALib under Linux. The idea was to use a 320x240 disp
💻 CPP
字号:
/*   listb.h  List browser class.  This program is free software; you can redistribute it and/or modify it  under the terms of the GNU General Public License as published by the  Free Software Foundation; either version 2 of the License, or (at your  option) any later version.  This program is distributed in the hope that it will be useful, but  WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  General Public License for more details, www.gnu.org.  Copyright (C) 2000  Simon Harrison (email smh@N_O_S_P_A_M@dr.com)*/#include "listb.h"/*    List browser class.    Provides managed list browsing functionality.*/void CString::SetName(char * n){   if (n) {     int il=strlen(n)+1;     if (alloc_len<il) {       delete [] name;       name = new char[il];       alloc_len = il;     }     if (name)       strcpy( name, n );        }}CListBrowser::CListBrowser( int page=15 ) :             PAGE_MAX(page),plist(NULL),nlistents(0),scroll_freq(0),            ppagelist(NULL),display_sel(1),scroller(NULL),scroll_on(false){      ppagelist = new CString[PAGE_MAX];      cur_select = 1;                                          }int CListBrowser::GetPageEnts() {   // Chances are we need a new scroller here?   return npageents;  }void CListBrowser::ScrollOn( int n, bool b, int freq ){   scroll_on = b;   scroll_max = n;   scroll_freq = freq;   if (b) {       scroller = NULL;      update();   } else {      delete scroller;      scroller = NULL;      }}char* CListBrowser::GetScrolledSelected( int *offs ){   if (scroller && scroll_on) {      return scroller->update( offs);   } else {     return NULL;   }}void CListBrowser::update( )////   Update of the internal display list.//{int n;CString* ps,*pd;int c;char buffer[1024];int page = cur_select/PAGE_MAX;       // the page we're on.   if (cur_select%PAGE_MAX) page++;   page--;  // now zero based    n = nlistents;    // size of the big list.   ps = plist;    // The big list   pd = ppagelist;   //  the bit we seeint i = page*PAGE_MAX;    ps+=i;              // start at the beginning of the page.   c=0;      pd->SetName( "" );   /* page zero-based */   while (i<n) {      if (i==(cur_select-1)) {         pd->SetName( ps->GetName() );         // time to make another objee de scroll.         if (scroll_on) {            if (scroller) delete scroller;            scroller = new CScroller(scroll_max);            scroller->load( ps->GetName(), scroll_freq );         }         display_sel = c;      } else {         pd->SetName( ps->GetName() );      }      ps++;      pd++;      i++;      c++;      if (c==PAGE_MAX) break;   }   npageents = c;}int CListBrowser::findindex( char* match ) {CString* p=plist;int i=0;      /* index zero-based */   while (i<nlistents) {      if (strcmp( p->GetName(), match )==0) {         return i+1;      }      p++;      i++;   }   return 0;}void CListBrowser::up(){            /* previous file in list */            if (cur_select>1) {               cur_select--;               update();               //sprintf( lastaction, "New selection: %d", cur_select );            } else {              //sprintf( lastaction, "Already at first selection." );            }}void CListBrowser::uplots(){	    /* next file in list */            if (cur_select>1) {	       cur_select-=5;	       if (cur_select<=1) cur_select=1;	       update( );               //sprintf( lastaction, "New selection: %d", cur_select );	       	    } else {               //sprintf( lastaction, "Already on first file." );	                   }}void CListBrowser::down(){	    /* next file in list */	    if (cur_select<nlistents) {	       cur_select++;	       update();               //sprintf( lastaction, "New selection: %d", cur_select );	       	    } else {	      //sprintf( lastaction, "Already on last file." );	    }}void CListBrowser::downlots(){	    /* next file in list */	    if (cur_select<nlistents) {	       cur_select+=5;	       if (cur_select>=nlistents) cur_select = nlistents;	       update();               //sprintf( lastaction, "New selection: %d", cur_select );	       	    } else {               //sprintf( lastaction, "Already on last file." );	       	    	    }}void CListBrowser::left(){  // override this!}void CListBrowser::right(){  // override this!}char* CListBrowser::enter(){  // override this!  return NULL;}void CListBrowser::DebugDumpPage( CString* p, int n )/*  Dump out all the directory entries to stdout.*/{CString* pd=p;      printf( "%d entries..\n", n );   for (int i=0;i<n;i++) {      printf( "Name (%d) %s\n", i, pd->GetName() );      pd++;   }}void CListBrowser::clean(){   if (nlistents) {      delete [] plist;      plist = NULL;      nlistents = 0;    }   npageents = 0;   cur_page=0;}void CListBrowser::SetSelect( int s ){   cur_select = s;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -