Esempio n. 1
0
int fontGetWidth(lua_State *L) { // font:getWidth()

	love_font *self = luaobj_checkudata(L, 1, CLASS_TYPE);
	const char *text = luaL_checkstring(L, 2);

	lua_pushinteger(L, sftd_get_text_width(self->font, self->size, text));

	return 1;

}
Esempio n. 2
0
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++;
    }    
}
Esempio n. 3
0
static int graphicsPrintFormat(lua_State *L) {

	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);
			int limit = luaL_checkinteger(L, 4);
			char *align = luaL_optstring(L, 5, "left");

			int width = sftd_get_text_width(currentFont->font, currentFont->size, printText);

			if (strcmp(align, "center") == 0) {

				if (width < limit) {
					x += (limit / 2) - (width / 2);
				}

			} else if (strcmp(align, "right") == 0) {

				if (width < limit) {
					x += limit - width;
				}

			}

			translateCoords(&x, &y);

			if (x > 0) limit += x; // Quick text wrap fix, needs removing once sf2dlib is updated.

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

		}

	}

	return 0;

}
Esempio n. 4
0
File: gui.c Progetto: nop90/Vex3DS
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;
}
Esempio n. 5
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());
}