Пример #1
0
/***
Draw a text with a new line after a certain number of pixels.
Warning: No UTF32 support.
@function wrappedText
@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 integer width width of a line, in pixels
@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_wrappedText(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);
	unsigned int lineWidth = luaL_checkinteger(L, 4);
	
	int size = luaL_optinteger(L, 5, textSize);
	u32 color = luaL_optinteger(L, 6, color_default);
	font_userdata *font = luaL_testudata(L, 7, "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.)
	// Disabled as sftd_draw_wtext_wrap() doesn't exist.
	/*wchar_t wtext[len+1];
	len = mbstowcs(wtext, text, len);
	*(wtext+len) = 0x0; // text end */
	
	sftd_draw_text_wrap(font->font, x, y, color, size, lineWidth, text);
	
	return 0;
}
Пример #2
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;

}
Пример #3
0
void sharedExtManager()
{
    menu sharedMenu(128, 72, false);
    sharedMenu.addItem("E0000000");
    sharedMenu.addItem("F0000001");
    sharedMenu.addItem("F0000002");
    sharedMenu.addItem("F0000009");
    sharedMenu.addItem("F000000B");
    sharedMenu.addItem("F000000C");
    sharedMenu.addItem("F000000D");
    sharedMenu.addItem("F000000E");
    sharedMenu.addItem("Back");

    std::u32string info = U"Shared ExtData";
    bool loop = true;
    while(loop)
    {
        hidScanInput();

        u32 up = hidKeysUp();

        sharedMenu.handleInput(up);

        if(up & KEY_A)
        {
            FS_Archive shared;
            titleData sharedDat;
            bool opened = false;
            switch(sharedMenu.getSelected())
            {
                case e0:
                    opened = openSharedExt(&shared, 0xE0000000);
                    sharedDat.nameSafe = tou16("E0000000");
                    break;
                case f1:
                    opened = openSharedExt(&shared, 0xF0000001);
                    sharedDat.nameSafe = tou16("F0000001");
                    break;
                case f2:
                    opened = openSharedExt(&shared, 0xF0000002);
                    sharedDat.nameSafe = tou16("F0000002");
                    break;
                case f9:
                    opened = openSharedExt(&shared, 0xF0000009);
                    sharedDat.nameSafe = tou16("F0000009");
                    break;
                case fb:
                    opened = openSharedExt(&shared, 0xF000000B);
                    sharedDat.nameSafe = tou16("F000000B");
                    break;
                case fc:
                    opened = openSharedExt(&shared, 0xF000000C);
                    sharedDat.nameSafe = tou16("F000000C");
                    break;
                case fd:
                    opened = openSharedExt(&shared, 0xF000000D);
                    sharedDat.nameSafe = tou16("F000000D");
                    break;
                case fe:
                    opened = openSharedExt(&shared, 0xF000000E);
                    sharedDat.nameSafe = tou16("F0000000E");
                    break;
                case back:
                    loop = false;
                    break;
            }

            if(opened)
            {
                sharedBackupMenu(sharedDat, shared);
            }
            FSUSER_CloseArchive(&shared);
        }
        else if(up & KEY_B)
            break;

        sf2d_start_frame(GFX_TOP, GFX_LEFT);
            drawTopBar(info);
            sharedMenu.draw();
        sf2d_end_frame();

        sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
            sftd_draw_text_wrap(yashi, 0, 0, RGBA8(255, 255, 255, 255), 12, 320, descs[sharedMenu.getSelected()].c_str());
        sf2d_end_frame();

        sf2d_swapbuffers();
    }
}