Beispiel #1
0
/***
Draw a text on the current screen.
@function text
@tparam integer x text drawing origin horizontal coordinate, in pixels
@tparam integer y text drawing origin vertical coordinate, in pixels
@tparam string text the text to draw
@tparam[opt=default size] integer size drawing size, in pixels
@tparam[opt=default color] integer color drawing color
@tparam[opt=default font] font font to use
*/
static int gfx_text(lua_State *L) {
	int x = luaL_checkinteger(L, 1);
	int y = luaL_checkinteger(L, 2);
	size_t len;
	const char *text = luaL_checklstring(L, 3, &len);

	int size = luaL_optinteger(L, 4, textSize);
	u32 color = luaL_optinteger(L, 5, color_default);
	font_userdata *font = luaL_testudata(L, 6, "LFont");
	if (font == NULL) {
		lua_getfield(L, LUA_REGISTRYINDEX, "LFontDefault");
		font = luaL_testudata(L, -1, "LFont");
		if (font == NULL) luaL_error(L, "No default font set and no font object passed");
	}
	if (font->font == NULL) luaL_error(L, "The font object was unloaded");

	// Wide caracters support. (wchar = UTF32 on 3DS.)
	wchar_t wtext[len+1];
	len = mbstowcs(wtext, text, len);
	*(wtext+len) = 0x0; // text end

	sftd_draw_wtext(font->font, x, y, color, size, wtext);

	return 0;
}
Beispiel #2
0
// --------------------------------------------------
void BoxViewer::drawBox(box_s* box, int16_t x, int16_t y, bool cursor)
// --------------------------------------------------
{
	// Draw the box background
	sf2d_draw_texture_part(PHBanku::texture->boxBackgrounds, x, y, ((box->background % 16) % 4) * BACKGROUND_WIDTH, ((box->background % 16) / 4) * BACKGROUND_HEIGHT, BACKGROUND_WIDTH, BACKGROUND_HEIGHT);

	if (cursor)
	{
		// Draw CursorType buttons (Red|Blue|Green)
		drawCursorButton(x, y);
	}

	// Draw the box header
	sf2d_draw_texture_part(PHBanku::texture->boxBackgrounds, x, y + 15, ((box->background % 16) % 4) * BOX_HEADER_WIDTH, 840 + ((box->background % 16) / 4) * BOX_HEADER_HEIGHT, BOX_HEADER_WIDTH, BOX_HEADER_HEIGHT);

	// Draw the box arrows
	sf2d_draw_texture_part(PHBanku::texture->boxTiles, x + 4, y + 18, 96, 32, 16, 24);
	sf2d_draw_texture_part(PHBanku::texture->boxTiles, x + 200, y + 18, 112, 32, 16, 24);

	// Draw the box title
	wchar_t boxTitle[0x1a];
	// TODO: Remove that if statement when complete box->title.
	// TODO: Wait for sftd_get_wtext_wdith.
	if (box->title[0] != '\0') swprintf(boxTitle, 0x1a, (wchar_t*) box->title);
	else swprintf(boxTitle, 0x1a, L"Box %i", box->number+1);
	int boxTitleWidth = sftd_get_wtext_width(font, 12, boxTitle);
	sftd_draw_wtext(font, x + (BACKGROUND_WIDTH - boxTitleWidth) / 2, y + 21, RGBA8(0x22,0x22,0x22,0xFF), 12, boxTitle);

	// TODO: v DRY v

	// If there is a Pokémon currently selected
	if (sPkm)
	{
		// Draw Pokémon icons
		for (u8 i = 0; i < BOX_PKM_COUNT; i++)
		{
			// If the Pokémon isn't the selected Pokémon
			if (sPkm != &(box->slot[i]))
			{
				drawPokemon(&box->slot[i], x + (i % BOX_COL_PKM_COUNT) * PKM_WIDTH, y + PKM_BOX_MARGIN_TOP + (i / BOX_COL_PKM_COUNT) * PKM_HEIGHT, false);
			}
		}
	}
	// If there is no Pokémon currently selected
	else
	{
		// Draw Pokémon icons
		for (u8 i = 0; i < BOX_PKM_COUNT; i++)
		{
			drawPokemon(&box->slot[i], x + (i % BOX_COL_PKM_COUNT) * PKM_WIDTH, y + PKM_BOX_MARGIN_TOP + (i / BOX_COL_PKM_COUNT) * PKM_HEIGHT, false);
		}
	}
}