Initial commit

This commit is contained in:
Gericom
2025-11-22 17:21:45 +01:00
commit 5d6f67c612
517 changed files with 63025 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
#include "common.h"
#include "NotoSansJP-Regular-10_nft2.h"
#include "NotoSansJP-Medium-7_5_nft2.h"
#include "NotoSansJP-Medium-10_nft2.h"
#include "NotoSansJP-Medium-11_nft2.h"
#include "DefaultFontRepository.h"
const nft2_header_t* DefaultFontRepository::GetFont(FontType fontType) const
{
switch (fontType)
{
case FontType::Regular10:
{
return (const nft2_header_t*)NotoSansJP_Regular_10_nft2;
}
case FontType::Medium7_5:
{
return (const nft2_header_t*)NotoSansJP_Medium_7_5_nft2;
}
case FontType::Medium10:
{
return (const nft2_header_t*)NotoSansJP_Medium_10_nft2;
}
case FontType::Medium11:
{
return (const nft2_header_t*)NotoSansJP_Medium_11_nft2;
}
default:
{
return nullptr;
}
}
}

View File

@@ -0,0 +1,8 @@
#pragma once
#include "IFontRepository.h"
class DefaultFontRepository : public IFontRepository
{
public:
const nft2_header_t* GetFont(FontType fontType) const override;
};

View File

@@ -0,0 +1,9 @@
#pragma once
enum class FontType
{
Regular10,
Medium7_5,
Medium10,
Medium11
};

View File

@@ -0,0 +1,13 @@
#pragma once
#include "gui/font/nitroFont2.h"
#include "FontType.h"
class IFontRepository
{
public:
virtual ~IFontRepository() = 0;
virtual const nft2_header_t* GetFont(FontType fontType) const = 0;
};
inline IFontRepository::~IFontRepository() { }

View File

@@ -0,0 +1,32 @@
#pragma once
#include <memory>
#include "romBrowser/Theme/IThemeFileIconFactory.h"
#include "romBrowser/Theme/IRomBrowserViewFactory.h"
#include "IFontRepository.h"
#include "background/IThemeBackground.h"
#include "material/MaterialColorScheme.h"
#include "gui/font/nitroFont2.h"
#include "fat/File.h"
class VramContext;
class ITheme
{
public:
virtual ~ITheme() = 0;
virtual const IFontRepository* GetFontRepository() const = 0;
virtual const IThemeFileIconFactory* GetThemeFileIconFactory() const = 0;
virtual const IRomBrowserViewFactory* GetRomBrowserViewFactory() const = 0;
virtual std::unique_ptr<IThemeBackground> CreateRomBrowserTopBackground() const = 0;
virtual std::unique_ptr<IThemeBackground> CreateRomBrowserBottomBackground() const = 0;
virtual void LoadRomBrowserResources(const VramContext& mainVramContext, const VramContext& subVramContext) = 0;
virtual bool OpenThemeFile(File& file, const TCHAR* subPath) const = 0;
virtual const MaterialColorScheme& GetMaterialColorScheme() const = 0;
};
inline ITheme::~ITheme() { }

View File

@@ -0,0 +1,17 @@
#include "common.h"
#include "core/mini-printf.h"
#include "material/MaterialColorSchemeFactory.h"
#include "Theme.h"
Theme::Theme(const TCHAR* folderName, const Rgb<8, 8, 8>& primaryColor, bool darkMode)
: _folderName(folderName)
{
MaterialColorSchemeFactory::FromPrimaryColor(primaryColor, darkMode, _materialColorScheme);
}
bool Theme::OpenThemeFile(File& file, const TCHAR* subPath) const
{
TCHAR pathBuffer[128];
mini_snprintf(pathBuffer, sizeof(pathBuffer), "/_pico/themes/%s/%s", _folderName.GetString(), subPath);
return file.Open(pathBuffer, FA_OPEN_EXISTING | FA_READ) == FR_OK;
}

View File

@@ -0,0 +1,20 @@
#pragma once
#include "fat/ff.h"
#include "core/String.h"
#include "ITheme.h"
class Theme : public ITheme
{
public:
bool OpenThemeFile(File& file, const TCHAR* subPath) const override;
void LoadRomBrowserResources(const VramContext& mainVramContext, const VramContext& subVramContext) override { };
const MaterialColorScheme& GetMaterialColorScheme() const override { return _materialColorScheme; }
protected:
Theme(const TCHAR* folderName, const Rgb<8, 8, 8>& primaryColor, bool darkMode);
MaterialColorScheme _materialColorScheme;
private:
String<TCHAR, 64> _folderName;
};

View File

@@ -0,0 +1,29 @@
#include "common.h"
#include "material/MaterialTheme.h"
#include "custom/CustomTheme.h"
#include "ThemeFactory.h"
std::unique_ptr<ITheme> ThemeFactory::CreateFromThemeInfo(const ThemeInfo* themeInfo) const
{
switch (themeInfo->GetType())
{
case ThemeType::Material:
{
return std::make_unique<MaterialTheme>(
themeInfo->GetFolderName(),
themeInfo->GetPrimaryColor(),
themeInfo->GetIsDarkTheme());
}
case ThemeType::Custom:
{
return std::make_unique<CustomTheme>(
themeInfo->GetFolderName(),
themeInfo->GetPrimaryColor(),
themeInfo->GetIsDarkTheme());
}
default:
{
return nullptr;
}
}
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include <memory>
#include "ITheme.h"
#include "ThemeInfo.h"
#include "services/settings/IAppSettingsService.h"
class ThemeFactory
{
public:
std::unique_ptr<ITheme> CreateFromThemeInfo(const ThemeInfo* themeInfo) const;
};

View File

@@ -0,0 +1,38 @@
#pragma once
#include "common.h"
#include "ThemeType.h"
#include "core/String.h"
#include "core/math/Rgb.h"
class ThemeInfo
{
String<TCHAR, 64> _folderName;
ThemeType _type;
String<char16_t, 64> _name;
String<char16_t, 128> _description;
String<char16_t, 64> _author;
Rgb<8, 8, 8> _primaryColor;
bool _darkTheme;
public:
ThemeInfo(const TCHAR* folderName, ThemeType type, const char* name,
const char* description, const char* author, const Rgb<8, 8, 8>& primaryColor,
bool darkTheme)
: _folderName(folderName), _type(type), _name(name)
, _description(description), _author(author), _primaryColor(primaryColor)
, _darkTheme(darkTheme) { }
ThemeInfo(const TCHAR* folderName, ThemeType type, const char16_t* name,
const char16_t* description, const char16_t* author, const Rgb<8, 8, 8>& primaryColor,
bool darkTheme)
: _folderName(folderName), _type(type), _name(name)
, _description(description), _author(author), _primaryColor(primaryColor)
, _darkTheme(darkTheme) { }
constexpr const TCHAR* GetFolderName() const { return _folderName; }
constexpr ThemeType GetType() const { return _type; }
constexpr const char16_t* GetName() const { return _name; }
constexpr const char16_t* GetDescription() const { return _description; }
constexpr const char16_t* GetAuthor() const { return _author; }
constexpr const Rgb<8, 8, 8>& GetPrimaryColor() const { return _primaryColor; }
constexpr bool GetIsDarkTheme() const { return _darkTheme; }
};

View File

@@ -0,0 +1,14 @@
#pragma once
#include <memory>
#include "ThemeInfo.h"
class ThemeInfoFactory
{
public:
std::unique_ptr<ThemeInfo> CreateFromThemeFolder(const TCHAR* folderName) const;
std::unique_ptr<ThemeInfo> CreateFallbackTheme() const
{
return std::make_unique<ThemeInfo>("", ThemeType::Material, "Fallback", "", "", Rgb<8,8,8>(138, 217, 255), false);
}
};

View File

@@ -0,0 +1,104 @@
#include "common.h"
#include "common.h"
#include <memory>
#include "fat/File.h"
#include "json/ArduinoJson.h"
#include "core/mini-printf.h"
#include "core/math/Rgb.h"
#include "ThemeInfoFactory.h"
#pragma GCC optimize("Os")
#define JSON_RESERVED_SIZE 2048
#define KEY_TYPE "type"
#define KEY_NAME "name"
#define KEY_DESCRIPTION "description"
#define KEY_AUTHOR "author"
#define KEY_PRIMARY_COLOR "primaryColor"
#define KEY_COLOR_R "r"
#define KEY_COLOR_G "g"
#define KEY_COLOR_B "b"
#define KEY_DARK_THEME "darkTheme"
static bool tryParseThemeType(const char* themeTypeString, ThemeType& themeType)
{
if (!themeTypeString)
return false;
if (!strcasecmp(themeTypeString, "Material"))
themeType = ThemeType::Material;
else if (!strcasecmp(themeTypeString, "Custom"))
themeType = ThemeType::Custom;
else
return false;
return true;
}
static Rgb<8, 8, 8> parseColor(const JsonObjectConst& json, const Rgb<8, 8, 8>& defaultColor)
{
if (json.isNull())
{
return defaultColor;
}
return Rgb<8, 8, 8>(
json[KEY_COLOR_R] | 0,
json[KEY_COLOR_G] | 0,
json[KEY_COLOR_B] | 0
);
}
static std::unique_ptr<ThemeInfo> fromJson(const TCHAR* folderName, const JsonDocument& json)
{
ThemeType themeType;
if (!tryParseThemeType(json[KEY_TYPE].as<const char*>(), themeType))
{
themeType = ThemeType::Custom;
}
return std::make_unique<ThemeInfo>(
folderName,
themeType,
json[KEY_NAME] | "",
json[KEY_DESCRIPTION] | "",
json[KEY_AUTHOR] | "",
parseColor(json[KEY_PRIMARY_COLOR], Rgb<8, 8, 8>(0xFF, 0xFF, 0xFF)),
json[KEY_DARK_THEME] | false
);
}
std::unique_ptr<ThemeInfo> ThemeInfoFactory::CreateFromThemeFolder(const TCHAR* folderName) const
{
TCHAR pathBuffer[128];
mini_snprintf(pathBuffer, sizeof(pathBuffer), "/_pico/themes/%s/theme.json", folderName);
const auto file = std::make_unique<File>();
if (file->Open(pathBuffer, FA_READ | FA_OPEN_EXISTING) != FR_OK)
{
return nullptr;
}
u32 fileSize = file->GetSize();
if (fileSize == 0)
{
return nullptr;
}
std::unique_ptr<u8[]> fileData(new(cache_align) u8[fileSize]);
u8* fileDataPtr = fileData.get();
u32 bytesRead = 0;
if (file->Read(fileDataPtr, fileSize, bytesRead) != FR_OK)
{
return nullptr;
}
DynamicJsonDocument json(JSON_RESERVED_SIZE);
if (deserializeJson(json, fileDataPtr, fileSize) != DeserializationError::Ok)
{
return nullptr;
}
return fromJson(folderName, json);
}

View File

@@ -0,0 +1,7 @@
#pragma once
enum class ThemeType
{
Material,
Custom
};

View File

@@ -0,0 +1,29 @@
#pragma once
class GraphicsContext;
class VramContext;
class IVramManager;
class ITheme;
class IThemeBackground
{
public:
virtual ~IThemeBackground() = 0;
/// @brief Updates the background.
virtual void Update() { }
/// @brief Draws the background.
/// @param graphicsContext The graphics context to use.
virtual void Draw(GraphicsContext& graphicsContext) { }
/// @brief Performs vblank processes for the background.
virtual void VBlank() { }
/// @brief Loads the resources for this background.
/// @param theme The theme the background belongs to.
/// @param vramContext The vram context.
virtual void LoadResources(const ITheme& theme, const VramContext& vramContext) { }
};
inline IThemeBackground::~IThemeBackground() { }

View File

@@ -0,0 +1,43 @@
#include "common.h"
#include <string.h>
#include <libtwl/mem/memVram.h>
#include "gui/Gx.h"
#include "../ITheme.h"
#include "CustomMainBackground.h"
#define BLOCK_VTX_PACK(x, y, z) (((x)&0x3FF) | ((((y) >> 3) & 0x3FF) << 10) | ((z) << 20))
void CustomMainBackground::Draw(GraphicsContext& graphicsContext)
{
Gx::MtxIdentity();
Gx::PolygonAttr(GX_LIGHTMASK_NONE, GX_POLYGON_MODE_MODULATE, GX_DISPLAY_MODE_FRONT,
false, false, false, GX_DEPTH_FUNC_LESS, false, 31, 0);
Gx::Color(0x7FFF);
Gx::TexImageParam((128 * 1024) >> 3, false, false, false, false, GX_TEXSIZE_256,
GX_TEXSIZE_256, GX_TEXFMT_DIRECT, false, GX_TEXGEN_NONE);
Gx::Begin(GX_PRIMITIVE_QUAD);
Gx::TexCoord(0, 0);
REG_GX_VTX_10 = BLOCK_VTX_PACK(0, 0, 500);
Gx::TexCoord(0, 192);
REG_GX_VTX_10 = BLOCK_VTX_PACK(0, 192, 500);
Gx::TexCoord(256, 192);
REG_GX_VTX_10 = BLOCK_VTX_PACK(256, 192, 500);
Gx::TexCoord(256, 0);
REG_GX_VTX_10 = BLOCK_VTX_PACK(256, 0, 500);
Gx::End();
}
void CustomMainBackground::LoadResources(const ITheme& theme, const VramContext& vramContext)
{
auto tmpBuf = std::unique_ptr<u8[]>(new(cache_align) u8[256 * 192 * 2]);
const auto file = std::make_unique<File>();
if (theme.OpenThemeFile(*file, "bottombg.bin"))
{
u32 bytesRead = 0;
file->Read(tmpBuf.get(), 256 * 192 * 2, bytesRead);
mem_setVramAMapping(MEM_VRAM_AB_LCDC);
memcpy((void*)0x6800000, tmpBuf.get(), 256 * 192 * 2);
mem_setVramAMapping(MEM_VRAM_AB_TEX_SLOT_1);
file->Close();
}
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "../background/IThemeBackground.h"
class CustomMainBackground : public IThemeBackground
{
public:
void Draw(GraphicsContext& graphicsContext) override;
void LoadResources(const ITheme& theme, const VramContext& vramContext) override;
};

View File

@@ -0,0 +1,32 @@
#include "common.h"
#include <string.h>
#include <nds/arm9/background.h>
#include "../ITheme.h"
#include "CustomSubBackground.h"
void CustomSubBackground::VBlank()
{
REG_DISPCNT_SUB = (REG_DISPCNT_SUB & ~0xF) | 5 | (4 << 8);
REG_BG2CNT_SUB = BG_BMP16_256x256 | BG_PRIORITY_3 | BG_COLOR_16 | BG_MAP_BASE(2);
REG_BG2HOFS_SUB = 0;
REG_BG2VOFS_SUB = 0;
REG_BG2X_SUB = 0;
REG_BG2Y_SUB = 0;
REG_BG2PA_SUB = 256;
REG_BG2PB_SUB = 0;
REG_BG2PC_SUB = 0;
REG_BG2PD_SUB = 256;
}
void CustomSubBackground::LoadResources(const ITheme& theme, const VramContext& vramContext)
{
auto tmpBuf = std::unique_ptr<u8[]>(new(cache_align) u8[256 * 192 * 2]);
const auto file = std::make_unique<File>();
if (theme.OpenThemeFile(*file, "topbg.bin"))
{
u32 bytesRead = 0;
file->Read(tmpBuf.get(), 256 * 192 * 2, bytesRead);
memcpy((u8*)BG_GFX_SUB + 0x8000, tmpBuf.get(), 256 * 192 * 2);
file->Close();
}
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "../background/IThemeBackground.h"
class CustomSubBackground : public IThemeBackground
{
public:
void VBlank() override;
void LoadResources(const ITheme& theme, const VramContext& vramContext) override;
};

View File

@@ -0,0 +1,49 @@
#include "common.h"
#include <memory>
#include <libtwl/mem/memVram.h>
#include <libtwl/gfx/gfx.h>
#include <libtwl/gfx/gfxBackground.h>
#include "json/ArduinoJson.h"
#include "core/mini-printf.h"
#include "CustomTopBackgroundType.h"
#include "gui/VramContext.h"
#include "../material/MaterialColorSchemeFactory.h"
#include "romBrowser/views/IconButton3DView.h"
#include "CustomTheme.h"
#define JSON_RESERVED_SIZE 2048
static CustomTopBackgroundType parseTopBackgroundType(const char* topBackgroundTypeString)
{
return CustomTopBackgroundType::Bitmap;
}
void CustomTheme::LoadRomBrowserResources(const VramContext& mainVramContext, const VramContext& subVramContext)
{
const auto file = std::make_unique<File>();
OpenThemeFile(*file, "theme.json");
u32 fileSize = file->GetSize();
if (fileSize == 0)
return;
std::unique_ptr<u8[]> fileData(new(cache_align) u8[fileSize]);
u8* fileDataPtr = fileData.get();
u32 bytesRead = 0;
if (file->Read(fileDataPtr, fileSize, bytesRead) != FR_OK)
return;
DynamicJsonDocument json(JSON_RESERVED_SIZE);
if (deserializeJson(json, fileDataPtr, fileSize) != DeserializationError::Ok)
return;
_topBackgroundType = parseTopBackgroundType(json["topBackgroundType"].as<const char*>());
mem_setVramDMapping(MEM_VRAM_D_LCDC);
mem_setVramEMapping(MEM_VRAM_E_LCDC);
IconButton3DView::UploadGraphics(mainVramContext);
mem_setVramDMapping(MEM_VRAM_D_TEX_SLOT_0);
mem_setVramEMapping(MEM_VRAM_E_TEX_PLTT_SLOT_0123);
_romBrowserViewFactory.LoadResources(*this, mainVramContext);
}

View File

@@ -0,0 +1,50 @@
#pragma once
#include "fat/ff.h"
#include "fat/File.h"
#include "core/String.h"
#include "CustomMainBackground.h"
#include "CustomSubBackground.h"
#include "romBrowser/Theme/custom/CustomRomBrowserViewFactory.h"
#include "CustomTopBackgroundType.h"
#include "../DefaultFontRepository.h"
#include "../Theme.h"
class CustomTheme : public Theme
{
String<TCHAR, 64> _folderName;
CustomRomBrowserViewFactory _romBrowserViewFactory;
CustomTopBackgroundType _topBackgroundType;
DefaultFontRepository _fontRepository;
public:
CustomTheme(const TCHAR* folderName, const Rgb<8, 8, 8>& primaryColor, bool darkMode)
: Theme(folderName, primaryColor, darkMode)
, _romBrowserViewFactory(&_materialColorScheme, &_fontRepository) { }
const IFontRepository* GetFontRepository() const override
{
return &_fontRepository;
}
const IThemeFileIconFactory* GetThemeFileIconFactory() const override
{
return nullptr;
}
const IRomBrowserViewFactory* GetRomBrowserViewFactory() const override
{
return &_romBrowserViewFactory;
}
std::unique_ptr<IThemeBackground> CreateRomBrowserTopBackground() const override
{
return std::make_unique<CustomSubBackground>();
}
std::unique_ptr<IThemeBackground> CreateRomBrowserBottomBackground() const override
{
return std::make_unique<CustomMainBackground>();
}
void LoadRomBrowserResources(const VramContext& mainVramContext, const VramContext& subVramContext) override;
};

View File

@@ -0,0 +1,6 @@
#pragma once
enum class CustomTopBackgroundType
{
Bitmap
};

View File

@@ -0,0 +1,56 @@
#pragma once
#include "gui/materialDesign.h"
#include "core/math/Rgb.h"
struct MaterialColorScheme
{
using Rgb888 = Rgb<8, 8, 8>;
Rgb888 primary;
Rgb888 onPrimary;
Rgb888 secondaryContainer;
Rgb888 onSecondaryContainer;
Rgb888 tertiary;
Rgb888 onTertiary;
Rgb888 tertiaryContainer;
Rgb888 onTertiaryContainer;
Rgb888 surfaceBright;
Rgb888 inverseOnSurface;
Rgb888 onSurface;
Rgb888 onSurfaceVariant;
Rgb888 mainIconBg;
// Rgb888 surfaceContainerLow;
Rgb888 surfaceContainerHighest;
Rgb888 scrim;
Rgb888 outline;
constexpr const Rgb888& GetColor(md::sys::color color) const
{
switch (color)
{
case md::sys::color::primary:
return primary;
case md::sys::color::onPrimary:
return onPrimary;
case md::sys::color::inverseOnSurface:
return inverseOnSurface;
case md::sys::color::onSurface:
return onSurface;
case md::sys::color::onSurfaceVariant:
return onSurfaceVariant;
case md::sys::color::outline:
return outline;
case md::sys::color::secondaryContainer:
return secondaryContainer;
case md::sys::color::onSecondaryContainer:
return onSecondaryContainer;
case md::sys::color::surfaceBright:
return surfaceBright;
case md::sys::color::surfaceContainerHighest:
return surfaceContainerHighest;
default:
return inverseOnSurface;
}
}
};

View File

@@ -0,0 +1,47 @@
#include "common.h"
#include <algorithm>
#include "material/scheme/scheme.h"
#include "MaterialColorSchemeFactory.h"
using Rgb888 = Rgb<8, 8, 8>;
static material_color_utilities::Argb Rgb888ToMaterialArgb(const Rgb888& color)
{
return material_color_utilities::ArgbFromRgb(color.r, color.g, color.b);
}
static Rgb888 MaterialArgbToRgb888(material_color_utilities::Argb color)
{
return Rgb888(
material_color_utilities::RedFromInt(color),
material_color_utilities::GreenFromInt(color),
material_color_utilities::BlueFromInt(color));
}
void MaterialColorSchemeFactory::FromPrimaryColor(const Rgb<8, 8, 8>& primaryColor,
bool darkTheme, MaterialColorScheme& materialColorScheme)
{
auto materialPrimaryColor = Rgb888ToMaterialArgb(primaryColor);
auto corePalette = material_color_utilities::CorePalette::Of(materialPrimaryColor);
auto scheme = darkTheme
? material_color_utilities::MaterialDarkColorSchemeFromPalette(corePalette)
: material_color_utilities::MaterialLightColorSchemeFromPalette(corePalette);
materialColorScheme.primary = MaterialArgbToRgb888(scheme.primary);
materialColorScheme.onPrimary = MaterialArgbToRgb888(scheme.on_primary);
materialColorScheme.secondaryContainer = MaterialArgbToRgb888(scheme.secondary_container);
materialColorScheme.onSecondaryContainer = MaterialArgbToRgb888(scheme.on_secondary_container);
materialColorScheme.tertiary = MaterialArgbToRgb888(scheme.tertiary);
materialColorScheme.onTertiary = MaterialArgbToRgb888(scheme.on_tertiary);
materialColorScheme.tertiaryContainer = MaterialArgbToRgb888(scheme.tertiary_container);
materialColorScheme.onTertiaryContainer = MaterialArgbToRgb888(scheme.on_tertiary_container);
materialColorScheme.inverseOnSurface = MaterialArgbToRgb888(darkTheme ? corePalette.neutral().get(10.0) : scheme.inverse_on_surface);
materialColorScheme.onSurface = MaterialArgbToRgb888(scheme.on_surface);
materialColorScheme.onSurfaceVariant = MaterialArgbToRgb888(scheme.on_surface_variant);
materialColorScheme.surfaceBright = MaterialArgbToRgb888(corePalette.neutral().get(darkTheme ? 24.0 : 98.0));
materialColorScheme.mainIconBg = MaterialArgbToRgb888(corePalette.secondary().get(darkTheme ? 42.0 : 78.0));
// materialColorScheme.surfaceContainerLow = MaterialArgbToRgb888(corePalette.neutral().get(darkTheme ? 10.0 : 96.0));
materialColorScheme.surfaceContainerHighest = MaterialArgbToRgb888(corePalette.neutral().get(darkTheme ? 22.0 : 90.0));
materialColorScheme.scrim = MaterialArgbToRgb888(corePalette.neutral().get(darkTheme ? 70.0 : 30.0));
materialColorScheme.outline = MaterialArgbToRgb888(scheme.outline);
}

View File

@@ -0,0 +1,10 @@
#pragma once
#include "core/math/Rgb.h"
#include "MaterialColorScheme.h"
class MaterialColorSchemeFactory
{
public:
static void FromPrimaryColor(const Rgb<8, 8, 8>& primaryColor,
bool darkTheme, MaterialColorScheme& materialColorScheme);
};

View File

@@ -0,0 +1,33 @@
#include "common.h"
#include <string.h>
#include <libtwl/mem/memVram.h>
#include "gui/Gx.h"
#include "gui/GraphicsContext.h"
#include "../ITheme.h"
#include "MaterialMainBackground.h"
#define BLOCK_VTX_PACK(x, y, z) (((x)&0x3FF) | ((((y) >> 3) & 0x3FF) << 10) | ((z) << 20))
void MaterialMainBackground::Draw(GraphicsContext& graphicsContext)
{
Gx::MtxIdentity();
Gx::PolygonAttr(GX_LIGHTMASK_NONE, GX_POLYGON_MODE_MODULATE, GX_DISPLAY_MODE_FRONT,
false, false, false, GX_DEPTH_FUNC_LESS, false, 31, 0);
Gx::TexImageParam((128 * 1024) >> 3, false, false, false, false, GX_TEXSIZE_8,
GX_TEXSIZE_8, GX_TEXFMT_PLTT16, false, GX_TEXGEN_NONE);
graphicsContext.GetRgb6Palette()->ApplyColor(Rgb<6, 6, 6>(_materialColorScheme->inverseOnSurface));
Gx::Begin(GX_PRIMITIVE_QUAD);
Gx::TexCoord(0, 0);
REG_GX_VTX_10 = BLOCK_VTX_PACK(0, 0, 500);
REG_GX_VTX_10 = BLOCK_VTX_PACK(0, 192, 500);
REG_GX_VTX_10 = BLOCK_VTX_PACK(256, 192, 500);
REG_GX_VTX_10 = BLOCK_VTX_PACK(256, 0, 500);
Gx::End();
}
void MaterialMainBackground::LoadResources(const ITheme& theme, const VramContext& vramContext)
{
mem_setVramAMapping(MEM_VRAM_AB_LCDC);
*(vu32*)0x06800000 = 0;
mem_setVramAMapping(MEM_VRAM_AB_TEX_SLOT_1);
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include "../background/IThemeBackground.h"
class MaterialColorScheme;
class MaterialMainBackground : public IThemeBackground
{
public:
explicit MaterialMainBackground(const MaterialColorScheme* materialColorScheme)
: _materialColorScheme(materialColorScheme) { }
void Draw(GraphicsContext& graphicsContext) override;
void LoadResources(const ITheme& theme, const VramContext& vramContext) override;
private:
const MaterialColorScheme* _materialColorScheme;
};

View File

@@ -0,0 +1,25 @@
#include "common.h"
#include <nds/arm9/background.h>
#include <libtwl/dma/dmaNitro.h>
#include <libtwl/mem/memVram.h>
#include "core/math/RgbMixer.h"
#include "mainBg.h"
#include "MaterialSubBackground.h"
void MaterialSubBackground::LoadResources(const ITheme& theme, const VramContext& vramContext)
{
mem_setVramHMapping(MEM_VRAM_H_LCDC);
RgbMixer::MakeGradientPalette((u16*)0x06898020,
_materialColorScheme->inverseOnSurface, _materialColorScheme->secondaryContainer);
mem_setVramHMapping(MEM_VRAM_H_SUB_BG_EXT_PLTT_SLOT_0123);
dma_ntrCopy32(3, mainBgTiles, (vu8*)BG_GFX_SUB + 0x8000, mainBgTilesLen);
dma_ntrCopy32(3, mainBgMap, (vu8*)BG_GFX_SUB + 0x8800, mainBgMapLen);
}
void MaterialSubBackground::VBlank()
{
REG_DISPCNT_SUB |= (1 << 8);
REG_BG0CNT_SUB = BG_32x32 | BG_PRIORITY_3 | BG_COLOR_256 | BG_MAP_BASE(17) | BG_TILE_BASE(2);
REG_BG0HOFS_SUB = 0;
REG_BG0VOFS_SUB = 0;
}

View File

@@ -0,0 +1,16 @@
#pragma once
#include "../background/IThemeBackground.h"
#include "MaterialColorScheme.h"
class MaterialSubBackground : public IThemeBackground
{
public:
explicit MaterialSubBackground(const MaterialColorScheme* materialColorScheme)
: _materialColorScheme(materialColorScheme) { }
void LoadResources(const ITheme& theme, const VramContext& vramContext) override;
void VBlank() override;
private:
const MaterialColorScheme* _materialColorScheme;
};

View File

@@ -0,0 +1,13 @@
#include "common.h"
#include <libtwl/mem/memVram.h>
#include "romBrowser/Theme/Material/CarouselRecyclerView.h"
#include "MaterialTheme.h"
void MaterialTheme::LoadRomBrowserResources(const VramContext& mainVramContext, const VramContext& subVramContext)
{
mem_setVramDMapping(MEM_VRAM_D_LCDC);
mem_setVramEMapping(MEM_VRAM_E_LCDC);
CarouselRecyclerView::UploadGraphics(mainVramContext);
mem_setVramDMapping(MEM_VRAM_D_TEX_SLOT_0);
mem_setVramEMapping(MEM_VRAM_E_TEX_PLTT_SLOT_0123);
}

View File

@@ -0,0 +1,49 @@
#pragma once
#include <libtwl/gfx/gfxPalette.h>
#include "../Theme.h"
#include "MaterialColorScheme.h"
#include "core/math/Rgb.h"
#include "romBrowser/Theme/Material/MaterialThemeFileIconFactory.h"
#include "romBrowser/Theme/Material/MaterialRomBrowserViewFactory.h"
#include "MaterialMainBackground.h"
#include "MaterialSubBackground.h"
#include "../DefaultFontRepository.h"
class MaterialTheme : public Theme
{
MaterialThemeFileIconFactory _themeFileIconFactory;
MaterialRomBrowserViewFactory _romBrowserViewFactory;
DefaultFontRepository _fontRepository;
public:
MaterialTheme(const TCHAR* folderName, const Rgb<8, 8, 8>& primaryColor, bool darkMode)
: Theme(folderName, primaryColor, darkMode)
, _themeFileIconFactory(&_materialColorScheme, &_fontRepository)
, _romBrowserViewFactory(&_materialColorScheme, &_fontRepository) { }
const IFontRepository* GetFontRepository() const override
{
return &_fontRepository;
}
const IThemeFileIconFactory* GetThemeFileIconFactory() const override
{
return &_themeFileIconFactory;
}
const IRomBrowserViewFactory* GetRomBrowserViewFactory() const override
{
return &_romBrowserViewFactory;
}
std::unique_ptr<IThemeBackground> CreateRomBrowserTopBackground() const override
{
return std::make_unique<MaterialSubBackground>(&_materialColorScheme);
}
std::unique_ptr<IThemeBackground> CreateRomBrowserBottomBackground() const override
{
return std::make_unique<MaterialMainBackground>(&_materialColorScheme);
}
void LoadRomBrowserResources(const VramContext& mainVramContext, const VramContext& subVramContext) override;
};