diff --git a/gui/include/C2D_helper.h b/gui/include/C2D_helper.h index e6445f5..1c9b867 100644 --- a/gui/include/C2D_helper.h +++ b/gui/include/C2D_helper.h @@ -14,7 +14,6 @@ C3D_RenderTarget *RENDER_TOP, *RENDER_BOTTOM; C2D_TextBuf staticBuf, dynamicBuf, sizeBuf; -C2D_Image banner, drive_icon; typedef u32 Colour; @@ -26,5 +25,7 @@ float Draw_GetTextWidth(float size, const char *text); float Draw_GetTextHeight(float size, const char *text); bool Draw_Rect(float x, float y, float w, float h, Colour colour); bool Draw_Image(C2D_Image image, float x, float y); +bool Draw_ImageScale(C2D_Image image, float x, float y, float scaleX, float scaleY); +bool Draw_Image_Blend(C2D_Image image, float x, float y, Colour colour); #endif \ No newline at end of file diff --git a/gui/include/menu_control.h b/gui/include/menu_control.h new file mode 100644 index 0000000..a2e02c9 --- /dev/null +++ b/gui/include/menu_control.h @@ -0,0 +1,8 @@ +#ifndef _3DSIDENT_MENU_CONTROL_H_ +#define _3DSIDENT_MENU_CONTROL_H_ + +extern bool MENU_STATE_CONTROLS; + +void Menu_Controls(void); + +#endif \ No newline at end of file diff --git a/gui/include/textures.h b/gui/include/textures.h new file mode 100644 index 0000000..8607543 --- /dev/null +++ b/gui/include/textures.h @@ -0,0 +1,12 @@ +#ifndef _3DSIDENT_TEXTURES_H_ +#define _3DSIDENT_TEXTURES_H_ + +#include + +C2D_Image banner, drive_icon; +C2D_Image btn_A, btn_B, btn_X, btn_Y, btn_Start_Select, btn_L, btn_R, btn_ZL, btn_ZR, btn_Dpad, btn_Cpad, btn_Cstick, btn_home, cursor, volumeIcon; + +void Textures_Load(void); +void Textures_Free(void); + +#endif \ No newline at end of file diff --git a/gui/res/drawable/A.png b/gui/res/drawable/A.png new file mode 100644 index 0000000..47a0f12 Binary files /dev/null and b/gui/res/drawable/A.png differ diff --git a/gui/res/drawable/B.png b/gui/res/drawable/B.png new file mode 100644 index 0000000..86147d2 Binary files /dev/null and b/gui/res/drawable/B.png differ diff --git a/gui/res/drawable/C_stick.png b/gui/res/drawable/C_stick.png new file mode 100644 index 0000000..f4664fc Binary files /dev/null and b/gui/res/drawable/C_stick.png differ diff --git a/gui/res/drawable/Circle_pad.png b/gui/res/drawable/Circle_pad.png new file mode 100644 index 0000000..f8221c0 Binary files /dev/null and b/gui/res/drawable/Circle_pad.png differ diff --git a/gui/res/drawable/D_pad.png b/gui/res/drawable/D_pad.png new file mode 100644 index 0000000..9edb816 Binary files /dev/null and b/gui/res/drawable/D_pad.png differ diff --git a/gui/res/drawable/Home.png b/gui/res/drawable/Home.png new file mode 100644 index 0000000..079c6c8 Binary files /dev/null and b/gui/res/drawable/Home.png differ diff --git a/gui/res/drawable/L.png b/gui/res/drawable/L.png new file mode 100644 index 0000000..82aaf40 Binary files /dev/null and b/gui/res/drawable/L.png differ diff --git a/gui/res/drawable/R.png b/gui/res/drawable/R.png new file mode 100644 index 0000000..3977f77 Binary files /dev/null and b/gui/res/drawable/R.png differ diff --git a/gui/res/drawable/Start_select.png b/gui/res/drawable/Start_select.png new file mode 100644 index 0000000..9aab1cf Binary files /dev/null and b/gui/res/drawable/Start_select.png differ diff --git a/gui/res/drawable/X.png b/gui/res/drawable/X.png new file mode 100644 index 0000000..b207476 Binary files /dev/null and b/gui/res/drawable/X.png differ diff --git a/gui/res/drawable/Y.png b/gui/res/drawable/Y.png new file mode 100644 index 0000000..02f848f Binary files /dev/null and b/gui/res/drawable/Y.png differ diff --git a/gui/res/drawable/ZL.png b/gui/res/drawable/ZL.png new file mode 100644 index 0000000..cabf06d Binary files /dev/null and b/gui/res/drawable/ZL.png differ diff --git a/gui/res/drawable/ZR.png b/gui/res/drawable/ZR.png new file mode 100644 index 0000000..45b61ed Binary files /dev/null and b/gui/res/drawable/ZR.png differ diff --git a/gui/res/drawable/cursor.png b/gui/res/drawable/cursor.png new file mode 100644 index 0000000..c4fe784 Binary files /dev/null and b/gui/res/drawable/cursor.png differ diff --git a/gui/res/drawable/sprites.t3s b/gui/res/drawable/sprites.t3s index b528f50..4c3cbd9 100644 --- a/gui/res/drawable/sprites.t3s +++ b/gui/res/drawable/sprites.t3s @@ -1,3 +1,18 @@ --atlas -f rgba8888 -z auto +A.png +B.png +C_stick.png +Circle_pad.png +cursor.png +D_pad.png drive.png +Home.png icon.png +L.png +R.png +Start_select.png +volume.png +X.png +Y.png +ZL.png +ZR.png \ No newline at end of file diff --git a/gui/res/drawable/volume.png b/gui/res/drawable/volume.png new file mode 100644 index 0000000..d78975e Binary files /dev/null and b/gui/res/drawable/volume.png differ diff --git a/gui/romfs/res/drawable/sprites.t3x b/gui/romfs/res/drawable/sprites.t3x deleted file mode 100644 index a88f2e8..0000000 Binary files a/gui/romfs/res/drawable/sprites.t3x and /dev/null differ diff --git a/gui/source/C2D_helper.c b/gui/source/C2D_helper.c index b14bc14..eb87980 100644 --- a/gui/source/C2D_helper.c +++ b/gui/source/C2D_helper.c @@ -58,3 +58,15 @@ bool Draw_Image(C2D_Image image, float x, float y) { return C2D_DrawImageAt(image, x, y, 0.5f, NULL, 1.0f, 1.0f); } + +bool Draw_ImageScale(C2D_Image image, float x, float y, float scaleX, float scaleY) +{ + return C2D_DrawImageAt(image, x, y, 0.5f, NULL, scaleX, scaleY); +} + +bool Draw_Image_Blend(C2D_Image image, float x, float y, Colour colour) +{ + C2D_ImageTint tint; + C2D_PlainImageTint(&tint, colour, 0.50f); + return C2D_DrawImageAt(image, x, y, 0.5f, &tint, 1.0f, 1.0f); +} diff --git a/gui/source/main.c b/gui/source/main.c index 8cdefb5..e65c834 100644 --- a/gui/source/main.c +++ b/gui/source/main.c @@ -8,10 +8,10 @@ #include "fs.h" #include "menus.h" #include "sprites.h" +#include "textures.h" #include "utils.h" static u32 cpu_time_limit = 0; -static C2D_SpriteSheet spritesheet; static void Init_Services(void) { @@ -52,14 +52,12 @@ static void Init_Services(void) RENDER_TOP = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT); RENDER_BOTTOM = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT); - spritesheet = C2D_SpriteSheetLoad("romfs:/res/drawable/sprites.t3x"); - banner = C2D_SpriteSheetGetImage(spritesheet, sprites_icon_idx); - drive_icon = C2D_SpriteSheetGetImage(spritesheet, sprites_drive_idx); + Textures_Load(); } static void Term_Services(void) { - C2D_SpriteSheetFree(spritesheet); + Textures_Free(); C2D_TextBufDelete(sizeBuf); C2D_TextBufDelete(dynamicBuf); diff --git a/gui/source/menu_control.c b/gui/source/menu_control.c new file mode 100644 index 0000000..3d9479c --- /dev/null +++ b/gui/source/menu_control.c @@ -0,0 +1,158 @@ +#include <3ds.h> + +#include "C2D_helper.h" +#include "menu_control.h" +#include "textures.h" + +bool MENU_STATE_CONTROLS = false; + +void Menu_Controls(void) +{ + circlePosition cPad, cStick; + touchPosition touch; + + u16 touch_x = 0, touch_y = 0; + + u8 volume; + + int i = 0; + + while (MENU_STATE_CONTROLS) + { + hidScanInput(); + hidCircleRead(&cPad); + hidCstickRead(&cStick); + u32 kDown = hidKeysDown(); + u32 kHeld = hidKeysHeld(); + HIDUSER_GetSoundVolume(&volume); + + if (((kHeld & KEY_START) && (kDown & KEY_SELECT)) || ((kHeld & KEY_SELECT) && (kDown & KEY_START))) + MENU_STATE_CONTROLS = false; + + if (kHeld & KEY_TOUCH) + { + hidTouchRead(&touch); + touch_x = touch.px; + touch_y = touch.py; + } + + C3D_FrameBegin(C3D_FRAME_SYNCDRAW); + C2D_TargetClear(RENDER_TOP, C2D_Color32(60, 61, 63, 255)); + C2D_TargetClear(RENDER_BOTTOM, C2D_Color32(94, 39, 80, 255)); + C2D_SceneBegin(RENDER_TOP); + + Draw_Rect(75, 30, 250, 210, C2D_Color32(97, 101, 104, 255)); + Draw_Rect(85, 40, 230, 175, C2D_Color32(242, 241, 239, 255)); + Draw_Rect(85, 40, 230, 15, C2D_Color32(66, 65, 61, 255)); + + Draw_Textf(90, 40, 0.45f, C2D_Color32(230, 232, 214, 255), "3DSident Button Test"); + + Draw_Textf(90, 56, 0.45f, C2D_Color32(77, 76, 74, 255), "Circle pad: %04d, %04d", cPad.dx, cPad.dy); + Draw_Textf(90, 70, 0.45f, C2D_Color32(77, 76, 74, 255), "C stick: %04d, %04d", cStick.dx, cStick.dy); + Draw_Textf(90, 84, 0.45f, C2D_Color32(77, 76, 74, 255), "Touch position: %03d, %03d", touch.px, touch.py); + Draw_Textf(90, 84, 0.45f, C2D_Color32(77, 76, 74, 255), "Touch position: %03d, %03d", touch.px, touch.py); + + Draw_Image(volumeIcon, 90, 98); + double volPercent = (volume * 1.5873015873); + Draw_Rect(115, 104, 190, 5, C2D_Color32(219, 219, 219, 255)); + Draw_Rect(115, 104, ((volPercent / 100) * 190), 5, C2D_Color32(241, 122, 74, 255)); + + Draw_Textf(90, 118, 0.45f, C2D_Color32(77, 76, 74, 255), "3D"); + double _3dSliderPercent = (osGet3DSliderState() * 100.0); + Draw_Rect(115, 122, 190, 5, C2D_Color32(219, 219, 219, 255)); + Draw_Rect(115, 122, ((_3dSliderPercent / 100) * 190), 5, C2D_Color32(241, 122, 74, 255)); + + Draw_Textf(90, 138, 0.45f, C2D_Color32(77, 76, 74, 255), "Use home button to exit."); + + Draw_Image(btn_home, 180, 215); + + if (kHeld & KEY_L) + Draw_Image_Blend(btn_L, 0, 0, MENU_SELECTOR_COLOUR); + else + Draw_Image(btn_L, 0, 0); + + if (kHeld & KEY_R) + Draw_Image_Blend(btn_R, 345, 0, MENU_SELECTOR_COLOUR); + else + Draw_Image(btn_R, 345, 0); + + if (kHeld & KEY_ZL) + Draw_Image_Blend(btn_ZL, 60, 0, MENU_SELECTOR_COLOUR); + else + Draw_Image(btn_ZL, 60, 0); + + if (kHeld & KEY_ZR) + Draw_Image_Blend(btn_ZR, 300, 0, MENU_SELECTOR_COLOUR); + else + Draw_Image(btn_ZR, 300, 0); + + if (kHeld & KEY_A) + Draw_Image_Blend(btn_A, 370, 80, MENU_SELECTOR_COLOUR); + else + Draw_Image(btn_A, 370, 80); + + if (kHeld & KEY_B) + Draw_Image_Blend(btn_B, 350, 100, MENU_SELECTOR_COLOUR); + else + Draw_Image(btn_B, 350, 100); + + if (kHeld & KEY_X) + Draw_Image_Blend(btn_X, 350, 60, MENU_SELECTOR_COLOUR); + else + Draw_Image(btn_X, 350, 60); + + if (kHeld & KEY_Y) + Draw_Image_Blend(btn_Y, 330, 80, MENU_SELECTOR_COLOUR); + else + Draw_Image(btn_Y, 330, 80); + + if (kHeld & KEY_START) + Draw_Image_Blend(btn_Start_Select, 330, 140, MENU_SELECTOR_COLOUR); + else + Draw_Image(btn_Start_Select, 330, 140); + + if (kHeld & KEY_SELECT) + Draw_Image_Blend(btn_Start_Select, 330, 165, MENU_SELECTOR_COLOUR); + else + Draw_Image(btn_Start_Select, 330, 165); + + if (kHeld & KEY_CPAD_LEFT) + Draw_Image_Blend(btn_Cpad, 3, 55, MENU_SELECTOR_COLOUR); + else if (kHeld & KEY_CPAD_RIGHT) + Draw_Image_Blend(btn_Cpad, 13, 55, MENU_SELECTOR_COLOUR); + else if (kHeld & KEY_CPAD_UP) + Draw_Image_Blend(btn_Cpad, 8, 50, MENU_SELECTOR_COLOUR); + else if (kHeld & KEY_CPAD_DOWN) + Draw_Image_Blend(btn_Cpad, 8, 60, MENU_SELECTOR_COLOUR); + else + Draw_Image(btn_Cpad, 8, 55); + + if (kHeld & KEY_DLEFT) + Draw_Image_Blend(btn_Dpad, 0, 110, MENU_SELECTOR_COLOUR); + else if (kHeld & KEY_DRIGHT) + Draw_Image_Blend(btn_Dpad, 10, 110, MENU_SELECTOR_COLOUR); + else if (kHeld & KEY_DUP) + Draw_Image_Blend(btn_Dpad, 5, 105, MENU_SELECTOR_COLOUR); + else if (kHeld & KEY_DDOWN) + Draw_Image_Blend(btn_Dpad, 5, 115, MENU_SELECTOR_COLOUR); + else + Draw_Image(btn_Dpad, 5, 110); + + if (kHeld & KEY_CSTICK_LEFT) + Draw_Image_Blend(btn_Cstick, 325, 35, MENU_SELECTOR_COLOUR); + else if (kHeld & KEY_CSTICK_RIGHT) + Draw_Image_Blend(btn_Cstick, 335, 35, MENU_SELECTOR_COLOUR); + else if (kHeld & KEY_CSTICK_UP) + Draw_Image_Blend(btn_Cstick, 330, 30, MENU_SELECTOR_COLOUR); + else if (kHeld & KEY_CSTICK_DOWN) + Draw_Image_Blend(btn_Cstick, 330, 40, MENU_SELECTOR_COLOUR); + else + Draw_Image(btn_Cstick, 330, 35); + + C2D_SceneBegin(RENDER_BOTTOM); + + Draw_Image(cursor, touch_x, touch_y); + + Draw_EndFrame(); + } +} \ No newline at end of file diff --git a/gui/source/menus.c b/gui/source/menus.c index c174544..9f2e71d 100644 --- a/gui/source/menus.c +++ b/gui/source/menus.c @@ -10,10 +10,12 @@ #include "config.h" #include "hardware.h" #include "kernel.h" +#include "menu_control.h" #include "misc.h" #include "screenshot.h" #include "storage.h" #include "system.h" +#include "textures.h" #include "utils.h" #include "wifi.h" @@ -389,6 +391,7 @@ void Menu_Main(void) case 9: Draw_Text((400 - instr_width) / 2, (240 - instr_height) / 2, 0.5f, MENU_INFO_TITLE_COLOUR, "Press select to hide user-specific info"); Draw_Text((400 - instr_width) / 2, ((240 - instr_height) / 2) + 18, 0.5f, MENU_INFO_TITLE_COLOUR, " Press L + R to capture a screenshot "); + Draw_Text((400 - instr_width) / 2, ((240 - instr_height) / 2) + 36, 0.5f, MENU_INFO_TITLE_COLOUR, "Press START + SELECT to use button test"); break; } @@ -433,7 +436,9 @@ void Menu_Main(void) if (((kHeld & KEY_L) && (kDown & KEY_R)) || ((kHeld & KEY_R) && (kDown & KEY_L))) Screenshot_Capture(); - if (kDown & KEY_START) - longjmp(exitJmp, 1); + if (((kHeld & KEY_START) && (kDown & KEY_SELECT)) || ((kHeld & KEY_SELECT) && (kDown & KEY_START))) + MENU_STATE_CONTROLS = true; + + Menu_Controls(); } } diff --git a/gui/source/textures.c b/gui/source/textures.c new file mode 100644 index 0000000..0cc290e --- /dev/null +++ b/gui/source/textures.c @@ -0,0 +1,32 @@ +#include "sprites.h" +#include "textures.h" + +static C2D_SpriteSheet spritesheet; + +void Textures_Load(void) +{ + spritesheet = C2D_SpriteSheetLoad("romfs:/res/drawable/sprites.t3x"); + + banner = C2D_SpriteSheetGetImage(spritesheet, sprites_icon_idx); + drive_icon = C2D_SpriteSheetGetImage(spritesheet, sprites_drive_idx); + btn_A = C2D_SpriteSheetGetImage(spritesheet, sprites_A_idx); + btn_B = C2D_SpriteSheetGetImage(spritesheet, sprites_B_idx); + btn_X = C2D_SpriteSheetGetImage(spritesheet, sprites_X_idx); + btn_Y = C2D_SpriteSheetGetImage(spritesheet, sprites_Y_idx); + btn_Start_Select = C2D_SpriteSheetGetImage(spritesheet, sprites_Start_select_idx); + btn_L = C2D_SpriteSheetGetImage(spritesheet, sprites_L_idx); + btn_R = C2D_SpriteSheetGetImage(spritesheet, sprites_R_idx); + btn_ZL = C2D_SpriteSheetGetImage(spritesheet, sprites_ZL_idx); + btn_ZR = C2D_SpriteSheetGetImage(spritesheet, sprites_ZR_idx); + btn_Dpad = C2D_SpriteSheetGetImage(spritesheet, sprites_D_pad_idx); + btn_Cpad = C2D_SpriteSheetGetImage(spritesheet, sprites_Circle_pad_idx); + btn_Cstick = C2D_SpriteSheetGetImage(spritesheet, sprites_C_stick_idx); + btn_home = C2D_SpriteSheetGetImage(spritesheet, sprites_Home_idx); + cursor = C2D_SpriteSheetGetImage(spritesheet, sprites_cursor_idx); + volumeIcon = C2D_SpriteSheetGetImage(spritesheet, sprites_volume_idx); +} + +void Textures_Free(void) +{ + C2D_SpriteSheetFree(spritesheet); +} \ No newline at end of file