int main(void)
{	
	entry* entries = main_create_entries();
	list* menu = create_list(0,24,25,entries,MAINMENU_SIZE);
	nio_scrbuf_init();
	do
	{
		int selection = update_list(menu);
		if(selection != -1)
		{
			wait_no_key_pressed();
			switch(selection)
			{
				case 0:
					display_tasks_screen();
					break;
				case 1:
					display_pools_screen();
					break;
				case 2:
					display_events_screen();
					break;
				case 3:
					display_queues_screen();
					break;
				case 4:
					display_semaphores_screen();
					break;
				case 5:
					display_mailboxes_screen();
					break;
				default:
					display_settings_screen();
					break;
			}
		}
		
		nio_scrbuf_clear();
		
		nio_grid_printf(0,0,0,0,NIO_COLOR_WHITE,NIO_COLOR_BLACK,"TI-Nspire Task Manager (built %s %s)",__DATE__,__TIME__);
		int i;
		for(i = 0; i < 53; i++)
		{
			nio_grid_putc(0,0,i,2,'-',NIO_COLOR_WHITE,NIO_COLOR_BLACK);
			nio_grid_putc(0,0,i,28,'-',NIO_COLOR_WHITE,NIO_COLOR_BLACK);
		}
		draw_list(menu);
		nio_grid_puts(0,0,0,29,"Use UP/DOWN keys to navigate, ENTER to select",NIO_COLOR_WHITE,NIO_COLOR_BLACK);
		
		nio_scrbuf_flip();
		wait_key_pressed();
	} while(!isKeyPressed(KEY_NSPIRE_ESC));
	
	nio_scrbuf_free();
	free(entries);
	free(menu);
	return 0;
}
Exemple #2
0
int Read()
{
	VRAM   = init_VRAM();			AllClr_VRAM( VRAM   );
	char * VRAM_A = init_VRAM();	AllClr_VRAM( VRAM_A );
	char * VRAM_B = init_VRAM();	AllClr_VRAM( VRAM_B );
	int total_page , page = 0 , i ,last_key_pressed=0;
	char buff[1000] , statue_bar[100];
	int auto_down = 0 , _auto = 0 , mark = 1 ;
	int user_contrast = *p_contrast;
	long auto_time = 0 ;
	int msg_utf8 = 0;
	auto_down = _auto = 0 ;
	strcpy( txtname , fname );
	TXT = fopen( txtname , "rb" ) ;
	fseek(TXT , 0 , SEEK_END);
	filesize = ftell( TXT );
	
	total_page = divid();
	
	memset( buff , 0x0 , 1000 );
	
	load_mark( &page , total_page , 1 );

	fseek( TXT , pagepos[page] , SEEK_SET );
	fread( buff , pagepos[ page+1 ] - pagepos[ page ] , 1 , TXT );
	AllFill_VRAM(VRAM_A,cl_bg);
	PrintChStr( VRAM_A , 0 , 0 , buff , cl_fg , cl_bg );

	PutDisp_DDVRAM( VRAM_A );
	auto_down = 0 ;
	while( 1 )
	{
		if(isKeyPressed(KEY_NSPIRE_SCRATCHPAD))
		{
			wait_no_key_pressed();
			if(msg_utf8==0)
				i = show_msgbox_3b( "提示" , "调用API必须保证文本为UTF-8编码,也就是此时用nNovel无法正常阅读,要继续吗?" , "确定" , "取消" ,"确定且不再提示" );
			else
				i = 1;
			if( i == 3 )
			{
				i = 1;
				msg_utf8 = 1;
			}
			if( i == 1 )
			{
				wait_no_key_pressed();
				show_msgbox( "本页内容:" , buff );
			}
		}
		if(isKeyPressed(KEY_NSPIRE_MULTIPLY))
		{
			if( is_cx && (*p_contrast)< 225)
				(*p_contrast)++;
			else if( (!is_cx) && (*p_contrast) < 0xc0 )
				(*p_contrast)++;
		}
		else if(isKeyPressed(KEY_NSPIRE_DIVIDE))
		{
			if( is_cx && (*p_contrast)> 1 )
				(*p_contrast)--;
			else if( (!is_cx) && (*p_contrast) >50 )
				(*p_contrast)--;
		}
		else if(isKeyPressed(KEY_NSPIRE_TAB))
		{
			i = num_input(VRAM , 30 , 30 , "  ����ҳ��" );
			if( i == -1) continue;
			else if( i == 0 ){ page = 0;}
			else if( i > total_page){ page = total_page;}
			else page = i - 1;
			memset( buff , 0x0 , 1000 );
			fseek( TXT , pagepos[page] , SEEK_SET );
			fread( buff , pagepos[ page +1 ] - pagepos[ page ] , 1 , TXT );
			AllFill_VRAM(VRAM_A,cl_bg);
			PrintChStr( VRAM_A , 0 , 0 , buff , cl_fg , cl_bg );
			PutDisp_DDVRAM( VRAM_A );
			wait_no_key_pressed();
		}
		else if(isKeyPressed(KEY_NSPIRE_DOC))
		{
			save_mark( page , total_page , 0 );
			wait_no_key_pressed();
		}
		else if(isKeyPressed(KEY_NSPIRE_MENU))
		{
			load_mark( &page , total_page , 0 );
			memset( buff , 0x0 , 1000 );
			fseek( TXT , pagepos[page] , SEEK_SET );
			fread( buff , pagepos[ page +1 ] - pagepos[ page ] , 1 , TXT );
			AllFill_VRAM(VRAM_B,cl_bg);
			PrintChStr( VRAM_A , 0 , 0 , buff , cl_fg , cl_bg );
			PutDisp_DDVRAM( VRAM_A );
			wait_no_key_pressed();
		}
		else if(isKeyPressed(KEY_NSPIRE_SHIFT))
		{
			if(cl_bg == 15)
			{
				cl_fg = 15;
				cl_bg = 0;
			}
			else
			{
				cl_fg = 0;
				cl_bg = 15;
			}
			memset( buff , 0x0 , 1000 );
			fseek( TXT , pagepos[page] , SEEK_SET );
			fread( buff , pagepos[ page +1 ] - pagepos[ page ] , 1 , TXT );
			AllFill_VRAM(VRAM_A,cl_bg);
			PrintChStr( VRAM_A , 0 , 0 , buff , cl_fg , cl_bg );
			PutDisp_DDVRAM( VRAM_A );
			wait_no_key_pressed();
		}
		
		if((*p_RTC - auto_time)%(_auto) != 0)
			mark = 0;
		if( ( isKeyPressed(KEY_NSPIRE_DOWN ) || isKeyPressed(KEY_NSPIRE_MINUS )|| auto_down == 1 )&& page < total_page )
		{
			auto_down = 0;
			page++;
			memset( buff , 0x0 , 1000 );
			fseek( TXT , pagepos[page] , SEEK_SET );
			fread( buff , pagepos[ page +1 ] - pagepos[ page ] , 1 , TXT );
			if( cl_bg != 15 )
				AllFill_VRAM(VRAM_B,cl_bg);
			else
				AllClr_VRAM(VRAM_B);
			PrintChStr( VRAM_B , 0 , 0 , buff , cl_fg , cl_bg );
			if( config.show_page_slide == 1 )
				slide_down(statue_bar , VRAM_A , VRAM_B , 1 );
			else
			{
				Fill_Rect_VRAM( VRAM_B , 0 , 224 , 320 , 240 , 0 );
				PrintChStr( VRAM_B , 0 , 224 , statue_bar , 15 , 0 );
				PutDisp_DDVRAM(VRAM_B);
				for( i=0 ; i<=FIRST_KEY_WAIT ; i++ )
				{
					if((!isKeyPressed(KEY_NSPIRE_DOWN )|| isKeyPressed(KEY_NSPIRE_MINUS )))
						break;
					if(last_key_pressed)
						break;
					sleep(1);
					if( i == FIRST_KEY_WAIT )
						last_key_pressed = 1;
				}
			}
			memcpy(VRAM_A,VRAM_B,SCREEN_BYTES_SIZE);
		}
		else if( isKeyPressed(KEY_NSPIRE_UP )|| isKeyPressed(KEY_NSPIRE_PLUS ) )
		{
			if( page == 0 )
				continue;
			page --;
			memset( buff , 0x0 , 1000 );
			fseek( TXT , pagepos[page] , SEEK_SET );
			fread( buff , pagepos[ page +1 ] - pagepos[ page ], 1 , TXT );
			AllFill_VRAM(VRAM_B,cl_bg);
			PrintChStr( VRAM_B , 0 , 0 , buff , cl_fg , cl_bg );
			if( config.show_page_slide == 1 )
				slide_up( statue_bar , VRAM_B , VRAM_A , 1 );
			else
			{
				Fill_Rect_VRAM( VRAM_B , 0 , 224 , 320 , 240 , 0 );
				PrintChStr( VRAM_B , 0 , 224 , statue_bar , 15 , 0 );
				PutDisp_DDVRAM(VRAM_B);
				for( i=0 ; i<=FIRST_KEY_WAIT ; i++ )
				{
					if((!isKeyPressed(KEY_NSPIRE_UP )|| isKeyPressed(KEY_NSPIRE_PLUS )))
						break;
					if(last_key_pressed)
						break;
					sleep(1);
					if( i == FIRST_KEY_WAIT )
						last_key_pressed = 1;
				}
			}
			memcpy(VRAM_A,VRAM_B,SCREEN_BYTES_SIZE);
		}
		else
			last_key_pressed = 0;
		memcpy(VRAM,VRAM_A,SCREEN_BYTES_SIZE);
		Fill_Rect_VRAM( VRAM , 0 , 224 , 320 , 240 , 0 );
		if( config.show_time )
		{
			update_time();
			if( config.show_second )
				sprintf(statue_bar , " %d%d:%d%d:%d%d     %5d/%5d   %4s", time.hour/10 , time.hour%10 , time.minute/10, time.minute%10 , time.second/10 , time.second%10 , page +1 , total_page +1 , _auto == 0?"":"Auto");
			else
				sprintf(statue_bar , " %d%d:%d%d        %5d/%5d   %4s", time.hour/10 , time.hour%10 , time.minute/10, time.minute%10 , page +1 , total_page +1 ,_auto == 0?"":"Auto");
		}
		else 
		{
			sprintf(statue_bar , "              %5d/%5d", page +1 , total_page +1 );
		}
		PrintChStr( VRAM , 0 , 224 , statue_bar , 15 , 0 );
//		DrawMiniString_VRAM(VRAM , 0 , 228 , statue_bar , 15 , 0 );
		PutDisp_DDVRAM(VRAM);
			
		if( ! config.show_time )
		{
			if( !(isKeyPressed(KEY_NSPIRE_UP)||isKeyPressed(KEY_NSPIRE_DOWN)) )
				wait_key_pressed();
		}
		
		if( isKeyPressed(KEY_NSPIRE_ESC))
		{
			if(isKeyPressed(KEY_NSPIRE_CTRL))
				goto exit;
			switch(menu(VRAM,10,10,"    �˵�\nҳ����ת(Tab)\n�Զ���ҳ\n��ȡ��ǩ(menu)\n������ǩ(doc)\n����\nҹ��ģʽ(shift)\n�����ǩ��ҳ���˳�\n����API�鿴��ҳ(��ǩ��)\n�˳�(ctrl+esc)\n","\n������λ����ת������λ��\n����/�ر��Զ���ҳ\n����ǩ�ļ��ж�ȡ����\n����ǩ�ļ���д�����\n�鿴���޸�����\n����ҹ��ģʽ(��ɫ)\n��������ɵ�������ǩ�ͷ�ҳ�Ľ���ļ�\n����MsgBox����ʾ��ҳ����\n�˳�����\n") )
			{
				case 1://ҳ����ת
				{
					i = num_input(SCREEN_BASE_ADDRESS , 30 , 30 , "  ����ҳ��" );
					if( i == -1) break;
					else if( i == 0 ){ page = 0;}
					else if( i > total_page){ page = total_page;}
					else page = i - 1;
					memset( buff , 0x0 , 1000 );
					fseek( TXT , pagepos[page] , SEEK_SET );
					fread( buff , pagepos[ page +1 ] - pagepos[ page ] , 1 , TXT );
					AllFill_VRAM(VRAM_A,cl_bg);
					PrintChStr( VRAM_A , 0 , 0 , buff , cl_fg , cl_bg );
					PutDisp_DDVRAM( VRAM_A );
					break;
				}
				case 2://�Զ���ҳ
				{
					if( _auto != 0 )
					{
						_auto = 0 ;
						mark = 1;
						break;
					}
					_auto = num_input( SCREEN_BASE_ADDRESS , 30 , 30 , "��������" );
					if(_auto == -1)
						_auto = 0;
					auto_time = *p_RTC;
					
					break;
				}
				case 3: //��ȡ��ǩ
				{
					load_mark( &page , total_page , 0 );
					memset( buff , 0x0 , 1000 );
					fseek( TXT , pagepos[page] , SEEK_SET );
					fread( buff , pagepos[ page +1 ] - pagepos[ page ] , 1 , TXT );
					AllFill_VRAM(VRAM_B,cl_bg);
					PrintChStr( VRAM_A , 0 , 0 , buff , cl_fg , cl_bg );
					PutDisp_DDVRAM( VRAM_A );
					break;
				}
				case 4: save_mark( page , total_page , 0 );break;//������ǩ
				case 5:	//����
				{
					setup_config();
					memset( buff , 0x0 , 1000 );
					fseek( TXT , pagepos[page] , SEEK_SET );
					fread( buff , pagepos[ page +1 ] - pagepos[ page ] , 1 , TXT );
					AllFill_VRAM(VRAM_A,cl_bg);
					PrintChStr( VRAM_A , 0 , 0 , buff , cl_fg , cl_bg );
					PutDisp_DDVRAM( VRAM_A );
					break;
				}
				case 6: //��ɫ
				{
					if(cl_bg == 15)
					{
						cl_fg = 15;
						cl_bg = 0;
					}
					else
					{
						cl_fg = 0;
						cl_bg = 15;
					}
					memset( buff , 0x0 , 1000 );
					fseek( TXT , pagepos[page] , SEEK_SET );
					fread( buff , pagepos[ page +1 ] - pagepos[ page ] , 1 , TXT );
					AllFill_VRAM(VRAM_A,cl_bg);
					PrintChStr( VRAM_A , 0 , 0 , buff , cl_fg , cl_bg );
					PutDisp_DDVRAM( VRAM_A );
					break;
				}
				case 7: //�����ǩ
				{
					char path[ 50 ];
					for( i = 0 ; i < strlen(txtname) - 8 ; i ++ )
						path[i] = txtname[i] ;
					path[ i ] = 0;
					strcat( path , ".div" );
					remove(path);
					for( i = 0 ; i < strlen(txtname) - 8 ; i ++ )
						path[i] = txtname[i] ;
					path[ i ] = 0;
					strcat( path , ".sav" );
					remove(path);
					goto exit2;
				}
				case 8://API
				{
					wait_no_key_pressed();
					if(msg_utf8==0)
						i = show_msgbox_3b( "提示" , "调用API必须保证文本为UTF-8编码,也就是此时用nNovel无法正常阅读,要继续吗?" , "确定" , "取消" ,"确定且不再提示" );
					else
						i = 1;
					if( i == 3 )
					{
						i = 1;
						msg_utf8 = 1;
					}
					if( i == 1 )
					{
						wait_no_key_pressed();
						show_msgbox( "本页内容:" , buff );
						break;
					}
					else
						break;
				}
				case 9: goto exit;//�˳�
				default :wait_no_key_pressed();break;
			}
			wait_no_key_pressed();
		}
		if( config.auto_save )
			if( page%config.auto_save_time==0 )
				save_mark( page , total_page , 1 );
		if( (*p_RTC - auto_time)%(_auto) == 0 && mark == 0)
		{
			mark = 1 ;
			auto_down = 1 ;
			auto_time = *p_RTC;
		}
	}
	exit:
	save_mark( page , total_page , 1 );
	exit2:
	* p_contrast = user_contrast;
	fclose( TXT );
	close_VRAM( VRAM_A );close_VRAM( VRAM_B );
	close_VRAM( VRAM );
	return 0;
}
Exemple #3
0
// Run a program. Returns 0xDEAD if can't run it or 0xBEEF if the error dialog should be skipped. Else returns the program return code.
// If resident_ptr isn't NULL, the program's memory block isn't freed and is stored in resident_ptr. It may be freed later with ld_free(). 
// Resident program shouldn't use argv after returning.
// argsn/args don't include the program path. args doesn't need to be NULL terminated. Can be 0/NULL.
int ld_exec_with_args(const char *path, int argsn, char *args[], void **resident_ptr) {
	char prgm_path[FILENAME_MAX];
	char doc_path[FILENAME_MAX]; // non const
	unsigned i;
	char **argv = NULL;
	char **argvptr;
	int argc;
	int ret;
	BOOL isassoc = FALSE;
	strcpy(doc_path, path);
	strcpy(prgm_path, path); // may deffer if using file association

	// File association
	char extbuf[FILENAME_MAX];
	strcpy(extbuf, prgm_path);
	char *ext = strrchr(extbuf, '.');
	if (!ext || ext == extbuf) {
		puts("ld_exec: can't find file extension");
		return 0xDEAD; // shouldn't happen, all files have a .tns extension
	}
	*ext = '\0'; // keep the extension before .tns
	ext = strrchr(extbuf, '.');
	unsigned pathlen = strlen(extbuf);
	// without '.'
	#define MAX_EXT_LEN 8
	if (ext && extbuf + pathlen - ext <= (MAX_EXT_LEN+1) && extbuf + pathlen - ext > 1) { // looks like an extension
		cfg_open();
		char ext_key[4 + MAX_EXT_LEN + 1]; // ext.extension
		strcpy(ext_key, "ext");
		strcat(ext_key, ext);
		char *prgm_name_noext = cfg_get(ext_key);
		if (prgm_name_noext) {
			char prgm_name[FILENAME_MAX + 4];
			strcpy(prgm_name, prgm_name_noext);
			strcat(prgm_name, ".tns");
			struct assoc_file_each_cb_ctx context = {prgm_name, prgm_path, &isassoc};
			file_each("/", assoc_file_each_cb, &context);
		}
		cfg_close();
	}

	ld_bin_format = LD_ERROR_BIN;

	uint32_t signature;

	NUC_FILE *prgm = nuc_fopen(prgm_path, "rb");
	if(nuc_fread(&signature, sizeof(signature), 1, prgm) != 1)
	{
		// empty file?
		nuc_fclose(prgm);
		return 0xDEAD;
	}

	nuc_fseek(prgm, 0, SEEK_SET);

	void *base = 0;
	int (*entry)(int argc, char *argv[]);

	switch(signature)
	{
	case 0x00475250: //"PRG\0"
		if((ret = ndless_load(prgm_path, prgm, &base, &entry)) == 0)
		{
			nuc_fclose(prgm);
			ld_bin_format = LD_PRG_BIN;
			break;
		}

		nuc_fclose(prgm);
		return ret == 1 ? 0xDEAD : 0xBEEF;
	case 0x544c4662: //"bFLT"
		if(bflt_load(prgm, &base, &entry) == 0)
		{
			nuc_fclose(prgm);
			ld_bin_format = LD_BFLT_BIN;
			break;
		}

		nuc_fclose(prgm);
		return 0xDEAD;
	case 0x6e68655a: //"Zehn"
		if((ret = zehn_load(prgm, &base, &entry)) == 0)
		{
			nuc_fclose(prgm);
			ld_bin_format = LD_ZEHN_BIN;
			break;
		}
		if(base && base != emu_debug_alloc_ptr)
			free(base);

		nuc_fclose(prgm);
		return ret == 1 ? 0xDEAD : 0xBEEF;
	default:
		nuc_fclose(prgm);
		return 0xDEAD;
	}	
	
	int intmask = TCT_Local_Control_Interrupts(-1); /* TODO workaround: disable the interrupts to avoid the clock on the screen */
	wait_no_key_pressed(); // let the user release the Enter key, to avoid being read by the program
	void *savedscr = malloc(SCREEN_BYTES_SIZE);
	if (!savedscr) {
		puts("ld_exec: can't malloc savedscr");
		ret = 0xDEAD;
		goto ld_exec_with_args_quit;
	}
	memcpy(savedscr, (void*) SCREEN_BASE_ADDRESS, SCREEN_BYTES_SIZE);
	
	argc = 1 + argsn;
	if (isassoc)
		argc++;

	argv = malloc((argc + 1) * sizeof(char*));
	if (!argv) {
		puts("ld_exec: can't malloc argv");
		ret = 0xDEAD;
		goto ld_exec_with_args_quit;
	}
	argv[0] = prgm_path;
	argvptr = &argv[1];
	if (isassoc) {
		argv[1] = doc_path;
		argvptr++;
	}
	if (args)
		memcpy(argvptr, args, argsn * sizeof(char*));

	argv[argc] = NULL;
	
	if (has_colors) {
		volatile unsigned *palette = (volatile unsigned*)0xC0000200;
		for (i = 0; i < 16/2; i++)
			*palette++ = ((i * 2 + 1) << (1 + 16)) | ((i * 2 + 1) << (6 + 16)) | ((i * 2 + 1) << (11 + 16)) | ((i * 2) << 1) | ((i * 2) << 6) | ((i * 2) << 11); // set the grayscale palette
		ut_disable_watchdog(); // seems to be sometimes renabled by the OS
	}
	
	is_current_prgm_resident = FALSE;
	clear_cache();
	ret = entry(argc, argv); /* run the program */
	if (has_colors)
		lcd_incolor(); // in case not restored by the program

	if (!plh_noscrredraw)
		memcpy((void*) SCREEN_BASE_ADDRESS, savedscr, SCREEN_BYTES_SIZE);
	
ld_exec_with_args_quit:
	free(savedscr);
	wait_no_key_pressed(); // let the user release the key used to exit the program, to avoid being read by the OS
	TCT_Local_Control_Interrupts(intmask);
	if (ret != 0xDEAD && resident_ptr) {
		*resident_ptr = base;
		return ret;
	}
	if (is_current_prgm_resident) // required by the program itself
		return ret;
	if (!emu_debug_alloc_ptr)
	    free(base);

	free(argv);
	return ret;
}
Exemple #4
0
int main(int argc, char *argv[])
{
   wait_no_key_pressed();

   // Initialize console 1.
   nio_console c1;

   nio_init(&c1, NIO_MAX_COLS, NIO_MAX_ROWS, 0, 0, NIO_COLOR_BLACK, NIO_COLOR_WHITE, TRUE);
   nio_set_default(&c1);
   nio_fflush(&c1);

   nio_printf("%s built at %s, %s\n", __FILE__, __DATE__, __TIME__);
   nio_printf("For help with this console, type \"help\"!\n\n");
   while (1)
   {
      char text[100];
      nio_printf("> ");
      // If no text was entered, exit
      if (!nio_gets(text))
         continue;

      // Check for interesting text
      if (!strcmp(text, "help")) {
         nio_printf("HexCellsLib Test Help\n");
         nio_printf("  runtests\n");
         nio_printf("    Runs the unit tests\n");
         nio_printf("  setcursor cursor\n");
         nio_printf("    Set the cursor type.\n");
         nio_printf("    cursor can be from 0-3, where:\n");
         nio_printf("      0 is a block cursor\n");
         nio_printf("      1 is an underscore cursor\n");
         nio_printf("      2 is a verical bar cursor\n");
         nio_printf("      3 is a custom cursor\n");
         nio_printf("  setcursorwidth\n");
         nio_printf("    Set the cursor width.\n");
         nio_printf("  clear\n");
         nio_printf("    Clear the console.\n");
         nio_printf("  exit\n");
         nio_printf("    Exit this console.\n");
      }

      if (!strcmp(text, "setcursor 0")) {
         nio_cursor_type(&c1, NIO_CURSOR_BLOCK);
         nio_printf(" Cursor type is now set to block cursor.\n");
      }
      if (!strcmp(text, "setcursor 1")) {
         nio_cursor_type(&c1, NIO_CURSOR_UNDERSCORE);
         nio_printf(" Cursor type is now set to underscore cursor.\n");
      }
      if (!strcmp(text, "setcursor 2")) {
         nio_cursor_type(&c1, NIO_CURSOR_VERTICAL);
         nio_printf(" Cursor type is now set to vertical bar cursor.\n");
      }

      if (!strcmp(text, "setcursorwidth")) {
         nio_printf("Specify cursor width: ");
         char num[10];
         nio_gets(num);
         nio_cursor_width(&c1, atoi(num));
      }

      if (StartsWith(text, "RunTests")) {
         RunTests();
      }

      if (!strcmp(text, "clear")) {
         nio_clear(&c1);
      }

      if (StartsWith(text, "exit")) break;
   }

   nio_free(&c1);

   //if(has_colors)
   //	lcd_incolor();

   return 0;
}
Exemple #5
0
int MainMenuLoop(struct MainMenu* pMenu)
{
   Gc gc = gui_gc_global_GC();

   gui_gc_begin(gc);

   DrawBackground(pMenu->m_pBackground, &gc);

   DrawMenuPieces(pMenu, &gc);

   gui_gc_setColorRGB(gc, 0, 0, 0);

   char* strMenu = "n\0S\0q\0u\0a\0r\0e\0C\0e\0l\0l\0s\0\0";
   gui_gc_drawString(gc, strMenu, 110, 5, GC_SM_TOP);

   char* strOptions = "O\0p\0t\0i\0o\0n\0s\0\0";
   gui_gc_drawString(gc, strOptions, 75, SCREEN_HEIGHT-30, GC_SM_TOP);

   char* strHelp = "H\0e\0l\0p\0\0";
   gui_gc_drawString(gc, strHelp, SCREEN_WIDTH-115, SCREEN_HEIGHT-30, GC_SM_TOP);

   if( pMenu->m_eChoice == Options ) {
      gui_gc_setColorRGB(gc, 255, 0, 0);
      gui_gc_drawRect(gc, 73, SCREEN_HEIGHT-30, 60, 20);
   }
   else if( pMenu->m_eChoice == Help ) {
      gui_gc_setColorRGB(gc, 255, 0, 0);
      gui_gc_drawRect(gc, SCREEN_WIDTH-117, SCREEN_HEIGHT-30, 45, 20);
   }

   gui_gc_blit_to_screen(gc);
   gui_gc_finish(gc);

   if( isKeyPressed(KEY_NSPIRE_ESC) ) {
      pMenu->m_eChoice = Quit;
      return 0;
   }
   if( ( isKeyPressed(KEY_NSPIRE_UP) || isKeyPressed(KEY_NSPIRE_8) ) && ( pMenu->m_eChoice == Options || pMenu->m_eChoice == Help ) ) {
      wait_no_key_pressed();
      pMenu->m_eChoice = Play;
   }
   else if( ( isKeyPressed(KEY_NSPIRE_UP) || isKeyPressed(KEY_NSPIRE_8) ) && pMenu->m_eChoice == Play && pMenu->m_nLevelNum > 6 ) {
      wait_no_key_pressed();
      pMenu->m_nLevelNum -= 6;
   }
   else if( ( isKeyPressed(KEY_NSPIRE_DOWN) || isKeyPressed(KEY_NSPIRE_2) ) && pMenu->m_eChoice == Play && pMenu->m_nLevelNum >= 31 && pMenu->m_nLevelNum <= 36 ) {
      wait_no_key_pressed();
      pMenu->m_eChoice = Options;
   }
   else if( ( isKeyPressed(KEY_NSPIRE_DOWN) || isKeyPressed(KEY_NSPIRE_2) ) && pMenu->m_eChoice == Play && pMenu->m_nLevelNum < 31 ) {
      wait_no_key_pressed();
      pMenu->m_nLevelNum += 6;
   }

   if( isKeyPressed(KEY_NSPIRE_ENTER) ) {
      wait_no_key_pressed();
      return 0;
   }

   if( ( isKeyPressed(KEY_NSPIRE_LEFT) || isKeyPressed(KEY_NSPIRE_4) ) && pMenu->m_eChoice == Play && pMenu->m_nLevelNum > 1 ) {
      wait_no_key_pressed();
      pMenu->m_nLevelNum--;
   }
   else if( ( isKeyPressed(KEY_NSPIRE_LEFT) || isKeyPressed(KEY_NSPIRE_4) ) && pMenu->m_eChoice == Help ) {
      wait_no_key_pressed();
      pMenu->m_eChoice = Options;
   }
   else if( ( isKeyPressed(KEY_NSPIRE_RIGHT) || isKeyPressed(KEY_NSPIRE_6) ) && pMenu->m_eChoice == Play && pMenu->m_nLevelNum < 36 ) {
      wait_no_key_pressed();
      pMenu->m_nLevelNum++;
   }
   else if( ( isKeyPressed(KEY_NSPIRE_RIGHT) || isKeyPressed(KEY_NSPIRE_6) ) && pMenu->m_eChoice == Options ) {
      wait_no_key_pressed();
      pMenu->m_eChoice = Help;
   }
   
   return 1;
}
Exemple #6
0
int filebrowser(void* scrbuf, char* file, char* title)
{
    char currentdir[FILENAME_MAX + 1];
    char* filenames[1024];
    char filenameinput[FILENAME_MAX + 1] = "";
    char blockc = '\0';
    int focus_filenameinput = 1;
    int num_files;
    int filescroll = 0;
    int fileselected = 0;
    int i;
    int inputpause = 0;
    if (get_last_doc(currentdir) != 0) {
        getcwd(currentdir, FILENAME_MAX + 1);
    }
    else {
        *(strrchr(currentdir, '/') + 1) = '\0';
    }

    num_files = get_filenames(currentdir, filenames);
    if (num_files == -1)
        return 1;

    wait_no_key_pressed();
    while (1) {
        //disp:
        clearScreen(scrbuf);
        filledRect(scrbuf, 0, TITLE_Y, SCREEN_WIDTH, TITLE_HEIGHT, 0);
        dispStringColor(scrbuf, 4, (TITLE_HEIGHT - CHAR_HEIGHT) / 2, title, WHITE_COLOR, 0);
        dispHorizLine(scrbuf, 0, DIR_Y + DIR_HEIGHT - 1, 320, 0);
        dispString(scrbuf, 4, DIR_Y + (DIR_HEIGHT - CHAR_HEIGHT) / 2, currentdir);
        dispHorizLine(scrbuf, 0, FILENAMEINPUT_Y, 320, 0);
        dispString(scrbuf, 4, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, "Filename:");
        dispString(scrbuf, 4 + 10 * CHAR_WIDTH, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, filenameinput);
        if (focus_filenameinput)//if cursor is in the file name input field, disp an underline to show it
            putChar(scrbuf, 4 + (10 + strlen(filenameinput)) * CHAR_WIDTH, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, '_');
        for (i = filescroll; i < filescroll + FILES_SHOWN && i < num_files; i++) {
            //disp file symbol
            if (is_dir(filenames[i]) && strcmp(filenames[i], ".") && strcmp(filenames[i], ".."))
                putChar(scrbuf, CHAR_WIDTH * 2, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, '\\');
            //disp filename, filesize and selection
            if (i != fileselected || focus_filenameinput) {
                dispString(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, filenames[i]);
                if (!is_dir(filenames[i])) {
                    char size[16];
                    get_filesize(filenames[i], size);
                    dispString(scrbuf, FILENAME_WIDTH, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, size);
                }
            }
            else {
                filledRect(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT - 1, SCREEN_WIDTH - CHAR_WIDTH * 4, CHAR_HEIGHT + 2, MENU_SELECTION_COLOR);
                dispStringColor(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, filenames[i], WHITE_COLOR, MENU_SELECTION_COLOR);
                if (!is_dir(filenames[i])) {
                    char size[16];
                    get_filesize(filenames[i], size);
                    dispStringColor(scrbuf, FILENAME_WIDTH, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, size, WHITE_COLOR, MENU_SELECTION_COLOR);
                }
            }
        }
        showBuffer(scrbuf);


        //input
        if (!any_key_pressed())
            inputpause = 0;
        else
            inputpause--;

        if (isKeyPressed(KEY_NSPIRE_ESC))
            break;
        if (isKeyPressed(KEY_NSPIRE_TAB)) {
            focus_filenameinput = !focus_filenameinput;
            wait_no_key_pressed();
        }

        if (!focus_filenameinput) {
            if (isKeyPressed(KEY_NSPIRE_ENTER) && (blockc != '\n' || inputpause <= 0)) {
                inputpause = INPUTPAUSE;
                blockc = '\n';
                if (is_dir(filenames[fileselected])) {
                    chdir(filenames[fileselected]);
                    filescroll = 0;
                    fileselected = 0;
                    free_filenames(filenames);
                    getcwd(currentdir, FILENAME_MAX + 1);
                    num_files = get_filenames(currentdir, filenames);
                }
                else {
                    strcpy(file, currentdir);
                    strcat(file, filenames[fileselected]);
                    free_filenames(filenames);
                    printf("%s\n", file);
                    return 0;
                }
            }
            else if (isKeyPressed(KEY_NSPIRE_UP) && (blockc != 0x1 || inputpause <= 0)) {
                inputpause = INPUTPAUSE;
                blockc = 0x1;
                fileselected--;
                if (fileselected < 0) {
                    fileselected = num_files - 1;
                    filescroll = num_files - FILES_SHOWN;
                    if (filescroll < 0)
                        filescroll = 0;
                }
                else if (fileselected - filescroll < 0)
                    filescroll--;
                strcpy(filenameinput, filenames[fileselected]);
            }
            else if (isKeyPressed(KEY_NSPIRE_DOWN) && (blockc != 0x2 || inputpause <= 0)) {
                inputpause = INPUTPAUSE;
                blockc = 0x2;
                fileselected++;
                if (fileselected >= num_files) {
                    fileselected = 0;
                    filescroll = 0;
                }
                else if (fileselected - filescroll >= FILES_SHOWN)
                    ++filescroll;
                strcpy(filenameinput, filenames[fileselected]);
            }
        }
        else { //focus_filenameinput
            char c = readc();
            if (c == blockc && inputpause > 0)
                continue;
            if (c != '\0' && c != '\t' && c != '\n') {
                inputpause = INPUTPAUSE;
                blockc = c;
                if (c == '\b') {
                    if (filenameinput[0] != '\0')
                        filenameinput[strlen(filenameinput) - 1] = '\0';
                }
                else {
                    filenameinput[strlen(filenameinput)] = c;
                    filenameinput[strlen(filenameinput) + 1] = '\0';
                }
            }
            if (isKeyPressed(KEY_NSPIRE_UP) || isKeyPressed(KEY_NSPIRE_TAB)) {
                inputpause = INPUTPAUSE;
                focus_filenameinput = 0;
            }
            if (isKeyPressed(KEY_NSPIRE_ENTER)) {
                strcpy(file, currentdir);
                strcat(file, filenameinput);
                free_filenames(filenames);
                printf("%s\n", file);
                return 0;
            }
        }
        sleep(10);
    }

    free_filenames(filenames);
    return 1;
}