mirror of
https://github.com/LNH-team/pico-launcher.git
synced 2026-06-02 09:06:54 +02:00
Initial commit
This commit is contained in:
43
arm9/source/themes/custom/CustomMainBackground.cpp
Normal file
43
arm9/source/themes/custom/CustomMainBackground.cpp
Normal 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();
|
||||
}
|
||||
}
|
||||
9
arm9/source/themes/custom/CustomMainBackground.h
Normal file
9
arm9/source/themes/custom/CustomMainBackground.h
Normal 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;
|
||||
};
|
||||
32
arm9/source/themes/custom/CustomSubBackground.cpp
Normal file
32
arm9/source/themes/custom/CustomSubBackground.cpp
Normal 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();
|
||||
}
|
||||
}
|
||||
9
arm9/source/themes/custom/CustomSubBackground.h
Normal file
9
arm9/source/themes/custom/CustomSubBackground.h
Normal 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;
|
||||
};
|
||||
49
arm9/source/themes/custom/CustomTheme.cpp
Normal file
49
arm9/source/themes/custom/CustomTheme.cpp
Normal 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);
|
||||
}
|
||||
50
arm9/source/themes/custom/CustomTheme.h
Normal file
50
arm9/source/themes/custom/CustomTheme.h
Normal 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;
|
||||
};
|
||||
6
arm9/source/themes/custom/CustomTopBackgroundType.h
Normal file
6
arm9/source/themes/custom/CustomTopBackgroundType.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
enum class CustomTopBackgroundType
|
||||
{
|
||||
Bitmap
|
||||
};
|
||||
Reference in New Issue
Block a user