Exemple #1
0
bool FontManager::loadFonts(void)
{
	printf("Loading font: %p\n", (font = sftd_load_font_mem(NotoSans_Regular_ttf, NotoSans_Regular_ttf_size)));
	font = sftd_load_font_mem(NotoSans_Regular_ttf, NotoSans_Regular_ttf_size);
	printf("Loading font: @%p\n", font);
	if (!font) return false;

	return (font);
	return true;
}
Exemple #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;
}
Exemple #3
0
const char *fontDefaultInit(love_font *self, int size) {

	self->font = sftd_load_font_mem(Vera_ttf, Vera_ttf_size);
	self->size = size;

	return NULL;

}
Exemple #4
0
/***
Set a font as the default one.
@function setDefault
@tparam font font the font to set as the default one.
*/
static int font_setDefault(lua_State *L) {
	if (luaL_testudata(L, 1, "LFont") == NULL) {
		font_userdata *font = lua_newuserdata(L, sizeof(*font));
		luaL_getmetatable(L, "LFont");
		lua_setmetatable(L, -2);

		font->font = sftd_load_font_mem(vera_ttf, vera_ttf_size);
	}

	lua_setfield(L, LUA_REGISTRYINDEX, "LFontDefault");

	return 0;
}
Exemple #5
0
void load_font_lib(lua_State *L) {
	// Load default font
	font_userdata *font = lua_newuserdata(L, sizeof(*font));
	luaL_getmetatable(L, "LFont");
	lua_setmetatable(L, -2);

	font->font = sftd_load_font_mem(vera_ttf, vera_ttf_size);

	lua_setfield(L, LUA_REGISTRYINDEX, "LFontDefault");

	// Load lib
	luaL_requiref(L, "ctr.gfx.font", luaopen_font_lib, false);
}
Exemple #6
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;
}
Exemple #7
0
int main()
{
	char* names[] = {
		"nul/20",
		"item1",
		"second item",
		"the third one",
		"item4",
		"item5",
		"item6",
		"item7",
		"item8",
		"item9",
		"item10",
		"item11",
		"item12",
		"item13",
		"item14",
		"item15",
		"item16",
		"item17",
		"item18",
		"item19",
		"item20",
		"item21",
		"item22",
		"item23",
		"item24",
		"item25",
		"item26",
		"item27",
		"item28",
		"item29"
	};

	int nbitems = 30;
	uint8_t owneditem[nbitems];
	for (int i=0; i<nbitems; i++) owneditem[i] = 0;

	sf2d_init();
	sf2d_set_clear_color(RGBA8(255, 255, 255, 255));
	sf2d_set_vblank_wait(0);

	// Font loading
	sftd_init();
	sftd_font* font = sftd_load_font_mem(FreeSans_ttf, FreeSans_ttf_size);

	int fontSize = 20;

	int row = 0;
	int nbrow = 10;
	int firstrow = 0;

#define LONG_TIMEOUT 500
#define SHORT_TIMEOUT_MAX 100
#define SHORT_TIMEOUT_MIN 20

	u64 oldTime = osGetTime();
	u64 timer = 0;
	u64 timeout = LONG_TIMEOUT;

	while (aptMainLoop()) {

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

		if ((hidKeysHeld() & KEY_UP) && timer == 0) row--;
		if (row == -1) {
			row++;
			firstrow--;
			if (firstrow == -1) {
				row = nbrow-1;
				firstrow = nbitems-nbrow;
			}
		}

		if ((hidKeysHeld() & KEY_DOWN) && timer == 0) row++;
		if (row == nbrow) {
			row--;
			firstrow++;
			if (firstrow+nbrow == nbitems+1) {
				firstrow = 0;
				row = 0;
			}
		}

		int index = firstrow+row;
		owneditem[index] += 100;
		if (hidKeysDown() & KEY_LEFT) owneditem[index]--;
		if (hidKeysDown() & KEY_RIGHT) owneditem[index]++;
		owneditem[index] %= 100;

		// use osGetTime to have key repetition
		u64 newTime = osGetTime();
		u64 delay = newTime-oldTime;
		oldTime = newTime;
		if (hidKeysHeld()) {
			timer += delay;
			if (timer>timeout) {
				timer = 0;
				if (timeout == LONG_TIMEOUT) {
					timeout = SHORT_TIMEOUT_MAX;
				} else {
					timeout = umax(timeout-2, SHORT_TIMEOUT_MIN);
				}
			}
		} else {
			timer = 0;
			timeout = LONG_TIMEOUT;
		}

		sf2d_start_frame(GFX_TOP, GFX_LEFT);
		{
			for (int i=0; i<nbrow; i++) {
				unsigned int color = RGBA8(0, 0, 0, 255);
				if (i == row) {
					sf2d_draw_rectangle(0, i*fontSize, 400, fontSize, RGBA8(0, 0, 0, 255));
					color = RGBA8(255, 255, 255, 255);
				}
				sftd_draw_textf(font, 010, i*fontSize, color, fontSize, names[firstrow+i]);
				sftd_draw_textf(font, 210, i*fontSize, color, fontSize, "%i", owneditem[firstrow+i]);
			}
		}
		sf2d_end_frame();

		sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
		{
			sftd_draw_textf(font, 0, 20, RGBA8(0, 255, 0, 255), 20, "Press START to exit");
			sftd_draw_textf(font, 0, 40, RGBA8(0, 255, 0, 255), 20, "Timeout: %i", timeout);
		}
		sf2d_end_frame();

		sf2d_swapbuffers();
	}

	sftd_free_font(font);
	sftd_fini();

	sf2d_fini();
	return 0;
}