Пример #1
0
s32 FileSelect()
{
	s8 text[SAL_MAX_PATH];
	s8 previewPath[SAL_MAX_PATH];
	s8 previousRom[SAL_MAX_PATH];
	u16 romPreview[262 * 186];
	bool8 havePreview = FALSE;
	s32 action=0;
	s32 smooth=0;
	u16 color=0;
	s32 i=0;
	s32 focus=ROM_SELECTOR_DEFAULT_FOCUS;
	s32 menuExit=0;
	s32 scanstart=0,scanend=0;
	u32 keys=0;
	s32 size=0, check=SAL_OK;
	
	previousRom[0] = '\0';
	
	if (FileScan() != SAL_OK)
	{
		strcpy(mRomDir, sal_DirectoryGetUser());
		if (FileScan() != SAL_OK)
		{
			MenuMessageBox("Home directory inaccessible","","",MENU_MESSAGE_BOX_MODE_PAUSE);
			mRomCount=ROM_SELECTOR_DEFAULT_FOCUS;
			menuExit = 1;
			return 0;
		}
	}
	
	focus = LoadLastSelectedRomPos(); //try to load a saved position in the romlist

	smooth=focus<<8;
	sal_InputIgnore();
	while (menuExit==0)
	{
		keys=sal_InputPollRepeat();
		
		if (keys & INP_BUTTON_MENU_SELECT)
		{
			switch(focus)
			{
				case ROM_SELECTOR_SAVE_DEFAULT_DIR: //Save default directory
					DelLastSelectedRomPos(); //delete any previously saved position in the romlist
					SaveMenuOptions(mSystemDir, DEFAULT_ROM_DIR_FILENAME, DEFAULT_ROM_DIR_EXT, mRomDir, strlen(mRomDir), 1);
					break;

				case ROM_SELECTOR_MAIN_MENU: //Return to menu
					action=0;
					menuExit=1;
					break;
				
				case ROM_SELECTOR_DEFAULT_FOCUS: //blank space - do nothing
					break;
					
				default:
					// normal file or dir selected
					if (mRomList[focus].type == SAL_FILE_TYPE_DIRECTORY)
					{
						//Check for special directory names "." and ".."
						if (sal_StringCompare(mRomList[focus].filename,".") == 0)
						{
							//goto root directory

						}
						else if (sal_StringCompare(mRomList[focus].filename,"..") == 0)
						{
							// up a directory
							//Remove a directory from RomPath and rescan
							//Code below will never let you go further up than \SD Card\ on the Gizmondo
							//This is by design.
							sal_DirectoryGetParent(mRomDir);
							FileScan();
							focus=ROM_SELECTOR_DEFAULT_FOCUS; // default menu to non menu item
														// just to stop directory scan being started 
							smooth=focus<<8;
							sal_InputIgnore();
							break;
						}
						else
						{
							//go to sub directory
							sal_DirectoryCombine(mRomDir,mRomList[focus].filename);
							FileScan();
							focus=ROM_SELECTOR_DEFAULT_FOCUS; // default menu to non menu item
														// just to stop directory scan being started 
							smooth=focus<<8;
						}
					}
					else
					{
						// user has selected a rom, so load it
						SaveLastSelectedRomPos(focus); // save the current position in the romlist
						strcpy(mRomName, mRomDir);
						sal_DirectoryCombine(mRomName,mRomList[focus].filename);
						mQuickSavePresent=0;  // reset any quick saves
						action=1;
						menuExit=1;
					}
					sal_InputIgnore();
					break;
			}
		}
		else if (keys & INP_BUTTON_MENU_CANCEL) {
			sal_InputWaitForRelease();

			action=0;
			menuExit=1;
		}
		else if ((keys & (SAL_INPUT_UP | SAL_INPUT_DOWN))
		      && (keys & (SAL_INPUT_UP | SAL_INPUT_DOWN)) != (SAL_INPUT_UP | SAL_INPUT_DOWN))
		{
			if (keys & SAL_INPUT_UP)
				focus--; // Up
			else if (keys & SAL_INPUT_DOWN)
				focus++; // Down
		}
		else if ((keys & (SAL_INPUT_LEFT | SAL_INPUT_RIGHT))
		      && (keys & (SAL_INPUT_LEFT | SAL_INPUT_RIGHT)) != (SAL_INPUT_LEFT | SAL_INPUT_RIGHT))
		{
			if (keys & SAL_INPUT_LEFT)
				focus-=12;
			else if (keys & SAL_INPUT_RIGHT)
				focus+=12;
			
			if (focus>mRomCount-1)
				focus=mRomCount-1;
			else if (focus<0)
				focus=0;

			smooth=(focus<<8)-1;
		}

		if (focus>mRomCount-1)
		{
			focus=0;
			smooth=(focus<<8)-1;
		}
		else if (focus<0)
		{
			focus=mRomCount-1;
			smooth=(focus<<8)-1;
		}

		// Draw screen:
		PrintTitle("ROM selection");

		if (strcmp(mRomList[focus].displayName, previousRom) != 0) {
			char dummy[SAL_MAX_PATH], fileNameNoExt[SAL_MAX_PATH];
			sal_DirectorySplitFilename(mRomList[focus].filename, dummy, fileNameNoExt, dummy);
			sprintf(previewPath, "%s/previews/%s.%s", sal_DirectoryGetHome(), fileNameNoExt, "png");
			strcpy(previousRom, mRomList[focus].displayName);
			havePreview = sal_ImageLoad(previewPath, &romPreview, 262, 186) != SAL_ERROR;
			if (havePreview) {
				sal_VideoBitmapDim(romPreview, 262 * 186);
			}
		}

		if (havePreview) {
			sal_ImageDraw(romPreview, 262, 186, 0, 16);
		}

		smooth=smooth*7+(focus<<8); smooth>>=3;

		scanstart=focus-15;
		if (scanstart<0) scanstart=0;
		scanend = focus+15;
		if (scanend>mRomCount) scanend=mRomCount;
		
		for (i=scanstart;i<scanend;i++)
		{
			s32 x=0,y=0;
      
			y=(i<<4)-(smooth>>4);
			x=0;
			y+=112 - 28;
			if (y<=48 - 28 || y>=232 - 36) continue;
           
			if (i==focus)
			{
				color=SAL_RGB(31,31,31);
				PrintBar(y-4);
			}
			else
			{
				color=SAL_RGB(31,31,31);
			}

			 
			// Draw Directory icon if current entry is a directory
			if(mRomList[i].type == SAL_FILE_TYPE_DIRECTORY)
			{
				sprintf(text,"<%s>",mRomList[i].displayName);
				sal_VideoPrint(x,y,text,color);
			}
			else
			{
				sal_VideoPrint(x,y,mRomList[i].displayName,color);
			}

			
		}

		sal_VideoPrint(0,4,mRomDir,SAL_RGB(31,8,8));

		sal_VideoFlip(1);
		usleep(10000);
	}
	sal_InputIgnore();

	freeRomLists();

	return action;
}
Пример #2
0
int dialog_end(int* rombrowsing){

	guievent_t ev;
	field_t *field;
	dirty_t dirty;

	int i, pad, pad2, exit=0, delay=0;
	int up=0, down=0, left=0, right=0;
	int loopcount=0;

	gui_setclip(0,0,gui.w,gui.h);
	gui_cls();

	dialog->pos = 0;
	dialog->title_x = (gui.w-font_textwidth(dfont,dialog->title))/2;
	dialog->status_x = (gui.w-font_textwidth(dfont,dialog->status))/2;
	dialog->field_h = dfont->height;
	dialog->title_h = dfont->height+8;
	dialog->status_h = dfont->height+8;
	dialog->visible_count = (gui.h-dialog->title_h-dialog->status_h)/dialog->field_h;
	if(dialog->visible_count > dialog->field_count) dialog->visible_count = dialog->field_count;
	dialog->client_h = dialog->visible_count * dialog->field_h;
	dialog->title_h = (gui.h -dialog->client_h )/2;
	dialog->status_h = gui.h - dialog->title_h - dialog->client_h;
	
	if(rombrowsing==1){
		dialog->selected = LoadLastSelectedRomPos();
		if(dialog->selected >= dialog->pos+dialog->visible_count) {
			dialog->pos = dialog->selected-dialog->visible_count+1;
		}
	}

	pad = dpad;
	pad2 = dpad << 1;

	for(i=0; i<dialog->field_count; i++){
		int prompt_w=0, body_w=0;

		field = &(dialog->fields[i]);

		prompt_w = field->prompt_w;
		if(prompt_w) prompt_w += pad2;
		if(prompt_w > dialog->prompt_w) dialog->prompt_w = prompt_w;

		body_w = field->body_w;
		if(body_w) body_w += pad2;
		if(body_w > dialog->body_w) dialog->body_w = body_w;

		if(dialog->selected==i && !(field->flags & FIELD_SELECTABLE)) dialog->selected++;
	}

	if(dialog->selected == dialog->field_count) dialog->selected = -1;

	if((dialog->prompt_w + dialog->body_w) > gui.w){
		if(dialog->prompt_w>gui.w) dialog->prompt_w = gui.w;
		dialog->body_w = gui.w-dialog->prompt_w;
	}

	dialog->prompt_x = (gui.w - dialog->prompt_w - dialog->body_w)/2;
	dialog->body_x = dialog->prompt_x + dialog->prompt_w;

	dirty.update=0;
	dirty.field_start = 0;
	dirty.field_count = dialog->visible_count;
	dirty.title = 1;
	dirty.status = 1;

	dialog_drawdirty(&dirty);
	dirty.update = gui_update();

	while(!exit){

		field = &(dialog->fields[dialog->selected]);

		if(gui_pollevent(&ev)){
			switch(ev.key){
				case GUI_UP:
					up = ev.state;
					break;
				case GUI_DOWN:
					down = ev.state;
					break;
				case GUI_LEFT:
					left = ev.state;
					break;
				case GUI_RIGHT:
					right = ev.state;
					break;
				case GUI_SELECT:
					if(ev.state && field->type == FIELD_TEXT)
						exit = dialog->selected+1;
					break;
				case GUI_BACK:
					if(ev.state) exit = -1;
					break;
			}
			delay = ev.state ? -1 : 0;
		}

		if(delay>0){
			delay--;
		} else {
			if(delay<0) delay = 4;
			if(dirty.update == GUI_FLIP)
			dialog_drawdirty(&dirty);

			if(up){
				int s = dialog->selected;
				while(--s>=0 && !(dialog->fields[s].flags & FIELD_SELECTABLE));
				if(s>=0){
					if(s < dialog->pos){
						dialog->pos = s;
						if(dirty.update){
							dirty.field_start = 0;
							dirty.field_count = dialog->visible_count;
							dirty.title = 1;
							dirty.status = 1;
						}
					} else if(dirty.update){
						dirty.field_start = s-dialog->pos;
						dirty.field_count = dialog->selected-s+1;
						dirty.title = 0;
						dirty.status = 0;
					}
					dialog->selected = s;
				} else if(s<0){                      /* LOOP */ 
					dialog->pos = dialog->field_count-dialog->visible_count;
					s = dialog->field_count-1;
					
					loopcount=0;
					checkloop_up:           /*prevents the selection of a non-selectable field when looping the selection*/
					if(!(dialog->fields[s].flags & FIELD_SELECTABLE)){
						s--;
						loopcount++;
						if(loopcount < dialog->visible_count) goto checkloop_up;  /*set a limited number of loops, equal to the visible number of lines, to prevent an infinite loop when all fields are non-selectable*/
					}
					
					if(dirty.update){
						dirty.field_start = 0;
						dirty.field_count = dialog->visible_count;
						dirty.title = 1;
						dirty.status = 1;
					}
					dialog->selected = s;
				}
				
			} else if(down) {

				int s = dialog->selected;

				while(++s<=(dialog->field_count-1) && !(dialog->fields[s].flags & FIELD_SELECTABLE));
				if(s<dialog->field_count){
					if(s >= dialog->pos+dialog->visible_count) {
						dialog->pos = s-dialog->visible_count+1;
						if(dirty.update){
							dirty.field_start = 0;
							dirty.field_count = dialog->visible_count;
							dirty.title = 1;
							dirty.status = 1;
						}
					} else if(dirty.update){
						dirty.field_start = dialog->selected-dialog->pos;
						dirty.field_count = s-dialog->selected+1;
						dirty.title = 0;
						dirty.status = 0;
					}
					dialog->selected = s;
				} else if(s>=dialog->field_count){     /* LOOP */
					dialog->pos = 0;
					s = 0;
					
					loopcount=0;
					checkloop_down:           /*prevents the selection of a non-selectable field when looping the selection*/
					if(!(dialog->fields[s].flags & FIELD_SELECTABLE)){
						s++;
						loopcount++;
						if(loopcount < dialog->visible_count) goto checkloop_down;  /*set a limited number of loops, equal to the visible number of lines, to prevent an infinite loop when all fields are non-selectable*/
					}
					
					if(dirty.update){
						dirty.field_start = 0;
						dirty.field_count = dialog->visible_count;
						dirty.title = 1;
						dirty.status = 1;
					}
					dialog->selected = s;
				}
				
			} else if(dialog->field_count > dialog->visible_count && field->type == FIELD_TEXT){  /* FAST SCROLLING */		
				if(left){
					int s = dialog->selected;
					int p = dialog->pos;
					
					if (p <= 0 && s <= 0){
						p = dialog->field_count-dialog->visible_count;
						s = dialog->field_count-(dialog->visible_count-dialog->selected);
					} else {
						p = dialog->selected-dialog->visible_count;
						s = dialog->selected-dialog->visible_count;
					}
					if (p < 0){
						p = 0;
					}
					if (s < 0){
						s = 0;
					}
					if(dirty.update){
						dirty.field_start = 0;
						dirty.field_count = dialog->visible_count;
						dirty.title = 1;
						dirty.status = 1;
					}
					dialog->pos = p;
					dialog->selected = s;
					
				} else if(right){
					int s = dialog->selected;
					int p = dialog->pos;
					
					if (p >= dialog->field_count-dialog->visible_count && s >= dialog->field_count-1){
						p = 0;
						s = (dialog->selected+dialog->visible_count)-dialog->field_count;
					} else {
						p = dialog->selected+1;
						s = dialog->selected+dialog->visible_count;
					}
					if (p > (dialog->field_count-dialog->visible_count)){
						p = dialog->field_count-dialog->visible_count;
					}
					if (s > dialog->field_count-1){
						s = dialog->field_count-1;
					}
					if(dirty.update){
						dirty.field_start = 0;
						dirty.field_count = dialog->visible_count;
						dirty.title = 1;
						dirty.status = 1;
					}
					dialog->pos = p;
					dialog->selected = s;
				}
				
			} else if(field->type == FIELD_OPTION){

				if(left){
					(*field->selected)--;
					if(*field->selected < 0) *field->selected = field->count-1;
					field->body = field->options[*field->selected];
					if(dirty.update){
						dirty.field_start = dialog->selected-dialog->pos;
						dirty.field_count = 1;
						dirty.title = 0;
						dirty.status = 0;
					}
				} else if(right){
					(*field->selected)++;
					if(*field->selected >= field->count) *field->selected = 0;
					field->body = field->options[*field->selected];
					if(dirty.update){
						dirty.field_start = dialog->selected-dialog->pos;
						dirty.field_count = 1;
						dirty.title = 0;
						dirty.status = 0;
					}
				}
			}

			dialog_drawdirty(&dirty);
			dirty.update = gui_update();
			#if defined(DINGOO_OPENDINGUX)
			dialog_drawdirty(&dirty);         /*Fix for flickering menu when using double buffer*/
			dirty.update = gui_update();      /*Paints the menu 2 times to prevent flickering*/
			#endif /*DINGOO_OPENDINGUX*/
		}

		gui_sleep(50000);
	}

	if(exit==-1) exit = 0;
	if(rombrowsing==1){
		if(exit>=1){
			SaveLastSelectedRomPos(dialog->selected);
		}
	}
	
	free(dialog);
	dialog = NULL;
	return exit;
}