int lockScreen() { lockscreenBg = sf2d_create_texture_mem_RGBA8(lockscreen_img.pixel_data, lockscreen_img.width, lockscreen_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); time_t unixTime = time(NULL); struct tm* timeStruct = gmtime((const time_t *)&unixTime); int hours = timeStruct->tm_hour; int minutes = timeStruct->tm_min; int day = timeStruct->tm_mday; sf2d_set_clear_color(RGBA8(0, 0, 0, 0)); while (1) { hidScanInput(); u32 kDown = hidKeysDown(); sf2d_start_frame(GFX_TOP, GFX_LEFT); sf2d_draw_texture(background, 0, 0); sf2d_draw_texture(lockscreenBg, 0, 0); sftd_draw_textf(roboto, 142, 20, RGBA8(255, 255, 255, 255), 34, "0%2d : %02d", hours, minutes); sftd_draw_textf(roboto, 140, 80, RGBA8(255, 255, 255, 255), 10, "Monday"); sftd_draw_textf(roboto, 200, 80, RGBA8(255, 255, 255, 255), 10, "%d", day); sftd_draw_textf(roboto, 220, 80, RGBA8(255, 255, 255, 255), 10, "October"); digitalTime(350, 2); batteryStatus(316, 2); cursorController(); sf2d_end_frame(); if ((touch.px >= 160 && touch.px <= 235 && touch.py >= 210 && touch.py <= 240) && (kDown & KEY_A)) { sf2d_free_texture(lockscreenBg); return 1; } sf2d_swapbuffers(); } sf2d_free_texture(lockscreenBg); return 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; }
int batteryStatus(int x, int y) { int batt = 100; //This is temporary until I find how to get battery status. I know 3DS doesn't use percentages, but only values from 1-5. sf2d_draw_texture(_100, 300, 2); sftd_draw_textf(roboto, x, y, RGBA8(255, 255, 255, 255), 12, "%d%%", batt); return 0; }
int dayNightWidget() { time_t unixTime = time(NULL); struct tm* timeStruct = gmtime((const time_t *)&unixTime); int hours = timeStruct->tm_hour; int minutes = timeStruct->tm_min; int day = timeStruct->tm_mday; //int month = timeStruct->tm_mon; if (hours < 6) sf2d_draw_texture(dayWidget, 172, 60); else sf2d_draw_texture(nightWidget, 167, 60); sftd_draw_textf(roboto, 142, 20, RGBA8(255, 255, 255, 255), 34, "0%2d : %02d", hours, minutes); sftd_draw_textf(roboto, 130, 80, RGBA8(255, 255, 255, 255), 10, "Monday"); sftd_draw_textf(roboto, 230, 80, RGBA8(255, 255, 255, 255), 10, "%d", day); sftd_draw_textf(roboto, 245, 80, RGBA8(255, 255, 255, 255), 10, "October"); return 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(); }
int aboutMenu() { aboutBg = sf2d_create_texture_mem_RGBA8(about_img.pixel_data, about_img.width, about_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); highlight = sf2d_create_texture_mem_RGBA8(highlight_img.pixel_data, highlight_img.width, highlight_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); sf2d_set_clear_color(RGBA8(0, 0, 0, 0)); while (aptMainLoop()) { hidScanInput(); u32 kDown = hidKeysDown(); sf2d_start_frame(GFX_TOP, GFX_LEFT); sf2d_draw_texture(aboutBg, 0, 0); sftd_draw_textf(roboto, 20, 68, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsAbout[language][0]); sftd_draw_textf(roboto, 20, 83, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsAbout[language][1]); sftd_draw_textf(roboto, 20, 116, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsAbout[language][2]); //sftd_draw_textf(roboto, 20, 132, RGBA8(0, 0, 0, 255), 12, "Model = NULL"); sftd_draw_textf(roboto, 20, 168, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsAbout[language][5]); //sftd_draw_textf(roboto, 20, 183, RGBA8(0, 0, 0, 255), 12, "NinjaHax version: NULL"); if (touch.px >= 0 && touch.px <= 480 && touch.py >= 58 && touch.py <= 105) { sf2d_draw_texture(highlight, 0, 56); sftd_draw_textf(roboto, 20, 68, RGBA8(0, 0, 0, 255), 12, "Cyanogen3DS Updates"); sftd_draw_textf(roboto, 20, 83, RGBA8(0, 0, 0, 255), 12, "Click for, view or isntall available updates"); } else if (touch.px >= 0 && touch.px <= 480 && touch.py >= 106 && touch.py <= 157) { sf2d_draw_texture(highlight, 0, 105); sftd_draw_textf(roboto, 20, 116, RGBA8(0, 0, 0, 255), 12, "Cyanogen3DS version: 0.01-20151019-UNOFFICIAL"); sftd_draw_textf(roboto, 20, 132, RGBA8(0, 0, 0, 255), 12, "Model = NULL"); } digitalTime(350, 2); batteryStatus(316, 2); androidQuickSettings(); cursorController(); sf2d_end_frame(); navbarControls(1); if (kDown & KEY_Y) powerMenu(); if (kDown & KEY_L) lockScreen(); if (kDown & KEY_B) { sf2d_free_texture(aboutBg); sf2d_free_texture(highlight); settingsMenu(); } if ((touch.px >= 44 && touch.px <= 119 && touch.py >= 201 && touch.py <= 240) && (kDown & KEY_A)) { sf2d_free_texture(aboutBg); sf2d_free_texture(highlight); settingsMenu(); } else if ((touch.px >= 120 && touch.px <= 195 && touch.py >= 201 && touch.py <= 240) && (kDown & KEY_A)) { sf2d_free_texture(aboutBg); sf2d_free_texture(highlight); home(); } sf2d_swapbuffers(); } sf2d_free_texture(aboutBg); sf2d_free_texture(highlight); return 0; }
int settingsMenu() { settingsBg = sf2d_create_texture_mem_RGBA8(settings_img.pixel_data, settings_img.width, settings_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); about_highlight = sf2d_create_texture_mem_RGBA8(about_highlight_img.pixel_data, about_highlight_img.width, about_highlight_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); display_highlight = sf2d_create_texture_mem_RGBA8(display_highlight_img.pixel_data, display_highlight_img.width, display_highlight_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); developeroptions_highlight = sf2d_create_texture_mem_RGBA8(developeroptions_highlight_img.pixel_data, developeroptions_highlight_img.width, developeroptions_highlight_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); performance_highlight = sf2d_create_texture_mem_RGBA8(performance_highlight_img.pixel_data, performance_highlight_img.width, performance_highlight_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); security_highlight = sf2d_create_texture_mem_RGBA8(security_highlight_img.pixel_data, security_highlight_img.width, security_highlight_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); wifi_highlight = sf2d_create_texture_mem_RGBA8(wifi_highlight_img.pixel_data, wifi_highlight_img.width, wifi_highlight_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM); sf2d_set_clear_color(RGBA8(0, 0, 0, 0)); while (aptMainLoop()) { hidScanInput(); u32 kDown = hidKeysDown(); sf2d_start_frame(GFX_TOP, GFX_LEFT); sf2d_draw_texture(settingsBg, 0, 0); sftd_draw_textf(roboto, 48, 106, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsMain[language][0]); sftd_draw_textf(roboto, 48, 153, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsMain[language][1]); sftd_draw_textf(roboto, 48, 202, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsMain[language][2]); sftd_draw_textf(roboto, 250, 106, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsMain[language][3]); sftd_draw_textf(roboto, 250, 153, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsMain[language][4]); sftd_draw_textf(roboto, 250, 202, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsMain[language][5]); settingsHighlight(); digitalTime(350, 2); batteryStatus(316, 2); androidQuickSettings(); cursorController(); sf2d_end_frame(); navbarControls(1); if (kDown & KEY_Y) powerMenu(); if (kDown & KEY_L) lockScreen(); if (kDown & KEY_B) { settingsUnload(); appDrawer(); } if ((touch.px >= 44 && touch.px <= 119 && touch.py >= 201 && touch.py <= 240) && (kDown & KEY_A)) { settingsUnload(); appDrawer(); } else if ((touch.px >= 120 && touch.px <= 195 && touch.py >= 201 && touch.py <= 240) && (kDown & KEY_A)) { settingsUnload(); home(); } sf2d_swapbuffers(); } settingsUnload(); return 0; }
int settingsHighlight() { u32 kDown = hidKeysDown(); if (touch.px >= 0 && touch.px <= 198 && touch.py >= 75 && touch.py <= 133) { sf2d_draw_texture(wifi_highlight, 0, 87); sftd_draw_textf(roboto, 48, 106, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsMain[language][0]); /*if (kDown & KEY_A) { settingsUnload(); }*/ } else if (touch.px >= 0 && touch.px <= 198 && touch.py >= 134 && touch.py <= 174) { sf2d_draw_texture(display_highlight, 0, 135); sftd_draw_textf(roboto, 48, 153, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsMain[language][1]); /*if (kDown & KEY_A) { settingsUnload(); }*/ } else if (touch.px >= 0 && touch.px <= 198 && touch.py >= 175 && touch.py <= 240) { sf2d_draw_texture(developeroptions_highlight, 0, 183); sftd_draw_textf(roboto, 48, 202, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsMain[language][2]); /*if (kDown & KEY_A) { settingsUnload(); }*/ } else if (touch.px >= 203 && touch.px <= 400 && touch.py >= 75 && touch.py <= 133) { sf2d_draw_texture(security_highlight, 199, 87); sftd_draw_textf(roboto, 250, 106, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsMain[language][3]); /*if (kDown & KEY_A) { settingsUnload(); }*/ } else if (touch.px >= 203 && touch.px <= 400 && touch.py >= 134 && touch.py <= 174) { sf2d_draw_texture(performance_highlight, 203, 135); sftd_draw_textf(roboto, 250, 153, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsMain[language][4]); /*if (kDown & KEY_A) { settingsUnload(); }*/ } else if (touch.px >= 203 && touch.px <= 400 && touch.py >= 175 && touch.py <= 240) { sf2d_draw_texture(about_highlight, 203, 183); sftd_draw_textf(roboto, 250, 202, RGBA8(0, 0, 0, 255), 12, "%s", lang_settingsMain[language][5]); if (kDown & KEY_TOUCH) { settingsUnload(); aboutMenu(); } } return 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; }