mirror of
https://github.com/hax4dazy/TinWoo.git
synced 2025-02-09 19:25:05 +01:00
Delete include directory
This commit is contained in:
parent
d67f0409c7
commit
cb09bcb702
@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <filesystem>
|
|
||||||
#include <vector>
|
|
||||||
namespace nspInstStuff_B {
|
|
||||||
void installNspFromFile(std::vector<std::filesystem::path> ourNspList, int whereToInstall);
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,19 +0,0 @@
|
|||||||
Copyright (c) 2018-2019 XorTroll
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
@ -1,14 +0,0 @@
|
|||||||
|
|
||||||
.PHONY: lib clean
|
|
||||||
|
|
||||||
lib:
|
|
||||||
@$(MAKE) -C Plutonium/
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@$(MAKE) clean -C Plutonium/
|
|
||||||
@$(MAKE) clean -C Example/
|
|
||||||
|
|
||||||
example: lib
|
|
||||||
@$(MAKE) -C Example/
|
|
||||||
|
|
||||||
all: lib example
|
|
@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file Plutonium
|
|
||||||
@brief Plutonium library's main header. (include this to use this library properly)
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <pu/pu_CFW.hpp>
|
|
||||||
|
|
||||||
#include <pu/audio/audio_Music.hpp>
|
|
||||||
#include <pu/audio/audio_Sfx.hpp>
|
|
||||||
|
|
||||||
#include <pu/ui/ui_Application.hpp>
|
|
||||||
#include <pu/ui/ui_Types.hpp>
|
|
||||||
#include <pu/ui/ui_Container.hpp>
|
|
||||||
#include <pu/ui/ui_Dialog.hpp>
|
|
||||||
#include <pu/ui/ui_Layout.hpp>
|
|
||||||
#include <pu/ui/ui_Overlay.hpp>
|
|
||||||
|
|
||||||
#include <pu/ui/elm/elm_Button.hpp>
|
|
||||||
#include <pu/ui/elm/elm_Element.hpp>
|
|
||||||
#include <pu/ui/elm/elm_Image.hpp>
|
|
||||||
#include <pu/ui/elm/elm_Menu.hpp>
|
|
||||||
#include <pu/ui/elm/elm_ProgressBar.hpp>
|
|
||||||
#include <pu/ui/elm/elm_Rectangle.hpp>
|
|
||||||
#include <pu/ui/elm/elm_TextBlock.hpp>
|
|
||||||
#include <pu/ui/elm/elm_Toggle.hpp>
|
|
||||||
|
|
||||||
#include <pu/ui/extras/extras_Toast.hpp>
|
|
||||||
|
|
||||||
#include <pu/ui/render/render_Renderer.hpp>
|
|
||||||
#include <pu/ui/render/render_SDL2.hpp>
|
|
@ -1,35 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file audio_Music.hpp
|
|
||||||
@brief Music (BGM) support
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <SDL2/SDL_mixer.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace pu::audio
|
|
||||||
{
|
|
||||||
typedef Mix_Music *Music;
|
|
||||||
|
|
||||||
Music Open(std::string Path);
|
|
||||||
void Play(Music Mus, int Loops);
|
|
||||||
void PlayWithFadeIn(Music Mus, int Loops, int Milli);
|
|
||||||
bool IsPlaying();
|
|
||||||
void Pause();
|
|
||||||
void Resume();
|
|
||||||
void SetVolume(int Volume);
|
|
||||||
int GetVolume();
|
|
||||||
void FadeOut(int Milli);
|
|
||||||
void Rewind();
|
|
||||||
void Stop();
|
|
||||||
void SetPosition(double Sec);
|
|
||||||
void Delete(Music Mus);
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file audio_Sfx.hpp
|
|
||||||
@brief Sfx (sound effects) support
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <SDL2/SDL_mixer.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace pu::audio
|
|
||||||
{
|
|
||||||
typedef Mix_Chunk *Sfx;
|
|
||||||
|
|
||||||
Sfx Load(std::string Path);
|
|
||||||
void Play(Sfx Sfx);
|
|
||||||
void DeleteSfx(Sfx Sfx);
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file pu_CFW.hpp
|
|
||||||
@brief CFW detecting code
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace pu
|
|
||||||
{
|
|
||||||
bool IsAtmosphere();
|
|
||||||
bool IsReiNX();
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
// Defines a static function (::New(...)) as a constructor for smart ptrs, also defines a custom type (::Ref) to simplify it
|
|
||||||
#define PU_SMART_CTOR(type) \
|
|
||||||
using Ref = std::shared_ptr<type>; \
|
|
||||||
template<typename ...Args> \
|
|
||||||
static Ref New(Args &&...CtorArgs) \
|
|
||||||
{ \
|
|
||||||
return std::move(std::make_shared<type>(std::forward<Args>(CtorArgs)...)); \
|
|
||||||
}
|
|
@ -1,197 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file switch/types.h
|
|
||||||
* @brief Various system types.
|
|
||||||
* @copyright libnx Authors
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdalign.h>
|
|
||||||
|
|
||||||
/// The maximum value of a u64.
|
|
||||||
#define U64_MAX UINT64_MAX
|
|
||||||
|
|
||||||
#ifndef SSIZE_MAX
|
|
||||||
#ifdef SIZE_MAX
|
|
||||||
#define SSIZE_MAX ((SIZE_MAX) >> 1)
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef uint8_t u8; ///< 8-bit unsigned integer.
|
|
||||||
typedef uint16_t u16; ///< 16-bit unsigned integer.
|
|
||||||
typedef uint32_t u32; ///< 32-bit unsigned integer.
|
|
||||||
typedef uint64_t u64; ///< 64-bit unsigned integer.
|
|
||||||
typedef __uint128_t u128; ///< 128-bit unsigned integer.
|
|
||||||
|
|
||||||
typedef int8_t s8; ///< 8-bit signed integer.
|
|
||||||
typedef int16_t s16; ///< 16-bit signed integer.
|
|
||||||
typedef int32_t s32; ///< 32-bit signed integer.
|
|
||||||
typedef int64_t s64; ///< 64-bit signed integer.
|
|
||||||
typedef __int128_t s128; ///< 128-bit unsigned integer.
|
|
||||||
|
|
||||||
typedef volatile u8 vu8; ///< 8-bit volatile unsigned integer.
|
|
||||||
typedef volatile u16 vu16; ///< 16-bit volatile unsigned integer.
|
|
||||||
typedef volatile u32 vu32; ///< 32-bit volatile unsigned integer.
|
|
||||||
typedef volatile u64 vu64; ///< 64-bit volatile unsigned integer.
|
|
||||||
typedef volatile u128 vu128; ///< 128-bit volatile unsigned integer.
|
|
||||||
|
|
||||||
typedef volatile s8 vs8; ///< 8-bit volatile signed integer.
|
|
||||||
typedef volatile s16 vs16; ///< 16-bit volatile signed integer.
|
|
||||||
typedef volatile s32 vs32; ///< 32-bit volatile signed integer.
|
|
||||||
typedef volatile s64 vs64; ///< 64-bit volatile signed integer.
|
|
||||||
typedef volatile s128 vs128; ///< 128-bit volatile signed integer.
|
|
||||||
|
|
||||||
typedef u32 Handle; ///< Kernel object handle.
|
|
||||||
typedef u32 Result; ///< Function error code result type.
|
|
||||||
typedef void (*ThreadFunc)(void *); ///< Thread entrypoint function.
|
|
||||||
typedef void (*VoidFn)(void); ///< Function without arguments nor return value.
|
|
||||||
|
|
||||||
/// Creates a bitmask from a bit number.
|
|
||||||
#ifndef BIT
|
|
||||||
#define BIT(n) (1U<<(n))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Packs a struct so that it won't include padding bytes.
|
|
||||||
#ifndef PACKED
|
|
||||||
#define PACKED __attribute__((packed))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Marks a function as not returning, for the purposes of compiler optimization.
|
|
||||||
#ifndef NORETURN
|
|
||||||
#define NORETURN __attribute__((noreturn))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Performs a dummy operation on the specified argument in order to silence compiler warnings about unused arguments.
|
|
||||||
#ifndef IGNORE_ARG
|
|
||||||
#define IGNORE_ARG(x) (void)(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Flags a function as deprecated.
|
|
||||||
#ifndef DEPRECATED
|
|
||||||
#ifndef LIBNX_NO_DEPRECATION
|
|
||||||
#define DEPRECATED __attribute__ ((deprecated))
|
|
||||||
#else
|
|
||||||
#define DEPRECATED
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Flags a function as (always) inline.
|
|
||||||
#define NX_INLINE __attribute__((always_inline)) static inline
|
|
||||||
|
|
||||||
/// Flags a function as constexpr in C++14 and above; or as (always) inline otherwise.
|
|
||||||
#if __cplusplus >= 201402L
|
|
||||||
#define NX_CONSTEXPR NX_INLINE constexpr
|
|
||||||
#else
|
|
||||||
#define NX_CONSTEXPR NX_INLINE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Invalid handle.
|
|
||||||
#define INVALID_HANDLE ((Handle) 0)
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
KEY_A = BIT(0), ///< A
|
|
||||||
KEY_B = BIT(1), ///< B
|
|
||||||
KEY_X = BIT(2), ///< X
|
|
||||||
KEY_Y = BIT(3), ///< Y
|
|
||||||
KEY_LSTICK = BIT(4), ///< Left Stick Button
|
|
||||||
KEY_RSTICK = BIT(5), ///< Right Stick Button
|
|
||||||
KEY_L = BIT(6), ///< L
|
|
||||||
KEY_R = BIT(7), ///< R
|
|
||||||
KEY_ZL = BIT(8), ///< ZL
|
|
||||||
KEY_ZR = BIT(9), ///< ZR
|
|
||||||
KEY_PLUS = BIT(10), ///< Plus
|
|
||||||
KEY_MINUS = BIT(11), ///< Minus
|
|
||||||
KEY_DLEFT = BIT(12), ///< D-Pad Left
|
|
||||||
KEY_DUP = BIT(13), ///< D-Pad Up
|
|
||||||
KEY_DRIGHT = BIT(14), ///< D-Pad Right
|
|
||||||
KEY_DDOWN = BIT(15), ///< D-Pad Down
|
|
||||||
KEY_LSTICK_LEFT = BIT(16), ///< Left Stick Left
|
|
||||||
KEY_LSTICK_UP = BIT(17), ///< Left Stick Up
|
|
||||||
KEY_LSTICK_RIGHT = BIT(18), ///< Left Stick Right
|
|
||||||
KEY_LSTICK_DOWN = BIT(19), ///< Left Stick Down
|
|
||||||
KEY_RSTICK_LEFT = BIT(20), ///< Right Stick Left
|
|
||||||
KEY_RSTICK_UP = BIT(21), ///< Right Stick Up
|
|
||||||
KEY_RSTICK_RIGHT = BIT(22), ///< Right Stick Right
|
|
||||||
KEY_RSTICK_DOWN = BIT(23), ///< Right Stick Down
|
|
||||||
KEY_SL_LEFT = BIT(24), ///< SL on Left Joy-Con
|
|
||||||
KEY_SR_LEFT = BIT(25), ///< SR on Left Joy-Con
|
|
||||||
KEY_SL_RIGHT = BIT(26), ///< SL on Right Joy-Con
|
|
||||||
KEY_SR_RIGHT = BIT(27), ///< SR on Right Joy-Con
|
|
||||||
|
|
||||||
KEY_HOME = BIT(18), ///< HOME button, only available for use with HiddbgHdlsState::buttons.
|
|
||||||
KEY_CAPTURE = BIT(19), ///< Capture button, only available for use with HiddbgHdlsState::buttons.
|
|
||||||
|
|
||||||
// Pseudo-key for at least one finger on the touch screen
|
|
||||||
KEY_TOUCH = BIT(28),
|
|
||||||
|
|
||||||
// Buttons by orientation (for single Joy-Con), also works with Joy-Con pairs, Pro Controller
|
|
||||||
KEY_JOYCON_RIGHT = BIT(0),
|
|
||||||
KEY_JOYCON_DOWN = BIT(1),
|
|
||||||
KEY_JOYCON_UP = BIT(2),
|
|
||||||
KEY_JOYCON_LEFT = BIT(3),
|
|
||||||
|
|
||||||
// Generic catch-all directions, also works for single Joy-Con
|
|
||||||
KEY_UP = KEY_DUP | KEY_LSTICK_UP | KEY_RSTICK_UP, ///< D-Pad Up or Sticks Up
|
|
||||||
KEY_DOWN = KEY_DDOWN | KEY_LSTICK_DOWN | KEY_RSTICK_DOWN, ///< D-Pad Down or Sticks Down
|
|
||||||
KEY_LEFT = KEY_DLEFT | KEY_LSTICK_LEFT | KEY_RSTICK_LEFT, ///< D-Pad Left or Sticks Left
|
|
||||||
KEY_RIGHT = KEY_DRIGHT | KEY_LSTICK_RIGHT | KEY_RSTICK_RIGHT, ///< D-Pad Right or Sticks Right
|
|
||||||
KEY_SL = KEY_SL_LEFT | KEY_SL_RIGHT, ///< SL on Left or Right Joy-Con
|
|
||||||
KEY_SR = KEY_SR_LEFT | KEY_SR_RIGHT, ///< SR on Left or Right Joy-Con
|
|
||||||
} HidControllerKeys;
|
|
||||||
|
|
||||||
/// HidControllerID
|
|
||||||
typedef enum {
|
|
||||||
CONTROLLER_PLAYER_1 = 0,
|
|
||||||
CONTROLLER_PLAYER_2 = 1,
|
|
||||||
CONTROLLER_PLAYER_3 = 2,
|
|
||||||
CONTROLLER_PLAYER_4 = 3,
|
|
||||||
CONTROLLER_PLAYER_5 = 4,
|
|
||||||
CONTROLLER_PLAYER_6 = 5,
|
|
||||||
CONTROLLER_PLAYER_7 = 6,
|
|
||||||
CONTROLLER_PLAYER_8 = 7,
|
|
||||||
CONTROLLER_HANDHELD = 8,
|
|
||||||
CONTROLLER_UNKNOWN = 9,
|
|
||||||
CONTROLLER_P1_AUTO = 10, ///< Not an actual HID-sysmodule ID. Only for hidKeys*()/hidJoystickRead()/hidSixAxisSensorValuesRead()/hidGetControllerType()/hidGetControllerColors()/hidIsControllerConnected(). Automatically uses CONTROLLER_PLAYER_1 when connected, otherwise uses CONTROLLER_HANDHELD.
|
|
||||||
} HidControllerID;
|
|
||||||
|
|
||||||
/// touchPosition
|
|
||||||
typedef struct touchPosition {
|
|
||||||
u32 id;
|
|
||||||
u32 px;
|
|
||||||
u32 py;
|
|
||||||
u32 dx;
|
|
||||||
u32 dy;
|
|
||||||
u32 angle;
|
|
||||||
} touchPosition;
|
|
||||||
|
|
||||||
/// HidVector
|
|
||||||
typedef struct HidVector {
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
float z;
|
|
||||||
} HidVector;
|
|
||||||
|
|
||||||
/// SixAxisSensorValues
|
|
||||||
typedef struct SixAxisSensorValues {
|
|
||||||
HidVector accelerometer;
|
|
||||||
HidVector gyroscope;
|
|
||||||
HidVector unk;
|
|
||||||
HidVector orientation[3];
|
|
||||||
} SixAxisSensorValues;
|
|
||||||
|
|
||||||
/// HID controller type
|
|
||||||
typedef enum {
|
|
||||||
TYPE_PROCONTROLLER = BIT(0),
|
|
||||||
TYPE_HANDHELD = BIT(1),
|
|
||||||
TYPE_JOYCON_PAIR = BIT(2),
|
|
||||||
TYPE_JOYCON_LEFT = BIT(3),
|
|
||||||
TYPE_JOYCON_RIGHT = BIT(4),
|
|
||||||
|
|
||||||
TYPE_SYSTEM_EXT = BIT(29),
|
|
||||||
TYPE_SYSTEM = BIT(30),
|
|
||||||
} HidControllerType;
|
|
||||||
|
|
||||||
#define R_SUCCEEDED(res) ((res)==0)
|
|
@ -1,57 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file Button.hpp
|
|
||||||
@brief A Button is an Element for option selecting.
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <functional>
|
|
||||||
#include <pu/ui/elm/elm_Element.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
class Button : public Element
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Button(s32 X, s32 Y, s32 Width, s32 Height, const std::string& Content, Color TextColor, Color Color);
|
|
||||||
PU_SMART_CTOR(Button)
|
|
||||||
~Button();
|
|
||||||
|
|
||||||
s32 GetX();
|
|
||||||
void SetX(s32 X);
|
|
||||||
s32 GetY();
|
|
||||||
void SetY(s32 Y);
|
|
||||||
s32 GetWidth();
|
|
||||||
void SetWidth(s32 Width);
|
|
||||||
s32 GetHeight();
|
|
||||||
void SetHeight(s32 Height);
|
|
||||||
std::string GetContent();
|
|
||||||
void SetContent(const std::string& Content);
|
|
||||||
Color GetColor();
|
|
||||||
void SetColor(Color Color);
|
|
||||||
void SetFontSize(s32 FontSize);
|
|
||||||
void SetOnClick(std::function<void()> ClickCallback);
|
|
||||||
void OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y);
|
|
||||||
void OnInput(u64 Down, u64 Up, u64 Held, Touch Pos);
|
|
||||||
private:
|
|
||||||
s32 x;
|
|
||||||
s32 y;
|
|
||||||
s32 w;
|
|
||||||
s32 h;
|
|
||||||
render::NativeFont font = nullptr;
|
|
||||||
render::NativeFont meme = nullptr;
|
|
||||||
Color clr;
|
|
||||||
std::string cnt;
|
|
||||||
std::function<void()> clickcb;
|
|
||||||
bool hover;
|
|
||||||
s32 hoverfact;
|
|
||||||
render::NativeTexture ntex = nullptr;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file Element.hpp
|
|
||||||
@brief An Element is the base of Plutonium UI's content.
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <pu/pu_Macros.hpp>
|
|
||||||
#include <pu/ui/render/render_Renderer.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
enum class HorizontalAlign
|
|
||||||
{
|
|
||||||
Left,
|
|
||||||
Center,
|
|
||||||
Right,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class VerticalAlign
|
|
||||||
{
|
|
||||||
Up,
|
|
||||||
Center,
|
|
||||||
Down,
|
|
||||||
};
|
|
||||||
|
|
||||||
class Element
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Element();
|
|
||||||
PU_SMART_CTOR(Element)
|
|
||||||
virtual ~Element();
|
|
||||||
|
|
||||||
// In order to make custom UI Elements, need to implement this functions
|
|
||||||
virtual s32 GetX() = 0;
|
|
||||||
virtual s32 GetY() = 0;
|
|
||||||
virtual s32 GetWidth() = 0;
|
|
||||||
virtual s32 GetHeight() = 0;
|
|
||||||
virtual void OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y) = 0;
|
|
||||||
virtual void OnInput(u64 Down, u64 Up, u64 Held, Touch Pos) = 0;
|
|
||||||
|
|
||||||
bool IsVisible();
|
|
||||||
void SetVisible(bool Visible);
|
|
||||||
void SetParent(void *Base);
|
|
||||||
void *GetParent();
|
|
||||||
void SetHorizontalAlign(HorizontalAlign Align);
|
|
||||||
HorizontalAlign GetHorizontalAlign();
|
|
||||||
void SetVerticalAlign(VerticalAlign Align);
|
|
||||||
VerticalAlign GetVerticalAlign();
|
|
||||||
bool HasParent();
|
|
||||||
s32 GetProcessedX();
|
|
||||||
s32 GetProcessedY();
|
|
||||||
protected:
|
|
||||||
bool visible;
|
|
||||||
HorizontalAlign halign;
|
|
||||||
VerticalAlign valign;
|
|
||||||
void *parent;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file Image.hpp
|
|
||||||
@brief An Image is an Element showing a picture. (JPEG, PNG, TGA, BMP)
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <pu/ui/elm/elm_Element.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
class Image : public Element
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Image(s32 X, s32 Y, const std::string& Image);
|
|
||||||
Image(s32 X, s32 Y, void* jpegbuffer, s32 size);
|
|
||||||
Image(s32 X, s32 Y, void* rgbBuffer, u64 width, u64 height, u8 depth);
|
|
||||||
PU_SMART_CTOR(Image)
|
|
||||||
~Image();
|
|
||||||
|
|
||||||
s32 GetX();
|
|
||||||
void SetX(s32 X);
|
|
||||||
s32 GetY();
|
|
||||||
void SetY(s32 Y);
|
|
||||||
s32 GetWidth();
|
|
||||||
void SetWidth(s32 Width);
|
|
||||||
s32 GetHeight();
|
|
||||||
void SetHeight(s32 Height);
|
|
||||||
float GetRotation();
|
|
||||||
void SetRotation(float Angle);
|
|
||||||
void SetImage(const std::string& Image);
|
|
||||||
void SetJpegImage(void* buffer, s32 size);
|
|
||||||
void SetRgbImage(void* buffer, u64 width, u64 height, u8 depth = 4);
|
|
||||||
bool IsImageValid();
|
|
||||||
void OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y);
|
|
||||||
void OnInput(u64 Down, u64 Up, u64 Held, Touch Pos);
|
|
||||||
private:
|
|
||||||
render::NativeTexture ntex = nullptr;
|
|
||||||
render::NativeTextureRenderOptions rendopts;
|
|
||||||
s32 x;
|
|
||||||
s32 y;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,110 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file Menu.hpp
|
|
||||||
@brief A Menu is a very useful Element for option browsing or selecting.
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <pu/ui/elm/elm_Element.hpp>
|
|
||||||
#include <vector>
|
|
||||||
#include <chrono>
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
class MenuItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MenuItem(const std::string& Name);
|
|
||||||
PU_SMART_CTOR(MenuItem)
|
|
||||||
|
|
||||||
std::string GetName();
|
|
||||||
void SetName(const std::string& Name);
|
|
||||||
Color GetColor();
|
|
||||||
void SetColor(Color Color);
|
|
||||||
void AddOnClick(std::function<void()> Callback, u64 Key = KEY_A);
|
|
||||||
s32 GetCallbackCount();
|
|
||||||
std::function<void()> GetCallback(s32 Index);
|
|
||||||
u64 GetCallbackKey(s32 Index);
|
|
||||||
std::string GetIcon();
|
|
||||||
void SetIcon(std::string Icon);
|
|
||||||
bool HasIcon();
|
|
||||||
void SetFactor(float Factor);
|
|
||||||
float GetFactor();
|
|
||||||
private:
|
|
||||||
std::string name;
|
|
||||||
Color clr;
|
|
||||||
bool hasicon = false;
|
|
||||||
std::string icon;
|
|
||||||
float factor = 0;
|
|
||||||
std::vector<std::function<void()>> cbs;
|
|
||||||
std::vector<u64> cbipts;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Menu : public Element
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Menu(s32 X, s32 Y, s32 Width, Color OptionColor, s32 ItemSize, s32 ItemsToShow, s32 fontSize = 25);
|
|
||||||
PU_SMART_CTOR(Menu)
|
|
||||||
|
|
||||||
s32 GetX();
|
|
||||||
void SetX(s32 X);
|
|
||||||
s32 GetY();
|
|
||||||
void SetY(s32 Y);
|
|
||||||
s32 GetWidth();
|
|
||||||
void SetWidth(s32 Width);
|
|
||||||
s32 GetHeight();
|
|
||||||
s32 GetItemSize();
|
|
||||||
void SetItemSize(s32 ItemSize);
|
|
||||||
s32 GetNumberOfItemsToShow();
|
|
||||||
void SetNumberOfItemsToShow(s32 ItemsToShow);
|
|
||||||
Color GetColor();
|
|
||||||
void SetColor(Color Color);
|
|
||||||
Color GetOnFocusColor();
|
|
||||||
void SetOnFocusColor(Color Color);
|
|
||||||
Color GetScrollbarColor();
|
|
||||||
void SetScrollbarColor(Color Color);
|
|
||||||
void SetOnSelectionChanged(std::function<void()> Callback);
|
|
||||||
void AddItem(MenuItem::Ref &Item);
|
|
||||||
void ClearItems();
|
|
||||||
void SetCooldownEnabled(bool Cooldown);
|
|
||||||
MenuItem::Ref &GetSelectedItem();
|
|
||||||
std::vector<MenuItem::Ref> &GetItems();
|
|
||||||
s32 GetSelectedIndex();
|
|
||||||
void SetSelectedIndex(s32 Index);
|
|
||||||
void OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y);
|
|
||||||
void OnInput(u64 Down, u64 Up, u64 Held, Touch Pos);
|
|
||||||
private:
|
|
||||||
void ReloadItemRenders();
|
|
||||||
bool dtouch;
|
|
||||||
s32 x;
|
|
||||||
s32 y;
|
|
||||||
s32 w;
|
|
||||||
s32 isize;
|
|
||||||
s32 ishow;
|
|
||||||
s32 previsel;
|
|
||||||
s32 fisel;
|
|
||||||
s32 isel;
|
|
||||||
s32 pselfact;
|
|
||||||
s32 selfact;
|
|
||||||
Color scb;
|
|
||||||
Color clr;
|
|
||||||
Color fcs;
|
|
||||||
bool icdown;
|
|
||||||
int basestatus;
|
|
||||||
std::chrono::time_point<std::chrono::steady_clock> basetime;
|
|
||||||
std::function<void()> onselch;
|
|
||||||
std::vector<MenuItem::Ref> itms;
|
|
||||||
render::NativeFont font;
|
|
||||||
render::NativeFont meme;
|
|
||||||
std::vector<render::NativeTexture> loadednames;
|
|
||||||
std::vector<render::NativeTexture> loadedicons;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file ProgressBar.hpp
|
|
||||||
@brief A ProgressBar is an Element which represents a progress (a percentage) by filling a bar.
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <pu/ui/elm/elm_Element.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
class ProgressBar : public Element
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ProgressBar(s32 X, s32 Y, s32 Width, s32 Height, double MaxValue);
|
|
||||||
PU_SMART_CTOR(ProgressBar)
|
|
||||||
|
|
||||||
s32 GetX();
|
|
||||||
void SetX(s32 X);
|
|
||||||
s32 GetY();
|
|
||||||
void SetY(s32 Y);
|
|
||||||
s32 GetWidth();
|
|
||||||
void SetWidth(s32 Width);
|
|
||||||
s32 GetHeight();
|
|
||||||
void SetHeight(s32 Height);
|
|
||||||
Color GetColor();
|
|
||||||
void SetColor(Color Color);
|
|
||||||
Color GetProgressColor();
|
|
||||||
void SetProgressColor(Color Color);
|
|
||||||
double GetProgress();
|
|
||||||
void SetProgress(double Progress);
|
|
||||||
void IncrementProgress(double Progress);
|
|
||||||
void DecrementProgress(double Progress);
|
|
||||||
void SetMaxValue(double Max);
|
|
||||||
double GetMaxValue();
|
|
||||||
void FillProgress();
|
|
||||||
void ClearProgress();
|
|
||||||
bool IsCompleted();
|
|
||||||
void OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y);
|
|
||||||
void OnInput(u64 Down, u64 Up, u64 Held, Touch Pos);
|
|
||||||
private:
|
|
||||||
s32 x;
|
|
||||||
s32 y;
|
|
||||||
s32 w;
|
|
||||||
s32 h;
|
|
||||||
double val;
|
|
||||||
double maxval;
|
|
||||||
Color clr;
|
|
||||||
Color oclr;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file Rectangle.hpp
|
|
||||||
@brief A Rectangle is an Element which simply draws a filled rectangle.
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <pu/ui/elm/elm_Element.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
class Rectangle : public Element
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Rectangle(s32 X, s32 Y, s32 Width, s32 Height, Color RecColor, s32 BorderRadius = 0);
|
|
||||||
PU_SMART_CTOR(Rectangle)
|
|
||||||
|
|
||||||
s32 GetX();
|
|
||||||
void SetX(s32 X);
|
|
||||||
s32 GetY();
|
|
||||||
void SetY(s32 Y);
|
|
||||||
s32 GetWidth();
|
|
||||||
void SetWidth(s32 Width);
|
|
||||||
s32 GetHeight();
|
|
||||||
void SetHeight(s32 Height);
|
|
||||||
s32 GetBorderRadius();
|
|
||||||
void SetBorderRadius(s32 Radius);
|
|
||||||
Color GetColor();
|
|
||||||
void SetColor(Color RecColor);
|
|
||||||
void OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y);
|
|
||||||
void OnInput(u64 Down, u64 Up, u64 Held, Touch Pos);
|
|
||||||
private:
|
|
||||||
s32 borderr;
|
|
||||||
s32 x;
|
|
||||||
s32 y;
|
|
||||||
s32 w;
|
|
||||||
s32 h;
|
|
||||||
Color clr;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file TextBlock.hpp
|
|
||||||
@brief A TextBlock is a very useful Element which is used to draw text on the screen.
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <pu/ui/elm/elm_Element.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
class TextBlock : public Element
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TextBlock(s32 X, s32 Y, const std::string& Text, s32 FontSize = 25);
|
|
||||||
PU_SMART_CTOR(TextBlock)
|
|
||||||
~TextBlock();
|
|
||||||
|
|
||||||
s32 GetX();
|
|
||||||
void SetX(s32 X);
|
|
||||||
s32 GetY();
|
|
||||||
void SetY(s32 Y);
|
|
||||||
s32 GetWidth();
|
|
||||||
s32 GetHeight();
|
|
||||||
s32 GetTextWidth();
|
|
||||||
s32 GetTextHeight();
|
|
||||||
std::string GetText();
|
|
||||||
void SetText(const std::string& Text);
|
|
||||||
void SetFontSize(s32 FontSize);
|
|
||||||
Color GetColor();
|
|
||||||
void SetColor(Color Color);
|
|
||||||
void OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y);
|
|
||||||
void OnInput(u64 Down, u64 Up, u64 Held, Touch Pos);
|
|
||||||
private:
|
|
||||||
std::string text;
|
|
||||||
s32 x;
|
|
||||||
s32 y;
|
|
||||||
render::NativeFont font;
|
|
||||||
render::NativeFont meme;
|
|
||||||
Color clr;
|
|
||||||
render::NativeTexture ntex = nullptr;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file Toggle.hpp
|
|
||||||
@brief A Toggle is an Element used to switch between two options by toggling the item.
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <pu/ui/elm/elm_Element.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
class Toggle : public Element
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Toggle(s32 X, s32 Y, const std::string& Content, u64 Key, Color Color);
|
|
||||||
PU_SMART_CTOR(Toggle)
|
|
||||||
~Toggle();
|
|
||||||
|
|
||||||
s32 GetX();
|
|
||||||
void SetX(s32 X);
|
|
||||||
s32 GetY();
|
|
||||||
void SetY(s32 Y);
|
|
||||||
s32 GetWidth();
|
|
||||||
s32 GetHeight();
|
|
||||||
std::string GetContent();
|
|
||||||
void SetContent(const std::string& Content);
|
|
||||||
void SetFontSize(s32 FontSize);
|
|
||||||
Color GetColor();
|
|
||||||
void SetColor(Color General);
|
|
||||||
u64 GetKey();
|
|
||||||
void SetKey(u64 Key);
|
|
||||||
bool IsChecked();
|
|
||||||
void OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y);
|
|
||||||
void OnInput(u64 Down, u64 Up, u64 Held, Touch Pos);
|
|
||||||
private:
|
|
||||||
std::string cnt;
|
|
||||||
s32 x;
|
|
||||||
s32 y;
|
|
||||||
u64 key;
|
|
||||||
bool checked;
|
|
||||||
Color clr;
|
|
||||||
render::NativeFont font;
|
|
||||||
render::NativeFont meme;
|
|
||||||
s32 togfact;
|
|
||||||
render::NativeTexture ntex = nullptr;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file extras_Toast.hpp
|
|
||||||
@brief An Overlay similar to Android's toast notifications
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <pu/ui/ui_Overlay.hpp>
|
|
||||||
#include <pu/ui/elm/elm_TextBlock.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::extras
|
|
||||||
{
|
|
||||||
class Toast final : public Overlay
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Toast(const std::string& Text, s32 FontSize, Color TextColor, Color BaseColor);
|
|
||||||
PU_SMART_CTOR(Toast)
|
|
||||||
|
|
||||||
void SetText(const std::string& Text);
|
|
||||||
void OnPreRender(render::Renderer::Ref &Drawer);
|
|
||||||
void OnPostRender(render::Renderer::Ref &Drawer);
|
|
||||||
private:
|
|
||||||
pu::ui::elm::TextBlock::Ref text;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,294 +0,0 @@
|
|||||||
/*
|
|
||||||
SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts
|
|
||||||
Copyright (C) 2001-2019 Sam Lantinga <slouken@libsdl.org>
|
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
|
||||||
warranty. In no event will the authors be held liable for any damages
|
|
||||||
arising from the use of this software.
|
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
|
||||||
including commercial applications, and to alter it and redistribute it
|
|
||||||
freely, subject to the following restrictions:
|
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
|
||||||
claim that you wrote the original software. If you use this software
|
|
||||||
in a product, an acknowledgment in the product documentation would be
|
|
||||||
appreciated but is not required.
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
misrepresented as being the original software.
|
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* This library is a wrapper around the excellent FreeType 2.0 library,
|
|
||||||
available at:
|
|
||||||
http://www.freetype.org/
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Note: In many places, SDL_ttf will say "glyph" when it means "code point."
|
|
||||||
Unicode is hard, we learn as we go, and we apologize for adding to the
|
|
||||||
confusion. */
|
|
||||||
|
|
||||||
#ifndef SDL_TTF_H_
|
|
||||||
#define SDL_TTF_H_
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <SDL2/begin_code.h>
|
|
||||||
|
|
||||||
/* Set up for C function definitions, even when using C++ */
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
|
|
||||||
*/
|
|
||||||
#define SDL_TTF_MAJOR_VERSION 2
|
|
||||||
#define SDL_TTF_MINOR_VERSION 0
|
|
||||||
#define SDL_TTF_PATCHLEVEL 15
|
|
||||||
|
|
||||||
/* This macro can be used to fill a version structure with the compile-time
|
|
||||||
* version of the SDL_ttf library.
|
|
||||||
*/
|
|
||||||
#define SDL_TTF_VERSION(X) \
|
|
||||||
{ \
|
|
||||||
(X)->major = SDL_TTF_MAJOR_VERSION; \
|
|
||||||
(X)->minor = SDL_TTF_MINOR_VERSION; \
|
|
||||||
(X)->patch = SDL_TTF_PATCHLEVEL; \
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Backwards compatibility */
|
|
||||||
#define TTF_MAJOR_VERSION SDL_TTF_MAJOR_VERSION
|
|
||||||
#define TTF_MINOR_VERSION SDL_TTF_MINOR_VERSION
|
|
||||||
#define TTF_PATCHLEVEL SDL_TTF_PATCHLEVEL
|
|
||||||
#define TTF_VERSION(X) SDL_TTF_VERSION(X)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the version number macro for the current SDL_ttf version.
|
|
||||||
*/
|
|
||||||
#define SDL_TTF_COMPILEDVERSION \
|
|
||||||
SDL_VERSIONNUM(SDL_TTF_MAJOR_VERSION, SDL_TTF_MINOR_VERSION, SDL_TTF_PATCHLEVEL)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This macro will evaluate to true if compiled with SDL_ttf at least X.Y.Z.
|
|
||||||
*/
|
|
||||||
#define SDL_TTF_VERSION_ATLEAST(X, Y, Z) \
|
|
||||||
(SDL_TTF_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
|
|
||||||
|
|
||||||
/* Make sure this is defined (only available in newer SDL versions) */
|
|
||||||
#ifndef SDL_DEPRECATED
|
|
||||||
#define SDL_DEPRECATED
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* This function gets the version of the dynamically linked SDL_ttf library.
|
|
||||||
it should NOT be used to fill a version structure, instead you should
|
|
||||||
use the SDL_TTF_VERSION() macro.
|
|
||||||
*/
|
|
||||||
extern DECLSPEC const SDL_version * SDLCALL TTF_Linked_Version(void);
|
|
||||||
|
|
||||||
/* ZERO WIDTH NO-BREAKSPACE (Unicode byte order mark) */
|
|
||||||
#define UNICODE_BOM_NATIVE 0xFEFF
|
|
||||||
#define UNICODE_BOM_SWAPPED 0xFFFE
|
|
||||||
|
|
||||||
/* This function tells the library whether UNICODE text is generally
|
|
||||||
byteswapped. A UNICODE BOM character in a string will override
|
|
||||||
this setting for the remainder of that string.
|
|
||||||
*/
|
|
||||||
extern DECLSPEC void SDLCALL TTF_ByteSwappedUNICODE(int swapped);
|
|
||||||
|
|
||||||
/* The internal structure containing font information */
|
|
||||||
typedef struct _TTF_Font TTF_Font;
|
|
||||||
|
|
||||||
/* Initialize the TTF engine - returns 0 if successful, -1 on error */
|
|
||||||
extern DECLSPEC int SDLCALL TTF_Init(void);
|
|
||||||
|
|
||||||
/* Open a font file and create a font of the specified point size.
|
|
||||||
* Some .fon fonts will have several sizes embedded in the file, so the
|
|
||||||
* point size becomes the index of choosing which size. If the value
|
|
||||||
* is too high, the last indexed size will be the default. */
|
|
||||||
extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFont(const char *file, int ptsize);
|
|
||||||
extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndex(const char *file, int ptsize, long index);
|
|
||||||
extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize);
|
|
||||||
extern DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIndexRW(SDL_RWops *src, int freesrc, int ptsize, long index);
|
|
||||||
|
|
||||||
/* Set and retrieve the font style */
|
|
||||||
#define TTF_STYLE_NORMAL 0x00
|
|
||||||
#define TTF_STYLE_BOLD 0x01
|
|
||||||
#define TTF_STYLE_ITALIC 0x02
|
|
||||||
#define TTF_STYLE_UNDERLINE 0x04
|
|
||||||
#define TTF_STYLE_STRIKETHROUGH 0x08
|
|
||||||
extern DECLSPEC int SDLCALL TTF_GetFontStyle(const TTF_Font *font);
|
|
||||||
extern DECLSPEC void SDLCALL TTF_SetFontStyle(TTF_Font *font, int style);
|
|
||||||
extern DECLSPEC int SDLCALL TTF_GetFontOutline(const TTF_Font *font);
|
|
||||||
extern DECLSPEC void SDLCALL TTF_SetFontOutline(TTF_Font *font, int outline);
|
|
||||||
|
|
||||||
/* Set and retrieve FreeType hinter settings */
|
|
||||||
#define TTF_HINTING_NORMAL 0
|
|
||||||
#define TTF_HINTING_LIGHT 1
|
|
||||||
#define TTF_HINTING_MONO 2
|
|
||||||
#define TTF_HINTING_NONE 3
|
|
||||||
extern DECLSPEC int SDLCALL TTF_GetFontHinting(const TTF_Font *font);
|
|
||||||
extern DECLSPEC void SDLCALL TTF_SetFontHinting(TTF_Font *font, int hinting);
|
|
||||||
|
|
||||||
/* Get the total height of the font - usually equal to point size */
|
|
||||||
extern DECLSPEC int SDLCALL TTF_FontHeight(const TTF_Font *font);
|
|
||||||
|
|
||||||
/* Get the offset from the baseline to the top of the font
|
|
||||||
This is a positive value, relative to the baseline.
|
|
||||||
*/
|
|
||||||
extern DECLSPEC int SDLCALL TTF_FontAscent(const TTF_Font *font);
|
|
||||||
|
|
||||||
/* Get the offset from the baseline to the bottom of the font
|
|
||||||
This is a negative value, relative to the baseline.
|
|
||||||
*/
|
|
||||||
extern DECLSPEC int SDLCALL TTF_FontDescent(const TTF_Font *font);
|
|
||||||
|
|
||||||
/* Get the recommended spacing between lines of text for this font */
|
|
||||||
extern DECLSPEC int SDLCALL TTF_FontLineSkip(const TTF_Font *font);
|
|
||||||
|
|
||||||
/* Get/Set whether or not kerning is allowed for this font */
|
|
||||||
extern DECLSPEC int SDLCALL TTF_GetFontKerning(const TTF_Font *font);
|
|
||||||
extern DECLSPEC void SDLCALL TTF_SetFontKerning(TTF_Font *font, int allowed);
|
|
||||||
|
|
||||||
/* Get the number of faces of the font */
|
|
||||||
extern DECLSPEC long SDLCALL TTF_FontFaces(const TTF_Font *font);
|
|
||||||
|
|
||||||
/* Get the font face attributes, if any */
|
|
||||||
extern DECLSPEC int SDLCALL TTF_FontFaceIsFixedWidth(const TTF_Font *font);
|
|
||||||
extern DECLSPEC char * SDLCALL TTF_FontFaceFamilyName(const TTF_Font *font);
|
|
||||||
extern DECLSPEC char * SDLCALL TTF_FontFaceStyleName(const TTF_Font *font);
|
|
||||||
|
|
||||||
/* Check wether a glyph is provided by the font or not */
|
|
||||||
extern DECLSPEC int SDLCALL TTF_GlyphIsProvided(const TTF_Font *font, Uint16 ch);
|
|
||||||
|
|
||||||
/* Get the metrics (dimensions) of a glyph
|
|
||||||
To understand what these metrics mean, here is a useful link:
|
|
||||||
http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
|
|
||||||
*/
|
|
||||||
extern DECLSPEC int SDLCALL TTF_GlyphMetrics(TTF_Font *font, Uint16 ch,
|
|
||||||
int *minx, int *maxx,
|
|
||||||
int *miny, int *maxy, int *advance);
|
|
||||||
|
|
||||||
/* Get the dimensions of a rendered string of text */
|
|
||||||
extern DECLSPEC int SDLCALL TTF_SizeText(TTF_Font *font, TTF_Font *meme, const char *text, int *w, int *h);
|
|
||||||
extern DECLSPEC int SDLCALL TTF_SizeUTF8(TTF_Font *font, TTF_Font *meme, const char *text, int *w, int *h);
|
|
||||||
extern DECLSPEC int SDLCALL TTF_SizeUNICODE(TTF_Font *font, TTF_Font *meme, const Uint16 *text, int *w, int *h);
|
|
||||||
|
|
||||||
/* Create an 8-bit palettized surface and render the given text at
|
|
||||||
fast quality with the given font and color. The 0 pixel is the
|
|
||||||
colorkey, giving a transparent background, and the 1 pixel is set
|
|
||||||
to the text color.
|
|
||||||
This function returns the new surface, or NULL if there was an error.
|
|
||||||
*/
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font, TTF_Font *meme,
|
|
||||||
const char *text, SDL_Color fg);
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Solid(TTF_Font *font, TTF_Font *meme,
|
|
||||||
const char *text, SDL_Color fg);
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Solid(TTF_Font *font, TTF_Font *meme,
|
|
||||||
const Uint16 *text, SDL_Color fg);
|
|
||||||
|
|
||||||
/* Create an 8-bit palettized surface and render the given glyph at
|
|
||||||
fast quality with the given font and color. The 0 pixel is the
|
|
||||||
colorkey, giving a transparent background, and the 1 pixel is set
|
|
||||||
to the text color. The glyph is rendered without any padding or
|
|
||||||
centering in the X direction, and aligned normally in the Y direction.
|
|
||||||
This function returns the new surface, or NULL if there was an error.
|
|
||||||
*/
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Solid(TTF_Font *font, TTF_Font *meme,
|
|
||||||
Uint16 ch, SDL_Color fg);
|
|
||||||
|
|
||||||
/* Create an 8-bit palettized surface and render the given text at
|
|
||||||
high quality with the given font and colors. The 0 pixel is background,
|
|
||||||
while other pixels have varying degrees of the foreground color.
|
|
||||||
This function returns the new surface, or NULL if there was an error.
|
|
||||||
*/
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded(TTF_Font *font, TTF_Font *meme,
|
|
||||||
const char *text, SDL_Color fg, SDL_Color bg);
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Shaded(TTF_Font *font, TTF_Font *meme,
|
|
||||||
const char *text, SDL_Color fg, SDL_Color bg);
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Shaded(TTF_Font *font, TTF_Font *meme,
|
|
||||||
const Uint16 *text, SDL_Color fg, SDL_Color bg);
|
|
||||||
|
|
||||||
/* Create an 8-bit palettized surface and render the given glyph at
|
|
||||||
high quality with the given font and colors. The 0 pixel is background,
|
|
||||||
while other pixels have varying degrees of the foreground color.
|
|
||||||
The glyph is rendered without any padding or centering in the X
|
|
||||||
direction, and aligned normally in the Y direction.
|
|
||||||
This function returns the new surface, or NULL if there was an error.
|
|
||||||
*/
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Shaded(TTF_Font *font, TTF_Font *meme,
|
|
||||||
Uint16 ch, SDL_Color fg, SDL_Color bg);
|
|
||||||
|
|
||||||
/* Create a 32-bit ARGB surface and render the given text at high quality,
|
|
||||||
using alpha blending to dither the font with the given color.
|
|
||||||
This function returns the new surface, or NULL if there was an error.
|
|
||||||
*/
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended(TTF_Font *font, TTF_Font *meme,
|
|
||||||
const char *text, SDL_Color fg);
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Blended(TTF_Font *font, TTF_Font *meme,
|
|
||||||
const char *text, SDL_Color fg);
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Blended(TTF_Font *font, TTF_Font *meme,
|
|
||||||
const Uint16 *text, SDL_Color fg);
|
|
||||||
|
|
||||||
|
|
||||||
/* Create a 32-bit ARGB surface and render the given text at high quality,
|
|
||||||
using alpha blending to dither the font with the given color.
|
|
||||||
Text is wrapped to multiple lines on line endings and on word boundaries
|
|
||||||
if it extends beyond wrapLength in pixels.
|
|
||||||
This function returns the new surface, or NULL if there was an error.
|
|
||||||
*/
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended_Wrapped(TTF_Font *font, TTF_Font *meme,
|
|
||||||
const char *text, SDL_Color fg, Uint32 wrapLength);
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Blended_Wrapped(TTF_Font *font, TTF_Font *meme,
|
|
||||||
const char *text, SDL_Color fg, Uint32 wrapLength);
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Blended_Wrapped(TTF_Font *font, TTF_Font *meme,
|
|
||||||
const Uint16 *text, SDL_Color fg, Uint32 wrapLength);
|
|
||||||
|
|
||||||
/* Create a 32-bit ARGB surface and render the given glyph at high quality,
|
|
||||||
using alpha blending to dither the font with the given color.
|
|
||||||
The glyph is rendered without any padding or centering in the X
|
|
||||||
direction, and aligned normally in the Y direction.
|
|
||||||
This function returns the new surface, or NULL if there was an error.
|
|
||||||
*/
|
|
||||||
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Blended(TTF_Font *font, TTF_Font *meme,
|
|
||||||
Uint16 ch, SDL_Color fg);
|
|
||||||
|
|
||||||
/* For compatibility with previous versions, here are the old functions */
|
|
||||||
#define TTF_RenderText(font, text, fg, bg) \
|
|
||||||
TTF_RenderText_Shaded(font, text, fg, bg)
|
|
||||||
#define TTF_RenderUTF8(font, text, fg, bg) \
|
|
||||||
TTF_RenderUTF8_Shaded(font, text, fg, bg)
|
|
||||||
#define TTF_RenderUNICODE(font, text, fg, bg) \
|
|
||||||
TTF_RenderUNICODE_Shaded(font, text, fg, bg)
|
|
||||||
|
|
||||||
/* Close an opened font file */
|
|
||||||
extern DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font);
|
|
||||||
|
|
||||||
/* De-initialize the TTF engine */
|
|
||||||
extern DECLSPEC void SDLCALL TTF_Quit(void);
|
|
||||||
|
|
||||||
/* Check if the TTF engine is initialized */
|
|
||||||
extern DECLSPEC int SDLCALL TTF_WasInit(void);
|
|
||||||
|
|
||||||
/* Get the kerning size of two glyphs indices */
|
|
||||||
/* DEPRECATED: this function requires FreeType font indexes, not glyphs,
|
|
||||||
by accident, which we don't expose through this API, so it could give
|
|
||||||
wildly incorrect results, especially with non-ASCII values.
|
|
||||||
Going forward, please use TTF_GetFontKerningSizeGlyphs() instead, which
|
|
||||||
does what you probably expected this function to do. */
|
|
||||||
extern DECLSPEC int TTF_GetFontKerningSize(TTF_Font *font, int prev_index, int index) SDL_DEPRECATED;
|
|
||||||
|
|
||||||
/* Get the kerning size of two glyphs */
|
|
||||||
extern DECLSPEC int TTF_GetFontKerningSizeGlyphs(TTF_Font *font, Uint16 previous_ch, Uint16 ch);
|
|
||||||
|
|
||||||
/* We'll use SDL for reporting errors */
|
|
||||||
#define TTF_SetError SDL_SetError
|
|
||||||
#define TTF_GetError SDL_GetError
|
|
||||||
|
|
||||||
/* Ends C function definitions when using C++ */
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#include <SDL2/close_code.h>
|
|
||||||
|
|
||||||
#endif /* SDL_TTF_H_ */
|
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -1,112 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file render_Renderer.hpp
|
|
||||||
@brief A Renderer is the object performing basic rendering. (simply, a SDL2 wrapper)
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <switch.h>
|
|
||||||
#include <pu/pu_Macros.hpp>
|
|
||||||
#include <pu/ui/ui_Types.hpp>
|
|
||||||
#include <pu/ui/render/render_SDL2.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
namespace pu::ui::render
|
|
||||||
{
|
|
||||||
struct RendererInitOptions
|
|
||||||
{
|
|
||||||
bool InitTTF;
|
|
||||||
bool InitMixer;
|
|
||||||
u32 MixerFlags;
|
|
||||||
bool InitIMG;
|
|
||||||
u32 IMGFlags;
|
|
||||||
bool InitPL;
|
|
||||||
bool InitRomFs;
|
|
||||||
|
|
||||||
// Only plain SDL2
|
|
||||||
static const RendererInitOptions RendererSDLOnly;
|
|
||||||
|
|
||||||
// SDL2, PL, RomFs, TTF, Mixer and IMG
|
|
||||||
static const RendererInitOptions RendererEverything;
|
|
||||||
|
|
||||||
// SDL2, PL and RomFs
|
|
||||||
static const RendererInitOptions RendererSimple;
|
|
||||||
|
|
||||||
// Everything except Mixer (SDL2, PL, RomFs, TTF, Mixer)
|
|
||||||
static const RendererInitOptions RendererNoSound;
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr u32 MixerAllFlags = (MIX_INIT_FLAC | MIX_INIT_MOD | MIX_INIT_MP3 | MIX_INIT_OGG);
|
|
||||||
static constexpr u32 IMGAllFlags = (IMG_INIT_PNG | IMG_INIT_JPG | IMG_INIT_TIF | IMG_INIT_WEBP);
|
|
||||||
static constexpr u32 RendererSoftwareFlags = SDL_RENDERER_SOFTWARE;
|
|
||||||
static constexpr u32 RendererHardwareFlags = (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
|
||||||
|
|
||||||
inline constexpr const RendererInitOptions RendererInitOptions::RendererSDLOnly = { false, false, 0, false, 0, false, false };
|
|
||||||
inline constexpr const RendererInitOptions RendererInitOptions::RendererEverything = { true, true, MixerAllFlags, true, IMGAllFlags, true, true };
|
|
||||||
inline constexpr const RendererInitOptions RendererInitOptions::RendererSimple = { false, false, 0, false, 0, true, true };
|
|
||||||
inline constexpr const RendererInitOptions RendererInitOptions::RendererNoSound = { true, false, 0, true, IMGAllFlags, true, true };
|
|
||||||
|
|
||||||
struct NativeTextureRenderOptions
|
|
||||||
{
|
|
||||||
int AlphaMod;
|
|
||||||
s32 Width;
|
|
||||||
s32 Height;
|
|
||||||
float Angle;
|
|
||||||
|
|
||||||
// No extra alpha, no custom size, no rotation
|
|
||||||
static const NativeTextureRenderOptions Default;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline constexpr const NativeTextureRenderOptions NativeTextureRenderOptions::Default = { .AlphaMod = -1, .Width = -1, .Height = -1, .Angle = -1.0f };
|
|
||||||
|
|
||||||
class Renderer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Renderer(u32 SDLFlags, RendererInitOptions Options, u32 NativeRendererFlags, u32 Width = 1280, u32 Height = 720);
|
|
||||||
PU_SMART_CTOR(Renderer)
|
|
||||||
|
|
||||||
void Initialize();
|
|
||||||
void Finalize();
|
|
||||||
bool HasInitialized();
|
|
||||||
bool HasRomFs();
|
|
||||||
void InitializeRender(Color Color);
|
|
||||||
void FinalizeRender();
|
|
||||||
void RenderTexture(NativeTexture Texture, s32 X, s32 Y, NativeTextureRenderOptions Options = NativeTextureRenderOptions::Default);
|
|
||||||
void RenderRectangle(Color Color, s32 X, s32 Y, s32 Width, s32 Height);
|
|
||||||
void RenderRectangleFill(Color Color, s32 X, s32 Y, s32 Width, s32 Height);
|
|
||||||
void RenderRectangleOutline(Color Color, u32 X, u32 Y, u32 Width, u32 Height, u32 BorderWidth);
|
|
||||||
void RenderRoundedRectangle(Color Color, s32 X, s32 Y, s32 Width, s32 Height, s32 Radius);
|
|
||||||
void RenderRoundedRectangleFill(Color Color, s32 X, s32 Y, s32 Width, s32 Height, s32 Radius);
|
|
||||||
void RenderCircle(Color Color, s32 X, s32 Y, s32 Radius);
|
|
||||||
void RenderCircleFill(Color Color, s32 X, s32 Y, s32 Radius);
|
|
||||||
void RenderShadowSimple(s32 X, s32 Y, s32 Width, s32 Height, s32 BaseAlpha, u8 MainAlpha = 255);
|
|
||||||
void SetBaseRenderPosition(s32 X, s32 Y);
|
|
||||||
void UnsetBaseRenderPosition();
|
|
||||||
void SetBaseRenderAlpha(u8 Alpha);
|
|
||||||
void UnsetBaseRenderAlpha();
|
|
||||||
private:
|
|
||||||
RendererInitOptions initopts;
|
|
||||||
u32 sdlflags;
|
|
||||||
u32 nrendflags;
|
|
||||||
bool okromfs;
|
|
||||||
bool okpl;
|
|
||||||
u32 ww;
|
|
||||||
u32 wh;
|
|
||||||
bool initialized;
|
|
||||||
NativeWindow rendwd;
|
|
||||||
NativeSurface rendsf;
|
|
||||||
s32 basex;
|
|
||||||
s32 basey;
|
|
||||||
int basea;
|
|
||||||
};
|
|
||||||
|
|
||||||
NativeRenderer GetMainRenderer();
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file render_SDL2.hpp
|
|
||||||
@brief Wrapper code to simplify SDL2 usage
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <pu/ui/ui_Types.hpp>
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <SDL2/SDL_image.h>
|
|
||||||
#include <pu/ui/render/SDL_ttf.h>
|
|
||||||
#include <SDL2/SDL2_gfxPrimitives.h>
|
|
||||||
#include <SDL2/SDL_mixer.h>
|
|
||||||
|
|
||||||
namespace pu::ui::render
|
|
||||||
{
|
|
||||||
typedef SDL_Window *NativeWindow;
|
|
||||||
typedef SDL_Renderer *NativeRenderer;
|
|
||||||
typedef SDL_Surface *NativeSurface;
|
|
||||||
typedef SDL_Texture *NativeTexture;
|
|
||||||
typedef TTF_Font *NativeFont;
|
|
||||||
|
|
||||||
enum class SharedFont
|
|
||||||
{
|
|
||||||
Standard,
|
|
||||||
ChineseSimplified,
|
|
||||||
ExtendedChineseSimplified,
|
|
||||||
ChineseTraditional,
|
|
||||||
Korean,
|
|
||||||
NintendoExtended,
|
|
||||||
};
|
|
||||||
|
|
||||||
NativeTexture ConvertToTexture(NativeSurface Surface);
|
|
||||||
NativeTexture RenderText(NativeFont Font, NativeFont Meme, const std::string& Text, Color Color);
|
|
||||||
NativeTexture LoadImage(const std::string& Path);
|
|
||||||
NativeTexture LoadJpegImage(void* buffer, s32 size);
|
|
||||||
NativeTexture LoadRgbImage(void* buffer, u64 width, u64 height, u8 depth);
|
|
||||||
NativeFont LoadSharedFont(SharedFont Type, s32 Size);
|
|
||||||
NativeFont LoadFont(const std::string& Path, s32 Size);
|
|
||||||
void SetDefaultFont(const std::string& Path);
|
|
||||||
void SetDefaultFontFromShared(SharedFont Type);
|
|
||||||
NativeFont LoadDefaultFont(s32 Size);
|
|
||||||
s32 GetTextureWidth(NativeTexture Texture);
|
|
||||||
s32 GetTextureHeight(NativeTexture Texture);
|
|
||||||
std::pair<s32,s32> GetTextureSize(NativeTexture Texture);
|
|
||||||
void SetAlphaValue(NativeTexture Texture, u8 Alpha);
|
|
||||||
void DeleteFont(NativeFont& Font);
|
|
||||||
void DeleteTexture(NativeTexture& Texture);
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file ui_Application.hpp
|
|
||||||
@brief An Application is the base to use the UI system of this library.
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <vector>
|
|
||||||
#include <functional>
|
|
||||||
#include <chrono>
|
|
||||||
#include <pu/ui/ui_Dialog.hpp>
|
|
||||||
#include <pu/ui/ui_Layout.hpp>
|
|
||||||
#include <pu/ui/ui_Overlay.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui
|
|
||||||
{
|
|
||||||
class Application
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Application(render::Renderer::Ref Renderer);
|
|
||||||
PU_SMART_CTOR(Application)
|
|
||||||
|
|
||||||
void LoadLayout(std::shared_ptr<Layout> Layout);
|
|
||||||
|
|
||||||
void Prepare();
|
|
||||||
// Force create a derived Application which should initialize everything here
|
|
||||||
virtual void OnLoad() = 0;
|
|
||||||
|
|
||||||
void AddThread(std::function<void()> Callback);
|
|
||||||
void SetOnInput(std::function<void(u64 Down, u64 Up, u64 Held, Touch Pos)> Callback);
|
|
||||||
s32 ShowDialog(Dialog::Ref &ToShow);
|
|
||||||
int CreateShowDialog(const std::string& Title, const std::string& Content, std::vector<std::string> Options, bool UseLastOptionAsCancel, const std::string& Icon = "");
|
|
||||||
|
|
||||||
void StartOverlay(std::shared_ptr<Overlay> Overlay);
|
|
||||||
void StartOverlayWithTimeout(std::shared_ptr<Overlay> Overlay, u64 Milli);
|
|
||||||
|
|
||||||
void EndOverlay();
|
|
||||||
void Show();
|
|
||||||
void ShowWithFadeIn();
|
|
||||||
bool IsShown();
|
|
||||||
bool CallForRender();
|
|
||||||
bool CallForRenderWithRenderOver(std::function<bool(render::Renderer::Ref&)> RenderFunc);
|
|
||||||
void FadeIn();
|
|
||||||
void FadeOut();
|
|
||||||
bool IsFadedIn();
|
|
||||||
void SetFadeAlphaAmountPerFrame(u8 Alpha);
|
|
||||||
void OnRender();
|
|
||||||
void Close();
|
|
||||||
void CloseWithFadeOut();
|
|
||||||
protected:
|
|
||||||
bool loaded;
|
|
||||||
bool rover;
|
|
||||||
std::function<bool(render::Renderer::Ref&)> rof;
|
|
||||||
bool show;
|
|
||||||
u8 aapf;
|
|
||||||
s32 fadea;
|
|
||||||
bool closefact;
|
|
||||||
Layout::Ref lyt;
|
|
||||||
u64 tmillis;
|
|
||||||
std::chrono::steady_clock::time_point tclock;
|
|
||||||
bool fovl;
|
|
||||||
bool ffovl;
|
|
||||||
Overlay::Ref ovl;
|
|
||||||
std::vector<std::function<void()>> thds;
|
|
||||||
std::function<void(u64, u64, u64, Touch)> cbipt;
|
|
||||||
render::Renderer::Ref rend;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file ui_Container.hpp
|
|
||||||
@brief A Container is a basic object which contains a bunch of Elements.
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <pu/ui/elm/elm_Element.hpp>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace pu::ui
|
|
||||||
{
|
|
||||||
class Container
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Container(s32 X, s32 Y, s32 Width, s32 Height);
|
|
||||||
PU_SMART_CTOR(Container)
|
|
||||||
|
|
||||||
template<typename Elem>
|
|
||||||
void Add(std::shared_ptr<Elem> Elm)
|
|
||||||
{
|
|
||||||
static_assert(std::is_base_of<elm::Element, Elem>::value, "Elements must inherit from pu::ui::elm::Element!");
|
|
||||||
|
|
||||||
elms.push_back(std::dynamic_pointer_cast<elm::Element>(Elm));
|
|
||||||
}
|
|
||||||
|
|
||||||
elm::Element::Ref &At(s32 Index);
|
|
||||||
bool Has(elm::Element::Ref &Elm);
|
|
||||||
void Clear();
|
|
||||||
s32 GetCount();
|
|
||||||
void SetX(s32 X);
|
|
||||||
s32 GetX();
|
|
||||||
void SetY(s32 Y);
|
|
||||||
s32 GetY();
|
|
||||||
void SetWidth(s32 Width);
|
|
||||||
s32 GetWidth();
|
|
||||||
void SetHeight(s32 Height);
|
|
||||||
s32 GetHeight();
|
|
||||||
void PreRender();
|
|
||||||
protected:
|
|
||||||
s32 x;
|
|
||||||
s32 y;
|
|
||||||
s32 w;
|
|
||||||
s32 h;
|
|
||||||
std::vector<elm::Element::Ref> elms;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file ui_Dialog.hpp
|
|
||||||
@brief A Dialog is an easy way to ask the user to choose between several options.
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <pu/ui/render/render_Renderer.hpp>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace pu::ui
|
|
||||||
{
|
|
||||||
class Dialog
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Dialog(const std::string& Title, const std::string& Content);
|
|
||||||
PU_SMART_CTOR(Dialog)
|
|
||||||
~Dialog();
|
|
||||||
|
|
||||||
void AddOption(const std::string& Name);
|
|
||||||
void SetCancelOption(const std::string& Name = "Cancel");
|
|
||||||
void RemoveCancelOption();
|
|
||||||
bool HasCancelOption();
|
|
||||||
void SetIcon(const std::string& Icon);
|
|
||||||
bool Hasicon();
|
|
||||||
s32 Show(render::Renderer::Ref &Drawer, void *App);
|
|
||||||
bool UserCancelled();
|
|
||||||
bool IsOk();
|
|
||||||
private:
|
|
||||||
bool hcancel;
|
|
||||||
std::string scancel;
|
|
||||||
render::NativeFont titleFont;
|
|
||||||
render::NativeFont contentFont;
|
|
||||||
render::NativeFont optionsFont;
|
|
||||||
render::NativeFont titleFontEx;
|
|
||||||
render::NativeFont contentFontEx;
|
|
||||||
render::NativeFont optionsFontEx;
|
|
||||||
std::string stitle;
|
|
||||||
std::string scnt;
|
|
||||||
render::NativeTexture title = nullptr;
|
|
||||||
render::NativeTexture cnt = nullptr;
|
|
||||||
std::vector<std::string> sopts;
|
|
||||||
std::vector<render::NativeTexture> opts;
|
|
||||||
s32 osel;
|
|
||||||
bool cancel;
|
|
||||||
bool hicon;
|
|
||||||
render::NativeTexture icon = nullptr;
|
|
||||||
s32 prevosel;
|
|
||||||
s32 pselfact;
|
|
||||||
s32 selfact;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file ui_Layout.hpp
|
|
||||||
@brief Contains pu::Layout class, the object used to render within applications
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <pu/ui/ui_Container.hpp>
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
namespace pu::ui
|
|
||||||
{
|
|
||||||
class Layout : public Container
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Layout();
|
|
||||||
PU_SMART_CTOR(Layout)
|
|
||||||
~Layout();
|
|
||||||
|
|
||||||
bool HasChilds();
|
|
||||||
void SetOnInput(std::function<void(u64 Down, u64 Up, u64 Held, Touch Pos)> Callback);
|
|
||||||
std::function<void(u64 Down, u64 Up, u64 Held, Touch Pos)> GetOnInput();
|
|
||||||
void AddThread(std::function<void()> Callback);
|
|
||||||
std::vector<std::function<void()>> GetAllThreads();
|
|
||||||
void SetBackgroundImage(const std::string& Path);
|
|
||||||
void SetBackgroundJpegImage(void* JpegBuffer, s32 size);
|
|
||||||
void SetBackgroundRgbImage(void* RgbBuffer, u64 width, u64 height, u8 depth = 4);
|
|
||||||
void SetBackgroundColor(Color Color);
|
|
||||||
void SimulateTouch(Touch Custom);
|
|
||||||
Touch GetSimulatedTouch();
|
|
||||||
render::NativeTexture GetBackgroundImageTexture();
|
|
||||||
Color GetBackgroundColor();
|
|
||||||
bool HasBackgroundImage();
|
|
||||||
private:
|
|
||||||
bool hasimage;
|
|
||||||
Color overbgcolor;
|
|
||||||
Touch simtouch;
|
|
||||||
render::NativeTexture overbgtex = nullptr;
|
|
||||||
std::function<void(u64, u64, u64, Touch)> onipt;
|
|
||||||
std::vector<std::function<void()>> thds;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file ui_Overlay.hpp
|
|
||||||
@brief An overlay is some kind of "pop-up", like notification messages or similar items
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <pu/ui/ui_Container.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui
|
|
||||||
{
|
|
||||||
class Overlay : public Container
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Overlay(s32 X, s32 Y, s32 Width, s32 Height, Color Background, bool Rounded = true);
|
|
||||||
PU_SMART_CTOR(Overlay)
|
|
||||||
|
|
||||||
void SetRadius(s32 Radius);
|
|
||||||
s32 GetRadius();
|
|
||||||
virtual void OnPreRender(render::Renderer::Ref &Drawer);
|
|
||||||
virtual void OnPostRender(render::Renderer::Ref &Drawer);
|
|
||||||
bool Render(render::Renderer::Ref &Drawer);
|
|
||||||
void NotifyEnding(bool End);
|
|
||||||
private:
|
|
||||||
s32 fadea;
|
|
||||||
Color bg;
|
|
||||||
s32 rad;
|
|
||||||
bool end;
|
|
||||||
bool round;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Plutonium library
|
|
||||||
|
|
||||||
@file ui_Types.hpp
|
|
||||||
@brief Several basic types helpful for UI and rendering, such as Color
|
|
||||||
@author XorTroll
|
|
||||||
|
|
||||||
@copyright Plutonium project - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <switch.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace pu::ui
|
|
||||||
{
|
|
||||||
struct Color
|
|
||||||
{
|
|
||||||
Color();
|
|
||||||
Color(u8 R, u8 G, u8 B, u8 A);
|
|
||||||
u8 R;
|
|
||||||
u8 G;
|
|
||||||
u8 B;
|
|
||||||
u8 A;
|
|
||||||
|
|
||||||
static Color FromHex(const std::string& HexFmt);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Touch
|
|
||||||
{
|
|
||||||
s32 X;
|
|
||||||
s32 Y;
|
|
||||||
|
|
||||||
bool IsEmpty();
|
|
||||||
|
|
||||||
static const Touch Empty;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline constexpr const Touch Touch::Empty = { -1, -1 };
|
|
||||||
}
|
|
@ -1,129 +0,0 @@
|
|||||||
#---------------------------------------------------------------------------------
|
|
||||||
.SUFFIXES:
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ifeq ($(strip $(DEVKITPRO)),)
|
|
||||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
|
||||||
endif
|
|
||||||
|
|
||||||
include $(DEVKITPRO)/devkitA64/base_rules
|
|
||||||
include $(DEVKITPRO)/libnx/switch_rules
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# TARGET is the name of the output
|
|
||||||
# SOURCES is a list of directories containing source code
|
|
||||||
# DATA is a list of directories containing data files
|
|
||||||
# INCLUDES is a list of directories containing header files
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
BUILD := Build
|
|
||||||
TARGET := pu
|
|
||||||
SOURCES := Source Source/pu Source/pu/audio Source/pu/ui Source/pu/ui/elm Source/pu/ui/extras Source/pu/ui/render Source/pu/web
|
|
||||||
INCLUDES := Include Include/pu Include/pu/audio Include/pu/ui Include/pu/ui/elm Include/pu/ui/extras Include/pu/ui/render Include/pu/web
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# options for code generation
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec
|
|
||||||
|
|
||||||
CFLAGS := -g -D__SWITCH__ \
|
|
||||||
-ffunction-sections \
|
|
||||||
-fdata-sections \
|
|
||||||
$(ARCH) \
|
|
||||||
|
|
||||||
CFLAGS += $(INCLUDE)
|
|
||||||
CFLAGS += `freetype-config --cflags` -Wall
|
|
||||||
|
|
||||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17 -Wall
|
|
||||||
|
|
||||||
ASFLAGS := -g $(ARCH)
|
|
||||||
LDFLAGS = -specs=${DEVKITPRO}/libnx/switch.specs -g $(ARCH) -Wl,-r,-Map,$(notdir $*.map)
|
|
||||||
|
|
||||||
# LIBS := -lnx -lfreetype -lSDL2_ttf -lSDL2_mixer -lmodplug -lmpg123 -lvorbisidec -logg -lSDL2_gfx -lSDL2_image -lSDL2 -lEGL -lGLESv2 -lglapi -ldrm_nouveau -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs`
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# list of directories containing libraries, this must be the top level containing
|
|
||||||
# include and lib
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
LIBDIRS := $(PORTLIBS) $(LIBNX)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# no real need to edit anything past this point unless you need to add additional
|
|
||||||
# rules for different file extensions
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
|
||||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
|
||||||
|
|
||||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
|
||||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
|
||||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
|
||||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# use CXX for linking C++ projects, CC for standard C
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
ifeq ($(strip $(CPPFILES)),)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
export LD := $(CC)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
else
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
export LD := $(CXX)
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
endif
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
export OUTPUT := $(CURDIR)/Output/lib/lib$(TARGET).a
|
|
||||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
|
||||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
|
||||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
|
||||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
|
||||||
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
|
||||||
|
|
||||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
|
||||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
|
||||||
-I$(CURDIR)/$(BUILD)
|
|
||||||
|
|
||||||
.PHONY: $(BUILD) clean all
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
all: $(BUILD)
|
|
||||||
|
|
||||||
$(BUILD):
|
|
||||||
@[ -d $@ ] || mkdir -p $@
|
|
||||||
@[ -d Output/lib ] || mkdir -p Output/lib
|
|
||||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
|
||||||
@rm -rf Output/include
|
|
||||||
@cp -r Include Output/include
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
clean:
|
|
||||||
@echo clean ...
|
|
||||||
@rm -rf Output
|
|
||||||
@rm -fr $(BUILD) $(OUTPUT).a
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
else
|
|
||||||
|
|
||||||
DEPENDS := $(OFILES:.o=.d)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
# main targets
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
$(OUTPUT) : $(OFILES)
|
|
||||||
|
|
||||||
$(OFILES_SRC) : $(HFILES)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
%_bin.h %.bin.o : %.bin
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
@echo $(notdir $<)
|
|
||||||
@$(bin2o)
|
|
||||||
|
|
||||||
|
|
||||||
-include $(DEPENDS)
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------------
|
|
||||||
endif
|
|
||||||
#---------------------------------------------------------------------------------------
|
|
@ -1,70 +0,0 @@
|
|||||||
#include <pu/audio/audio_Music.hpp>
|
|
||||||
|
|
||||||
namespace pu::audio
|
|
||||||
{
|
|
||||||
Music Open(std::string Path)
|
|
||||||
{
|
|
||||||
return Mix_LoadMUS(Path.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Play(Music Mus, int Loops)
|
|
||||||
{
|
|
||||||
Mix_PlayMusic(Mus, Loops);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayWithFadeIn(Music Mus, int Loops, int Milli)
|
|
||||||
{
|
|
||||||
Mix_FadeInMusic(Mus, Loops, Milli);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsPlaying()
|
|
||||||
{
|
|
||||||
return Mix_PlayingMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Pause()
|
|
||||||
{
|
|
||||||
Mix_PauseMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Resume()
|
|
||||||
{
|
|
||||||
Mix_ResumeMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetVolume(int Volume)
|
|
||||||
{
|
|
||||||
Mix_VolumeMusic(Volume);
|
|
||||||
}
|
|
||||||
|
|
||||||
int GetVolume()
|
|
||||||
{
|
|
||||||
return Mix_VolumeMusic(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FadeOut(int Milli)
|
|
||||||
{
|
|
||||||
Mix_FadeOutMusic(Milli);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Rewind()
|
|
||||||
{
|
|
||||||
Mix_RewindMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Stop()
|
|
||||||
{
|
|
||||||
Mix_HaltMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetPosition(double Sec)
|
|
||||||
{
|
|
||||||
Mix_SetMusicPosition(Sec);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Delete(Music Mus)
|
|
||||||
{
|
|
||||||
Mix_FreeMusic(Mus);
|
|
||||||
Mus = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
#include <pu/audio/audio_Sfx.hpp>
|
|
||||||
|
|
||||||
namespace pu::audio
|
|
||||||
{
|
|
||||||
Sfx Load(std::string Path)
|
|
||||||
{
|
|
||||||
return Mix_LoadWAV(Path.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Play(Sfx Sfx)
|
|
||||||
{
|
|
||||||
Mix_PlayChannel(-1, Sfx, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeleteSfx(Sfx Sfx)
|
|
||||||
{
|
|
||||||
Mix_FreeChunk(Sfx);
|
|
||||||
Sfx = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
#include <pu/pu_CFW.hpp>
|
|
||||||
#include <switch.h>
|
|
||||||
|
|
||||||
namespace pu
|
|
||||||
{
|
|
||||||
bool IsAtmosphere()
|
|
||||||
{
|
|
||||||
SecmonArgs args;
|
|
||||||
args.X[0] = 0xF0000404;
|
|
||||||
args.X[1] = 0;
|
|
||||||
args.X[2] = (u64)nullptr;
|
|
||||||
svcCallSecureMonitor(&args);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsReiNX()
|
|
||||||
{
|
|
||||||
SmServiceName rnx = smEncodeName("rnx");
|
|
||||||
Handle tmph = 0;
|
|
||||||
Result rc = smRegisterService(&tmph, rnx, false, 1);
|
|
||||||
if(R_FAILED(rc)) return true;
|
|
||||||
smUnregisterService(rnx);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,159 +0,0 @@
|
|||||||
#include <pu/ui/elm/elm_Button.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
Button::Button(s32 X, s32 Y, s32 Width, s32 Height, const std::string& Content, Color TextColor, Color Color)
|
|
||||||
: Element::Element(), x(X), y(Y), w(Width), h(Height), cnt(Content), clr(Color)
|
|
||||||
{
|
|
||||||
this->hover = false;
|
|
||||||
this->hoverfact = 255;
|
|
||||||
this->SetFontSize(25);
|
|
||||||
this->clickcb = [](){};
|
|
||||||
}
|
|
||||||
|
|
||||||
Button::~Button()
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Button::GetX()
|
|
||||||
{
|
|
||||||
return this->x;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetX(s32 X)
|
|
||||||
{
|
|
||||||
this->x = X;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Button::GetY()
|
|
||||||
{
|
|
||||||
return this->y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetY(s32 Y)
|
|
||||||
{
|
|
||||||
this->y = Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Button::GetWidth()
|
|
||||||
{
|
|
||||||
return this->w;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetWidth(s32 Width)
|
|
||||||
{
|
|
||||||
this->w = Width;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Button::GetHeight()
|
|
||||||
{
|
|
||||||
return this->h;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetHeight(s32 Height)
|
|
||||||
{
|
|
||||||
this->h = Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Button::GetContent()
|
|
||||||
{
|
|
||||||
return this->cnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetContent(const std::string& Content)
|
|
||||||
{
|
|
||||||
this->cnt = Content;
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->ntex = render::RenderText(this->font, this->meme, Content, this->clr);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color Button::GetColor()
|
|
||||||
{
|
|
||||||
return this->clr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetColor(Color Color)
|
|
||||||
{
|
|
||||||
this->clr = Color;
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->ntex = render::RenderText(this->font, this->meme, this->cnt, Color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetFontSize(s32 FontSize)
|
|
||||||
{
|
|
||||||
this->font = render::LoadDefaultFont(FontSize);
|
|
||||||
this->meme = render::LoadSharedFont(render::SharedFont::NintendoExtended, FontSize);
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->ntex = render::RenderText(this->font, this->meme, this->cnt, this->clr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetOnClick(std::function<void()> ClickCallback)
|
|
||||||
{
|
|
||||||
this->clickcb = ClickCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y)
|
|
||||||
{
|
|
||||||
s32 rdx = X;
|
|
||||||
s32 rdy = Y;
|
|
||||||
s32 clrr = this->clr.R;
|
|
||||||
s32 clrg = this->clr.G;
|
|
||||||
s32 clrb = this->clr.B;
|
|
||||||
s32 nr = clrr - 70;
|
|
||||||
if(nr < 0) nr = 0;
|
|
||||||
s32 ng = clrg - 70;
|
|
||||||
if(ng < 0) ng = 0;
|
|
||||||
s32 nb = clrb - 70;
|
|
||||||
if(nb < 0) nb = 0;
|
|
||||||
Color nclr(nr, ng, nb, this->clr.A);
|
|
||||||
if(this->hover)
|
|
||||||
{
|
|
||||||
Drawer->RenderRectangleFill(this->clr, rdx, rdy, this->w, this->h);
|
|
||||||
if(this->hoverfact < 255)
|
|
||||||
{
|
|
||||||
Drawer->RenderRectangleFill({ nr, ng, nb, this->hoverfact }, rdx, rdy, this->w, this->h);
|
|
||||||
this->hoverfact += 48;
|
|
||||||
}
|
|
||||||
else Drawer->RenderRectangleFill(nclr, rdx, rdy, this->w, this->h);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Drawer->RenderRectangleFill(this->clr, rdx, rdy, this->w, this->h);
|
|
||||||
if(this->hoverfact > 0)
|
|
||||||
{
|
|
||||||
Drawer->RenderRectangleFill({ nr, ng, nb, this->hoverfact }, rdx, rdy, this->w, this->h);
|
|
||||||
this->hoverfact -= 48;
|
|
||||||
}
|
|
||||||
else Drawer->RenderRectangleFill(this->clr, rdx, rdy, this->w, this->h);
|
|
||||||
}
|
|
||||||
auto [xw,xh] = render::GetTextureSize(this->ntex);
|
|
||||||
s32 tx = ((this->w - xw) / 2) + rdx;
|
|
||||||
s32 ty = ((this->h - xh) / 2) + rdy;
|
|
||||||
Drawer->RenderTexture(this->ntex, tx, ty);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::OnInput(u64 Down, u64 Up, u64 Held, Touch Pos)
|
|
||||||
{
|
|
||||||
if(this->hover)
|
|
||||||
{
|
|
||||||
if(Pos.IsEmpty())
|
|
||||||
{
|
|
||||||
(this->clickcb)();
|
|
||||||
this->hover = false;
|
|
||||||
this->hoverfact = 255;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(!Pos.IsEmpty())
|
|
||||||
{
|
|
||||||
if((Pos.X >= x) && (Pos.X < (x + w)) && (Pos.Y >= y) && (Pos.Y < (y + h)))
|
|
||||||
{
|
|
||||||
this->hover = true;
|
|
||||||
this->hoverfact = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,106 +0,0 @@
|
|||||||
#include <pu/ui/elm/elm_Element.hpp>
|
|
||||||
#include <pu/ui/ui_Layout.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
Element::Element()
|
|
||||||
{
|
|
||||||
this->visible = true;
|
|
||||||
this->halign = HorizontalAlign::Left;
|
|
||||||
this->valign = VerticalAlign::Up;
|
|
||||||
this->parent = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Element::~Element()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Element::IsVisible()
|
|
||||||
{
|
|
||||||
return this->visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Element::SetVisible(bool Visible)
|
|
||||||
{
|
|
||||||
this->visible = Visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Element::SetParent(void *Base)
|
|
||||||
{
|
|
||||||
this->parent = Base;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *Element::GetParent()
|
|
||||||
{
|
|
||||||
return this->parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Element::SetHorizontalAlign(HorizontalAlign Align)
|
|
||||||
{
|
|
||||||
this->halign = Align;
|
|
||||||
}
|
|
||||||
|
|
||||||
HorizontalAlign Element::GetHorizontalAlign()
|
|
||||||
{
|
|
||||||
return this->halign;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Element::SetVerticalAlign(VerticalAlign Align)
|
|
||||||
{
|
|
||||||
this->valign = Align;
|
|
||||||
}
|
|
||||||
|
|
||||||
VerticalAlign Element::GetVerticalAlign()
|
|
||||||
{
|
|
||||||
return this->valign;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Element::HasParent()
|
|
||||||
{
|
|
||||||
return (this->parent != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Element::GetProcessedX()
|
|
||||||
{
|
|
||||||
s32 rx = this->GetX();
|
|
||||||
if(this->parent != NULL)
|
|
||||||
{
|
|
||||||
Container *cont = (Container*)this->parent;
|
|
||||||
rx += cont->GetX();
|
|
||||||
switch(this->halign)
|
|
||||||
{
|
|
||||||
case HorizontalAlign::Center:
|
|
||||||
rx = cont->GetX() + ((cont->GetWidth() - this->GetWidth()) / 2);
|
|
||||||
break;
|
|
||||||
case HorizontalAlign::Right:
|
|
||||||
rx = cont->GetX() + (cont->GetWidth() - this->GetWidth());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rx;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Element::GetProcessedY()
|
|
||||||
{
|
|
||||||
s32 ry = this->GetY();
|
|
||||||
if(this->parent != NULL)
|
|
||||||
{
|
|
||||||
Container *cont = (Container*)this->parent;
|
|
||||||
ry += cont->GetY();
|
|
||||||
switch(this->valign)
|
|
||||||
{
|
|
||||||
case VerticalAlign::Center:
|
|
||||||
ry = cont->GetY() + ((cont->GetHeight() - this->GetHeight()) / 2);
|
|
||||||
break;
|
|
||||||
case VerticalAlign::Down:
|
|
||||||
ry = cont->GetY() + (cont->GetHeight() - this->GetHeight());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ry;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,133 +0,0 @@
|
|||||||
#include <pu/ui/elm/elm_Image.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
Image::Image(s32 X, s32 Y, const std::string& Image)
|
|
||||||
: Element::Element(), x(X), y(Y)
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->rendopts = render::NativeTextureRenderOptions::Default;
|
|
||||||
this->SetImage(Image);
|
|
||||||
}
|
|
||||||
|
|
||||||
Image::Image(s32 X, s32 Y, void* jpegbuffer, s32 size)
|
|
||||||
: Element::Element(), x(X), y(Y)
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->rendopts = render::NativeTextureRenderOptions::Default;
|
|
||||||
this->SetJpegImage(jpegbuffer, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
Image::Image(s32 X, s32 Y, void* rgbBuffer, u64 width, u64 height, u8 depth)
|
|
||||||
: Element::Element(), x(X), y(Y)
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->rendopts = render::NativeTextureRenderOptions::Default;
|
|
||||||
this->SetRgbImage(rgbBuffer, width, height, depth);
|
|
||||||
}
|
|
||||||
|
|
||||||
Image::~Image()
|
|
||||||
{
|
|
||||||
if(this->ntex != nullptr)
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Image::GetX()
|
|
||||||
{
|
|
||||||
return this->x;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::SetX(s32 X)
|
|
||||||
{
|
|
||||||
this->x = X;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Image::GetY()
|
|
||||||
{
|
|
||||||
return this->y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::SetY(s32 Y)
|
|
||||||
{
|
|
||||||
this->y = Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Image::GetWidth()
|
|
||||||
{
|
|
||||||
return this->rendopts.Width;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::SetWidth(s32 Width)
|
|
||||||
{
|
|
||||||
this->rendopts.Width = Width;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Image::GetHeight()
|
|
||||||
{
|
|
||||||
return this->rendopts.Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::SetHeight(s32 Height)
|
|
||||||
{
|
|
||||||
this->rendopts.Height = Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
float Image::GetRotation()
|
|
||||||
{
|
|
||||||
return this->rendopts.Angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::SetRotation(float Angle)
|
|
||||||
{
|
|
||||||
this->rendopts.Angle = Angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::SetImage(const std::string& Image)
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
std::ifstream ifs(Image);
|
|
||||||
bool ok = ifs.good();
|
|
||||||
ifs.close();
|
|
||||||
if(ok)
|
|
||||||
{
|
|
||||||
this->ntex = render::LoadImage(Image);
|
|
||||||
auto [w,h] = render::GetTextureSize(this->ntex);
|
|
||||||
this->rendopts.Width = w;
|
|
||||||
this->rendopts.Height = h;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::SetJpegImage(void* buffer, s32 size)
|
|
||||||
{
|
|
||||||
if (size == 0)
|
|
||||||
return;
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->ntex = render::LoadJpegImage(buffer, size);
|
|
||||||
auto [w,h] = render::GetTextureSize(this->ntex);
|
|
||||||
this->rendopts.Width = w;
|
|
||||||
this->rendopts.Height = h;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::SetRgbImage(void* buffer, u64 width, u64 height, u8 depth)
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->ntex = render::LoadRgbImage(buffer, width, height, depth);
|
|
||||||
auto [w,h] = render::GetTextureSize(this->ntex);
|
|
||||||
this->rendopts.Width = w;
|
|
||||||
this->rendopts.Height = h;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Image::IsImageValid()
|
|
||||||
{
|
|
||||||
return ntex != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y)
|
|
||||||
{
|
|
||||||
Drawer->RenderTexture(this->ntex, X, Y, this->rendopts);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::OnInput(u64 Down, u64 Up, u64 Held, Touch Pos)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,528 +0,0 @@
|
|||||||
#include <pu/ui/elm/elm_Menu.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
MenuItem::MenuItem(const std::string& Name)
|
|
||||||
{
|
|
||||||
this->clr = { 10, 10, 10, 255 };
|
|
||||||
this->name = Name;
|
|
||||||
this->hasicon = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string MenuItem::GetName()
|
|
||||||
{
|
|
||||||
return this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuItem::SetName(const std::string& Name)
|
|
||||||
{
|
|
||||||
this->name = Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color MenuItem::GetColor()
|
|
||||||
{
|
|
||||||
return this->clr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuItem::SetColor(Color Color)
|
|
||||||
{
|
|
||||||
this->clr = Color;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuItem::AddOnClick(std::function<void()> Callback, u64 Key)
|
|
||||||
{
|
|
||||||
this->cbs.push_back(Callback);
|
|
||||||
this->cbipts.push_back(Key);
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 MenuItem::GetCallbackCount()
|
|
||||||
{
|
|
||||||
return this->cbs.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::function<void()> MenuItem::GetCallback(s32 Index)
|
|
||||||
{
|
|
||||||
if(this->cbs.empty()) return [&](){};
|
|
||||||
return this->cbs[Index];
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 MenuItem::GetCallbackKey(s32 Index)
|
|
||||||
{
|
|
||||||
return this->cbipts[Index];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string MenuItem::GetIcon()
|
|
||||||
{
|
|
||||||
return this->icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuItem::SetIcon(std::string Icon)
|
|
||||||
{
|
|
||||||
std::ifstream ifs(Icon);
|
|
||||||
if(ifs.good())
|
|
||||||
{
|
|
||||||
this->icon = Icon;
|
|
||||||
this->hasicon = true;
|
|
||||||
this->factor = 0;
|
|
||||||
}
|
|
||||||
ifs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MenuItem::HasIcon()
|
|
||||||
{
|
|
||||||
return this->hasicon;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuItem::SetFactor(float Factor)
|
|
||||||
{
|
|
||||||
this->factor = Factor;
|
|
||||||
}
|
|
||||||
|
|
||||||
float MenuItem::GetFactor()
|
|
||||||
{
|
|
||||||
return this->factor;
|
|
||||||
}
|
|
||||||
|
|
||||||
Menu::Menu(s32 X, s32 Y, s32 Width, Color OptionColor, s32 ItemSize, s32 ItemsToShow, s32 fontSize)
|
|
||||||
: Element::Element(), x(X), y(Y), w(Width), clr(OptionColor), isize(ItemSize), ishow(ItemsToShow)
|
|
||||||
{
|
|
||||||
this->scb = { 110, 110, 110, 255 };
|
|
||||||
this->previsel = 0;
|
|
||||||
this->isel = 0;
|
|
||||||
this->fisel = 0;
|
|
||||||
this->selfact = 255;
|
|
||||||
this->pselfact = 0;
|
|
||||||
this->onselch = [&](){};
|
|
||||||
this->icdown = false;
|
|
||||||
this->dtouch = false;
|
|
||||||
this->fcs = { 40, 40, 40, 255 };
|
|
||||||
this->basestatus = 0;
|
|
||||||
this->font = render::LoadDefaultFont(fontSize);
|
|
||||||
this->meme = render::LoadSharedFont(render::SharedFont::NintendoExtended, fontSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Menu::GetX()
|
|
||||||
{
|
|
||||||
return this->x;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::SetX(s32 X)
|
|
||||||
{
|
|
||||||
this->x = X;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Menu::GetY()
|
|
||||||
{
|
|
||||||
return this->y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::SetY(s32 Y)
|
|
||||||
{
|
|
||||||
this->y = Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Menu::GetWidth()
|
|
||||||
{
|
|
||||||
return this->w;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::SetWidth(s32 Width)
|
|
||||||
{
|
|
||||||
this->w = Width;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Menu::GetHeight()
|
|
||||||
{
|
|
||||||
return (this->isize * this->ishow);
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Menu::GetItemSize()
|
|
||||||
{
|
|
||||||
return this->isize;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::SetItemSize(s32 ItemSize)
|
|
||||||
{
|
|
||||||
this->isize = ItemSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Menu::GetNumberOfItemsToShow()
|
|
||||||
{
|
|
||||||
return this->ishow;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::SetNumberOfItemsToShow(s32 ItemsToShow)
|
|
||||||
{
|
|
||||||
this->ishow = ItemsToShow;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color Menu::GetColor()
|
|
||||||
{
|
|
||||||
return this->clr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::SetColor(Color Color)
|
|
||||||
{
|
|
||||||
this->clr = Color;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color Menu::GetOnFocusColor()
|
|
||||||
{
|
|
||||||
return this->fcs;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::SetOnFocusColor(Color Color)
|
|
||||||
{
|
|
||||||
this->fcs = Color;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color Menu::GetScrollbarColor()
|
|
||||||
{
|
|
||||||
return this->scb;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::SetScrollbarColor(Color Color)
|
|
||||||
{
|
|
||||||
this->scb = Color;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::SetOnSelectionChanged(std::function<void()> Callback)
|
|
||||||
{
|
|
||||||
this->onselch = Callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::AddItem(MenuItem::Ref &Item)
|
|
||||||
{
|
|
||||||
this->itms.push_back(Item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::ClearItems()
|
|
||||||
{
|
|
||||||
this->itms.clear();
|
|
||||||
this->loadednames.clear();
|
|
||||||
this->loadedicons.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::SetCooldownEnabled(bool Cooldown)
|
|
||||||
{
|
|
||||||
this->icdown = Cooldown;
|
|
||||||
}
|
|
||||||
|
|
||||||
MenuItem::Ref &Menu::GetSelectedItem()
|
|
||||||
{
|
|
||||||
return this->itms[this->isel];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<MenuItem::Ref> &Menu::GetItems()
|
|
||||||
{
|
|
||||||
return this->itms;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Menu::GetSelectedIndex()
|
|
||||||
{
|
|
||||||
return this->isel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::SetSelectedIndex(s32 Index)
|
|
||||||
{
|
|
||||||
if(this->itms.size() > Index)
|
|
||||||
{
|
|
||||||
this->isel = Index;
|
|
||||||
this->fisel = 0;
|
|
||||||
if(this->isel >= (this->itms.size() - this->ishow)) this->fisel = this->itms.size() - this->ishow;
|
|
||||||
else if(this->isel < this->ishow) this->fisel = 0;
|
|
||||||
else this->fisel = this->isel;
|
|
||||||
|
|
||||||
ReloadItemRenders();
|
|
||||||
this->selfact = 255;
|
|
||||||
this->pselfact = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y)
|
|
||||||
{
|
|
||||||
if(!this->itms.empty())
|
|
||||||
{
|
|
||||||
s32 cx = X;
|
|
||||||
s32 cy = Y;
|
|
||||||
s32 cw = this->w;
|
|
||||||
s32 ch = this->isize;
|
|
||||||
s32 its = this->ishow;
|
|
||||||
if(its > this->itms.size()) its = this->itms.size();
|
|
||||||
if((its + this->fisel) > this->itms.size()) its = this->itms.size() - this->fisel;
|
|
||||||
if(this->loadednames.empty()) ReloadItemRenders();
|
|
||||||
for(s32 i = this->fisel; i < (its + this->fisel); i++)
|
|
||||||
{
|
|
||||||
s32 clrr = this->clr.R;
|
|
||||||
s32 clrg = this->clr.G;
|
|
||||||
s32 clrb = this->clr.B;
|
|
||||||
s32 nr = clrr - 70;
|
|
||||||
if(nr < 0) nr = 0;
|
|
||||||
s32 ng = clrg - 70;
|
|
||||||
if(ng < 0) ng = 0;
|
|
||||||
s32 nb = clrb - 70;
|
|
||||||
if(nb < 0) nb = 0;
|
|
||||||
Color nclr(nr, ng, nb, this->clr.A);
|
|
||||||
auto loadedidx = i - this->fisel;
|
|
||||||
auto curname = this->loadednames[loadedidx];
|
|
||||||
auto curicon = this->loadedicons[loadedidx];
|
|
||||||
if(this->isel == i)
|
|
||||||
{
|
|
||||||
Drawer->RenderRectangleFill(this->fcs, cx, cy, cw, ch);
|
|
||||||
if(this->selfact < 255)
|
|
||||||
{
|
|
||||||
this->selfact += 48;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(this->previsel == i)
|
|
||||||
{
|
|
||||||
Drawer->RenderRectangleFill(this->clr, cx, cy, cw, ch);
|
|
||||||
if(this->pselfact > 0)
|
|
||||||
{
|
|
||||||
this->pselfact -= 48;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else Drawer->RenderRectangleFill(this->clr, cx, cy, cw, ch);
|
|
||||||
auto itm = this->itms[i];
|
|
||||||
s32 xh = render::GetTextureHeight(curname);
|
|
||||||
s32 tx = (cx + 25);
|
|
||||||
s32 ty = ((ch - xh) / 2) + cy;
|
|
||||||
if(itm->HasIcon())
|
|
||||||
{
|
|
||||||
if (itm->GetFactor() == 0) {
|
|
||||||
auto [w,h] = render::GetTextureSize(curicon);
|
|
||||||
itm->SetFactor((float)h/w);
|
|
||||||
}
|
|
||||||
float factor = itm->GetFactor();
|
|
||||||
s32 icw = (this->isize - 10);
|
|
||||||
s32 ich = icw;
|
|
||||||
s32 icx = (cx + 25);
|
|
||||||
s32 icy = (cy + 5);
|
|
||||||
tx = (icx + icw + 25);
|
|
||||||
if(factor < 1)
|
|
||||||
{
|
|
||||||
ich = ich*factor;
|
|
||||||
icy = icy+((this->isize-ich)/2);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
icw = icw/factor;
|
|
||||||
icx = icx+((this->isize-icw)/2);
|
|
||||||
}
|
|
||||||
Drawer->RenderTexture(curicon, icx, icy, { -1, icw, ich, -1.0f });
|
|
||||||
}
|
|
||||||
Drawer->RenderTexture(curname, tx, ty);
|
|
||||||
cy += ch;
|
|
||||||
}
|
|
||||||
if(this->ishow < this->itms.size())
|
|
||||||
{
|
|
||||||
s32 sccr = this->scb.R;
|
|
||||||
s32 sccg = this->scb.G;
|
|
||||||
s32 sccb = this->scb.B;
|
|
||||||
s32 snr = sccr - 30;
|
|
||||||
if(snr < 0) snr = 0;
|
|
||||||
s32 sng = sccg - 30;
|
|
||||||
if(sng < 0) sng = 0;
|
|
||||||
s32 snb = sccb - 30;
|
|
||||||
if(snb < 0) snb = 0;
|
|
||||||
Color sclr(snr, sng, snb, this->scb.A);
|
|
||||||
s32 scx = X + (this->w - 20);
|
|
||||||
s32 scy = Y;
|
|
||||||
s32 scw = 20;
|
|
||||||
s32 sch = (this->ishow * this->isize);
|
|
||||||
Drawer->RenderRectangleFill(this->scb, scx, scy, scw, sch);
|
|
||||||
s32 fch = ((this->ishow * sch) / this->itms.size());
|
|
||||||
s32 fcy = scy + (this->fisel * (sch / this->itms.size()));
|
|
||||||
Drawer->RenderRectangleFill(sclr, scx, fcy, scw, fch);
|
|
||||||
}
|
|
||||||
//Drawer->RenderShadowSimple(cx, cy, cw, 5, 160);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::OnInput(u64 Down, u64 Up, u64 Held, Touch Pos)
|
|
||||||
{
|
|
||||||
if(itms.empty()) return;
|
|
||||||
if(basestatus == 1)
|
|
||||||
{
|
|
||||||
auto curtime = std::chrono::steady_clock::now();
|
|
||||||
auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(curtime - basetime).count();
|
|
||||||
if(diff >= 150)
|
|
||||||
{
|
|
||||||
basestatus = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!Pos.IsEmpty())
|
|
||||||
{
|
|
||||||
s32 cx = this->GetProcessedX();
|
|
||||||
s32 cy = this->GetProcessedY();
|
|
||||||
s32 cw = this->w;
|
|
||||||
s32 ch = this->isize;
|
|
||||||
s32 its = this->ishow;
|
|
||||||
if(its > this->itms.size()) its = this->itms.size();
|
|
||||||
if((its + this->fisel) > this->itms.size()) its = this->itms.size() - this->fisel;
|
|
||||||
for(s32 i = this->fisel; i < (this->fisel + its); i++)
|
|
||||||
{
|
|
||||||
if(((cx + cw) > Pos.X) && (Pos.X > cx) && ((cy + ch) > Pos.Y) && (Pos.Y > cy))
|
|
||||||
{
|
|
||||||
this->dtouch = true;
|
|
||||||
this->previsel = this->isel;
|
|
||||||
this->isel = i;
|
|
||||||
(this->onselch)();
|
|
||||||
if(i == this->isel) this->selfact = 255;
|
|
||||||
else if(i == this->previsel) this->pselfact = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
cy += this->isize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(this->dtouch)
|
|
||||||
{
|
|
||||||
if((this->selfact >= 255) && (this->pselfact <= 0))
|
|
||||||
{
|
|
||||||
if(this->icdown) this->icdown = false;
|
|
||||||
else (this->itms[this->isel]->GetCallback(0))();
|
|
||||||
this->dtouch = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if((Down & KEY_DOWN) || (Held & KEY_RSTICK_DOWN))
|
|
||||||
{
|
|
||||||
bool move = true;
|
|
||||||
if(Held & KEY_RSTICK_DOWN)
|
|
||||||
{
|
|
||||||
move = false;
|
|
||||||
if(basestatus == 0)
|
|
||||||
{
|
|
||||||
basetime = std::chrono::steady_clock::now();
|
|
||||||
basestatus = 1;
|
|
||||||
}
|
|
||||||
else if(basestatus == 2)
|
|
||||||
{
|
|
||||||
basestatus = 0;
|
|
||||||
move = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(move)
|
|
||||||
{
|
|
||||||
if(this->isel < (this->itms.size() - 1))
|
|
||||||
{
|
|
||||||
if((this->isel - this->fisel) == (this->ishow - 1))
|
|
||||||
{
|
|
||||||
this->fisel++;
|
|
||||||
this->isel++;
|
|
||||||
(this->onselch)();
|
|
||||||
ReloadItemRenders();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->previsel = this->isel;
|
|
||||||
this->isel++;
|
|
||||||
(this->onselch)();
|
|
||||||
if(!this->itms.empty()) for(s32 i = 0; i < this->itms.size(); i++)
|
|
||||||
{
|
|
||||||
if(i == this->isel) this->selfact = 0;
|
|
||||||
else if(i == this->previsel) this->pselfact = 255;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->isel = 0;
|
|
||||||
this->fisel = 0;
|
|
||||||
if(this->itms.size() > this->ishow)
|
|
||||||
{
|
|
||||||
ReloadItemRenders();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if((Down & KEY_UP) || (Held & KEY_RSTICK_UP))
|
|
||||||
{
|
|
||||||
bool move = true;
|
|
||||||
if(Held & KEY_RSTICK_UP)
|
|
||||||
{
|
|
||||||
move = false;
|
|
||||||
if(basestatus == 0)
|
|
||||||
{
|
|
||||||
basetime = std::chrono::steady_clock::now();
|
|
||||||
basestatus = 1;
|
|
||||||
}
|
|
||||||
else if(basestatus == 2)
|
|
||||||
{
|
|
||||||
basestatus = 0;
|
|
||||||
move = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(move)
|
|
||||||
{
|
|
||||||
if(this->isel > 0)
|
|
||||||
{
|
|
||||||
if(this->isel == this->fisel)
|
|
||||||
{
|
|
||||||
this->fisel--;
|
|
||||||
this->isel--;
|
|
||||||
(this->onselch)();
|
|
||||||
ReloadItemRenders();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->previsel = this->isel;
|
|
||||||
this->isel--;
|
|
||||||
(this->onselch)();
|
|
||||||
if(!this->itms.empty()) for(s32 i = 0; i < this->itms.size(); i++)
|
|
||||||
{
|
|
||||||
if(i == this->isel) this->selfact = 0;
|
|
||||||
else if(i == this->previsel) this->pselfact = 255;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->isel = this->itms.size() - 1;
|
|
||||||
this->fisel = 0;
|
|
||||||
if(this->itms.size() > this->ishow) {
|
|
||||||
this->fisel = this->itms.size() - this->ishow;
|
|
||||||
ReloadItemRenders();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
s32 ipc = this->itms[this->isel]->GetCallbackCount();
|
|
||||||
if(ipc > 0) for(s32 i = 0; i < ipc; i++)
|
|
||||||
{
|
|
||||||
if(Down & this->itms[this->isel]->GetCallbackKey(i))
|
|
||||||
{
|
|
||||||
if(this->icdown) this->icdown = false;
|
|
||||||
else (this->itms[this->isel]->GetCallback(i))();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::ReloadItemRenders()
|
|
||||||
{
|
|
||||||
for(u32 i = 0; i < this->loadednames.size(); i++) render::DeleteTexture(this->loadednames[i]);
|
|
||||||
for(u32 i = 0; i < this->loadedicons.size(); i++) render::DeleteTexture(this->loadedicons[i]);
|
|
||||||
this->loadednames.clear();
|
|
||||||
this->loadedicons.clear();
|
|
||||||
s32 its = this->ishow;
|
|
||||||
if(its > this->itms.size()) its = this->itms.size();
|
|
||||||
if((its + this->fisel) > this->itms.size()) its = this->itms.size() - this->fisel;
|
|
||||||
for(s32 i = this->fisel; i < (its + this->fisel); i++)
|
|
||||||
{
|
|
||||||
auto strname = this->itms[i]->GetName();
|
|
||||||
auto tex = render::RenderText(this->font, this->meme, strname, this->itms[i]->GetColor());
|
|
||||||
this->loadednames.push_back(tex);
|
|
||||||
if(this->itms[i]->HasIcon())
|
|
||||||
{
|
|
||||||
auto stricon = this->itms[i]->GetIcon();
|
|
||||||
auto icontex = render::LoadImage(stricon);
|
|
||||||
this->loadedicons.push_back(icontex);
|
|
||||||
}
|
|
||||||
else this->loadedicons.push_back(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,135 +0,0 @@
|
|||||||
#include <pu/ui/elm/elm_ProgressBar.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
ProgressBar::ProgressBar(s32 X, s32 Y, s32 Width, s32 Height, double MaxValue)
|
|
||||||
: Element::Element(), x(X), y(Y), w(Width), h(Height), maxval(MaxValue)
|
|
||||||
{
|
|
||||||
this->clr = { 140, 140, 140, 255 };
|
|
||||||
this->oclr = { 139, 195, 74, 255 };
|
|
||||||
this->val = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 ProgressBar::GetX()
|
|
||||||
{
|
|
||||||
return this->x;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::SetX(s32 X)
|
|
||||||
{
|
|
||||||
this->x = X;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 ProgressBar::GetY()
|
|
||||||
{
|
|
||||||
return this->y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::SetY(s32 Y)
|
|
||||||
{
|
|
||||||
this->y = Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 ProgressBar::GetWidth()
|
|
||||||
{
|
|
||||||
return this->w;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::SetWidth(s32 Width)
|
|
||||||
{
|
|
||||||
this->w = Width;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 ProgressBar::GetHeight()
|
|
||||||
{
|
|
||||||
return this->h;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::SetHeight(s32 Height)
|
|
||||||
{
|
|
||||||
this->h = Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color ProgressBar::GetColor()
|
|
||||||
{
|
|
||||||
return this->clr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::SetColor(Color Color)
|
|
||||||
{
|
|
||||||
this->clr = Color;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color ProgressBar::GetProgressColor()
|
|
||||||
{
|
|
||||||
return this->oclr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::SetProgressColor(Color Color)
|
|
||||||
{
|
|
||||||
this->oclr = Color;
|
|
||||||
}
|
|
||||||
|
|
||||||
double ProgressBar::GetProgress()
|
|
||||||
{
|
|
||||||
return this->val;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::SetProgress(double Progress)
|
|
||||||
{
|
|
||||||
if(Progress >= this->maxval) this->FillProgress();
|
|
||||||
else this->val = Progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::IncrementProgress(double Progress)
|
|
||||||
{
|
|
||||||
double res = (this->val + Progress);
|
|
||||||
if(res >= this->maxval) this->FillProgress();
|
|
||||||
else this->val = res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::DecrementProgress(double Progress)
|
|
||||||
{
|
|
||||||
if(this->val > Progress) this->ClearProgress();
|
|
||||||
else this->val -= Progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::SetMaxValue(double Max)
|
|
||||||
{
|
|
||||||
this->maxval = Max;
|
|
||||||
}
|
|
||||||
|
|
||||||
double ProgressBar::GetMaxValue()
|
|
||||||
{
|
|
||||||
return this->maxval;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::FillProgress()
|
|
||||||
{
|
|
||||||
this->val = this->maxval;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::ClearProgress()
|
|
||||||
{
|
|
||||||
this->val = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ProgressBar::IsCompleted()
|
|
||||||
{
|
|
||||||
return (this->val >= this->maxval);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y)
|
|
||||||
{
|
|
||||||
s32 rdx = X;
|
|
||||||
s32 rdy = Y;
|
|
||||||
s32 pcw = (s32)((this->val / this->maxval) * (double)this->w);
|
|
||||||
s32 rad = (this->h / 3);
|
|
||||||
Drawer->RenderRoundedRectangleFill(this->clr, rdx, rdy, this->w, this->h, rad);
|
|
||||||
Drawer->RenderRoundedRectangleFill(this->oclr, rdx, rdy, std::max(this->h, pcw), this->h, rad);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressBar::OnInput(u64 Down, u64 Up, u64 Held, Touch Pos)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,80 +0,0 @@
|
|||||||
#include <pu/ui/elm/elm_Rectangle.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
Rectangle::Rectangle(s32 X, s32 Y, s32 Width, s32 Height, Color RecColor, s32 BorderRadius)
|
|
||||||
: Element::Element(), x(X), y(Y), w(Width), h(Height), clr(RecColor), borderr(BorderRadius)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Rectangle::GetX()
|
|
||||||
{
|
|
||||||
return this->x;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Rectangle::SetX(s32 X)
|
|
||||||
{
|
|
||||||
this->x = X;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Rectangle::GetY()
|
|
||||||
{
|
|
||||||
return this->y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Rectangle::SetY(s32 Y)
|
|
||||||
{
|
|
||||||
this->y = Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Rectangle::GetWidth()
|
|
||||||
{
|
|
||||||
return this->w;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Rectangle::SetWidth(s32 Width)
|
|
||||||
{
|
|
||||||
this->w = Width;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Rectangle::GetHeight()
|
|
||||||
{
|
|
||||||
return this->h;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Rectangle::SetHeight(s32 Height)
|
|
||||||
{
|
|
||||||
this->h = Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Rectangle::GetBorderRadius()
|
|
||||||
{
|
|
||||||
return this->h;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Rectangle::SetBorderRadius(s32 Radius)
|
|
||||||
{
|
|
||||||
this->borderr = Radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color Rectangle::GetColor()
|
|
||||||
{
|
|
||||||
return this->clr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Rectangle::SetColor(Color RecColor)
|
|
||||||
{
|
|
||||||
this->clr = RecColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Rectangle::OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y)
|
|
||||||
{
|
|
||||||
s32 rdx = X;
|
|
||||||
s32 rdy = Y;
|
|
||||||
Drawer->RenderRoundedRectangleFill(this->clr, rdx, rdy, this->w, this->h, this->borderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Rectangle::OnInput(u64 Down, u64 Up, u64 Held, Touch Pos)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,99 +0,0 @@
|
|||||||
#include <pu/ui/elm/elm_TextBlock.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
TextBlock::TextBlock(s32 X, s32 Y, const std::string& Text, s32 FontSize)
|
|
||||||
: Element::Element(), x(X), y(Y), text(Text)
|
|
||||||
{
|
|
||||||
this->clr = { 0, 0, 0, 255 };
|
|
||||||
this->SetFontSize(FontSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
TextBlock::~TextBlock()
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 TextBlock::GetX()
|
|
||||||
{
|
|
||||||
return this->x;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextBlock::SetX(s32 X)
|
|
||||||
{
|
|
||||||
this->x = X;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 TextBlock::GetY()
|
|
||||||
{
|
|
||||||
return this->y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextBlock::SetY(s32 Y)
|
|
||||||
{
|
|
||||||
this->y = Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 TextBlock::GetWidth()
|
|
||||||
{
|
|
||||||
return this->GetTextWidth();
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 TextBlock::GetHeight()
|
|
||||||
{
|
|
||||||
return this->GetTextHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 TextBlock::GetTextWidth()
|
|
||||||
{
|
|
||||||
return render::GetTextureWidth(this->ntex);
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 TextBlock::GetTextHeight()
|
|
||||||
{
|
|
||||||
return render::GetTextureHeight(this->ntex);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string TextBlock::GetText()
|
|
||||||
{
|
|
||||||
return this->text;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextBlock::SetText(const std::string& Text)
|
|
||||||
{
|
|
||||||
this->text = Text;
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->ntex = render::RenderText(this->font, this->meme, Text, this->clr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextBlock::SetFontSize(s32 FontSize)
|
|
||||||
{
|
|
||||||
this->font = render::LoadDefaultFont(FontSize);
|
|
||||||
this->meme = render::LoadSharedFont(render::SharedFont::NintendoExtended, FontSize);
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->ntex = render::RenderText(this->font, this->meme, this->text, this->clr);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color TextBlock::GetColor()
|
|
||||||
{
|
|
||||||
return this->clr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextBlock::SetColor(Color Color)
|
|
||||||
{
|
|
||||||
this->clr = Color;
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->ntex = render::RenderText(this->font, this->meme, this->text, Color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextBlock::OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y)
|
|
||||||
{
|
|
||||||
s32 rdx = X;
|
|
||||||
s32 rdy = Y;
|
|
||||||
Drawer->RenderTexture(this->ntex, rdx, rdy);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextBlock::OnInput(u64 Down, u64 Up, u64 Held, Touch Pos)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,132 +0,0 @@
|
|||||||
#include <pu/ui/elm/elm_Toggle.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::elm
|
|
||||||
{
|
|
||||||
Toggle::Toggle(s32 X, s32 Y, const std::string& Content, u64 Key, Color Color)
|
|
||||||
: Element::Element(), x(X), y(Y), key(Key), cnt(Content), clr(Color)
|
|
||||||
{
|
|
||||||
this->togfact = 255;
|
|
||||||
this->checked = false;
|
|
||||||
this->SetFontSize(25);
|
|
||||||
}
|
|
||||||
|
|
||||||
Toggle::~Toggle()
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Toggle::GetX()
|
|
||||||
{
|
|
||||||
return this->x;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Toggle::SetX(s32 X)
|
|
||||||
{
|
|
||||||
this->x = X;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Toggle::GetY()
|
|
||||||
{
|
|
||||||
return this->y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Toggle::SetY(s32 Y)
|
|
||||||
{
|
|
||||||
this->y = Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Toggle::GetWidth()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Toggle::GetHeight()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Toggle::GetContent()
|
|
||||||
{
|
|
||||||
return this->cnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Toggle::SetContent(const std::string& Content)
|
|
||||||
{
|
|
||||||
this->cnt = Content;
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->ntex = render::RenderText(this->font, this->meme, Content, this->clr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Toggle::SetFontSize(s32 FontSize)
|
|
||||||
{
|
|
||||||
this->font = render::LoadDefaultFont(FontSize);
|
|
||||||
this->meme = render::LoadSharedFont(render::SharedFont::NintendoExtended, FontSize);
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->ntex = render::RenderText(this->font, this->meme, this->cnt, this->clr);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color Toggle::GetColor()
|
|
||||||
{
|
|
||||||
return this->clr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Toggle::SetColor(Color Color)
|
|
||||||
{
|
|
||||||
this->clr = Color;
|
|
||||||
render::DeleteTexture(this->ntex);
|
|
||||||
this->ntex = render::RenderText(this->font, this->meme, this->cnt, Color);
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 Toggle::GetKey()
|
|
||||||
{
|
|
||||||
return this->key;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Toggle::SetKey(u64 Key)
|
|
||||||
{
|
|
||||||
this->key = Key;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Toggle::IsChecked()
|
|
||||||
{
|
|
||||||
return this->checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Toggle::OnRender(render::Renderer::Ref &Drawer, s32 X, s32 Y)
|
|
||||||
{
|
|
||||||
s32 tw = render::GetTextureWidth(this->ntex);
|
|
||||||
s32 th = render::GetTextureHeight(this->ntex);
|
|
||||||
s32 rw = th;
|
|
||||||
s32 rh = (2 * th);
|
|
||||||
s32 rx = X;
|
|
||||||
s32 ry = Y;
|
|
||||||
s32 tx = rx + rw + (th / 2);
|
|
||||||
s32 ty = ry + (th / 2);
|
|
||||||
if(this->checked)
|
|
||||||
{
|
|
||||||
Drawer->RenderRectangleFill({ 130, 130, 130, 255 }, rx, ry, rw, rh);
|
|
||||||
if(this->togfact < 255)
|
|
||||||
{
|
|
||||||
Drawer->RenderRectangleFill({ this->clr.R, this->clr.G, this->clr.B, (255 - this->togfact) }, rx, ry, rw, rh);
|
|
||||||
this->togfact += 48;
|
|
||||||
}
|
|
||||||
else Drawer->RenderRectangleFill({ 130, 130, 130, 255 }, rx, ry, rw, rh);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Drawer->RenderRectangleFill(this->clr, rx, ry, rw, rh);
|
|
||||||
if(this->togfact > 0)
|
|
||||||
{
|
|
||||||
Drawer->RenderRectangleFill({ 130, 130, 130, this->togfact }, rx, ry, rw, rh);
|
|
||||||
this->togfact -= 48;
|
|
||||||
}
|
|
||||||
else Drawer->RenderRectangleFill(this->clr, rx, ry, rw, rh);
|
|
||||||
}
|
|
||||||
Drawer->RenderTexture(this->ntex, tx, ty);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Toggle::OnInput(u64 Down, u64 Up, u64 Held, Touch Pos)
|
|
||||||
{
|
|
||||||
if((Down & this->key) || ((this->key == KEY_TOUCH) && !Pos.IsEmpty())) this->checked = !this->checked;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
#include <pu/ui/extras/extras_Toast.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui::extras
|
|
||||||
{
|
|
||||||
Toast::Toast(const std::string& Text, s32 FontSize, Color TextColor, Color BaseColor) : Overlay(0, 550, 0, 0, BaseColor)
|
|
||||||
{
|
|
||||||
this->text = elm::TextBlock::New(0, 0, Text, FontSize);
|
|
||||||
this->text->SetColor(TextColor);
|
|
||||||
this->text->SetHorizontalAlign(pu::ui::elm::HorizontalAlign::Center);
|
|
||||||
this->text->SetVerticalAlign(pu::ui::elm::VerticalAlign::Center);
|
|
||||||
s32 textw = this->text->GetTextWidth();
|
|
||||||
s32 texth = this->text->GetTextHeight();
|
|
||||||
s32 toastw = textw + (texth * 4);
|
|
||||||
s32 toasth = texth * 3;
|
|
||||||
this->SetX((1280 - toastw) / 2);
|
|
||||||
this->SetWidth(toastw);
|
|
||||||
this->SetHeight(toasth);
|
|
||||||
this->Add(this->text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Toast::SetText(const std::string& Text)
|
|
||||||
{
|
|
||||||
this->text->SetText(Text);
|
|
||||||
s32 textw = this->text->GetTextWidth();
|
|
||||||
s32 texth = this->text->GetTextHeight();
|
|
||||||
s32 toastw = textw + (texth * 4);
|
|
||||||
s32 toasth = texth * 3;
|
|
||||||
this->SetX((1280 - toastw) / 2);
|
|
||||||
this->SetWidth(toastw);
|
|
||||||
this->SetHeight(toasth);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Toast::OnPreRender(render::Renderer::Ref &Drawer)
|
|
||||||
{
|
|
||||||
Drawer->SetBaseRenderAlpha(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Toast::OnPostRender(render::Renderer::Ref &Drawer)
|
|
||||||
{
|
|
||||||
Drawer->UnsetBaseRenderAlpha();
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,235 +0,0 @@
|
|||||||
#include <pu/ui/render/render_Renderer.hpp>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
namespace pu::ui::render
|
|
||||||
{
|
|
||||||
NativeRenderer purend = NULL;
|
|
||||||
|
|
||||||
extern std::unordered_map<u32, std::unordered_map<std::string, NativeFont>> filefonts;
|
|
||||||
extern std::unordered_map<u32, std::unordered_map<SharedFont, NativeFont>> shfonts;
|
|
||||||
|
|
||||||
Renderer::Renderer(u32 SDLFlags, RendererInitOptions Options, u32 NativeRendererFlags, u32 Width, u32 Height)
|
|
||||||
{
|
|
||||||
this->sdlflags = SDLFlags;
|
|
||||||
this->nrendflags = NativeRendererFlags;
|
|
||||||
this->initopts = Options;
|
|
||||||
this->initialized = false;
|
|
||||||
this->ww = Width;
|
|
||||||
this->wh = Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::Initialize()
|
|
||||||
{
|
|
||||||
if(!this->initialized)
|
|
||||||
{
|
|
||||||
|
|
||||||
this->okromfs = false;
|
|
||||||
if(this->initopts.InitRomFs)
|
|
||||||
{
|
|
||||||
Result rc = romfsInit();
|
|
||||||
this->okromfs = R_SUCCEEDED(rc);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->okpl = false;
|
|
||||||
if(this->initopts.InitPL)
|
|
||||||
{
|
|
||||||
Result rc = plInitialize(PlServiceType_User);
|
|
||||||
this->okpl = R_SUCCEEDED(rc);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Init(this->sdlflags);
|
|
||||||
this->rendwd = SDL_CreateWindow("Plutonium-SDL2", 0, 0, this->ww, this->wh, 0);
|
|
||||||
purend = SDL_CreateRenderer(this->rendwd, -1, this->nrendflags);
|
|
||||||
this->rendsf = SDL_GetWindowSurface(this->rendwd);
|
|
||||||
SDL_SetRenderDrawBlendMode(purend, SDL_BLENDMODE_BLEND);
|
|
||||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
|
|
||||||
|
|
||||||
if(this->initopts.InitIMG) IMG_Init(this->initopts.IMGFlags);
|
|
||||||
|
|
||||||
if(this->initopts.InitTTF) TTF_Init();
|
|
||||||
|
|
||||||
if(this->initopts.InitMixer)
|
|
||||||
{
|
|
||||||
Mix_Init(this->initopts.MixerFlags);
|
|
||||||
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->initialized = true;
|
|
||||||
this->basea = -1;
|
|
||||||
this->basex = 0;
|
|
||||||
this->basey = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::Finalize()
|
|
||||||
{
|
|
||||||
for(auto &map: shfonts)
|
|
||||||
for (auto &font: map.second)
|
|
||||||
render::DeleteFont(font.second);
|
|
||||||
|
|
||||||
for(auto &map: filefonts)
|
|
||||||
for (auto &font: map.second)
|
|
||||||
render::DeleteFont(font.second);
|
|
||||||
|
|
||||||
if(this->initialized)
|
|
||||||
{
|
|
||||||
if(this->initopts.InitTTF) TTF_Quit();
|
|
||||||
if(this->initopts.InitIMG) IMG_Quit();
|
|
||||||
if(this->initopts.InitMixer) Mix_CloseAudio();
|
|
||||||
if(this->okpl) plExit();
|
|
||||||
if(this->okromfs) romfsExit();
|
|
||||||
SDL_DestroyRenderer(purend);
|
|
||||||
SDL_FreeSurface(this->rendsf);
|
|
||||||
SDL_DestroyWindow(this->rendwd);
|
|
||||||
SDL_Quit();
|
|
||||||
this->initialized = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Renderer::HasInitialized()
|
|
||||||
{
|
|
||||||
return this->initialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Renderer::HasRomFs()
|
|
||||||
{
|
|
||||||
return this->okromfs;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::InitializeRender(Color Color)
|
|
||||||
{
|
|
||||||
SDL_SetRenderDrawColor(purend, Color.R, Color.G, Color.B, Color.A);
|
|
||||||
SDL_RenderClear(purend);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::FinalizeRender()
|
|
||||||
{
|
|
||||||
SDL_RenderPresent(purend);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::RenderTexture(NativeTexture Texture, s32 X, s32 Y, NativeTextureRenderOptions Options)
|
|
||||||
{
|
|
||||||
SDL_Rect pos;
|
|
||||||
pos.x = X + this->basex;
|
|
||||||
pos.y = Y + this->basey;
|
|
||||||
if((Options.Width >= 0) && (Options.Height >= 0))
|
|
||||||
{
|
|
||||||
pos.w = Options.Width;
|
|
||||||
pos.h = Options.Height;
|
|
||||||
}
|
|
||||||
else SDL_QueryTexture(Texture, NULL, NULL, &pos.w, &pos.h);
|
|
||||||
float angle = 0;
|
|
||||||
if(Options.Angle >= 0) angle = Options.Angle;
|
|
||||||
if(Options.AlphaMod >= 0) SetAlphaValue(Texture, (u8)Options.AlphaMod);
|
|
||||||
if(this->basea >= 0) SetAlphaValue(Texture, (u8)this->basea);
|
|
||||||
SDL_RenderCopyEx(purend, Texture, NULL, &pos, angle, NULL, SDL_FLIP_NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::RenderRectangle(Color Color, s32 X, s32 Y, s32 Width, s32 Height)
|
|
||||||
{
|
|
||||||
SDL_Rect rect;
|
|
||||||
rect.x = X + this->basex;
|
|
||||||
rect.y = Y + this->basey;
|
|
||||||
rect.w = Width;
|
|
||||||
rect.h = Height;
|
|
||||||
u8 alpha = Color.A;
|
|
||||||
if(this->basea >= 0) alpha = (u8)this->basea;
|
|
||||||
SDL_SetRenderDrawColor(purend, Color.R, Color.G, Color.B, alpha);
|
|
||||||
SDL_RenderDrawRect(purend, &rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::RenderRectangleFill(Color Color, s32 X, s32 Y, s32 Width, s32 Height)
|
|
||||||
{
|
|
||||||
SDL_Rect rect;
|
|
||||||
rect.x = X + this->basex;
|
|
||||||
rect.y = Y + this->basey;
|
|
||||||
rect.w = Width;
|
|
||||||
rect.h = Height;
|
|
||||||
u8 alpha = Color.A;
|
|
||||||
if(this->basea >= 0) alpha = (u8)this->basea;
|
|
||||||
SDL_SetRenderDrawColor(purend, Color.R, Color.G, Color.B, alpha);
|
|
||||||
SDL_RenderFillRect(purend, &rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::RenderRectangleOutline(Color Color, u32 X, u32 Y, u32 Width, u32 Height, u32 BorderWidth)
|
|
||||||
{
|
|
||||||
this->RenderRectangleFill(Color, X - BorderWidth, Y - BorderWidth, Width + (BorderWidth * 2), Height + (BorderWidth * 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::RenderRoundedRectangle(Color Color, s32 X, s32 Y, s32 Width, s32 Height, s32 Radius)
|
|
||||||
{
|
|
||||||
u8 alpha = Color.A;
|
|
||||||
if(this->basea >= 0) alpha = (u8)this->basea;
|
|
||||||
roundedRectangleRGBA(purend, X + this->basex, Y + this->basey, X + this->basex + Width, Y + this->basey + Height, Radius, Color.R, Color.G, Color.B, alpha);
|
|
||||||
SDL_SetRenderDrawBlendMode(purend, SDL_BLENDMODE_BLEND);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::RenderRoundedRectangleFill(Color Color, s32 X, s32 Y, s32 Width, s32 Height, s32 Radius)
|
|
||||||
{
|
|
||||||
u8 alpha = Color.A;
|
|
||||||
if(this->basea >= 0) alpha = (u8)this->basea;
|
|
||||||
roundedBoxRGBA(purend, X + this->basex, Y + this->basey, X + this->basex + Width, Y + this->basey + Height, Radius, Color.R, Color.G, Color.B, alpha);
|
|
||||||
SDL_SetRenderDrawBlendMode(purend, SDL_BLENDMODE_BLEND);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::RenderCircle(Color Color, s32 X, s32 Y, s32 Radius)
|
|
||||||
{
|
|
||||||
u8 alpha = Color.A;
|
|
||||||
if(this->basea >= 0) alpha = (u8)this->basea;
|
|
||||||
circleRGBA(purend, X + this->basex, Y + this->basey, Radius - 1, Color.R, Color.G, Color.B, alpha);
|
|
||||||
aacircleRGBA(purend, X + this->basex, Y + this->basey, Radius - 1, Color.R, Color.G, Color.B, alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::RenderCircleFill(Color Color, s32 X, s32 Y, s32 Radius)
|
|
||||||
{
|
|
||||||
u8 alpha = Color.A;
|
|
||||||
if(this->basea >= 0) alpha = (u8)this->basea;
|
|
||||||
filledCircleRGBA(purend, X + this->basex, Y + this->basey, Radius - 1, Color.R, Color.G, Color.B, alpha);
|
|
||||||
aacircleRGBA(purend, X + this->basex, Y + this->basey, Radius - 1, Color.R, Color.G, Color.B, alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::RenderShadowSimple(s32 X, s32 Y, s32 Width, s32 Height, s32 BaseAlpha, u8 MainAlpha)
|
|
||||||
{
|
|
||||||
bool crop = false;
|
|
||||||
s32 shw = Width;
|
|
||||||
s32 shx = X;
|
|
||||||
s32 shy = Y;
|
|
||||||
for(s32 al = BaseAlpha; al > 0; al -= (180 / Height))
|
|
||||||
{
|
|
||||||
this->RenderRectangleFill({ 130, 130, 130, (al * (MainAlpha / 255)) }, shx + this->basex, shy + this->basey, shw, 1);
|
|
||||||
if(crop)
|
|
||||||
{
|
|
||||||
shw -= 2;
|
|
||||||
shx++;
|
|
||||||
}
|
|
||||||
crop = !crop;
|
|
||||||
shy++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SetBaseRenderPosition(s32 X, s32 Y)
|
|
||||||
{
|
|
||||||
this->basex = X;
|
|
||||||
this->basey = Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::UnsetBaseRenderPosition()
|
|
||||||
{
|
|
||||||
this->SetBaseRenderPosition(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::SetBaseRenderAlpha(u8 Alpha)
|
|
||||||
{
|
|
||||||
this->basea = (int)Alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Renderer::UnsetBaseRenderAlpha()
|
|
||||||
{
|
|
||||||
this->basea = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeRenderer GetMainRenderer()
|
|
||||||
{
|
|
||||||
return purend;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,152 +0,0 @@
|
|||||||
#include <pu/ui/render/render_SDL2.hpp>
|
|
||||||
#include <pu/ui/render/render_Renderer.hpp>
|
|
||||||
#include <utility>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
namespace pu::ui::render
|
|
||||||
{
|
|
||||||
std::unordered_map<u32, std::unordered_map<std::string, NativeFont>> filefonts;
|
|
||||||
std::unordered_map<u32, std::unordered_map<SharedFont, NativeFont>> shfonts;
|
|
||||||
|
|
||||||
static SharedFont shfont = SharedFont::Standard;
|
|
||||||
static std::string fontpth;
|
|
||||||
|
|
||||||
NativeTexture ConvertToTexture(NativeSurface Surface)
|
|
||||||
{
|
|
||||||
NativeTexture tex = SDL_CreateTextureFromSurface(GetMainRenderer(), Surface);
|
|
||||||
SDL_FreeSurface(Surface);
|
|
||||||
return tex;
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeTexture RenderText(NativeFont Font, NativeFont Meme, const std::string& Text, Color Color)
|
|
||||||
{
|
|
||||||
NativeSurface txsrf = TTF_RenderUTF8_Blended_Wrapped(Font, Meme, Text.c_str(), { Color.R, Color.G, Color.B, Color.A }, 1280);
|
|
||||||
SDL_SetSurfaceAlphaMod(txsrf, 255);
|
|
||||||
return ConvertToTexture(txsrf);
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeTexture LoadImage(const std::string& Path)
|
|
||||||
{
|
|
||||||
return ConvertToTexture(IMG_Load(Path.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeTexture LoadJpegImage(void* buffer, s32 size)
|
|
||||||
{
|
|
||||||
return ConvertToTexture(IMG_Load_RW(SDL_RWFromMem(buffer, size), size));
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeTexture LoadRgbImage(void* buffer, u64 width, u64 height, u8 depth) {
|
|
||||||
return ConvertToTexture(SDL_CreateRGBSurfaceFrom(buffer, width, height, depth*8, depth*width, 0x000000ff, 0x0000ff00, 0x00ff0000, depth == 4 ? 0xff000000 : 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeFont LoadSharedFont(SharedFont Type, s32 Size)
|
|
||||||
{
|
|
||||||
auto it_size = shfonts.find(Size);
|
|
||||||
if(it_size != shfonts.end()) {
|
|
||||||
auto it_path = it_size->second.find(Type);
|
|
||||||
if (it_path != it_size->second.end()) {
|
|
||||||
return it_path->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PlFontData plfont;
|
|
||||||
NativeFont font = NULL;
|
|
||||||
SDL_RWops *mem = NULL;
|
|
||||||
Result rc = plGetSharedFontByType(&plfont, static_cast<PlSharedFontType>(Type));
|
|
||||||
if(rc == 0)
|
|
||||||
{
|
|
||||||
mem = SDL_RWFromMem(plfont.address, plfont.size);
|
|
||||||
font = TTF_OpenFontRW(mem, 1, Size);
|
|
||||||
}
|
|
||||||
if(font != NULL) {
|
|
||||||
if(it_size == shfonts.end()) {
|
|
||||||
std::unordered_map<SharedFont, NativeFont> typeMap;
|
|
||||||
typeMap.insert(std::make_pair(Type, font));
|
|
||||||
shfonts.insert(std::make_pair(Size, typeMap));
|
|
||||||
} else {
|
|
||||||
it_size->second.insert(std::make_pair(Type, font));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return font;
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeFont LoadFont(const std::string& Path, s32 Size)
|
|
||||||
{
|
|
||||||
auto it_size = filefonts.find(Size);
|
|
||||||
if(it_size != filefonts.end()) {
|
|
||||||
auto it_path = it_size->second.find(Path);
|
|
||||||
if (it_path != it_size->second.end()) {
|
|
||||||
return it_path->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
auto font = TTF_OpenFont(Path.c_str(), Size);
|
|
||||||
if(font != NULL) {
|
|
||||||
if(it_size == filefonts.end()) {
|
|
||||||
std::unordered_map<std::string, NativeFont> pathMap;
|
|
||||||
pathMap.insert(std::make_pair(Path, font));
|
|
||||||
filefonts.insert(std::make_pair(Size, pathMap));
|
|
||||||
} else {
|
|
||||||
it_size->second.insert(std::make_pair(Path, font));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return font;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetDefaultFont(const std::string& Path)
|
|
||||||
{
|
|
||||||
fontpth = Path;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetDefaultFontFromShared(SharedFont Type)
|
|
||||||
{
|
|
||||||
shfont = Type;
|
|
||||||
}
|
|
||||||
|
|
||||||
NativeFont LoadDefaultFont(s32 Size)
|
|
||||||
{
|
|
||||||
if(!fontpth.empty()) return LoadFont(fontpth, Size);
|
|
||||||
return LoadSharedFont(shfont, Size);
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 GetTextureWidth(NativeTexture Texture)
|
|
||||||
{
|
|
||||||
int w = 0;
|
|
||||||
SDL_QueryTexture(Texture, NULL, NULL, &w, NULL);
|
|
||||||
return (s32)w;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 GetTextureHeight(NativeTexture Texture)
|
|
||||||
{
|
|
||||||
int h = 0;
|
|
||||||
SDL_QueryTexture(Texture, NULL, NULL, NULL, &h);
|
|
||||||
return (s32)h;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::pair<s32,s32> GetTextureSize(NativeTexture Texture)
|
|
||||||
{
|
|
||||||
int w, h;
|
|
||||||
SDL_QueryTexture(Texture, NULL, NULL, &w, &h);
|
|
||||||
return std::make_pair(w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetAlphaValue(NativeTexture Texture, u8 Alpha)
|
|
||||||
{
|
|
||||||
SDL_SetTextureBlendMode(Texture, SDL_BLENDMODE_BLEND);
|
|
||||||
SDL_SetTextureAlphaMod(Texture, Alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeleteFont(NativeFont& Font)
|
|
||||||
{
|
|
||||||
if (Font != nullptr) {
|
|
||||||
TTF_CloseFont(Font);
|
|
||||||
Font = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeleteTexture(NativeTexture& Texture)
|
|
||||||
{
|
|
||||||
if (Texture != nullptr) {
|
|
||||||
SDL_DestroyTexture(Texture);
|
|
||||||
Texture = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,237 +0,0 @@
|
|||||||
#include <pu/ui/ui_Application.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui
|
|
||||||
{
|
|
||||||
Application::Application(render::Renderer::Ref Renderer)
|
|
||||||
{
|
|
||||||
this->rend = Renderer;
|
|
||||||
this->rend->Initialize();
|
|
||||||
this->show = false;
|
|
||||||
this->cbipt = [&](u64,u64,u64,Touch){};
|
|
||||||
this->rover = false;
|
|
||||||
this->ovl = nullptr;
|
|
||||||
this->closefact = false;
|
|
||||||
this->fovl = false;
|
|
||||||
this->ffovl = false;
|
|
||||||
this->lyt = nullptr;
|
|
||||||
this->loaded = false;
|
|
||||||
this->rof = [](render::Renderer::Ref&) -> bool { return true; };
|
|
||||||
this->fadea = 255;
|
|
||||||
this->aapf = 35;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::LoadLayout(std::shared_ptr<Layout> Layout)
|
|
||||||
{
|
|
||||||
this->lyt = Layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::Prepare()
|
|
||||||
{
|
|
||||||
if(!this->loaded)
|
|
||||||
{
|
|
||||||
this->OnLoad();
|
|
||||||
this->loaded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::AddThread(std::function<void()> Callback)
|
|
||||||
{
|
|
||||||
this->thds.push_back(Callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::SetOnInput(std::function<void(u64 Down, u64 Up, u64 Held, Touch Pos)> Callback)
|
|
||||||
{
|
|
||||||
this->cbipt = Callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Application::ShowDialog(Dialog::Ref &ToShow)
|
|
||||||
{
|
|
||||||
return ToShow->Show(this->rend, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Application::CreateShowDialog(const std::string& Title, const std::string& Content, std::vector<std::string> Options, bool UseLastOptionAsCancel, const std::string& Icon)
|
|
||||||
{
|
|
||||||
Dialog dlg(Title, Content);
|
|
||||||
for(s32 i = 0; i < Options.size(); i++)
|
|
||||||
{
|
|
||||||
if(UseLastOptionAsCancel && (i == Options.size() - 1)) dlg.SetCancelOption(Options[i]);
|
|
||||||
else dlg.AddOption(Options[i]);
|
|
||||||
}
|
|
||||||
if(!Icon.empty()) dlg.SetIcon(Icon);
|
|
||||||
int opt = dlg.Show(this->rend, this);
|
|
||||||
if(dlg.UserCancelled()) opt = -1;
|
|
||||||
else if(!dlg.IsOk()) opt = -2;
|
|
||||||
return opt;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::StartOverlay(std::shared_ptr<Overlay> Overlay)
|
|
||||||
{
|
|
||||||
this->ovl = Overlay;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::StartOverlayWithTimeout(std::shared_ptr<Overlay> Overlay, u64 Milli)
|
|
||||||
{
|
|
||||||
if(this->ovl == nullptr)
|
|
||||||
{
|
|
||||||
this->ovl = std::dynamic_pointer_cast<ui::Overlay>(Overlay);
|
|
||||||
this->tmillis = Milli;
|
|
||||||
this->tclock = std::chrono::steady_clock::now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::EndOverlay()
|
|
||||||
{
|
|
||||||
if(this->ovl != nullptr)
|
|
||||||
{
|
|
||||||
this->ovl->NotifyEnding(false);
|
|
||||||
this->tmillis = 0;
|
|
||||||
this->ovl = nullptr;
|
|
||||||
this->fovl = false;
|
|
||||||
this->ffovl = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::Show()
|
|
||||||
{
|
|
||||||
if(!this->loaded) return;
|
|
||||||
if(this->lyt == nullptr) return;
|
|
||||||
this->show = true;
|
|
||||||
while(this->show) this->CallForRender();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::ShowWithFadeIn()
|
|
||||||
{
|
|
||||||
this->FadeIn();
|
|
||||||
this->Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Application::IsShown()
|
|
||||||
{
|
|
||||||
return this->show;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Application::CallForRender()
|
|
||||||
{
|
|
||||||
if(!this->loaded) return false;
|
|
||||||
if(this->lyt == nullptr) return false;
|
|
||||||
bool c = true;
|
|
||||||
this->rend->InitializeRender(this->lyt->GetBackgroundColor());
|
|
||||||
this->OnRender();
|
|
||||||
if(this->rover)
|
|
||||||
{
|
|
||||||
c = (this->rof)(this->rend);
|
|
||||||
this->rover = false;
|
|
||||||
this->rof = [](render::Renderer::Ref &Drawer) -> bool { return true; };
|
|
||||||
}
|
|
||||||
this->rend->FinalizeRender();
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Application::CallForRenderWithRenderOver(std::function<bool(render::Renderer::Ref &Drawer)> RenderFunc)
|
|
||||||
{
|
|
||||||
this->rover = true;
|
|
||||||
this->rof = RenderFunc;
|
|
||||||
return this->CallForRender();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::FadeIn()
|
|
||||||
{
|
|
||||||
fadea = 0;
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
CallForRender();
|
|
||||||
fadea += aapf;
|
|
||||||
if(fadea > 255)
|
|
||||||
{
|
|
||||||
fadea = 255;
|
|
||||||
CallForRender();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::FadeOut()
|
|
||||||
{
|
|
||||||
fadea = 255;
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
CallForRender();
|
|
||||||
fadea -= aapf;
|
|
||||||
if(fadea < 0)
|
|
||||||
{
|
|
||||||
fadea = 0;
|
|
||||||
CallForRender();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Application::IsFadedIn()
|
|
||||||
{
|
|
||||||
return (fadea > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::SetFadeAlphaAmountPerFrame(u8 Alpha)
|
|
||||||
{
|
|
||||||
aapf = Alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::OnRender()
|
|
||||||
{
|
|
||||||
hidScanInput();
|
|
||||||
u64 d = hidKeysDown(CONTROLLER_P1_AUTO);
|
|
||||||
u64 u = hidKeysUp(CONTROLLER_P1_AUTO);
|
|
||||||
u64 h = hidKeysHeld(CONTROLLER_P1_AUTO);
|
|
||||||
u64 th = hidKeysDown(CONTROLLER_HANDHELD);
|
|
||||||
Touch tch = Touch::Empty;
|
|
||||||
if(th & KEY_TOUCH)
|
|
||||||
{
|
|
||||||
touchPosition nxtch;
|
|
||||||
hidTouchRead(&nxtch, 0);
|
|
||||||
tch.X = nxtch.px;
|
|
||||||
tch.Y = nxtch.py;
|
|
||||||
}
|
|
||||||
auto simtch = this->lyt->GetSimulatedTouch();
|
|
||||||
if(!simtch.IsEmpty()) tch = simtch;
|
|
||||||
if(!this->thds.empty()) for(s32 i = 0; i < this->thds.size(); i++) (this->thds[i])();
|
|
||||||
this->lyt->PreRender();
|
|
||||||
auto lyth = this->lyt->GetAllThreads();
|
|
||||||
if(!lyth.empty()) for(s32 i = 0; i < lyth.size(); i++) (lyth[i])();
|
|
||||||
if(!this->rover) (this->cbipt)(d, u, h, tch);
|
|
||||||
if(this->lyt->HasBackgroundImage()) this->rend->RenderTexture(this->lyt->GetBackgroundImageTexture(), 0, 0);
|
|
||||||
if(!this->rover) (this->lyt->GetOnInput())(d, u, h, tch);
|
|
||||||
if(this->lyt->HasChilds()) for(s32 i = 0; i < this->lyt->GetCount(); i++)
|
|
||||||
{
|
|
||||||
auto elm = this->lyt->At(i);
|
|
||||||
if(elm->IsVisible())
|
|
||||||
{
|
|
||||||
elm->OnRender(this->rend, elm->GetProcessedX(), elm->GetProcessedY());
|
|
||||||
if(!this->rover) elm->OnInput(d, u, h, tch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(this->ovl != NULL)
|
|
||||||
{
|
|
||||||
bool rok = this->ovl->Render(this->rend);
|
|
||||||
if(this->tmillis > 0)
|
|
||||||
{
|
|
||||||
auto nclk = std::chrono::steady_clock::now();
|
|
||||||
u64 cctime = std::chrono::duration_cast<std::chrono::milliseconds>(nclk - this->tclock).count();
|
|
||||||
if(cctime >= this->tmillis) this->ovl->NotifyEnding(true);
|
|
||||||
}
|
|
||||||
if(!rok) this->EndOverlay();
|
|
||||||
}
|
|
||||||
this->rend->RenderRectangleFill({ 0, 0, 0, 255 - (u8)fadea }, 0, 0, 1280, 720);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::Close()
|
|
||||||
{
|
|
||||||
this->show = false;
|
|
||||||
this->rend->Finalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::CloseWithFadeOut()
|
|
||||||
{
|
|
||||||
this->FadeOut();
|
|
||||||
this->Close();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
#include <pu/ui/ui_Container.hpp>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
namespace pu::ui
|
|
||||||
{
|
|
||||||
Container::Container(s32 X, s32 Y, s32 Width, s32 Height)
|
|
||||||
{
|
|
||||||
this->x = X;
|
|
||||||
this->y = Y;
|
|
||||||
this->w = Width;
|
|
||||||
this->h = Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
elm::Element::Ref &Container::At(s32 Index)
|
|
||||||
{
|
|
||||||
return this->elms.at(Index);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Container::Has(elm::Element::Ref &Elm)
|
|
||||||
{
|
|
||||||
auto it = std::find(this->elms.begin(), this->elms.end(), Elm);
|
|
||||||
return (it != this->elms.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Container::Clear()
|
|
||||||
{
|
|
||||||
this->elms.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Container::GetCount()
|
|
||||||
{
|
|
||||||
return this->elms.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Container::SetX(s32 X)
|
|
||||||
{
|
|
||||||
this->x = X;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Container::GetX()
|
|
||||||
{
|
|
||||||
return this->x;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Container::SetY(s32 Y)
|
|
||||||
{
|
|
||||||
this->y = Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Container::GetY()
|
|
||||||
{
|
|
||||||
return this->y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Container::SetWidth(s32 Width)
|
|
||||||
{
|
|
||||||
this->w = Width;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Container::GetWidth()
|
|
||||||
{
|
|
||||||
return this->w;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Container::SetHeight(s32 Height)
|
|
||||||
{
|
|
||||||
this->h = Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Container::GetHeight()
|
|
||||||
{
|
|
||||||
return this->h;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Container::PreRender()
|
|
||||||
{
|
|
||||||
for(auto &elm : this->elms)
|
|
||||||
{
|
|
||||||
elm->SetParent(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,261 +0,0 @@
|
|||||||
#include <pu/ui/ui_Dialog.hpp>
|
|
||||||
#include <pu/ui/ui_Application.hpp>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
namespace pu::ui
|
|
||||||
{
|
|
||||||
Dialog::Dialog(const std::string& Title, const std::string& Content)
|
|
||||||
: stitle(Title), scnt(Content)
|
|
||||||
{
|
|
||||||
this->titleFont = render::LoadDefaultFont(30);
|
|
||||||
this->contentFont = render::LoadDefaultFont(20);
|
|
||||||
this->optionsFont = render::LoadDefaultFont(18);
|
|
||||||
this->titleFontEx = render::LoadSharedFont(render::SharedFont::NintendoExtended, 30);
|
|
||||||
this->contentFontEx = render::LoadSharedFont(render::SharedFont::NintendoExtended, 20);
|
|
||||||
this->optionsFontEx = render::LoadSharedFont(render::SharedFont::NintendoExtended, 18);
|
|
||||||
this->title = render::RenderText(this->titleFont, this->titleFontEx, Title, { 10, 10, 10, 255 });
|
|
||||||
this->cnt = render::RenderText(this->contentFont, this->contentFontEx, Content, { 20, 20, 20, 255 });
|
|
||||||
this->osel = 0;
|
|
||||||
this->prevosel = 0;
|
|
||||||
this->selfact = 255;
|
|
||||||
this->pselfact = 0;
|
|
||||||
this->hicon = false;
|
|
||||||
this->cancel = false;
|
|
||||||
this->hcancel = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dialog::~Dialog()
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->title);
|
|
||||||
render::DeleteTexture(this->cnt);
|
|
||||||
render::DeleteTexture(this->icon);
|
|
||||||
for(auto &opt: this->opts) render::DeleteTexture(opt);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Dialog::AddOption(const std::string& Name)
|
|
||||||
{
|
|
||||||
this->opts.push_back(render::RenderText(this->optionsFont, this->optionsFontEx, Name, { 10, 10, 10, 255 }));
|
|
||||||
this->sopts.push_back(Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Dialog::SetCancelOption(const std::string& Name)
|
|
||||||
{
|
|
||||||
this->hcancel = true;
|
|
||||||
this->scancel = Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Dialog::RemoveCancelOption()
|
|
||||||
{
|
|
||||||
this->hcancel = false;
|
|
||||||
this->scancel = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Dialog::HasCancelOption()
|
|
||||||
{
|
|
||||||
return this->hcancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Dialog::SetIcon(const std::string& Icon)
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->icon);
|
|
||||||
this->icon = render::LoadImage(Icon);
|
|
||||||
this->hicon = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Dialog::Hasicon()
|
|
||||||
{
|
|
||||||
return this->hicon;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Dialog::Show(render::Renderer::Ref &Drawer, void *App)
|
|
||||||
{
|
|
||||||
if(this->hcancel) this->AddOption(this->scancel);
|
|
||||||
if(this->opts.empty()) return 0;
|
|
||||||
s32 dw = (20 * (this->opts.size() - 1)) + 250;
|
|
||||||
for(s32 i = 0; i < this->opts.size(); i++)
|
|
||||||
{
|
|
||||||
s32 tw = render::GetTextureWidth(this->opts[i]);
|
|
||||||
dw += tw + 20;
|
|
||||||
}
|
|
||||||
if(dw > 1280) dw = 1280;
|
|
||||||
s32 icm = 30;
|
|
||||||
s32 elemh = 60;
|
|
||||||
s32 tdw = render::GetTextureWidth(this->cnt) + 90;
|
|
||||||
if(tdw > dw) dw = tdw;
|
|
||||||
tdw = render::GetTextureWidth(this->title) + 90;
|
|
||||||
if(tdw > dw) dw = tdw;
|
|
||||||
s32 ely = render::GetTextureHeight(this->title) + render::GetTextureHeight(this->cnt) + 140;
|
|
||||||
if(this->hicon)
|
|
||||||
{
|
|
||||||
s32 tely = render::GetTextureHeight(this->icon) + icm + 25;
|
|
||||||
if(tely > ely) ely = tely;
|
|
||||||
tdw = render::GetTextureWidth(this->cnt) + 90 + render::GetTextureWidth(this->icon) + 20;
|
|
||||||
if(tdw > dw) dw = tdw;
|
|
||||||
tdw = render::GetTextureWidth(this->title) + 90 + render::GetTextureWidth(this->icon) + 20;
|
|
||||||
if(tdw > dw) dw = tdw;
|
|
||||||
}
|
|
||||||
if(dw > 1280) dw = 1280;
|
|
||||||
s32 dh = ely + elemh + 30;
|
|
||||||
if(dh > 720) dh = 720;
|
|
||||||
s32 dx = (1280 - dw) / 2;
|
|
||||||
s32 dy = (720 - dh) / 2;
|
|
||||||
ely += dy;
|
|
||||||
s32 elemw = ((dw - (20 * (this->opts.size() + 1))) / this->opts.size());
|
|
||||||
s32 elx = dx + ((dw - ((elemw * this->opts.size()) + (20 * (this->opts.size() - 1)))) / 2);
|
|
||||||
s32 r = 35;
|
|
||||||
s32 nr = 180;
|
|
||||||
s32 ng = 180;
|
|
||||||
s32 nb = 200;
|
|
||||||
bool end = false;
|
|
||||||
s32 initfact = 0;
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
bool ok = ((Application*)App)->CallForRenderWithRenderOver([&](render::Renderer::Ref &Drawer) -> bool
|
|
||||||
{
|
|
||||||
u64 k = hidKeysDown(CONTROLLER_P1_AUTO);
|
|
||||||
u64 h = hidKeysHeld(CONTROLLER_P1_AUTO);
|
|
||||||
if((k & KEY_DLEFT) || (k & KEY_LSTICK_LEFT) || (h & KEY_RSTICK_LEFT))
|
|
||||||
{
|
|
||||||
if(this->osel > 0)
|
|
||||||
{
|
|
||||||
this->prevosel = this->osel;
|
|
||||||
this->osel--;
|
|
||||||
for(s32 i = 0; i < this->opts.size(); i++)
|
|
||||||
{
|
|
||||||
if(i == this->osel) this->selfact = 0;
|
|
||||||
else if(i == this->prevosel) this->pselfact = 255;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if((k & KEY_DRIGHT) || (k & KEY_LSTICK_RIGHT) || (h & KEY_RSTICK_RIGHT))
|
|
||||||
{
|
|
||||||
if(this->osel < (this->opts.size() - 1))
|
|
||||||
{
|
|
||||||
this->prevosel = this->osel;
|
|
||||||
this->osel++;
|
|
||||||
for(s32 i = 0; i < this->opts.size(); i++)
|
|
||||||
{
|
|
||||||
if(i == this->osel) this->selfact = 0;
|
|
||||||
else if(i == this->prevosel) this->pselfact = 255;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(k & KEY_A)
|
|
||||||
{
|
|
||||||
this->cancel = false;
|
|
||||||
end = true;
|
|
||||||
}
|
|
||||||
else if(k & KEY_B)
|
|
||||||
{
|
|
||||||
this->cancel = true;
|
|
||||||
end = true;
|
|
||||||
}
|
|
||||||
else if(hidKeysDown(CONTROLLER_HANDHELD) & KEY_TOUCH)
|
|
||||||
{
|
|
||||||
touchPosition tch;
|
|
||||||
hidTouchRead(&tch, 0);
|
|
||||||
for(s32 i = 0; i < this->opts.size(); i++)
|
|
||||||
{
|
|
||||||
const std::string txt = this->sopts[i];
|
|
||||||
s32 rx = elx + ((elemw + 20) * i);
|
|
||||||
s32 ry = ely;
|
|
||||||
if(((rx + elemw) > tch.px) && (tch.px > rx) && ((ry + elemh) > tch.py) && (tch.py > ry))
|
|
||||||
{
|
|
||||||
this->osel = i;
|
|
||||||
this->cancel = false;
|
|
||||||
end = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s32 bw = dw;
|
|
||||||
s32 bh = dh;
|
|
||||||
s32 fw = bw - (r * 2);
|
|
||||||
s32 fh = bh - (r * 2);
|
|
||||||
Color clr = { 225, 225, 225, initfact };
|
|
||||||
s32 aclr = initfact;
|
|
||||||
if(aclr < 0) aclr = 0;
|
|
||||||
if(aclr > 125) aclr = 125;
|
|
||||||
Drawer->RenderRectangleFill({ 0, 0, 0, (u8)aclr }, 0, 0, 1280, 720);
|
|
||||||
Drawer->RenderRoundedRectangleFill(clr, dx, dy, bw, bh, r);
|
|
||||||
render::SetAlphaValue(this->title, initfact);
|
|
||||||
render::SetAlphaValue(this->cnt, initfact);
|
|
||||||
Drawer->RenderTexture(this->title, (dx + 45), (dy + 55));
|
|
||||||
Drawer->RenderTexture(this->cnt, (dx + 45), (dy + 140));
|
|
||||||
if(this->hicon)
|
|
||||||
{
|
|
||||||
s32 icw = render::GetTextureWidth(this->icon);
|
|
||||||
s32 icx = dx + (dw - (icw + icm));
|
|
||||||
s32 icy = dy + icm;
|
|
||||||
Drawer->RenderTexture(this->icon, icx, icy, { initfact, -1, -1, -1.0f });
|
|
||||||
}
|
|
||||||
for(s32 i = 0; i < this->opts.size(); i++)
|
|
||||||
{
|
|
||||||
const std::string txt = this->sopts[i];
|
|
||||||
auto [tw,th] = render::GetTextureSize(this->opts[i]);
|
|
||||||
s32 tx = elx + ((elemw - tw) / 2) + ((elemw + 20) * i);
|
|
||||||
s32 ty = ely + ((elemh - th) / 2);
|
|
||||||
s32 rx = elx + ((elemw + 20) * i);
|
|
||||||
s32 ry = ely;
|
|
||||||
s32 rr = (elemh / 2);
|
|
||||||
Color dclr = { nr, ng, nb, initfact };
|
|
||||||
if(this->osel == i)
|
|
||||||
{
|
|
||||||
if(this->selfact < 255)
|
|
||||||
{
|
|
||||||
dclr = { nr, ng, nb, this->selfact };
|
|
||||||
Drawer->RenderRoundedRectangleFill(dclr, rx, ry, elemw, elemh, rr);
|
|
||||||
this->selfact += 48;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dclr = { nr, ng, nb, initfact };
|
|
||||||
Drawer->RenderRoundedRectangleFill(dclr, rx, ry, elemw, elemh, rr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(this->prevosel == i)
|
|
||||||
{
|
|
||||||
if(this->pselfact > 0)
|
|
||||||
{
|
|
||||||
dclr = { nr, ng, nb, this->pselfact };
|
|
||||||
Drawer->RenderRoundedRectangleFill(dclr, rx, ry, elemw, elemh, rr);
|
|
||||||
this->pselfact -= 48;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
render::SetAlphaValue(this->opts[i], initfact);
|
|
||||||
Drawer->RenderTexture(this->opts[i], tx, ty);
|
|
||||||
}
|
|
||||||
if(end)
|
|
||||||
{
|
|
||||||
if(initfact == 0) return false;
|
|
||||||
if(initfact > 0) initfact -= 25;
|
|
||||||
if(initfact < 0) initfact = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(initfact < 255) initfact += 25;
|
|
||||||
if(initfact > 255) initfact = 255;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
if(!ok)
|
|
||||||
{
|
|
||||||
((Application*)App)->CallForRenderWithRenderOver([&](render::Renderer::Ref &Drawer) -> bool {});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this->osel;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Dialog::UserCancelled()
|
|
||||||
{
|
|
||||||
return this->cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Dialog::IsOk()
|
|
||||||
{
|
|
||||||
bool ok = true;
|
|
||||||
if(this->cancel) ok = false;
|
|
||||||
if(this->hcancel && (this->osel == (this->opts.size() - 1))) ok = false;
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,96 +0,0 @@
|
|||||||
#include <pu/ui/ui_Layout.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui
|
|
||||||
{
|
|
||||||
Layout::Layout() : Container(0, 0, 1280, 720)
|
|
||||||
{
|
|
||||||
this->onipt = [&](u64,u64,u64,Touch){};
|
|
||||||
this->hasimage = false;
|
|
||||||
this->overbgtex = NULL;
|
|
||||||
this->overbgcolor = Color(225, 225, 225, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
Layout::~Layout()
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->overbgtex);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Layout::HasChilds()
|
|
||||||
{
|
|
||||||
return !this->elms.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Layout::SetOnInput(std::function<void(u64 Down, u64 Up, u64 Held, Touch Pos)> Callback)
|
|
||||||
{
|
|
||||||
this->onipt = Callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::function<void(u64 Down, u64 Up, u64 Held, Touch Pos)> Layout::GetOnInput()
|
|
||||||
{
|
|
||||||
return this->onipt;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Layout::AddThread(std::function<void()> Callback)
|
|
||||||
{
|
|
||||||
this->thds.push_back(Callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::function<void()>> Layout::GetAllThreads()
|
|
||||||
{
|
|
||||||
return this->thds;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Layout::SetBackgroundImage(const std::string& Path)
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->overbgtex);
|
|
||||||
this->hasimage = true;
|
|
||||||
this->overbgtex = render::LoadImage(Path);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Layout::SetBackgroundJpegImage(void* JpegBuffer, s32 size)
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->overbgtex);
|
|
||||||
this->hasimage = true;
|
|
||||||
this->overbgtex = render::LoadJpegImage(JpegBuffer, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Layout::SetBackgroundRgbImage(void* RgbBuffer, u64 width, u64 height, u8 depth) {
|
|
||||||
render::DeleteTexture(this->overbgtex);
|
|
||||||
this->hasimage = true;
|
|
||||||
this->overbgtex = render::LoadRgbImage(RgbBuffer, width, height, depth);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Layout::SetBackgroundColor(Color Color)
|
|
||||||
{
|
|
||||||
render::DeleteTexture(this->overbgtex);
|
|
||||||
this->hasimage = false;
|
|
||||||
this->overbgcolor = Color;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Layout::SimulateTouch(Touch Custom)
|
|
||||||
{
|
|
||||||
this->simtouch = Custom;
|
|
||||||
}
|
|
||||||
|
|
||||||
Touch Layout::GetSimulatedTouch()
|
|
||||||
{
|
|
||||||
Touch simcpy = this->simtouch;
|
|
||||||
this->simtouch = Touch::Empty;
|
|
||||||
return simcpy; // Getting simulated touch resets it
|
|
||||||
}
|
|
||||||
|
|
||||||
render::NativeTexture Layout::GetBackgroundImageTexture()
|
|
||||||
{
|
|
||||||
return this->overbgtex;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color Layout::GetBackgroundColor()
|
|
||||||
{
|
|
||||||
return this->overbgcolor;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Layout::HasBackgroundImage()
|
|
||||||
{
|
|
||||||
return this->hasimage;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
#include <pu/ui/ui_Overlay.hpp>
|
|
||||||
#include <pu/ui/ui_Application.hpp>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
namespace pu::ui
|
|
||||||
{
|
|
||||||
Overlay::Overlay(s32 X, s32 Y, s32 Width, s32 Height, Color Background, bool Rounded) : Container(X, Y, Width, Height)
|
|
||||||
{
|
|
||||||
this->bg = Background;
|
|
||||||
this->round = Rounded;
|
|
||||||
this->rad = 25;
|
|
||||||
this->fadea = 0;
|
|
||||||
this->end = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Overlay::SetRadius(s32 Radius)
|
|
||||||
{
|
|
||||||
this->rad = Radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 Overlay::GetRadius()
|
|
||||||
{
|
|
||||||
return this->rad;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Overlay::OnPreRender(render::Renderer::Ref &Drawer)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Overlay::OnPostRender(render::Renderer::Ref &Drawer)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Overlay::Render(render::Renderer::Ref &Drawer)
|
|
||||||
{
|
|
||||||
this->OnPreRender(Drawer);
|
|
||||||
Drawer->SetBaseRenderAlpha(this->fadea);
|
|
||||||
if(this->round) Drawer->RenderRoundedRectangleFill(this->bg, this->x, this->y, this->w, this->h, this->rad);
|
|
||||||
else Drawer->RenderRectangleFill(this->bg, this->x, this->y, this->w, this->h);
|
|
||||||
this->PreRender();
|
|
||||||
for(auto &elm: this->elms)
|
|
||||||
{
|
|
||||||
if(elm->IsVisible()) elm->OnRender(Drawer, elm->GetProcessedX(), elm->GetProcessedY());
|
|
||||||
}
|
|
||||||
Drawer->UnsetBaseRenderAlpha();
|
|
||||||
if(this->end)
|
|
||||||
{
|
|
||||||
if(this->fadea > 0) this->fadea -= 25;
|
|
||||||
else this->fadea = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(this->fadea < 200) this->fadea += 25;
|
|
||||||
if(this->fadea > 200) this->fadea = 200;
|
|
||||||
}
|
|
||||||
this->OnPostRender(Drawer);
|
|
||||||
bool fin = (this->end && (this->fadea == 0));
|
|
||||||
if(fin)
|
|
||||||
{
|
|
||||||
this->end = false;
|
|
||||||
}
|
|
||||||
return !fin;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Overlay::NotifyEnding(bool End)
|
|
||||||
{
|
|
||||||
this->end = End;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
#include <pu/ui/ui_Types.hpp>
|
|
||||||
|
|
||||||
namespace pu::ui
|
|
||||||
{
|
|
||||||
Color::Color()
|
|
||||||
{
|
|
||||||
this->R = 0;
|
|
||||||
this->G = 0;
|
|
||||||
this->B = 0;
|
|
||||||
this->A = 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color::Color(u8 R, u8 G, u8 B, u8 A)
|
|
||||||
{
|
|
||||||
this->R = R;
|
|
||||||
this->G = G;
|
|
||||||
this->B = B;
|
|
||||||
this->A = A;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color Color::FromHex(const std::string& HexFmt)
|
|
||||||
{
|
|
||||||
Color clr;
|
|
||||||
std::string r = "00";
|
|
||||||
std::string g = "00";
|
|
||||||
std::string b = "00";
|
|
||||||
std::string a = "FF";
|
|
||||||
if(HexFmt.length() >= 9) a = HexFmt.substr(7, 2);
|
|
||||||
if(HexFmt.length() >= 7)
|
|
||||||
{
|
|
||||||
r = HexFmt.substr(1, 2);
|
|
||||||
g = HexFmt.substr(3, 2);
|
|
||||||
b = HexFmt.substr(5, 2);
|
|
||||||
}
|
|
||||||
clr.R = (u8)std::stoul(r, NULL, 16);
|
|
||||||
clr.G = (u8)std::stoul(g, NULL, 16);
|
|
||||||
clr.B = (u8)std::stoul(b, NULL, 16);
|
|
||||||
clr.A = (u8)std::stoul(a, NULL, 16);
|
|
||||||
return clr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Touch::IsEmpty()
|
|
||||||
{
|
|
||||||
return (this->X < 0) && (this->Y < 0);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
# Plutonium - an easy-to-use UI framework for Nintendo Switch homebrew
|
|
||||||
|
|
||||||
## What is Plutonium?
|
|
||||||
|
|
||||||
Plutonium is a high-level, C++ graphical library with the aim of making UIs in a more user-firendly way.
|
|
||||||
|
|
||||||
It uses libnx and SDL2, so both libraries are required.
|
|
||||||
|
|
||||||
To be more exact, this libraries should be installed via pacman:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
pacman -S switch-sdl2 switch-sdl2_ttf switch-sdl2_image switch-sdl2_gfx switch-sdl2_mixer switch-mesa switch-glad switch-glm switch-libdrm_nouveau switch-libwebp switch-libpng switch-freetype switch-bzip2 switch-libjpeg-turbo switch-opusfile switch-libopus
|
|
||||||
```
|
|
||||||
|
|
||||||
## Internal structure and performance
|
|
||||||
|
|
||||||
Plutonium uses SDL2 for UI rendering.
|
|
||||||
|
|
||||||
Plutonium's performance is based on WPF's system. The user doesn't directly interact with the rendering, as it's done via a main rendering system and different objects to render.
|
|
||||||
|
|
||||||
Same way WPF does, you can create an UI by making a custom Application class inheriting from `pu::Application` class, or simply creating a variable and adding elements to it.
|
|
||||||
|
|
||||||
The main function to initialize the application is `Show()`.
|
|
||||||
|
|
||||||
Check the [examples](Examples) for a basic usage of the libraries. In case you want to see a really powerful app which really shows what Plutonium is capable of, take a look at [Goldleaf](https://github.com/XorTroll/Goldleaf).
|
|
||||||
|
|
||||||
Check the [documentation](https://XorTroll.github.io/Plutonium/) for a more detailed explanation of the library's usage.
|
|
||||||
|
|
||||||
## Using this libraries
|
|
||||||
|
|
||||||
On the [releases](https://github.com/XorTroll/Plutonium/releases) page you have all the released versions. All of them are zipped files, containing `include` and `lib` directories.
|
|
||||||
|
|
||||||
### Simple project layout
|
|
||||||
|
|
||||||
This is how a regular Plutonium project would (more or less) have its Makefile and project layout using Plutonium:
|
|
||||||
|
|
||||||
- Makefile
|
|
||||||
|
|
||||||
```Makefile
|
|
||||||
...
|
|
||||||
|
|
||||||
LIBS := -lpu -lfreetype -lSDL2_mixer -lopusfile -lopus -lmodplug -lmpg123 -lvorbisidec -logg -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lSDL2 -lEGL -lGLESv2 -lglapi -ldrm_nouveau -lwebp -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lnx
|
|
||||||
LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/Plutonium
|
|
||||||
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
- Project directory
|
|
||||||
|
|
||||||
```txt
|
|
||||||
Project
|
|
||||||
|
|
|
||||||
|-- Makefile
|
|
||||||
|-- source
|
|
||||||
|-- include
|
|
||||||
|-- Plutonium
|
|
||||||
|
|
|
||||||
|-- include
|
|
||||||
|-- lib
|
|
||||||
```
|
|
||||||
|
|
||||||
## Building
|
|
||||||
|
|
||||||
Clone the repository, cd into `Plutonium` directory and run `make`.
|
|
||||||
|
|
||||||
You will need devkitPro, libnx and all the libraries mentioned above installed via pacman.
|
|
||||||
|
|
||||||
## Support
|
|
||||||
|
|
||||||
If you would like to be more informed about my projects' status and support, you should check [H&H](https://discord.gg/3KpFyaH), my Discord server. It's a simple server for Homebrew and Hacking, focused on my projects. If you would like to be a beta-tester, you might be interested on the nightly building system we have there for testers.
|
|
||||||
|
|
||||||
If you like my work, you should take a look at my [Patreon](https://patreon.com/xortroll) page. For those who support me, you will be credited on my projects, and you'll gain some nice extras on H&H!
|
|
@ -1,5 +0,0 @@
|
|||||||
# Plutonium API documentation
|
|
||||||
|
|
||||||
- Welcome to Plutonium library's documentation! You can browse the API's documentation here.
|
|
||||||
|
|
||||||
- More stuff will be added soon, like more info here, function and class descriptions...
|
|
@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
#include <switch/types.h>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "nx/ncm.hpp"
|
|
||||||
#include "nx/nca_writer.h"
|
|
||||||
|
|
||||||
namespace tin::data
|
|
||||||
{
|
|
||||||
static const size_t BUFFER_SEGMENT_DATA_SIZE = 0x800000; // Approximately 8MB
|
|
||||||
extern int NUM_BUFFER_SEGMENTS;
|
|
||||||
|
|
||||||
struct BufferSegment
|
|
||||||
{
|
|
||||||
std::atomic_bool isFinalized = false;
|
|
||||||
u64 writeOffset = 0;
|
|
||||||
u8 data[BUFFER_SEGMENT_DATA_SIZE] = {0};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Receives data in a circular buffer split into 8MB segments
|
|
||||||
class BufferedPlaceholderWriter
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
size_t m_totalDataSize = 0;
|
|
||||||
size_t m_sizeBuffered = 0;
|
|
||||||
size_t m_sizeWrittenToPlaceholder = 0;
|
|
||||||
|
|
||||||
// The current segment to which further data will be appended
|
|
||||||
u64 m_currentFreeSegment = 0;
|
|
||||||
BufferSegment* m_currentFreeSegmentPtr = NULL;
|
|
||||||
// The current segment that will be written to the placeholder
|
|
||||||
u64 m_currentSegmentToWrite = 0;
|
|
||||||
BufferSegment* m_currentSegmentToWritePtr = NULL;
|
|
||||||
|
|
||||||
std::unique_ptr<BufferSegment[]> m_bufferSegments;
|
|
||||||
|
|
||||||
std::shared_ptr<nx::ncm::ContentStorage> m_contentStorage;
|
|
||||||
NcmContentId m_ncaId;
|
|
||||||
NcaWriter m_writer;
|
|
||||||
|
|
||||||
public:
|
|
||||||
BufferedPlaceholderWriter(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId ncaId, size_t totalDataSize);
|
|
||||||
|
|
||||||
void AppendData(void* source, size_t length);
|
|
||||||
bool CanAppendData(size_t length);
|
|
||||||
|
|
||||||
void WriteSegmentToPlaceholder();
|
|
||||||
bool CanWriteSegmentToPlaceholder();
|
|
||||||
|
|
||||||
// Determine the number of segments required to fit data of this size
|
|
||||||
u32 CalcNumSegmentsRequired(size_t size);
|
|
||||||
|
|
||||||
// Check if there are enough free segments to fit data of this size
|
|
||||||
bool IsSizeAvailable(size_t size);
|
|
||||||
|
|
||||||
bool IsBufferDataComplete();
|
|
||||||
bool IsPlaceholderComplete();
|
|
||||||
|
|
||||||
size_t GetTotalDataSize();
|
|
||||||
size_t GetSizeBuffered();
|
|
||||||
size_t GetSizeWrittenToPlaceholder();
|
|
||||||
|
|
||||||
void DebugPrintBuffers();
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <switch/types.h>
|
|
||||||
#include <cstring>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace tin::data
|
|
||||||
{
|
|
||||||
class ByteBuffer
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
std::vector<u8> m_buffer;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ByteBuffer(size_t reserveSize=0);
|
|
||||||
|
|
||||||
size_t GetSize();
|
|
||||||
u8* GetData(); // TODO: Remove this, it shouldn't be needed
|
|
||||||
void Resize(size_t size);
|
|
||||||
|
|
||||||
void DebugPrintContents();
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T Read(u64 offset)
|
|
||||||
{
|
|
||||||
if (offset + sizeof(T) <= m_buffer.size())
|
|
||||||
return *((T*)&m_buffer.data()[offset]);
|
|
||||||
|
|
||||||
T def;
|
|
||||||
memset(&def, 0, sizeof(T));
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void Write(T data, u64 offset)
|
|
||||||
{
|
|
||||||
size_t requiredSize = offset + sizeof(T);
|
|
||||||
|
|
||||||
if (requiredSize > m_buffer.size())
|
|
||||||
m_buffer.resize(requiredSize, 0);
|
|
||||||
|
|
||||||
memcpy(m_buffer.data() + offset, &data, sizeof(T));
|
|
||||||
}
|
|
||||||
template <typename T>
|
|
||||||
void Append(T data)
|
|
||||||
{
|
|
||||||
this->Write(data, this->GetSize());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <switch/types.h>
|
|
||||||
#include "data/byte_buffer.hpp"
|
|
||||||
|
|
||||||
namespace tin::data
|
|
||||||
{
|
|
||||||
class ByteStream
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
u64 m_offset = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual void ReadBytes(void* dest, size_t length) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
// NOTE: This isn't generally useful, it's mainly for things like libpng
|
|
||||||
// which rely on streams
|
|
||||||
class BufferedByteStream : public ByteStream
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
ByteBuffer m_byteBuffer;
|
|
||||||
|
|
||||||
public:
|
|
||||||
BufferedByteStream(ByteBuffer buffer);
|
|
||||||
|
|
||||||
void ReadBytes(void* dest, size_t length) override;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <switch/types.h>
|
|
||||||
|
|
||||||
#define MAGIC_HFS0 0x30534648
|
|
||||||
|
|
||||||
namespace tin::install
|
|
||||||
{
|
|
||||||
struct HFS0FileEntry
|
|
||||||
{
|
|
||||||
u64 dataOffset;
|
|
||||||
u64 fileSize;
|
|
||||||
u32 stringTableOffset;
|
|
||||||
u32 hashedSize;
|
|
||||||
u64 padding;
|
|
||||||
unsigned char hash[0x20];
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
static_assert(sizeof(HFS0FileEntry) == 0x40, "HFS0FileEntry must be 0x18");
|
|
||||||
|
|
||||||
struct HFS0BaseHeader
|
|
||||||
{
|
|
||||||
u32 magic;
|
|
||||||
u32 numFiles;
|
|
||||||
u32 stringTableSize;
|
|
||||||
u32 reserved;
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
static_assert(sizeof(HFS0BaseHeader) == 0x10, "HFS0BaseHeader must be 0x10");
|
|
||||||
|
|
||||||
NX_INLINE const HFS0FileEntry *hfs0GetFileEntry(const HFS0BaseHeader *header, u32 i)
|
|
||||||
{
|
|
||||||
if (i >= header->numFiles)
|
|
||||||
return NULL;
|
|
||||||
return (const HFS0FileEntry*)(header + 0x1 + i * 0x4);
|
|
||||||
}
|
|
||||||
|
|
||||||
NX_INLINE const char *hfs0GetStringTable(const HFS0BaseHeader *header)
|
|
||||||
{
|
|
||||||
return (const char*)(header + 0x1 + header->numFiles * 0x4);
|
|
||||||
}
|
|
||||||
|
|
||||||
NX_INLINE u64 hfs0GetHeaderSize(const HFS0BaseHeader *header)
|
|
||||||
{
|
|
||||||
return 0x1 + header->numFiles * 0x4 + header->stringTableSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
NX_INLINE const char *hfs0GetFileName(const HFS0BaseHeader *header, u32 i)
|
|
||||||
{
|
|
||||||
return hfs0GetStringTable(header) + hfs0GetFileEntry(header, i)->stringTableOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
NX_INLINE const char *hfs0GetFileName(const HFS0BaseHeader *header, const HFS0FileEntry *entry)
|
|
||||||
{
|
|
||||||
return hfs0GetStringTable(header) + entry->stringTableOffset;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "install/nsp.hpp"
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace tin::install::nsp
|
|
||||||
{
|
|
||||||
class HTTPNSP : public NSP
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
tin::network::HTTPDownload m_download;
|
|
||||||
|
|
||||||
HTTPNSP(std::string url);
|
|
||||||
|
|
||||||
virtual void StreamToPlaceholder(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId placeholderId) override;
|
|
||||||
virtual void BufferData(void* buf, off_t offset, size_t size) override;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "install/xci.hpp"
|
|
||||||
#include "util/network_util.hpp"
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace tin::install::xci
|
|
||||||
{
|
|
||||||
class HTTPXCI : public XCI
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
tin::network::HTTPDownload m_download;
|
|
||||||
|
|
||||||
HTTPXCI(std::string url);
|
|
||||||
|
|
||||||
virtual void StreamToPlaceholder(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId placeholderId) override;
|
|
||||||
virtual void BufferData(void* buf, off_t offset, size_t size) override;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#include <switch/services/fs.h>
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <tuple>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "install/simple_filesystem.hpp"
|
|
||||||
#include "data/byte_buffer.hpp"
|
|
||||||
|
|
||||||
#include "nx/content_meta.hpp"
|
|
||||||
#include "nx/ipc/tin_ipc.h"
|
|
||||||
|
|
||||||
namespace tin::install
|
|
||||||
{
|
|
||||||
class Install
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
const NcmStorageId m_destStorageId;
|
|
||||||
bool m_ignoreReqFirmVersion = false;
|
|
||||||
bool m_declinedValidation = false;
|
|
||||||
|
|
||||||
std::vector<nx::ncm::ContentMeta> m_contentMeta;
|
|
||||||
|
|
||||||
Install(NcmStorageId destStorageId, bool ignoreReqFirmVersion);
|
|
||||||
|
|
||||||
virtual std::vector<std::tuple<nx::ncm::ContentMeta, NcmContentInfo>> ReadCNMT() = 0;
|
|
||||||
|
|
||||||
virtual void InstallContentMetaRecords(tin::data::ByteBuffer& installContentMetaBuf, int i);
|
|
||||||
virtual void InstallApplicationRecord(int i);
|
|
||||||
virtual void InstallTicketCert() = 0;
|
|
||||||
virtual void InstallNCA(const NcmContentId &ncaId) = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual ~Install();
|
|
||||||
|
|
||||||
virtual void Prepare();
|
|
||||||
virtual void Begin();
|
|
||||||
|
|
||||||
virtual u64 GetTitleId(int i = 0);
|
|
||||||
virtual NcmContentMetaType GetContentMetaType(int i = 0);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <switch.h>
|
|
||||||
#include <string>
|
|
||||||
#include "install/install.hpp"
|
|
||||||
#include "install/nsp.hpp"
|
|
||||||
|
|
||||||
namespace tin::install::nsp
|
|
||||||
{
|
|
||||||
class NSPInstall : public Install
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
const std::shared_ptr<NSP> m_NSP;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::vector<std::tuple<nx::ncm::ContentMeta, NcmContentInfo>> ReadCNMT() override;
|
|
||||||
void InstallNCA(const NcmContentId& ncaId) override;
|
|
||||||
void InstallTicketCert() override;
|
|
||||||
|
|
||||||
public:
|
|
||||||
NSPInstall(NcmStorageId destStorageId, bool ignoreReqFirmVersion, const std::shared_ptr<NSP>& remoteNSP);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <switch.h>
|
|
||||||
#include "install/install.hpp"
|
|
||||||
#include "install/xci.hpp"
|
|
||||||
#include "nx/content_meta.hpp"
|
|
||||||
#include "nx/ipc/tin_ipc.h"
|
|
||||||
|
|
||||||
namespace tin::install::xci
|
|
||||||
{
|
|
||||||
class XCIInstallTask : public Install
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
const std::shared_ptr<tin::install::xci::XCI> m_xci;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::vector<std::tuple<nx::ncm::ContentMeta, NcmContentInfo>> ReadCNMT() override;
|
|
||||||
void InstallNCA(const NcmContentId& ncaId) override;
|
|
||||||
void InstallTicketCert() override;
|
|
||||||
|
|
||||||
public:
|
|
||||||
XCIInstallTask(NcmStorageId destStorageId, bool ignoreReqFirmVersion, const std::shared_ptr<XCI>& xci);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
@ -1,77 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <switch.h>
|
|
||||||
|
|
||||||
#define NCA_HEADER_SIZE 0x4000
|
|
||||||
#define MAGIC_NCA3 0x3341434E /* "NCA3" */
|
|
||||||
namespace tin::install
|
|
||||||
{
|
|
||||||
struct NcaFsHeader
|
|
||||||
{
|
|
||||||
u8 _0x0;
|
|
||||||
u8 _0x1;
|
|
||||||
u8 partition_type;
|
|
||||||
u8 fs_type;
|
|
||||||
u8 crypt_type;
|
|
||||||
u8 _0x5[0x3];
|
|
||||||
u8 superblock_data[0x138];
|
|
||||||
/*union {
|
|
||||||
pfs0_superblock_t pfs0_superblock;
|
|
||||||
romfs_superblock_t romfs_superblock;
|
|
||||||
//nca0_romfs_superblock_t nca0_romfs_superblock;
|
|
||||||
bktr_superblock_t bktr_superblock;
|
|
||||||
};*/
|
|
||||||
union {
|
|
||||||
u64 section_ctr;
|
|
||||||
struct {
|
|
||||||
u32 section_ctr_low;
|
|
||||||
u32 section_ctr_high;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
u8 _0x148[0xB8]; /* Padding. */
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
static_assert(sizeof(NcaFsHeader) == 0x200, "NcaFsHeader must be 0x200");
|
|
||||||
|
|
||||||
struct NcaSectionEntry
|
|
||||||
{
|
|
||||||
u32 media_start_offset;
|
|
||||||
u32 media_end_offset;
|
|
||||||
u8 _0x8[0x8]; /* Padding. */
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
static_assert(sizeof(NcaSectionEntry) == 0x10, "NcaSectionEntry must be 0x10");
|
|
||||||
|
|
||||||
struct NcaHeader
|
|
||||||
{
|
|
||||||
u8 fixed_key_sig[0x100]; /* RSA-PSS signature over header with fixed key. */
|
|
||||||
u8 npdm_key_sig[0x100]; /* RSA-PSS signature over header with key in NPDM. */
|
|
||||||
u32 magic;
|
|
||||||
u8 distribution; /* System vs gamecard. */
|
|
||||||
u8 content_type;
|
|
||||||
u8 m_cryptoType; /* Which keyblob (field 1) */
|
|
||||||
u8 m_kaekIndex; /* Which kaek index? */
|
|
||||||
u64 nca_size; /* Entire archive size. */
|
|
||||||
u64 m_titleId;
|
|
||||||
u8 _0x218[0x4]; /* Padding. */
|
|
||||||
union {
|
|
||||||
uint32_t sdk_version; /* What SDK was this built with? */
|
|
||||||
struct {
|
|
||||||
u8 sdk_revision;
|
|
||||||
u8 sdk_micro;
|
|
||||||
u8 sdk_minor;
|
|
||||||
u8 sdk_major;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
u8 m_cryptoType2; /* Which keyblob (field 2) */
|
|
||||||
u8 _0x221[0xF]; /* Padding. */
|
|
||||||
u64 m_rightsId[2]; /* Rights ID (for titlekey crypto). */
|
|
||||||
NcaSectionEntry section_entries[4]; /* Section entry metadata. */
|
|
||||||
u8 section_hashes[4 * 0x20]; /* SHA-256 hashes for each section header. */
|
|
||||||
u8 m_keys[4 * 0x10]; /* Encrypted key area. */
|
|
||||||
u8 _0x340[0xC0]; /* Padding. */
|
|
||||||
NcaFsHeader fs_headers[4]; /* FS section headers. */
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
static_assert(sizeof(NcaHeader) == 0xc00, "NcaHeader must be 0xc00");
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <switch/types.h>
|
|
||||||
#include "install/pfs0.hpp"
|
|
||||||
#include "nx/ncm.hpp"
|
|
||||||
#include "util/network_util.hpp"
|
|
||||||
|
|
||||||
namespace tin::install::nsp
|
|
||||||
{
|
|
||||||
class NSP
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
std::vector<u8> m_headerBytes;
|
|
||||||
|
|
||||||
NSP();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual void StreamToPlaceholder(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId placeholderId) = 0;
|
|
||||||
virtual void BufferData(void* buf, off_t offset, size_t size) = 0;
|
|
||||||
|
|
||||||
virtual void RetrieveHeader();
|
|
||||||
virtual const PFS0BaseHeader* GetBaseHeader();
|
|
||||||
virtual u64 GetDataOffset();
|
|
||||||
|
|
||||||
virtual const PFS0FileEntry* GetFileEntry(unsigned int index);
|
|
||||||
virtual const PFS0FileEntry* GetFileEntryByName(std::string name);
|
|
||||||
virtual const PFS0FileEntry* GetFileEntryByNcaId(const NcmContentId& ncaId);
|
|
||||||
virtual std::vector<const PFS0FileEntry*> GetFileEntriesByExtension(std::string extension);
|
|
||||||
|
|
||||||
virtual const char* GetFileEntryName(const PFS0FileEntry* fileEntry);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <switch/types.h>
|
|
||||||
|
|
||||||
namespace tin::install
|
|
||||||
{
|
|
||||||
struct PFS0FileEntry
|
|
||||||
{
|
|
||||||
u64 dataOffset;
|
|
||||||
u64 fileSize;
|
|
||||||
u32 stringTableOffset;
|
|
||||||
u32 padding;
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
static_assert(sizeof(PFS0FileEntry) == 0x18, "PFS0FileEntry must be 0x18");
|
|
||||||
|
|
||||||
struct PFS0BaseHeader
|
|
||||||
{
|
|
||||||
u32 magic;
|
|
||||||
u32 numFiles;
|
|
||||||
u32 stringTableSize;
|
|
||||||
u32 reserved;
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
static_assert(sizeof(PFS0BaseHeader) == 0x10, "PFS0BaseHeader must be 0x10");
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "install/nsp.hpp"
|
|
||||||
|
|
||||||
namespace tin::install::nsp
|
|
||||||
{
|
|
||||||
class SDMCNSP : public NSP
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SDMCNSP(std::string path);
|
|
||||||
~SDMCNSP();
|
|
||||||
|
|
||||||
virtual void StreamToPlaceholder(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId ncaId) override;
|
|
||||||
virtual void BufferData(void* buf, off_t offset, size_t size) override;
|
|
||||||
private:
|
|
||||||
FILE* m_nspFile;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "install/xci.hpp"
|
|
||||||
|
|
||||||
namespace tin::install::xci
|
|
||||||
{
|
|
||||||
class SDMCXCI : public XCI
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SDMCXCI(std::string path);
|
|
||||||
~SDMCXCI();
|
|
||||||
|
|
||||||
virtual void StreamToPlaceholder(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId ncaId) override;
|
|
||||||
virtual void BufferData(void* buf, off_t offset, size_t size) override;
|
|
||||||
private:
|
|
||||||
FILE* m_xciFile;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include "nx/fs.hpp"
|
|
||||||
|
|
||||||
namespace tin::install::nsp
|
|
||||||
{
|
|
||||||
class SimpleFileSystem final
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
nx::fs::IFileSystem* m_fileSystem;
|
|
||||||
|
|
||||||
public:
|
|
||||||
const std::string m_rootPath;
|
|
||||||
const std::string m_absoluteRootPath;
|
|
||||||
|
|
||||||
SimpleFileSystem(nx::fs::IFileSystem& fileSystem, std::string rootPath, std::string absoluteRootPath);
|
|
||||||
~SimpleFileSystem();
|
|
||||||
|
|
||||||
nx::fs::IFile OpenFile(std::string path);
|
|
||||||
bool HasFile(std::string path);
|
|
||||||
std::string GetFileNameFromExtension(std::string path, std::string extension);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "install/nsp.hpp"
|
|
||||||
|
|
||||||
namespace tin::install::nsp
|
|
||||||
{
|
|
||||||
class USBNSP : public NSP
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
std::string m_nspName;
|
|
||||||
|
|
||||||
public:
|
|
||||||
USBNSP(std::string nspName);
|
|
||||||
|
|
||||||
virtual void StreamToPlaceholder(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId placeholderId) override;
|
|
||||||
virtual void BufferData(void* buf, off_t offset, size_t size) override;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "install/xci.hpp"
|
|
||||||
|
|
||||||
namespace tin::install::xci
|
|
||||||
{
|
|
||||||
class USBXCI : public XCI
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
std::string m_xciName;
|
|
||||||
|
|
||||||
public:
|
|
||||||
USBXCI(std::string xciName);
|
|
||||||
|
|
||||||
virtual void StreamToPlaceholder(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId placeholderId) override;
|
|
||||||
virtual void BufferData(void* buf, off_t offset, size_t size) override;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <switch/types.h>
|
|
||||||
#include "install/hfs0.hpp"
|
|
||||||
#include "nx/ncm.hpp"
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace tin::install::xci
|
|
||||||
{
|
|
||||||
class XCI
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
u64 m_secureHeaderOffset;
|
|
||||||
std::vector<u8> m_secureHeaderBytes;
|
|
||||||
|
|
||||||
XCI();
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual void StreamToPlaceholder(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId placeholderId) = 0;
|
|
||||||
virtual void BufferData(void* buf, off_t offset, size_t size) = 0;
|
|
||||||
|
|
||||||
virtual void RetrieveHeader();
|
|
||||||
virtual const HFS0BaseHeader* GetSecureHeader();
|
|
||||||
virtual u64 GetDataOffset();
|
|
||||||
|
|
||||||
virtual const HFS0FileEntry* GetFileEntry(unsigned int index);
|
|
||||||
virtual const HFS0FileEntry* GetFileEntryByName(std::string name);
|
|
||||||
virtual const HFS0FileEntry* GetFileEntryByNcaId(const NcmContentId& ncaId);
|
|
||||||
virtual std::vector<const HFS0FileEntry*> GetFileEntriesByExtension(std::string extension);
|
|
||||||
|
|
||||||
virtual const char* GetFileEntryName(const HFS0FileEntry* fileEntry);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace netInstStuff {
|
|
||||||
void installTitleNet(std::vector<std::string> ourUrlList, int ourStorage, std::vector<std::string> urlListAltNames, std::string ourSource);
|
|
||||||
std::vector<std::string> OnSelected();
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <switch/services/ncm.h>
|
|
||||||
#include <switch/types.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "data/byte_buffer.hpp"
|
|
||||||
|
|
||||||
namespace nx::ncm
|
|
||||||
{
|
|
||||||
struct PackagedContentInfo
|
|
||||||
{
|
|
||||||
u8 hash[0x20];
|
|
||||||
NcmContentInfo content_info;
|
|
||||||
} PACKED;
|
|
||||||
|
|
||||||
struct PackagedContentMetaHeader
|
|
||||||
{
|
|
||||||
u64 title_id;
|
|
||||||
u32 version;
|
|
||||||
u8 type;
|
|
||||||
u8 _0xd;
|
|
||||||
u16 extended_header_size;
|
|
||||||
u16 content_count;
|
|
||||||
u16 content_meta_count;
|
|
||||||
u8 attributes;
|
|
||||||
u8 storage_id;
|
|
||||||
u8 install_type;
|
|
||||||
bool comitted;
|
|
||||||
u32 required_system_version;
|
|
||||||
u32 _0x1c;
|
|
||||||
};
|
|
||||||
|
|
||||||
static_assert(sizeof(PackagedContentMetaHeader) == 0x20, "PackagedContentMetaHeader must be 0x20!");
|
|
||||||
|
|
||||||
class ContentMeta final
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
tin::data::ByteBuffer m_bytes;
|
|
||||||
|
|
||||||
public:
|
|
||||||
ContentMeta();
|
|
||||||
ContentMeta(u8* data, size_t size);
|
|
||||||
|
|
||||||
PackagedContentMetaHeader GetPackagedContentMetaHeader();
|
|
||||||
NcmContentMetaKey GetContentMetaKey();
|
|
||||||
std::vector<NcmContentInfo> GetContentInfos();
|
|
||||||
|
|
||||||
void GetInstallContentMeta(tin::data::ByteBuffer& installContentMetaBuffer, NcmContentInfo& cnmtContentInfo, bool ignoreReqFirmVersion);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#include <switch/types.h>
|
|
||||||
#include <switch/services/fs.h>
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "nx/ipc/tin_ipc.h"
|
|
||||||
|
|
||||||
namespace nx::fs
|
|
||||||
{
|
|
||||||
class IFileSystem;
|
|
||||||
|
|
||||||
class IFile
|
|
||||||
{
|
|
||||||
friend IFileSystem;
|
|
||||||
|
|
||||||
private:
|
|
||||||
FsFile m_file;
|
|
||||||
|
|
||||||
IFile(FsFile& file);
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Don't allow copying, or garbage may be closed by the destructor
|
|
||||||
IFile& operator=(const IFile&) = delete;
|
|
||||||
IFile(const IFile&) = delete;
|
|
||||||
|
|
||||||
~IFile();
|
|
||||||
|
|
||||||
void Read(u64 offset, void* buf, size_t size);
|
|
||||||
s64 GetSize();
|
|
||||||
};
|
|
||||||
|
|
||||||
class IDirectory
|
|
||||||
{
|
|
||||||
friend IFileSystem;
|
|
||||||
|
|
||||||
private:
|
|
||||||
FsDir m_dir;
|
|
||||||
|
|
||||||
IDirectory(FsDir& dir);
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Don't allow copying, or garbage may be closed by the destructor
|
|
||||||
IDirectory& operator=(const IDirectory&) = delete;
|
|
||||||
IDirectory(const IDirectory&) = delete;
|
|
||||||
|
|
||||||
~IDirectory();
|
|
||||||
|
|
||||||
void Read(s64 inval, FsDirectoryEntry* buf, size_t numEntries);
|
|
||||||
u64 GetEntryCount();
|
|
||||||
};
|
|
||||||
|
|
||||||
class IFileSystem
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
FsFileSystem m_fileSystem;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Don't allow copying, or garbage may be closed by the destructor
|
|
||||||
IFileSystem& operator=(const IFileSystem&) = delete;
|
|
||||||
IFileSystem(const IFileSystem&) = delete;
|
|
||||||
|
|
||||||
IFileSystem();
|
|
||||||
~IFileSystem();
|
|
||||||
|
|
||||||
Result OpenSdFileSystem();
|
|
||||||
void OpenFileSystemWithId(std::string path, FsFileSystemType fileSystemType, u64 titleId);
|
|
||||||
void CloseFileSystem();
|
|
||||||
|
|
||||||
IFile OpenFile(std::string path);
|
|
||||||
IDirectory OpenDirectory(std::string path, int flags);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <switch/services/ncm.h>
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
u8 c[0x10];
|
|
||||||
} RightsId;
|
|
||||||
|
|
||||||
Result esInitialize();
|
|
||||||
void esExit();
|
|
||||||
Service* esGetServiceSession();
|
|
||||||
|
|
||||||
Result esImportTicket(void const *tikBuf, size_t tikSize, void const *certBuf, size_t certSize); //1
|
|
||||||
Result esDeleteTicket(const RightsId *rightsIdBuf, size_t bufSize); //3
|
|
||||||
Result esGetTitleKey(const RightsId *rightsId, u8 *outBuf, size_t bufSize); //8
|
|
||||||
Result esCountCommonTicket(u32 *numTickets); //9
|
|
||||||
Result esCountPersonalizedTicket(u32 *numTickets); // 10
|
|
||||||
Result esListCommonTicket(u32 *numRightsIdsWritten, RightsId *outBuf, size_t bufSize);
|
|
||||||
Result esListPersonalizedTicket(u32 *numRightsIdsWritten, RightsId *outBuf, size_t bufSize);
|
|
||||||
Result esGetCommonTicketData(u64 *unkOut, void *outBuf1, size_t bufSize1, const RightsId* rightsId);
|
|
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <switch/services/ns.h>
|
|
||||||
#include <switch/services/ncm.h>
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
u64 titleID;
|
|
||||||
u64 unk;
|
|
||||||
u64 size;
|
|
||||||
} PACKED ApplicationRecord;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
NcmContentMetaKey metaRecord;
|
|
||||||
u64 storageId;
|
|
||||||
} PACKED ContentStorageRecord;
|
|
||||||
|
|
||||||
Result nsextInitialize(void);
|
|
||||||
void nsextExit(void);
|
|
||||||
|
|
||||||
Result nsPushApplicationRecord(u64 title_id, u8 last_modified_event, ContentStorageRecord *content_records_buf, size_t buf_size);
|
|
||||||
Result nsListApplicationRecordContentMeta(u64 offset, u64 titleID, void *out_buf, size_t out_buf_size, u32 *entries_read_out);
|
|
||||||
Result nsDeleteApplicationRecord(u64 titleID);
|
|
||||||
Result nsLaunchApplication(u64 titleID);
|
|
||||||
Result nsPushLaunchVersion(u64 titleID, u32 version);
|
|
||||||
Result nsDisableApplicationAutoUpdate(u64 titleID);
|
|
||||||
Result nsGetContentMetaStorage(const NcmContentMetaKey *record, u8 *out);
|
|
||||||
Result nsBeginInstallApplication(u64 tid, u32 unk, u8 storageId);
|
|
||||||
Result nsInvalidateAllApplicationControlCache(void);
|
|
||||||
Result nsInvalidateApplicationControlCache(u64 tid);
|
|
||||||
Result nsCheckApplicationLaunchRights(u64 tid);
|
|
||||||
Result nsGetApplicationContentPath(u64 titleId, u8 type, char *outBuf, size_t bufSize);
|
|
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "nx/ipc/es.h"
|
|
||||||
#include "nx/ipc/ns_ext.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <switch.h>
|
|
||||||
#include <vector>
|
|
||||||
#include "nx/ncm.hpp"
|
|
||||||
#include <memory>
|
|
||||||
#include "install/nca.hpp"
|
|
||||||
|
|
||||||
class NcaBodyWriter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
NcaBodyWriter(const NcmContentId& ncaId, u64 offset, std::shared_ptr<nx::ncm::ContentStorage>& contentStorage);
|
|
||||||
virtual ~NcaBodyWriter();
|
|
||||||
virtual u64 write(const u8* ptr, u64 sz);
|
|
||||||
|
|
||||||
bool isOpen() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::shared_ptr<nx::ncm::ContentStorage> m_contentStorage;
|
|
||||||
NcmContentId m_ncaId;
|
|
||||||
|
|
||||||
u64 m_offset;
|
|
||||||
};
|
|
||||||
|
|
||||||
class NcaWriter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
NcaWriter(const NcmContentId& ncaId, std::shared_ptr<nx::ncm::ContentStorage>& contentStorage);
|
|
||||||
virtual ~NcaWriter();
|
|
||||||
|
|
||||||
bool isOpen() const;
|
|
||||||
bool close();
|
|
||||||
u64 write(const u8* ptr, u64 sz);
|
|
||||||
void flushHeader();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
NcmContentId m_ncaId;
|
|
||||||
std::shared_ptr<nx::ncm::ContentStorage> m_contentStorage;
|
|
||||||
std::vector<u8> m_buffer;
|
|
||||||
std::shared_ptr<NcaBodyWriter> m_writer;
|
|
||||||
};
|
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#include <switch/services/fs.h>
|
|
||||||
#include <switch/services/ncm.h>
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "nx/ipc/tin_ipc.h"
|
|
||||||
|
|
||||||
namespace nx::ncm
|
|
||||||
{
|
|
||||||
class ContentStorage final
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
NcmContentStorage m_contentStorage;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Don't allow copying, or garbage may be closed by the destructor
|
|
||||||
ContentStorage& operator=(const ContentStorage&) = delete;
|
|
||||||
ContentStorage(const ContentStorage&) = delete;
|
|
||||||
|
|
||||||
ContentStorage(NcmStorageId storageId);
|
|
||||||
~ContentStorage();
|
|
||||||
|
|
||||||
void CreatePlaceholder(const NcmContentId &placeholderId, const NcmPlaceHolderId ®isteredId, size_t size);
|
|
||||||
void DeletePlaceholder(const NcmPlaceHolderId &placeholderId);
|
|
||||||
void WritePlaceholder(const NcmPlaceHolderId &placeholderId, u64 offset, void *buffer, size_t bufSize);
|
|
||||||
void Register(const NcmPlaceHolderId &placeholderId, const NcmContentId ®isteredId);
|
|
||||||
void Delete(const NcmContentId ®isteredId);
|
|
||||||
bool Has(const NcmContentId ®isteredId);
|
|
||||||
std::string GetPath(const NcmContentId ®isteredId);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,81 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
Microsoft Public License (Ms-PL)
|
|
||||||
|
|
||||||
This license governs use of the accompanying software. If you use the
|
|
||||||
software, you accept this license. If you do not accept the license,
|
|
||||||
do not use the software.
|
|
||||||
|
|
||||||
1. Definitions
|
|
||||||
|
|
||||||
The terms "reproduce," "reproduction," "derivative works," and
|
|
||||||
"distribution" have the same meaning here as under U.S. copyright
|
|
||||||
law.
|
|
||||||
|
|
||||||
A "contribution" is the original software, or any additions or
|
|
||||||
changes to the software.
|
|
||||||
|
|
||||||
A "contributor" is any person that distributes its contribution
|
|
||||||
under this license.
|
|
||||||
|
|
||||||
"Licensed patents" are a contributor's patent claims that read
|
|
||||||
directly on its contribution.
|
|
||||||
|
|
||||||
2. Grant of Rights
|
|
||||||
|
|
||||||
(A) Copyright Grant- Subject to the terms of this license,
|
|
||||||
including the license conditions and limitations in section 3,
|
|
||||||
each contributor grants you a non-exclusive, worldwide,
|
|
||||||
royalty-free copyright license to reproduce its contribution,
|
|
||||||
prepare derivative works of its contribution, and distribute its
|
|
||||||
contribution or any derivative works that you create.
|
|
||||||
|
|
||||||
(B) Patent Grant- Subject to the terms of this license, including
|
|
||||||
the license conditions and limitations in section 3, each
|
|
||||||
contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
license under its licensed patents to make, have made, use, sell,
|
|
||||||
offer for sale, import, and/or otherwise dispose of its
|
|
||||||
contribution in the software or derivative works of the
|
|
||||||
contribution in the software.
|
|
||||||
|
|
||||||
3. Conditions and Limitations
|
|
||||||
|
|
||||||
(A) No Trademark License- This license does not grant you rights
|
|
||||||
to use any contributors' name, logo, or trademarks.
|
|
||||||
|
|
||||||
(B) If you bring a patent claim against any contributor over
|
|
||||||
patents that you claim are infringed by the software, your patent
|
|
||||||
license from such contributor to the software ends automatically.
|
|
||||||
|
|
||||||
(C) If you distribute any portion of the software, you must retain
|
|
||||||
all copyright, patent, trademark, and attribution notices that are
|
|
||||||
present in the software.
|
|
||||||
|
|
||||||
(D) If you distribute any portion of the software in source code
|
|
||||||
form, you may do so only under this license by including a
|
|
||||||
complete copy of this license with your distribution. If you
|
|
||||||
distribute any portion of the software in compiled or object code
|
|
||||||
form, you may only do so under a license that complies with this
|
|
||||||
license.
|
|
||||||
|
|
||||||
(E) You may not distribute, copy, use, or link any portion of this
|
|
||||||
code to any other code that requires distribution of source code.
|
|
||||||
|
|
||||||
(F) The software is licensed "as-is." You bear the risk of using
|
|
||||||
it. The contributors give no express warranties, guarantees, or
|
|
||||||
conditions. You may have additional consumer rights under your
|
|
||||||
local laws which this license cannot change. To the extent
|
|
||||||
permitted under your local laws, the contributors exclude the
|
|
||||||
implied warranties of merchantability, fitness for a particular
|
|
||||||
purpose and non-infringement.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace nx::hdd
|
|
||||||
{
|
|
||||||
const char* rootPath(u32 index = 0);
|
|
||||||
u32 count();
|
|
||||||
|
|
||||||
bool init();
|
|
||||||
bool exit();
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <filesystem>
|
|
||||||
#include <vector>
|
|
||||||
namespace nspInstStuff {
|
|
||||||
void installNspFromFile(std::vector<std::filesystem::path> ourNspList, int whereToInstall);
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
namespace sig {
|
|
||||||
void installSigPatches ();
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <filesystem>
|
|
||||||
#include <pu/Plutonium>
|
|
||||||
|
|
||||||
using namespace pu::ui::elm;
|
|
||||||
namespace inst::ui {
|
|
||||||
class HDInstPage : public pu::ui::Layout
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
HDInstPage();
|
|
||||||
PU_SMART_CTOR(HDInstPage)
|
|
||||||
pu::ui::elm::Menu::Ref menu;
|
|
||||||
void startInstall();
|
|
||||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
|
|
||||||
TextBlock::Ref pageInfoText;
|
|
||||||
void drawMenuItems(bool clearItems, std::filesystem::path ourPath);
|
|
||||||
private:
|
|
||||||
std::vector<std::filesystem::path> ourDirectories;
|
|
||||||
std::vector<std::filesystem::path> ourFiles;
|
|
||||||
std::vector<std::filesystem::path> selectedTitles;
|
|
||||||
std::filesystem::path currentDir;
|
|
||||||
TextBlock::Ref butText;
|
|
||||||
Rectangle::Ref topRect;
|
|
||||||
Rectangle::Ref infoRect;
|
|
||||||
Rectangle::Ref botRect;
|
|
||||||
Image::Ref titleImage;
|
|
||||||
TextBlock::Ref appVersionText;
|
|
||||||
void followDirectory();
|
|
||||||
void selectNsp(int selectedIndex);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <pu/Plutonium>
|
|
||||||
#include "ui/mainPage.hpp"
|
|
||||||
#include "ui/netInstPage.hpp"
|
|
||||||
#include "ui/sdInstPage.hpp"
|
|
||||||
#include "ui/HDInstPage.hpp"
|
|
||||||
#include "ui/usbInstPage.hpp"
|
|
||||||
#include "ui/instPage.hpp"
|
|
||||||
#include "ui/optionsPage.hpp"
|
|
||||||
|
|
||||||
namespace inst::ui {
|
|
||||||
class MainApplication : public pu::ui::Application {
|
|
||||||
public:
|
|
||||||
using Application::Application;
|
|
||||||
PU_SMART_CTOR(MainApplication)
|
|
||||||
void OnLoad() override;
|
|
||||||
MainPage::Ref mainPage;
|
|
||||||
netInstPage::Ref netinstPage;
|
|
||||||
sdInstPage::Ref sdinstPage;
|
|
||||||
HDInstPage::Ref HDinstPage;
|
|
||||||
usbInstPage::Ref usbinstPage;
|
|
||||||
instPage::Ref instpage;
|
|
||||||
optionsPage::Ref optionspage;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <pu/Plutonium>
|
|
||||||
|
|
||||||
using namespace pu::ui::elm;
|
|
||||||
namespace inst::ui {
|
|
||||||
class instPage : public pu::ui::Layout
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
instPage();
|
|
||||||
PU_SMART_CTOR(instPage)
|
|
||||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
|
|
||||||
TextBlock::Ref pageInfoText;
|
|
||||||
TextBlock::Ref installInfoText;
|
|
||||||
Image::Ref awooImage;
|
|
||||||
pu::ui::elm::ProgressBar::Ref installBar;
|
|
||||||
static void setTopInstInfoText(std::string ourText);
|
|
||||||
static void setInstInfoText(std::string ourText);
|
|
||||||
static void setInstBarPerc(double ourPercent);
|
|
||||||
static void loadMainMenu();
|
|
||||||
static void loadInstallScreen();
|
|
||||||
private:
|
|
||||||
Rectangle::Ref infoRect;
|
|
||||||
Rectangle::Ref topRect;
|
|
||||||
Image::Ref titleImage;
|
|
||||||
TextBlock::Ref appVersionText;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <pu/Plutonium>
|
|
||||||
|
|
||||||
using namespace pu::ui::elm;
|
|
||||||
namespace inst::ui {
|
|
||||||
class MainPage : public pu::ui::Layout
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MainPage();
|
|
||||||
PU_SMART_CTOR(MainPage)
|
|
||||||
void installMenuItem_Click();
|
|
||||||
void netInstallMenuItem_Click();
|
|
||||||
void usbInstallMenuItem_Click();
|
|
||||||
void sigPatchesMenuItem_Click();
|
|
||||||
void settingsMenuItem_Click();
|
|
||||||
void exitMenuItem_Click();
|
|
||||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
|
|
||||||
Image::Ref awooImage;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool appletFinished;
|
|
||||||
bool updateFinished;
|
|
||||||
TextBlock::Ref butText;
|
|
||||||
Rectangle::Ref topRect;
|
|
||||||
Rectangle::Ref botRect;
|
|
||||||
Image::Ref titleImage;
|
|
||||||
TextBlock::Ref appVersionText;
|
|
||||||
pu::ui::elm::Menu::Ref optionMenu;
|
|
||||||
pu::ui::elm::MenuItem::Ref installMenuItem;
|
|
||||||
pu::ui::elm::MenuItem::Ref netInstallMenuItem;
|
|
||||||
pu::ui::elm::MenuItem::Ref usbInstallMenuItem;
|
|
||||||
pu::ui::elm::MenuItem::Ref sigPatchesMenuItem;
|
|
||||||
pu::ui::elm::MenuItem::Ref settingsMenuItem;
|
|
||||||
pu::ui::elm::MenuItem::Ref exitMenuItem;
|
|
||||||
Image::Ref eggImage;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <pu/Plutonium>
|
|
||||||
|
|
||||||
using namespace pu::ui::elm;
|
|
||||||
namespace inst::ui {
|
|
||||||
class netInstPage : public pu::ui::Layout
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
netInstPage();
|
|
||||||
PU_SMART_CTOR(netInstPage)
|
|
||||||
void startInstall(bool urlMode);
|
|
||||||
void startNetwork();
|
|
||||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
|
|
||||||
TextBlock::Ref pageInfoText;
|
|
||||||
private:
|
|
||||||
std::vector<std::string> ourUrls;
|
|
||||||
std::vector<std::string> selectedUrls;
|
|
||||||
std::vector<std::string> alternativeNames;
|
|
||||||
TextBlock::Ref butText;
|
|
||||||
Rectangle::Ref topRect;
|
|
||||||
Rectangle::Ref infoRect;
|
|
||||||
Rectangle::Ref botRect;
|
|
||||||
Image::Ref titleImage;
|
|
||||||
TextBlock::Ref appVersionText;
|
|
||||||
pu::ui::elm::Menu::Ref menu;
|
|
||||||
Image::Ref infoImage;
|
|
||||||
void drawMenuItems(bool clearItems);
|
|
||||||
void selectTitle(int selectedIndex);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <pu/Plutonium>
|
|
||||||
|
|
||||||
using namespace pu::ui::elm;
|
|
||||||
namespace inst::ui {
|
|
||||||
class optionsPage : public pu::ui::Layout
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
optionsPage();
|
|
||||||
PU_SMART_CTOR(optionsPage)
|
|
||||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
|
|
||||||
static void askToUpdate(std::vector<std::string> updateInfo);
|
|
||||||
private:
|
|
||||||
TextBlock::Ref butText;
|
|
||||||
Rectangle::Ref topRect;
|
|
||||||
Rectangle::Ref infoRect;
|
|
||||||
Rectangle::Ref botRect;
|
|
||||||
Image::Ref titleImage;
|
|
||||||
TextBlock::Ref appVersionText;
|
|
||||||
TextBlock::Ref pageInfoText;
|
|
||||||
pu::ui::elm::Menu::Ref menu;
|
|
||||||
void setMenuText();
|
|
||||||
std::string getMenuOptionIcon(bool ourBool);
|
|
||||||
std::string getMenuLanguage(int ourLangCode);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <filesystem>
|
|
||||||
#include <pu/Plutonium>
|
|
||||||
|
|
||||||
using namespace pu::ui::elm;
|
|
||||||
namespace inst::ui {
|
|
||||||
class sdInstPage : public pu::ui::Layout
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
sdInstPage();
|
|
||||||
PU_SMART_CTOR(sdInstPage)
|
|
||||||
pu::ui::elm::Menu::Ref menu;
|
|
||||||
void startInstall();
|
|
||||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
|
|
||||||
TextBlock::Ref pageInfoText;
|
|
||||||
void drawMenuItems(bool clearItems, std::filesystem::path ourPath);
|
|
||||||
private:
|
|
||||||
std::vector<std::filesystem::path> ourDirectories;
|
|
||||||
std::vector<std::filesystem::path> ourFiles;
|
|
||||||
std::vector<std::filesystem::path> selectedTitles;
|
|
||||||
std::filesystem::path currentDir;
|
|
||||||
TextBlock::Ref butText;
|
|
||||||
Rectangle::Ref topRect;
|
|
||||||
Rectangle::Ref infoRect;
|
|
||||||
Rectangle::Ref botRect;
|
|
||||||
Image::Ref titleImage;
|
|
||||||
TextBlock::Ref appVersionText;
|
|
||||||
void followDirectory();
|
|
||||||
void selectNsp(int selectedIndex);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <pu/Plutonium>
|
|
||||||
|
|
||||||
using namespace pu::ui::elm;
|
|
||||||
namespace inst::ui {
|
|
||||||
class usbInstPage : public pu::ui::Layout
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
usbInstPage();
|
|
||||||
PU_SMART_CTOR(usbInstPage)
|
|
||||||
void startInstall();
|
|
||||||
void startUsb();
|
|
||||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
|
|
||||||
TextBlock::Ref pageInfoText;
|
|
||||||
private:
|
|
||||||
std::vector<std::string> ourTitles;
|
|
||||||
std::vector<std::string> selectedTitles;
|
|
||||||
std::string lastUrl;
|
|
||||||
std::string lastFileID;
|
|
||||||
TextBlock::Ref butText;
|
|
||||||
Rectangle::Ref topRect;
|
|
||||||
Rectangle::Ref infoRect;
|
|
||||||
Rectangle::Ref botRect;
|
|
||||||
Image::Ref titleImage;
|
|
||||||
TextBlock::Ref appVersionText;
|
|
||||||
pu::ui::elm::Menu::Ref menu;
|
|
||||||
Image::Ref infoImage;
|
|
||||||
void drawMenuItems(bool clearItems);
|
|
||||||
void selectTitle(int selectedIndex);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace usbInstStuff {
|
|
||||||
std::vector<std::string> OnSelected();
|
|
||||||
void installTitleUsb(std::vector<std::string> ourNspList, int ourStorage);
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace inst::config {
|
|
||||||
static const std::string appDir = "sdmc:/switch/tinwoo";
|
|
||||||
static const std::string configPath = appDir + "/config.json";
|
|
||||||
static const std::string appVersion = "1.0.4";
|
|
||||||
|
|
||||||
extern std::string gAuthKey;
|
|
||||||
extern std::string sigPatchesUrl;
|
|
||||||
extern std::vector<std::string> updateInfo;
|
|
||||||
extern int languageSetting;
|
|
||||||
extern bool ignoreReqVers;
|
|
||||||
extern bool validateNCAs;
|
|
||||||
extern bool overClock;
|
|
||||||
extern bool deletePrompt;
|
|
||||||
extern bool autoUpdate;
|
|
||||||
extern bool usbAck;
|
|
||||||
extern bool gayMode;
|
|
||||||
extern bool useSound;
|
|
||||||
|
|
||||||
void setConfig();
|
|
||||||
void parseConfig();
|
|
||||||
}
|
|
@ -1,154 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <switch.h>
|
|
||||||
|
|
||||||
namespace Crypto
|
|
||||||
{
|
|
||||||
#define RSA_2048_BYTES 0x100
|
|
||||||
#define RSA_2048_BITS (RSA_2048_BYTES*8)
|
|
||||||
static const unsigned char NCAHeaderSignature[0x100] = { /* Fixed RSA key used to validate NCA signature 0. */
|
|
||||||
0xBF, 0xBE, 0x40, 0x6C, 0xF4, 0xA7, 0x80, 0xE9, 0xF0, 0x7D, 0x0C, 0x99, 0x61, 0x1D, 0x77, 0x2F,
|
|
||||||
0x96, 0xBC, 0x4B, 0x9E, 0x58, 0x38, 0x1B, 0x03, 0xAB, 0xB1, 0x75, 0x49, 0x9F, 0x2B, 0x4D, 0x58,
|
|
||||||
0x34, 0xB0, 0x05, 0xA3, 0x75, 0x22, 0xBE, 0x1A, 0x3F, 0x03, 0x73, 0xAC, 0x70, 0x68, 0xD1, 0x16,
|
|
||||||
0xB9, 0x04, 0x46, 0x5E, 0xB7, 0x07, 0x91, 0x2F, 0x07, 0x8B, 0x26, 0xDE, 0xF6, 0x00, 0x07, 0xB2,
|
|
||||||
0xB4, 0x51, 0xF8, 0x0D, 0x0A, 0x5E, 0x58, 0xAD, 0xEB, 0xBC, 0x9A, 0xD6, 0x49, 0xB9, 0x64, 0xEF,
|
|
||||||
0xA7, 0x82, 0xB5, 0xCF, 0x6D, 0x70, 0x13, 0xB0, 0x0F, 0x85, 0xF6, 0xA9, 0x08, 0xAA, 0x4D, 0x67,
|
|
||||||
0x66, 0x87, 0xFA, 0x89, 0xFF, 0x75, 0x90, 0x18, 0x1E, 0x6B, 0x3D, 0xE9, 0x8A, 0x68, 0xC9, 0x26,
|
|
||||||
0x04, 0xD9, 0x80, 0xCE, 0x3F, 0x5E, 0x92, 0xCE, 0x01, 0xFF, 0x06, 0x3B, 0xF2, 0xC1, 0xA9, 0x0C,
|
|
||||||
0xCE, 0x02, 0x6F, 0x16, 0xBC, 0x92, 0x42, 0x0A, 0x41, 0x64, 0xCD, 0x52, 0xB6, 0x34, 0x4D, 0xAE,
|
|
||||||
0xC0, 0x2E, 0xDE, 0xA4, 0xDF, 0x27, 0x68, 0x3C, 0xC1, 0xA0, 0x60, 0xAD, 0x43, 0xF3, 0xFC, 0x86,
|
|
||||||
0xC1, 0x3E, 0x6C, 0x46, 0xF7, 0x7C, 0x29, 0x9F, 0xFA, 0xFD, 0xF0, 0xE3, 0xCE, 0x64, 0xE7, 0x35,
|
|
||||||
0xF2, 0xF6, 0x56, 0x56, 0x6F, 0x6D, 0xF1, 0xE2, 0x42, 0xB0, 0x83, 0x40, 0xA5, 0xC3, 0x20, 0x2B,
|
|
||||||
0xCC, 0x9A, 0xAE, 0xCA, 0xED, 0x4D, 0x70, 0x30, 0xA8, 0x70, 0x1C, 0x70, 0xFD, 0x13, 0x63, 0x29,
|
|
||||||
0x02, 0x79, 0xEA, 0xD2, 0xA7, 0xAF, 0x35, 0x28, 0x32, 0x1C, 0x7B, 0xE6, 0x2F, 0x1A, 0xAA, 0x40,
|
|
||||||
0x7E, 0x32, 0x8C, 0x27, 0x42, 0xFE, 0x82, 0x78, 0xEC, 0x0D, 0xEB, 0xE6, 0x83, 0x4B, 0x6D, 0x81,
|
|
||||||
0x04, 0x40, 0x1A, 0x9E, 0x9A, 0x67, 0xF6, 0x72, 0x29, 0xFA, 0x04, 0xF0, 0x9D, 0xE4, 0xF4, 0x03
|
|
||||||
};
|
|
||||||
|
|
||||||
class Keys
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Keys()
|
|
||||||
{
|
|
||||||
u8 kek[0x10] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
|
|
||||||
splCryptoGenerateAesKek(headerKekSource, 0, 0, kek);
|
|
||||||
splCryptoGenerateAesKey(kek, headerKeySource, headerKey);
|
|
||||||
splCryptoGenerateAesKey(kek, headerKeySource + 0x10, headerKey + 0x10);
|
|
||||||
}
|
|
||||||
|
|
||||||
u8 headerKekSource[0x10] = { 0x1F, 0x12, 0x91, 0x3A, 0x4A, 0xCB, 0xF0, 0x0D, 0x4C, 0xDE, 0x3A, 0xF6, 0xD5, 0x23, 0x88, 0x2A };
|
|
||||||
u8 headerKeySource[0x20] = { 0x5A, 0x3E, 0xD8, 0x4F, 0xDE, 0xC0, 0xD8, 0x26, 0x31, 0xF7, 0xE2, 0x5D, 0x19, 0x7B, 0xF5, 0xD0, 0x1C, 0x9B, 0x7B, 0xFA, 0xF6, 0x28, 0x18, 0x3D, 0x71, 0xF6, 0x4D, 0x73, 0xF1, 0x50, 0xB9, 0xD2 };
|
|
||||||
|
|
||||||
u8 headerKey[0x20] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
};
|
|
||||||
|
|
||||||
void calculateMGF1andXOR(unsigned char* data, size_t data_size, const void* source, size_t source_size);
|
|
||||||
bool rsa2048PssVerify(const void *data, size_t len, const unsigned char *signature, const unsigned char *modulus);
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
T swapEndian(T s)
|
|
||||||
{
|
|
||||||
T result;
|
|
||||||
u8* dest = (u8*)&result;
|
|
||||||
u8* src = (u8*)&s;
|
|
||||||
for (unsigned int i = 0; i < sizeof(s); i++)
|
|
||||||
{
|
|
||||||
dest[i] = src[sizeof(s) - i - 1];
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
class AesCtr
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AesCtr() : m_high(0), m_low(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
AesCtr(u64 iv) : m_high(swapEndian(iv)), m_low(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
u64& high() { return m_high; }
|
|
||||||
u64& low() { return m_low; }
|
|
||||||
private:
|
|
||||||
u64 m_high;
|
|
||||||
u64 m_low;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Aes128Ctr
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Aes128Ctr(const u8* key, const AesCtr& iv)
|
|
||||||
{
|
|
||||||
counter = iv;
|
|
||||||
aes128CtrContextCreate(&ctx, key, &iv);
|
|
||||||
seek(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~Aes128Ctr()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void seek(u64 offset)
|
|
||||||
{
|
|
||||||
counter.low() = swapEndian(offset >> 4);
|
|
||||||
aes128CtrContextResetCtr(&ctx, &counter);
|
|
||||||
}
|
|
||||||
|
|
||||||
void encrypt(void *dst, const void *src, size_t l)
|
|
||||||
{
|
|
||||||
aes128CtrCrypt(&ctx, dst, src, l);
|
|
||||||
}
|
|
||||||
|
|
||||||
void decrypt(void *dst, const void *src, size_t l)
|
|
||||||
{
|
|
||||||
encrypt(dst, src, l);
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
AesCtr counter;
|
|
||||||
|
|
||||||
Aes128CtrContext ctx;
|
|
||||||
};
|
|
||||||
|
|
||||||
class AesXtr
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AesXtr(const u8* key, bool is_encryptor)
|
|
||||||
{
|
|
||||||
aes128XtsContextCreate(&ctx, key, key + 0x10, is_encryptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~AesXtr()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void encrypt(void *dst, const void *src, size_t l, size_t sector, size_t sector_size)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < l; i += sector_size)
|
|
||||||
{
|
|
||||||
aes128XtsContextResetSector(&ctx, sector++, true);
|
|
||||||
aes128XtsEncrypt(&ctx, dst, src, sector_size);
|
|
||||||
|
|
||||||
dst = (u8*)dst + sector_size;
|
|
||||||
src = (const u8*)src + sector_size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void decrypt(void *dst, const void *src, size_t l, size_t sector, size_t sector_size)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < l; i += sector_size)
|
|
||||||
{
|
|
||||||
aes128XtsContextResetSector(&ctx, sector++, true);
|
|
||||||
aes128XtsDecrypt(&ctx, dst, src, sector_size);
|
|
||||||
|
|
||||||
dst = (u8*)dst + sector_size;
|
|
||||||
src = (const u8*)src + sector_size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
Aes128XtsContext ctx;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace inst::curl {
|
|
||||||
bool downloadFile(const std::string ourUrl, const char *pagefilename, long timeout = 5000, bool writeProgress = false);
|
|
||||||
std::string downloadToBuffer (const std::string ourUrl, int firstRange = -1, int secondRange = -1, long timeout = 5000);
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <switch/types.h>
|
|
||||||
|
|
||||||
void printBytes(u8 *bytes, size_t size, bool includeHeader);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "util/debug.h"
|
|
||||||
|
|
||||||
#define ASSERT_OK(rc_out, desc) if (R_FAILED(rc_out)) { char msg[256] = {0}; snprintf(msg, 256-1, "%s:%u: %s. Error code: 0x%08x\n", __func__, __LINE__, desc, rc_out); throw std::runtime_error(msg); }
|
|
||||||
#define THROW_FORMAT(format, ...) { char error_prefix[512] = {0}; snprintf(error_prefix, 256-1, "%s:%u: ", __func__, __LINE__);\
|
|
||||||
char formatted_msg[256] = {0}; snprintf(formatted_msg, 256-1, format, ##__VA_ARGS__);\
|
|
||||||
strncat(error_prefix, formatted_msg, 512-1); throw std::runtime_error(error_prefix); }
|
|
||||||
|
|
||||||
#ifdef NXLINK_DEBUG
|
|
||||||
#define LOG_DEBUG(format, ...) { printf("%s:%u: ", __func__, __LINE__); printf(format, ##__VA_ARGS__); }
|
|
||||||
#else
|
|
||||||
#define LOG_DEBUG(format, ...) ;
|
|
||||||
#endif
|
|
@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <tuple>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "nx/content_meta.hpp"
|
|
||||||
|
|
||||||
namespace tin::util
|
|
||||||
{
|
|
||||||
NcmContentInfo CreateNSPCNMTContentRecord(const std::string& nspPath);
|
|
||||||
nx::ncm::ContentMeta GetContentMetaFromNCA(const std::string& ncaPath);
|
|
||||||
std::vector<std::string> GetNSPList();
|
|
||||||
}
|
|
22875
include/util/json.hpp
22875
include/util/json.hpp
File diff suppressed because it is too large
Load Diff
@ -1,28 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
|
||||||
#include <fstream>
|
|
||||||
#include "json.hpp"
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
namespace Language {
|
|
||||||
void Load();
|
|
||||||
std::string LanguageEntry(std::string key);
|
|
||||||
std::string GetRandomMsg();
|
|
||||||
inline json GetRelativeJson(json j, std::string key) {
|
|
||||||
std::istringstream ss(key);
|
|
||||||
std::string token;
|
|
||||||
|
|
||||||
while (std::getline(ss, token, '.') && j != nullptr) {
|
|
||||||
j = j[token];
|
|
||||||
}
|
|
||||||
|
|
||||||
return j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string operator ""_lang (const char* key, size_t size) {
|
|
||||||
return Language::LanguageEntry(std::string(key, size));
|
|
||||||
}
|
|
@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <switch/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <sys/errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <map>
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace tin::network
|
|
||||||
{
|
|
||||||
class HTTPHeader
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
std::string m_url;
|
|
||||||
std::map<std::string, std::string> m_values;
|
|
||||||
|
|
||||||
static size_t ParseHTMLHeader(char* bytes, size_t size, size_t numItems, void* userData);
|
|
||||||
|
|
||||||
public:
|
|
||||||
HTTPHeader(std::string url);
|
|
||||||
|
|
||||||
void PerformRequest();
|
|
||||||
|
|
||||||
bool HasValue(std::string key);
|
|
||||||
std::string GetValue(std::string key);
|
|
||||||
};
|
|
||||||
|
|
||||||
class HTTPDownload
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
std::string m_url;
|
|
||||||
HTTPHeader m_header;
|
|
||||||
bool m_rangesSupported = false;
|
|
||||||
|
|
||||||
static size_t ParseHTMLData(char* bytes, size_t size, size_t numItems, void* userData);
|
|
||||||
|
|
||||||
public:
|
|
||||||
HTTPDownload(std::string url);
|
|
||||||
|
|
||||||
void BufferDataRange(void* buffer, size_t offset, size_t size, std::function<void (size_t sizeRead)> progressFunc);
|
|
||||||
int StreamDataRange(size_t offset, size_t size, std::function<size_t (u8* bytes, size_t size)> streamFunc);
|
|
||||||
};
|
|
||||||
|
|
||||||
size_t WaitReceiveNetworkData(int sockfd, void* buf, size_t len);
|
|
||||||
size_t WaitSendNetworkData(int sockfd, void* buf, size_t len);
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2017-2018 Adubbz
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <switch/types.h>
|
|
||||||
#include <string>
|
|
||||||
#include "nx/content_meta.hpp"
|
|
||||||
#include "nx/ipc/tin_ipc.h"
|
|
||||||
|
|
||||||
namespace tin::util
|
|
||||||
{
|
|
||||||
u64 GetRightsIdTid(RightsId rightsId);
|
|
||||||
u64 GetRightsIdKeyGen(RightsId rightsId);
|
|
||||||
|
|
||||||
std::string GetNcaIdString(const NcmContentId& ncaId);
|
|
||||||
NcmContentId GetNcaIdFromString(std::string ncaIdStr);
|
|
||||||
|
|
||||||
u64 GetBaseTitleId(u64 titleId, NcmContentMetaType contentMetaType);
|
|
||||||
std::string GetBaseTitleName(u64 baseTitleId);
|
|
||||||
std::string GetTitleName(u64 titleId, NcmContentMetaType contentMetaType);
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user