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

📄 dirhandler.c

📁 神龙卡开发原代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * C Source file for the directory listing * Copyright (c) Sigma Designs 2002-2003.  All Rights Reserved * */#include <signal.h>#include <unistd.h>#include <errno.h>#include "OsdWindow.h"#include "id3v2lib/id3v2.h"#include "dirhandler.h"void GetFileInfo(FILE_INFO_EXT *fi){	fi->info = GetISOFileInfo();	fi->filename = filename;	fi->filesize = mfl[curfId]->size;	return;}static voidPhotoLibTimerHandler(int sig){		OsdMainLoop(SHOW_EOF);	return;}static GR_BOOL sleepWaitStop = GR_FALSE;static voidSleepWaitTimerHandler(){	ClearMsg(wgt);	wgt->KbdHandler = PlayfileKeydownHandler;	if (sleepWaitStop) {		sleepWaitStop = GR_FALSE;		OsdMainLoop(SHOW_STOP_KEYDOWN);	}}static voidSleepWaitKeyboardHandler(OSD_WINDOW *wPtr, DATA_POINTER ptr){	GR_EVENT *event = wPtr->lastevent;	GR_KEY rk = event->keystroke.ch;		if (rk == SHOW_PLAY_INFO_UPDATE || rk == SHOW_START_PLAYING) return;	ClearMsg(wgt);	wgt->KbdHandler = PlayfileKeydownHandler;	if (sleepWaitStop) {		sleepWaitStop = GR_FALSE;		event->keystroke.ch = SHOW_STOP_KEYDOWN;	}		PlayfileKeydownHandler(wPtr, ptr);		}static voidSleepWait(int sec, GR_BOOL stop){	wgt->KbdHandler = SleepWaitKeyboardHandler;	sleepWaitStop = stop;	signal(SIGALRM, SleepWaitTimerHandler);	alarm(sec);	}static void DrawIcon(int item, int yId){	GR_COORD y;		y = DIR_BG_YPOS+(DIR_YOFF*(yId-n_topItem));	switch (mfl[item]->ftype) {		case AUDIO_LIB:			OsdDrawPictureEx(wgt,DIR_ICON_XPOS,y,27,26,"img/lib/musicicon.png");			break;		case PHOTO_LIB:			OsdDrawPictureEx(wgt,DIR_ICON_XPOS,y,27,26,"img/lib/pixicon.png");			break;		case VIDEO_LIB:			OsdDrawPictureEx(wgt,DIR_ICON_XPOS,y,27,26,"img/lib/movieicon.png");			break;	}	return;}static void DrawImgBits(unsigned int *imagebits, GR_GC_ID gc, GR_COORD x, GR_COORD y, GR_SIZE width, GR_SIZE height){	unsigned int i, j, bits;			for (i=0; i<(unsigned int)height; i++) {		bits = 0x8000;		for (j=0; j<(unsigned int)width; j++, bits >>= 1) {			if (imagebits[i] & bits) {				//GrPoint(wPtr->wid,wPtr->gc,x+j,y+i);				GrPoint(wid,gc,x+j,y+i);			}		}	}	return;}static void DrawCursor(int id, GR_GC_ID gc){	GR_COORD y;		y = DIR_BG_YPOS+(DIR_YOFF*(id-n_topItem));	GrSetGCMode(gc, GR_MODE_XOR);		//if (visible) {		DrawImgBits(imagebits_leftend, gc, DIR_BG_XPOS, y, 13, 25);		//DrawImgBits(imagebits_rightend, gc, DIR_BG_XPOS+DIR_WIDTH-13,y,13, 25);	//}	//else {			//	GrFillRect(wid,gc_pal0,DIR_BG_XPOS,y,13,25);		//GrFillRect(wid,gc_pal0,DIR_BG_XPOS+DIR_WIDTH-13,y,13,25);	//}		//GrSetGCMode(gc, GR_MODE_XOR);	GrFillRect(wid,gc,DIR_BG_XPOS+13,y,DIR_WIDTH,DIR_YOFF);	GrSetGCMode(gc, GR_MODE_COPY);		//Flush cache//	asm ("mcr p15, 0, r0, c7, c10, 0\n");	return;}static void DrawInfo(int id, GR_GC_ID gc){	GR_COORD y;	int j;		if (gc)		DrawCursor(id, gc);	if (libType == RAW_PLAYLIST_LIB)		j = id;	else		j = fl[id];		// Write file info.	y = 405;	GrFillRect(wid,gc_pal0,DIR_BG_XPOS,y-DIR_YOFF,500,DIR_YOFF*3);	GrText(wid,gc1,DIR_BG_XPOS,y,mfl[j]->path,-1,GR_TFASCII);	y += DIR_YOFF;	GrText(wid,gc1,DIR_BG_XPOS,y,"Size:",-1,GR_TFASCII);	GrText(wid,gc1,DIR_BG_XPOS+52,y,mfl[j]->size,-1,GR_TFASCII);	GrText(wid,gc1,DIR_BG_XPOS+200,y,"Created:",-1,GR_TFASCII);	GrText(wid,gc1,DIR_BG_XPOS+282,y,mfl[j]->ltime,-1,GR_TFASCII);}static voidDrawNavList(){	int i, j;		GR_COORD y;		y = NAV_RETURN_YPOS;	//curNavId = curNavPage = 0;	i = 0;	navList[i].id = RETURN_BUTTON;	navList[i++].y = y;	if (n_topItem > 0) {		y -= 38;		prevNavId = i;		navList[i].id = PREV_PAGE_BUTTON;		navList[i++].y = y;	}	if (n_lastItem < n_files - 1) {		y -= 38;		nextNavId = i;		navList[i].id = NEXT_PAGE_BUTTON;		navList[i++].y = y;	}		if (libType == RAW_PLAYLIST_LIB) {		y -= 38;		navList[i].id = SELECT_ALL_BUTTON;		navList[i++].y = y;				y -= 38;		navList[i].id = REMOVE_ALL_BUTTON;		navList[i++].y = y;				y -= 38;		navList[i].id = VIEW_PLAYLIST_BUTTON;		navList[i++].y = y;	}	else {		if (libType == PLAYLIST_LIB) {			curNavPage = 1;			y -= 38;			navList[i].id = CREATE_EDIT_BUTTON;			navList[i++].y = y;		}				if (n_files > 1) {			y -= 38;			playrandomNavId = i;			navList[i].id = PLAY_RANDOM_BUTTON;			navList[i++].y = y;		}		if (n_files >=1) {			y -= 38;			playallNavId = i;			navList[i].id = PLAY_ALL_BUTTON;			navList[i++].y = y;		}	}	n_navItems = i;	i--;		// We start from 0		for (; i >= 0; i--) {		j = navList[i].id;		y = navList[i].y;		OsdDrawPictureEx(wgt,30,y,NAV_WIDTH,NAV_HEIGHT,navItem[j].imgOff);	}	if (curNavId != SELECT_ALL_BUTTON && curNavId != REMOVE_ALL_BUTTON)		curNavId = n_navItems - 1;		if (playMode == PLAY_RANDOM) {		curNavId = playrandomNavId;	}	if (playMode == PLAY_ALL) {	   		curNavId = playallNavId;				}	if (nextButton) {		curNavId = (nextNavId)?nextNavId:prevNavId;		nextButton = GR_FALSE;	}	if (prevButton) {		curNavId = (prevNavId)?prevNavId:nextNavId;		prevButton = GR_FALSE;	}		if (curNavPage) {		OsdDrawPictureEx(wgt,30,navList[curNavId].y,NAV_WIDTH,NAV_HEIGHT,navItem[navList[curNavId].id].imgOn);	}		return;}static voidDrawDirList(){	int i, j;		GR_COORD y;		if (bkgrnd_changed) {		GrClearWindow(wid, GR_FALSE);		ShowJpeg("img/lib/libbackground.jpg");		DrawLibText(wgt);			bkgrnd_changed = GR_FALSE;	}		CancelOsd(wgt);		GrFillRect(wid,gc_pal0,30,DIR_BG_YPOS,620,400);		for (i=n_topItem,y = DIR_FG_YPOS; i <= n_lastItem; i++,y += DIR_YOFF)	{		if (libType == RAW_PLAYLIST_LIB) {			//No need for translation			if (mfl[i]->selected) 				DrawIcon(i, i);			j = i;		} 		else {			//translation needed			j = fl[i];						if (libType == PLAYLIST_LIB)				DrawIcon(j, i);		}		GrText(wid,gc1,DIR_FG_XPOS,y,mfl[j]->name,-1,GR_TFASCII);	}		DrawNavList();}static voidDrawLoadingFileMsg(char *str){	ClearOsd(wgt);	GrFillRect(wid,gc_pal6,0,LOADING_MSG_YPOS,640,53);	GrText(wid,gc1,LOADING_MSG_XPOS+20,LOADING_MSG_YPOS+20,"Loading file:",-1,GR_TFASCII);	GrText(wid,gc1,LOADING_MSG_XPOS+20,LOADING_MSG_YPOS+40,str,-1,GR_TFASCII);	return;}static voidClearLoadingFileMsg(){	GrFillRect(wid,gc_pal0,0,LOADING_MSG_YPOS,640,53);	RedrawOsd(wgt);	return;}static voidPlayNextfile(){		stopfile();	alarm(0);	CancelVolume(wgt);		if (curfId == n_lastItem && n_lastItem != n_files-1) {		curfId = n_topItem = n_lastItem + 1;		n_lastItem = n_lastItem + n_items;		if (n_lastItem >= n_files) n_lastItem = n_files - 1;		curfId = n_topItem;		if (mfl[fl[curfId]]->ftype == AUDIO_LIB) {			DrawDirList();			DrawInfo(curfId, 0);		}		PlayAVPfile(fl[curfId]);	}	else {				if (curfId < n_lastItem) {			int prev_ftype = mfl[fl[curfId]]->ftype;						curfId++;						if (mfl[fl[curfId]]->ftype == AUDIO_LIB) {				if (bkgrnd_changed)					DrawDirList();								else if (prev_ftype == AUDIO_LIB)					DrawCursor(curfId-1, gc_pal244);								DrawInfo(curfId, 0);			}						PlayAVPfile(fl[curfId]);		}		else {			if (playMode) {								n_topItem = curfId = 0;				if (n_files <= n_items ) n_items = n_files;				n_lastItem = n_items - 1;				if (mfl[fl[curfId]]->ftype == AUDIO_LIB) {					DrawDirList();					DrawInfo(curfId, 0);				}				PlayAVPfile(fl[curfId]);							}			else				OsdMainLoop(SHOW_STOP_KEYDOWN);		}	}	return;	}static voidPlayPrevfile(){			stopfile();	alarm(0);	CancelVolume(wgt);		//If not first page, draw previous page, play last item on the page	if (curfId == n_topItem && n_topItem != 0) {		n_topItem = n_topItem - n_items;		if (n_topItem < 0) n_topItem = 0;						n_lastItem = n_topItem + n_items - 1;		if (n_lastItem >= n_files) n_lastItem = n_files - 1;		curfId = n_lastItem;		if (mfl[fl[curfId]]->ftype == AUDIO_LIB) {			DrawDirList();			DrawInfo(curfId, 0);		}		PlayAVPfile(fl[curfId]);	}	//First page	else {				//Within first page		if (curfId > 0) {					int prev_ftype = mfl[fl[curfId]]->ftype;			curfId--;								if (mfl[fl[curfId]]->ftype == AUDIO_LIB) {				if (bkgrnd_changed)					DrawDirList();									else if (prev_ftype == AUDIO_LIB)						DrawCursor(curfId+1, gc_pal244);								DrawInfo(curfId, 0);			}				PlayAVPfile(fl[curfId]);		}		else {			if (playMode) {					//Wrap around				curfId = n_files - 1;								if (n_files > n_items) {									n_lastItem = n_files - 1;						n_topItem = (n_files / n_items) * n_items;				}								if (mfl[fl[curfId]]->ftype == AUDIO_LIB) {					DrawDirList();											DrawInfo(curfId, 0);				}						PlayAVPfile(fl[curfId]);			}			else				OsdMainLoop(SHOW_STOP_KEYDOWN);		}	}	return;}static voidPlayAVPfile(int fid){		// XXX - for demo id3 tag	//ID3FileInf *tags;	int filetype = mfl[fid]->ftype;		//printf("curfid=%d - path=%s - file=%s\n", curfId,	//	       mfl[fid]->path, mfl[fid]->name );	// XXX - length check	       	strncpy(filename,mfl[fid]->path,255);	strncat(filename,"/",1);	strncat(filename,mfl[fid]->name,255);		wgt->KbdHandler = PlayfileKeydownHandler;		switch (filetype) {	case AUDIO_LIB:		bkgrnd_changed = GR_FALSE;		/*		tags = (ID3FileInf *)malloc(sizeof(ID3FileInf));		memset(tags,0,sizeof(ID3FileInf));		ParseID3v1Tags(filename, tags);					printf("Author [%s]\n",tags->v1SongTitle);		printf("Title [%s]\n",tags->v1Artist);		free(tags);		*/		DrawCursor(curfId, gc_pal244);		break;				case VIDEO_LIB:		case PHOTO_LIB:						GrClearWindow(wid, GR_FALSE);		if (bkgrnd_changed == GR_FALSE)			//Clear background to black			ShowJpeg("img/lib/black.jpg");						bkgrnd_changed = GR_TRUE;		//CancelOsd(wgt);		DrawLoadingFileMsg(mfl[fid]->name);		break;	}		GetExt(mfl[fid]->name,fileext);	playfile(filename,fileext);		if (filetype == PHOTO_LIB) {						if (errMsg == SHOW_CANNOT_DISPLAY_JPEG_FILE_MSG) {			SleepWait(3, GR_TRUE);			return;		}		// Clear loading msg		ClearLoadingFileMsg();		if (playMode != PLAY_SINGLE) {			//GrDestroyTimer(wgt->tid);			//wgt->TimerHandler = PhotoLibTimerHandler;			//wgt->tid = GrCreateTimer(wid, OSD_TIMEOUT);									/* Establish a handler for SIGALRM signals. */			signal (SIGALRM, PhotoLibTimerHandler);			/* Set an alarm to go off in a little while. */			alarm (3);		}	}	return;}void PlayfileKeydownHandler(OSD_WINDOW *wPtr,DATA_POINTER dptr){	GR_EVENT *event = wPtr->lastevent;	int filetype = mfl[fl[curfId]]->ftype;	GR_KEY rk = event->keystroke.ch;		//printf("rk=0x%x\n",rk);	if (rk == SHOW_PLAY_INFO_UPDATE) return;	if (rk == SHOW_START_PLAYING) {		//This message sent when we start to play audio or video file		if (filetype == VIDEO_LIB) {			//Clear loading message			ClearLoadingFileMsg();		}		return;	}		ClearOsd(wPtr);	if (rk == SHOW_VOLUP_KEYDOWN || rk == SHOW_VOLDOWN_KEYDOWN) {		DrawVolBar(wPtr);		return;	}	

⌨️ 快捷键说明

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