Beispiel #1
0
/*
	Shows menu items 
*/
void ShowMenu(MENU *menu)
{
	int i;
	MENUITEM *mi = menu->m;
	
	int boxColor;
	
    boxColor = RGBA8(0x44,   0x44, 0xaa,   0xff);

	// show menu lines
	for(i = 0; i < menu->itemNum; i++, mi++) {
		int fg_color;
		sf2d_draw_rectangle(10, 35 + i*26, 125, 19, (menu->itemCur == i)?boxColor:COLOR_INACTIVE_ITEM_BG); 
		if(menu->itemCur == i) fg_color = COLOR_ACTIVE_ITEM; else fg_color = COLOR_INACTIVE_ITEM;
		ShowMenuItem(12, 38 + i*26, mi, fg_color,(menu == &gui_MainMenu)?0:1);
	}

	// show preview screen
//	ShowPreview(menu);

	// print info string

    sftd_draw_text(font, 7, 7, RGBA8(0x66,   0x66, 0x66,   0xff), 10, "Vex3ds");
    sftd_draw_text(font, 5, 5, RGBA8(0xff,   0xff, 0xff,   0xff), 10, "Vex3ds");

/*	if (menu == &gui_MainMenu) {
		guitextwidth = sftd_get_text_width(font, 10, Handy_3DS_String_list[HANDY_STR_Back_to_Game]);
		sftd_draw_text(font, (320 - guitextwidth) / 2, 225, COLOR_HELP_TEXT, 10, Handy_3DS_String_list[HANDY_STR_Back_to_Game]);
	} else {
		guitextwidth = sftd_get_text_width(font, 10, Handy_3DS_String_list[HANDY_STR_Back_to_Previous]);
		sftd_draw_text(font, (320 - guitextwidth) / 2, 225, COLOR_HELP_TEXT, 10, Handy_3DS_String_list[HANDY_STR_Back_to_Previous]);
	}
 */
 }
Beispiel #2
0
int main()
{
	sf2d_init();
	sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF));

	consoleInit(GFX_BOTTOM, NULL);
	printf("sftd sample\n");

	// Font loading
	sftd_init();
	sftd_font *font = sftd_load_font_mem(airstrike_ttf, airstrike_ttf_size);

	while (aptMainLoop()) {

		hidScanInput();
		if (hidKeysDown() & KEY_START) break;

		sf2d_start_frame(GFX_TOP, GFX_LEFT);

			sftd_draw_text(font, 10, 10, RGBA8(255, 0, 0, 255), 20, "Font drawing on the top screen!");
			sftd_draw_textf(font, 10, 40, RGBA8(0, 255, 0, 255), 20, "FPS %f", sf2d_get_fps());

		sf2d_end_frame();

		sf2d_swapbuffers();
	}

	sftd_free_font(font);
	sftd_fini();

	sf2d_fini();
	return 0;
}
Beispiel #3
0
void render(void) {
    // Start frame on the top screen
    sf2d_start_frame(GFX_TOP, GFX_LEFT);

    // Draw the background (or in this case, the room)
    sf2d_draw_texture(rooms[room].bg.tex,
                      rooms[room].bg.pos.x - (int)camera_pos.x,
                      rooms[room].bg.pos.y - (int)camera_pos.y);

    // Draw the player's sprite
    sf2d_draw_texture(curr_tex,
                      (int)player_pos.x - (int)camera_pos.x,
                      (int)player_pos.y - (int)camera_pos.y);

    sf2d_draw_rectangle(0, 0, 800, 240, RGBA8(0x00, 0x00, 0x00, 0xFF - (int)roomTimer));

    // End frame
    sf2d_end_frame();

    // Start frame on the bottom screen
    sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);

    // If the easter egg variable is true, then activate it
    if (easterEgg) {
        // Draw the easter egg
        sftd_draw_text(font, 10, 140,  RGBA8(255, 0, 0, 255), 16, "* You IDIOT.");
        sftd_draw_text(font, 10, 170,  RGBA8(255, 255, 255, 255), 16, "* Nah, this is just");
        sftd_draw_text(font, 10, 200,  RGBA8(255, 255, 255, 255), 16, "   a simple test.");
        int y = -10;
        // Debug stuff
        switch (easterPage) {
            case 0:
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 0, 0, 255), 12, "FPS: %f", sf2d_get_fps());
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 0, 0, 255), 12, "Sprite Timer: %f", sprTimer);
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 255, 255, 255), 12, "Player X: %f, Y: %f", player_pos.x, player_pos.y);
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 255, 255, 255), 12, "Camera X: %f, Y: %f", camera_pos.x, camera_pos.y);
                break;
            case 1:
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 255, 255, 255), 12, "Block Position: %lu", home->block_pos);
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 255, 255, 255), 12, "Block: %u", home->block);
                sftd_draw_textf(font, 10, y+=20, RGBA8(255, 0, 0, 255), 12, "Status: %li", home->status);
                break;
        }
    };
    // End frame
    sf2d_end_frame();
}
Beispiel #4
0
void ShowMenuItem(int x, int y, MENUITEM *m, int fg_color, int showparam)
{
	static char i_str[24];

	sftd_draw_text(font, x, y, fg_color, 10, m->itemName);


	// if parameter, show it on the left
	if((m->itemPar != NULL) && showparam){
		if(m->itemParName == NULL ) {
			// if parameter is a digit
			sprintf(i_str, "%i", *m->itemPar);
		} else {
			// if parameter is a name in array
			sprintf(i_str, "%s", *(m->itemParName + *m->itemPar));
		}
		sftd_draw_text(font, x+125, y, fg_color, 10, i_str);
	}
}
void Editableoverlay::draw() {
    sf2d_draw_texture(texture, posx, posy);

    if( selected > 0 )
        sf2d_draw_texture(this->arrow, posx+texture->width-10-arrow->width, posy+10+arrow->height);
    
    if( selected < elements.size() - 1)
        sf2d_draw_texture_rotate(this->arrow, posx+texture->width-10-arrow->width+3, posy+texture->height-10-arrow->height, M_PI);
    
    int start = selected / todraw;
    int j = 0;
    for(unsigned int i = (start*todraw); i < elements.size() && j < todraw ; i++) {
        std::string towrite = elements[i];
        if( posx+5+sftd_get_text_width(font, 6, towrite.c_str()) >= this->getRightBorder() ) towrite = towrite.substr(0, 12) + "...";
        if( selected == i ) sftd_draw_text(font, posx+5, posy+10+(10*j), RGBA8(255, 255, 255, 255), 6, towrite.c_str());
        else sftd_draw_text(font, posx+5, posy+10+(10*j), RGBA8(0, 0, 0, 255), 6, towrite.c_str());
        j++;
    }    
}
Beispiel #6
0
static int graphicsPrint(lua_State *L) { // love.graphics.print()

	if (sf2d_get_current_screen() == currentScreen) {

		if (currentFont) {

			char *printText = luaL_checkstring(L, 1);
			int x = luaL_checkinteger(L, 2);
			int y = luaL_checkinteger(L, 3);

			translateCoords(&x, &y);

			sftd_draw_text(currentFont->font, x, y, getCurrentColor(), currentFont->size, printText);

		}

	}

	return 0;

}
Beispiel #7
0
int load_file(char **wildcards, char *result, bool startup)
{

	Handle dirHandle;
    FS_DirectoryEntry entry;
	char current_dir_name[MAX__PATH];
    char prev_dir_name[MAX__PATH];
	char current_dir_short[81];
	u32 current_dir_length;
	u32 total_filenames_allocated;
	u32 total_dirnames_allocated;
	char **file_list;
	char **dir_list;
	u32 num_files;
	u32 num_dirs;
	char *file_name;
	u32 file_name_length;
	u32 ext_pos = -1;
	s32 return_value = 1;
	u32 current_file_selection;
	u32 current_file_scroll_value;
	u32 current_dir_selection;
	u32 current_dir_scroll_value;
	u32 current_file_in_scroll;
	u32 current_dir_in_scroll;
	u32 current_file_number, current_dir_number;
	u32 current_column = 0;
	u32 repeat;
	u32 i;

    strcpy(current_dir_name, config_roms_path);
    strcpy(prev_dir_name, current_dir_name);
	while(return_value == 1) {
		current_file_selection = 0;
		current_file_scroll_value = 0;
		current_dir_selection = 0;
		current_dir_scroll_value = 0;
		current_file_in_scroll = 0;
		current_dir_in_scroll = 0;

		total_filenames_allocated = 32;
		total_dirnames_allocated = 32;
		file_list = (char **)malloc(sizeof(char *) * 32);
		dir_list = (char **)malloc(sizeof(char *) * 32);
		memset(file_list, 0, sizeof(char *) * 32);
		memset(dir_list, 0, sizeof(char *) * 32);

		num_files = 0;
		num_dirs = 0;
        
        file_name= (char*) malloc(0x105);

        FS_Path dirPath = (FS_Path){PATH_ASCII, strlen(current_dir_name)+1, (u8*)current_dir_name};
        FSUSER_OpenDirectory(&dirHandle, sdmcArchive, dirPath);

		// DEBUG
		printf("Current directory: %s\n", current_dir_name);
		u32 nread = 0;
		do {
            if(dirHandle) FSDIR_Read(dirHandle, &nread, 1, &entry);

            if(nread) { //(current_file) {
               strncpy_u2a(file_name, entry.name, 0x105);  //utf-16 to ascii function yoinked from blargSNES
				file_name_length = strlen(file_name);

                if(((file_name[0] != '.') || (file_name[1] == '.'))) {
					//if(S_ISDIR(file_info.st_mode)) {    //!!!!!!!!
                    if(entry.attributes & FS_ATTRIBUTE_DIRECTORY) {
                        if((strcmp(file_name, "filer") != 0) && (strcmp(file_name, "Nintendo 3DS") != 0) && (strcmp(file_name, "private") != 0)) {
                            dir_list[num_dirs] = (char *)malloc(file_name_length + 1);
                            strcpy(dir_list[num_dirs], file_name);

                            num_dirs++;
                        }
					} else {
					// Must match one of the wildcards, also ignore the .
						if(file_name_length >= 4) {
							if(file_name[file_name_length - 4] == '.') ext_pos = file_name_length - 4;
							else if(file_name[file_name_length - 3] == '.') ext_pos = file_name_length - 3;
							else ext_pos = 0;

							for(i = 0; wildcards[i] != NULL; i++) {
								if(!strcasecmp((file_name + ext_pos), wildcards[i])) {
									file_list[num_files] = (char *)malloc(file_name_length + 1);

									strcpy(file_list[num_files], file_name);

									num_files++;
									break;
								}
							}
						}
					}
				}

				if(num_files == total_filenames_allocated) {
					file_list = (char **)realloc(file_list, sizeof(char *) * total_filenames_allocated * 2);
					memset(file_list + total_filenames_allocated, 0, sizeof(char *) * total_filenames_allocated);
					total_filenames_allocated *= 2;
				}

				if(num_dirs == total_dirnames_allocated) {
					dir_list = (char **)realloc(dir_list, sizeof(char *) * total_dirnames_allocated * 2);
					memset(dir_list + total_dirnames_allocated, 0, sizeof(char *) * total_dirnames_allocated);
					total_dirnames_allocated *= 2;
				}
			}
        } while(nread); 

		qsort((void *)file_list, num_files, sizeof(char *), sort_function);
		qsort((void *)dir_list, num_dirs, sizeof(char *), sort_function);

        FSDIR_Close(dirHandle);

		current_dir_length = strlen(current_dir_name);

		if(current_dir_length > 80) {
			memcpy(current_dir_short, "...", 3);
			memcpy(current_dir_short + 3, current_dir_name + current_dir_length - 77, 77);
			current_dir_short[80] = 0;
		} else {
			memcpy(current_dir_short, current_dir_name, current_dir_length + 1);
		}

		repeat = 1;

		if(num_files == 0) current_column = 1;
		if(num_dirs == 0) current_column = 0;

		char print_buffer[81];

		while(repeat) {
			sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); //!!
			sftd_draw_text(font, 0, 4, COLOR_ACTIVE_ITEM, 10, current_dir_short);
			const char strMsg[] = "[A] Select Rom [X] Run BIOS [Y] Dir up [B] Back";
			guitextwidth = sftd_get_text_width(font, 10, strMsg);
			sftd_draw_text(font, (320 - guitextwidth) / 2, 225, COLOR_HELP_TEXT, 10, strMsg);
			
			for(i = 0, current_file_number = i + current_file_scroll_value; i < FILE_LIST_ROWS; i++, current_file_number++) {
				if(current_file_number < num_files) {
                    strncpy(print_buffer,file_list[current_file_number], 30);   //38);
                    print_buffer[30] = 0;   //38] = 0;
					if((current_file_number == current_file_selection) && (current_column == 0)) {
						sftd_draw_text(font, FILE_LIST_POSITION, ((i + 2) * 10), COLOR_ACTIVE_ITEM, 10, print_buffer);
					} else {
						sftd_draw_text(font, FILE_LIST_POSITION, ((i + 2) * 10), COLOR_INACTIVE_ITEM, 10, print_buffer);
					}
				}
			}
			for(i = 0, current_dir_number = i + current_dir_scroll_value; i < FILE_LIST_ROWS; i++, current_dir_number++) {
				if(current_dir_number < num_dirs) {
                    strncpy(print_buffer,dir_list[current_dir_number], 8);  //13);
                    print_buffer[9] = 0;    //14] = 0;
					if((current_dir_number == current_dir_selection) && (current_column == 1)) {
						sftd_draw_text(font, DIR_LIST_POSITION, ((i + 2) * 10), COLOR_ACTIVE_ITEM, 10, print_buffer);
					} else {
						sftd_draw_text(font, DIR_LIST_POSITION, ((i + 2) * 10), COLOR_INACTIVE_ITEM, 10, print_buffer);
					}
				}
			}

			// Catch input
			// change to read key state later
            if (aptGetStatus() == APP_PREPARE_SLEEPMODE) {
                aptSignalReadyForSleep();
                aptWaitStatusEvent();
            } else if (aptGetStatus() == APP_SUSPENDING) {
                aptReturnToMenu();
            }
            hidScanInput();
            u32 keydown = hidKeysDown();
                   if (keydown & KEY_A) {  
						if(current_column == 1) {
							if(num_dirs != 0) {
								repeat = 0;
								strcpy(prev_dir_name, current_dir_name);
								if (strlen(current_dir_name)>1) strcat(current_dir_name, "/");
								strcat(current_dir_name, dir_list[current_dir_selection]);
							}
						} else {
							if(num_files != 0) {
								repeat = 0;
								return_value = 0;
								//strcpy(result, file_list[current_file_selection]);
								sprintf(result, "%s/%s", current_dir_name, file_list[current_file_selection]);
								break;
							}
						}
					}
                    if (keydown & KEY_Y) {
                            repeat = 0;
                            char* findpath = strrchr(current_dir_name,'/');
                        if(findpath > current_dir_name) 
                            findpath[0] = '\0';
                        else 
                            findpath[1] = '\0';
                    }
					if (keydown & KEY_B ) { 
						return_value = -1;
						repeat = 0;
						break;
					}
					if (keydown & KEY_X ) { 
						return_value = 1;
						repeat = 0;
						break;
					}
					if (keydown & KEY_UP) {  
						if(current_column == 0) {
							if(current_file_selection) {
								current_file_selection--;
								if(current_file_in_scroll == 0) {
									//clear_screen(COLOR_BG);
									current_file_scroll_value--;
								} else {
									current_file_in_scroll--;
								}
							}
						} else {
							if(current_dir_selection) {
								current_dir_selection--;
								if(current_dir_in_scroll == 0) {
									//clear_screen(COLOR_BG);
									current_dir_scroll_value--;
								} else {
									current_dir_in_scroll--;
								}
							}
						}
					}
					if (keydown & KEY_DOWN) { 
						if(current_column == 0) {
							if(current_file_selection < (num_files - 1)) {
								current_file_selection++;
								if(current_file_in_scroll == (FILE_LIST_ROWS - 1)) {
									//clear_screen(COLOR_BG);
									current_file_scroll_value++;
								} else {
									current_file_in_scroll++;
								}
							}
						} else {
							if(current_dir_selection < (num_dirs - 1)) {
								current_dir_selection++;
								if(current_dir_in_scroll == (FILE_LIST_ROWS - 1)) {
									//clear_screen(COLOR_BG);
									current_dir_scroll_value++;
								} else {
									current_dir_in_scroll++;
								}
							}
						}
					}
					if (keydown & KEY_L) {  
						if(current_column == 0) {
							if(current_file_selection>FILE_LIST_ROWS) {
								current_file_selection-=FILE_LIST_ROWS;
								current_file_scroll_value -= FILE_LIST_ROWS;
								if (current_file_in_scroll>current_file_selection){
									//clear_screen(COLOR_BG);
									current_file_scroll_value=0;
									current_file_in_scroll=current_file_selection;
								}
							} else {
								current_file_selection=0;
								current_file_scroll_value=0;
								current_file_in_scroll=0;
							}
						} else {
							if(current_dir_selection) {
								current_dir_selection--;
								if(current_dir_in_scroll == 0) {
									//clear_screen(COLOR_BG);
									current_dir_scroll_value--;
								} else {
									current_dir_in_scroll--;
								}
							}
						}
					}
					if (keydown & KEY_R) {  
						if(current_column == 0) {
							if(current_file_selection < (num_files - 1 - FILE_LIST_ROWS)) {
								current_file_selection+=FILE_LIST_ROWS;
								current_file_scroll_value+=FILE_LIST_ROWS;
								if (current_file_scroll_value>(num_files - FILE_LIST_ROWS)){
									//clear_screen(COLOR_BG);
									current_file_scroll_value=num_files - FILE_LIST_ROWS;
									current_file_in_scroll=  FILE_LIST_ROWS - (num_files - current_file_selection);
								}
									//clear_screen(COLOR_BG);
							} else {
								current_file_selection = num_files - 1;
								current_file_in_scroll = (num_files<=FILE_LIST_ROWS - 1)?num_files:FILE_LIST_ROWS - 1;
								current_file_scroll_value = (num_files > FILE_LIST_ROWS)?num_files - FILE_LIST_ROWS:0;
							}
						} else {
							if(current_dir_selection < (num_dirs - 1)) {
								current_dir_selection++;
								if(current_dir_in_scroll == (FILE_LIST_ROWS - 1)) {
									//clear_screen(COLOR_BG);
									current_dir_scroll_value++;
								} else {
									current_dir_in_scroll++;
								}
							}
						}
					}
					if (keydown & KEY_LEFT) { 
						if(current_column == 1) {
							if(num_files != 0) current_column = 0;
						}
					}
					if (keydown & KEY_RIGHT) {  
						if(current_column == 0) {
							if(num_dirs != 0) current_column = 1;
						}
					}

            sf2d_end_frame();
            
			gui_DrawTopScreen();
            
            sf2d_swapbuffers();


		}

		// free pointers
		for(i = 0; i < num_files; i++) free(file_list[i]);
		free(file_list);

		for(i = 0; i < num_dirs; i++) free(dir_list[i]);
		free(dir_list);
        
        free(file_name);
	}
	
	
	return return_value;
}
Beispiel #8
0
int main()
{
	touchPosition touch;

	sf2d_init();
	sftd_init();

	sftd_font *text = sftd_load_font_mem(Roboto_ttf, Roboto_ttf_size);
	sftd_font *title = sftd_load_font_mem(RobotoThin_ttf, RobotoThin_ttf_size);

	sf2d_texture *logo = sfil_load_PNG_buffer(logo_png, SF2D_PLACE_RAM);
	sf2d_texture *record = sfil_load_PNG_buffer(record_png, SF2D_PLACE_RAM);
	sf2d_texture *stop = sfil_load_PNG_buffer(stop_png, SF2D_PLACE_RAM);

	sf2d_set_clear_color(RGBA8(0xFA, 0xFA, 0xFA, 0xFF));

	sharedmem = (u32*)memalign(0x1000, sharedmem_size);
	audiobuf = linearAlloc(audiobuf_size);

	MIC_Initialize(sharedmem, sharedmem_size, control, 0, 3, 1, 1);//See mic.h.

	// Threading stuff
	svcCreateEvent(&threadRequest,0);
	u32 *threadStack = memalign(32, STACKSIZE);
	svcCreateThread(&threadHandle, threadMic, 0, &threadStack[STACKSIZE/4], 0x3f, 0);

	while(aptMainLoop())
	{
		hidScanInput();
		hidTouchRead(&touch);

		u32 kDown = hidKeysDown();

		if (kDown & KEY_START)
			break; // break in order to return to hbmenu

		sf2d_start_frame(GFX_TOP, GFX_LEFT);
			sf2d_draw_texture(logo, 60, 70);
			sftd_draw_text(title, 177, 80, RGBA8(0, 0, 0, 222), 40, "Audio");
			sftd_draw_text(title, 175, 120, RGBA8(0, 0, 0, 222), 40, "Recorder");
		sf2d_end_frame();

		sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
			sf2d_draw_texture(record, 85, 85);
			sf2d_draw_texture(stop, 165, 85);
		sf2d_end_frame();

		svcSignalEvent(threadRequest);

		if(print == 1)
		{
			sf2d_start_frame(GFX_TOP, GFX_LEFT);
				sf2d_draw_texture(logo, 60, 70);
				sftd_draw_text(title, 177, 80, RGBA8(0, 0, 0, 222), 40, "Audio");
				sftd_draw_text(title, 175, 120, RGBA8(0, 0, 0, 222), 40, "Recorder");
				sftd_draw_text(text, 130, 209, RGBA8(0, 0, 0, 222), 16, "Recording audio...");
			sf2d_end_frame();
		}

		if(recording == 2)
		{
			sf2d_start_frame(GFX_TOP, GFX_LEFT);
				sf2d_draw_texture(logo, 60, 70);
				sftd_draw_text(title, 177, 80, RGBA8(0, 0, 0, 222), 40, "Audio");
				sftd_draw_text(title, 175, 120, RGBA8(0, 0, 0, 222), 40, "Recorder");
				sftd_draw_text(text, 130, 209, RGBA8(0, 0, 0, 222), 16, "Saving audio...");
			sf2d_end_frame();
		}

		sf2d_swapbuffers();
	}

	MIC_Shutdown();

	sftd_free_font(text);
	sftd_free_font(title);
	sf2d_free_texture(logo);
	sf2d_free_texture(record);
	sf2d_free_texture(stop);

	// tell thread to exit
	threadExit = true;

	// signal the thread
	svcSignalEvent(threadRequest);

	// give it time to exit
	svcSleepThread(10000000ULL);

	// close handles and free allocated stack
	svcCloseHandle(threadRequest);
	svcCloseHandle(threadHandle);
	free(threadStack);

	free(sharedmem);
	linearFree(audiobuf);
	linearFree(nomute_audiobuf);

	sf2d_fini();
	sftd_fini();
	return 0;
}
Beispiel #9
0
void Helpbox::draw() {
    std::string towrite(button+": "+msg);
    int textsize = sftd_get_text_width(font, 6, towrite.c_str());
    sf2d_draw_texture(this->texture, this->posx, this->posy);
    sftd_draw_text(font, (this->posx)+(this->texture->width/2)-(textsize/2), this->posy+3,  RGBA8(0, 0, 0, 255), 6, towrite.c_str());
}