Changes:
Formatting UI7 Docs/Sizing R2::GetCurrentScreenSize Hardware Fix BatteryPercent/AddGetWifiLevel
This commit is contained in:
parent
ec8743417d
commit
56fd24ed80
@ -18,12 +18,10 @@ def fmt_dir(path):
|
||||
|
||||
print('Formatting...')
|
||||
fmt_dir('source')
|
||||
fmt_dir('source/music')
|
||||
fmt_dir('include')
|
||||
fmt_dir('include/renderd7')
|
||||
fmt_dir('include/renderd7/music')
|
||||
|
||||
# Format LE and TF as well
|
||||
fmt_dir('rd7tf/source')
|
||||
fmt_dir('rd7le/source')
|
||||
#fmt_dir('rd7le/source')
|
||||
print('Done')
|
@ -29,13 +29,16 @@ bool IsHeadphones();
|
||||
/// @return true if System gets Charged
|
||||
bool IsCharging();
|
||||
/// @brief Check the Battery Percentage
|
||||
/// @return Persentage as float
|
||||
float GetBatteryPercentage();
|
||||
/// @return Persentage as int
|
||||
int GetBatteryPercentage();
|
||||
/// @brief Get current State of 3d Slider
|
||||
/// @return current 3dslider poition
|
||||
float Get3dSliderLevel();
|
||||
/// @brief Get Current state of Sound Slider
|
||||
/// @return current SoundSlider state
|
||||
float GetSoundSliderLevel();
|
||||
/// @brief Get Current Wifi Level
|
||||
/// @return current wifi level
|
||||
int GetWifiLevel();
|
||||
} // namespace Hardware
|
||||
} // namespace RenderD7
|
@ -30,6 +30,8 @@ namespace RenderD7 {
|
||||
class Image {
|
||||
public:
|
||||
Image() = default;
|
||||
Image(C2D_Image img) { this->img = img; }
|
||||
Image(const std::string& path) { this->Load(path); }
|
||||
~Image() = default;
|
||||
RD7_SMART_CTOR(Image)
|
||||
void Load(const std::string& path);
|
||||
|
@ -80,7 +80,7 @@ class R2Base {
|
||||
void SetTextSize(float szs);
|
||||
void DefaultTextSize();
|
||||
float GetTextSize();
|
||||
|
||||
R7Vec2 GetCurrentScreenSize();
|
||||
// Processing
|
||||
void Process();
|
||||
R7Vec2 GetTextDimensions(const std::string& text);
|
||||
|
@ -31,6 +31,7 @@ class Sheet {
|
||||
public:
|
||||
/// @brief Constructor
|
||||
Sheet() = default;
|
||||
Sheet(const std::string& path) { this->Load(path); }
|
||||
/// @brief Deconstructor
|
||||
~Sheet() {
|
||||
if (spritesheet) Free();
|
||||
@ -42,7 +43,7 @@ class Sheet {
|
||||
Result Load(const std::string& path);
|
||||
/// @brief Unload the Sheet
|
||||
void Free();
|
||||
Image::Ref GetImage(int idx);
|
||||
C2D_Image GetImage(int idx);
|
||||
C2D_SpriteSheet Get() { return this->spritesheet; }
|
||||
|
||||
private:
|
||||
|
@ -103,11 +103,11 @@ void RestoreCursor();
|
||||
void SameLine();
|
||||
float GetScrollingOffset();
|
||||
namespace Menu {
|
||||
// All of them return the Main BG DrawList if Menu is null
|
||||
UI7DrawList::Ref GetBackgroundList();
|
||||
UI7DrawList::Ref GetList();
|
||||
UI7DrawList::Ref GetForegroundList();
|
||||
}
|
||||
// All of them return the Main BG DrawList if Menu is null
|
||||
UI7DrawList::Ref GetBackgroundList();
|
||||
UI7DrawList::Ref GetList();
|
||||
UI7DrawList::Ref GetForegroundList();
|
||||
} // namespace Menu
|
||||
// DrawLists
|
||||
UI7DrawList::Ref GetForegroundList();
|
||||
UI7DrawList::Ref GetBackgroundList();
|
||||
|
@ -48,10 +48,10 @@ bool RenderD7::Hardware::IsCharging() {
|
||||
return (var == 0x01 ? true : false);
|
||||
}
|
||||
|
||||
float RenderD7::Hardware::GetBatteryPercentage() {
|
||||
uint8_t percentLevel;
|
||||
PTMU_GetBatteryLevel(&percentLevel);
|
||||
return (float)percentLevel / 100;
|
||||
int RenderD7::Hardware::GetBatteryPercentage() {
|
||||
uint8_t percentLevel = 0;
|
||||
MCUHWC_GetBatteryLevel(&percentLevel);
|
||||
return percentLevel;
|
||||
}
|
||||
|
||||
float RenderD7::Hardware::Get3dSliderLevel() { return osGet3DSliderState(); }
|
||||
@ -61,3 +61,5 @@ float RenderD7::Hardware::GetSoundSliderLevel() {
|
||||
MCUHWC_GetSoundSliderLevel(&percentLevel);
|
||||
return (float)percentLevel / 100;
|
||||
}
|
||||
|
||||
int RenderD7::Hardware::GetWifiLevel() { return osGetWifiStrength(); }
|
@ -137,8 +137,8 @@ void Image::Load(const std::string &path) {
|
||||
stbi_image_free(image);
|
||||
}
|
||||
// Create C2D_Image
|
||||
C3D_Tex* tex = new C3D_Tex;
|
||||
Tex3DS_SubTexture* subtex = new Tex3DS_SubTexture;
|
||||
C3D_Tex *tex = new C3D_Tex;
|
||||
Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture;
|
||||
__rd7i_maketex__(tex, subtex, wimg, w, h);
|
||||
_rd7i_logger()->Write(RenderD7::FormatString("Created Texture (%d, %d)",
|
||||
tex->width, tex->height));
|
||||
@ -149,8 +149,8 @@ void Image::From_NIMG(const nimg &image) {
|
||||
// Make sure to cleanup
|
||||
Delete();
|
||||
if (image.width > 1024 || image.height > 1024) return;
|
||||
C3D_Tex* tex = new C3D_Tex;
|
||||
Tex3DS_SubTexture* subtex = new Tex3DS_SubTexture;
|
||||
C3D_Tex *tex = new C3D_Tex;
|
||||
Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture;
|
||||
std::vector<unsigned char> mdpb = image.pixel_buffer;
|
||||
__rd7i_maketex__(tex, subtex, mdpb, image.width, image.height);
|
||||
img = {tex, subtex};
|
||||
|
@ -57,7 +57,7 @@ std::vector<Key> keyboard_layout_num{
|
||||
{"0", R7Vec2(5, 213), R7Vec2(74, 24), 0},
|
||||
{".", R7Vec2(81, 213), R7Vec2(36, 24), 0},
|
||||
// additional actions
|
||||
{"bksp", R7Vec2(119, 135), R7Vec2(74, 24), 2},
|
||||
{"<---", R7Vec2(119, 135), R7Vec2(74, 24), 2},
|
||||
//{"", R7Vec2(119, 161), R7Vec2(74, 24), 0},
|
||||
{"Confirm", R7Vec2(119, 187), R7Vec2(74, 24), 5},
|
||||
{"Cancel", R7Vec2(119, 213), R7Vec2(74, 24), 4},
|
||||
@ -78,7 +78,7 @@ std::vector<Key> keyboard_layout = {
|
||||
{"0", R7Vec2(205, 137), R7Vec2(18, 18), 0},
|
||||
{"-", R7Vec2(225, 137), R7Vec2(18, 18), 0},
|
||||
{"=", R7Vec2(245, 137), R7Vec2(18, 18), 0},
|
||||
{"Bksp", R7Vec2(265, 137), R7Vec2(50, 18), 2},
|
||||
{"<---", R7Vec2(265, 137), R7Vec2(50, 18), 2},
|
||||
// 2nd row
|
||||
{"Tab", R7Vec2(5, 157), R7Vec2(40, 18), 6},
|
||||
{"q", R7Vec2(47, 157), R7Vec2(18, 18), 0},
|
||||
@ -148,7 +148,7 @@ std::vector<Key> keyboard_layout_caps = {
|
||||
{"0", R7Vec2(205, 137), R7Vec2(18, 18), 0},
|
||||
{"-", R7Vec2(225, 137), R7Vec2(18, 18), 0},
|
||||
{"=", R7Vec2(245, 137), R7Vec2(18, 18), 0},
|
||||
{"Bksp", R7Vec2(265, 137), R7Vec2(50, 18), 2},
|
||||
{"<---", R7Vec2(265, 137), R7Vec2(50, 18), 2},
|
||||
// 2nd row
|
||||
{"Tab", R7Vec2(5, 157), R7Vec2(40, 18), 6},
|
||||
{"Q", R7Vec2(47, 157), R7Vec2(18, 18), 0},
|
||||
@ -218,7 +218,7 @@ std::vector<Key> keyboard_layout_shift = {
|
||||
{")", R7Vec2(205, 137), R7Vec2(18, 18), 0},
|
||||
{"_", R7Vec2(225, 137), R7Vec2(18, 18), 0},
|
||||
{"+", R7Vec2(245, 137), R7Vec2(18, 18), 0},
|
||||
{"Bksp", R7Vec2(265, 137), R7Vec2(50, 18), 2},
|
||||
{"<---", R7Vec2(265, 137), R7Vec2(50, 18), 2},
|
||||
// 2nd row
|
||||
{"Tab", R7Vec2(5, 157), R7Vec2(40, 18), 6},
|
||||
{"Q", R7Vec2(47, 157), R7Vec2(18, 18), 0},
|
||||
|
@ -79,6 +79,10 @@ std::string R2Base::WrapText(const std ::string& in, int maxlen) {
|
||||
return out;
|
||||
}
|
||||
|
||||
R7Vec2 R2Base::GetCurrentScreenSize() {
|
||||
return R7Vec2(this->current_screen == R2Screen_Bottom ? 320 : 400, 240);
|
||||
}
|
||||
|
||||
// Main Processing of Draw Calls
|
||||
void R2Base::Process() {
|
||||
for (auto& it : this->commands) {
|
||||
@ -90,16 +94,16 @@ void R2Base::Process() {
|
||||
if (it->type == 1) {
|
||||
// Rect
|
||||
if (it->lined) {
|
||||
C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pos.x + it->pszs.x, it->pos.y,
|
||||
it->clr, 1.f, 0.5f);
|
||||
C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pos.x, it->pos.y + it->pszs.y,
|
||||
it->clr, 1.f, 0.5f);
|
||||
C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pos.x + it->pszs.x,
|
||||
it->pos.y, it->clr, 1.f, 0.5f);
|
||||
C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pos.x,
|
||||
it->pos.y + it->pszs.y, it->clr, 1.f, 0.5f);
|
||||
C2D_DrawLine(it->pos.x + it->pszs.x, it->pos.y, it->clr,
|
||||
it->pos.x + it->pszs.x, it->pos.y + it->pszs.y, it->clr, 1.f,
|
||||
0.5f);
|
||||
it->pos.x + it->pszs.x, it->pos.y + it->pszs.y, it->clr,
|
||||
1.f, 0.5f);
|
||||
C2D_DrawLine(it->pos.x, it->pos.y + it->pszs.y, it->clr,
|
||||
it->pos.x + it->pszs.x, it->pos.y + it->pszs.y, it->clr, 1.f,
|
||||
0.5f);
|
||||
it->pos.x + it->pszs.x, it->pos.y + it->pszs.y, it->clr,
|
||||
1.f, 0.5f);
|
||||
} else {
|
||||
C2D_DrawRectSolid(it->pos.x, it->pos.y, 0.5, it->pszs.x, it->pszs.y,
|
||||
it->clr);
|
||||
@ -107,12 +111,12 @@ void R2Base::Process() {
|
||||
} else if (it->type == 2) {
|
||||
// Triangle
|
||||
if (it->lined) {
|
||||
C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pszs.x, it->pszs.y, it->clr,
|
||||
C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pszs.x, it->pszs.y,
|
||||
it->clr, 1, 0.5f);
|
||||
C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->ap.x, it->ap.y, it->clr,
|
||||
1, 0.5f);
|
||||
C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->ap.x, it->ap.y, it->clr, 1,
|
||||
0.5f);
|
||||
C2D_DrawLine(it->pszs.x, it->pszs.y, it->clr, it->ap.x, it->ap.y, it->clr, 1,
|
||||
0.5f);
|
||||
C2D_DrawLine(it->pszs.x, it->pszs.y, it->clr, it->ap.x, it->ap.y,
|
||||
it->clr, 1, 0.5f);
|
||||
} else {
|
||||
C2D_DrawTriangle(it->pos.x, it->pos.y, it->clr, it->pszs.x, it->pszs.y,
|
||||
it->clr, it->ap.x, it->ap.y, it->clr, 0.5);
|
||||
|
@ -34,9 +34,7 @@ void RenderD7::Sheet::Free() {
|
||||
this->spritesheet = nullptr;
|
||||
}
|
||||
|
||||
RenderD7::Image::Ref RenderD7::Sheet::GetImage(int idx) {
|
||||
if (!this->spritesheet) return nullptr;
|
||||
Image::Ref img = Image::New();
|
||||
img->GetRef() = C2D_SpriteSheetGetImage(this->spritesheet, idx);
|
||||
return img;
|
||||
C2D_Image RenderD7::Sheet::GetImage(int idx) {
|
||||
if (!this->spritesheet) return {nullptr, nullptr};
|
||||
return C2D_SpriteSheetGetImage(this->spritesheet, idx);
|
||||
}
|
@ -179,6 +179,7 @@ class DrawCmd {
|
||||
R7Vec2(rect.x + szs.x, rect.y),
|
||||
R7Vec2(rect.x, rect.y + szs.y), 0xff00ffff);
|
||||
} else if (stype == DrawCmdType_Image) {
|
||||
if (!img) return;
|
||||
rect.z = img->GetSize().x;
|
||||
rect.w = img->GetSize().y;
|
||||
RenderD7::R2()->DrawNextLined();
|
||||
@ -324,6 +325,7 @@ void UI7DrawList::AddDebugCall(std::shared_ptr<DrawCmd> cmd) {
|
||||
dcmd->text = cmd->text;
|
||||
dcmd->text_box = cmd->text_box;
|
||||
dcmd->text_flags = cmd->text_flags;
|
||||
dcmd->img = cmd->img;
|
||||
dcmd->type = DrawCmdType_Debug;
|
||||
dcmd->screen = RenderD7::R2()->GetCurrentScreen();
|
||||
UI7CtxPushDebugCmd(dcmd);
|
||||
@ -354,6 +356,8 @@ struct UI7Menu {
|
||||
R7Vec2 ms; // Max Size
|
||||
R7Vec2 msr; // Max Size Real (Slider)
|
||||
R7Vec2 mdp; // Mouse/Touch Initial pos
|
||||
R7Vec2 bslp; // Before SameLine Pos
|
||||
R7Vec2 lszs; // Last Size
|
||||
// For Smart Pointer
|
||||
RD7_SMART_CTOR(UI7Menu)
|
||||
};
|
||||
@ -426,13 +430,22 @@ void UI7CtxEndMenu() {
|
||||
ui7_ctx->cm->show_scroolbar = (ui7_ctx->cm->ms.y < 235 ? false : true);
|
||||
|
||||
if (ui7_ctx->cm->show_scroolbar) {
|
||||
int sw = (RenderD7::R2()->GetCurrentScreen() ? 400 : 320);
|
||||
// Screen Width
|
||||
int sw = RenderD7::R2()->GetCurrentScreenSize().x;
|
||||
// Top Start Pos
|
||||
int tsp = 5 + ui7_ctx->cm->tbh;
|
||||
// Slider Width
|
||||
int slider_w = 4;
|
||||
// Height of Slider
|
||||
int szs = 240 - tsp - 5;
|
||||
// Lowest Height of Slider Obj
|
||||
int lszs = 20; // Lowest Slider size
|
||||
// Calculate Slider Height
|
||||
float slider_h = (szs - 4) * (static_cast<float>(szs - 4) /
|
||||
static_cast<float>(ui7_ctx->cm->msr.y));
|
||||
// Create Real Slider Height
|
||||
int slider_rh = d7min(d7max(slider_h, (float)lszs), (float)(szs - 4));
|
||||
// Calculate Slider Position
|
||||
int slider_pos = d7min(
|
||||
static_cast<float>(tsp + szs - slider_rh - 4),
|
||||
d7max(static_cast<float>(tsp),
|
||||
@ -441,7 +454,7 @@ void UI7CtxEndMenu() {
|
||||
(szs) *
|
||||
(static_cast<float>(ui7_ctx->cm->scrolling_offset) /
|
||||
static_cast<float>(ui7_ctx->cm->msr.y)))));
|
||||
int slider_w = 4;
|
||||
// Render Slider
|
||||
ui7_ctx->cm->front->AddRectangle(
|
||||
R7Vec2(sw - 12, tsp), R7Vec2(slider_w * 2, szs), RD7Color_List0);
|
||||
ui7_ctx->cm->front->AddRectangle(R7Vec2(sw - 10, slider_pos + 2),
|
||||
@ -457,9 +470,15 @@ void UI7CtxEndMenu() {
|
||||
void UI7CtxCursorMove(R7Vec2 size) {
|
||||
if (!UI7CtxValidate()) return;
|
||||
if (!UI7CtxInMenu()) return;
|
||||
ui7_ctx->cm->lszs = size;
|
||||
ui7_ctx->cm->slc = ui7_ctx->cm->cursor + R7Vec2(size.x + 5, 0);
|
||||
ui7_ctx->cm->cursor.x = 5;
|
||||
if (ui7_ctx->cm->bslp.y) {
|
||||
ui7_ctx->cm->cursor += R7Vec2(0, ui7_ctx->cm->bslp.y + 5);
|
||||
ui7_ctx->cm->bslp = R7Vec2();
|
||||
} else {
|
||||
ui7_ctx->cm->cursor += R7Vec2(0, size.y + 5);
|
||||
}
|
||||
ui7_ctx->cm->ms = R7Vec2(ui7_ctx->cm->slc.x, ui7_ctx->cm->cursor.y);
|
||||
// TODO: Correct that calculation
|
||||
ui7_ctx->cm->msr = R7Vec2(ui7_ctx->cm->slc.x, ui7_ctx->cm->slc.y - 10);
|
||||
@ -637,8 +656,8 @@ void Label(const std::string &label, RD7TextFlags flags) {
|
||||
void Progressbar(float value) {
|
||||
if (!UI7CtxValidate()) return;
|
||||
R7Vec2 pos = GetCursorPos();
|
||||
R7Vec2 size = R7Vec2(
|
||||
(RenderD7::R2()->GetCurrentScreen() ? 400 : 320) - (pos.x * 2), 20);
|
||||
R7Vec2 size =
|
||||
R7Vec2(RenderD7::R2()->GetCurrentScreenSize().x - (pos.x * 2), 20);
|
||||
if (ui7_ctx->cm->show_scroolbar && ui7_ctx->cm->enable_scrolling)
|
||||
size.x -= 16;
|
||||
UI7CtxCursorMove(size);
|
||||
@ -688,7 +707,7 @@ void BrowserList(const std::vector<std::string> &entrys, int &selection,
|
||||
R7Vec2 pos = GetCursorPos();
|
||||
if (pos.y + 15 * max_entrys > 230) max_entrys = (int)((230 - pos.y) / 15);
|
||||
if (size.x == 0)
|
||||
size.x = (RenderD7::R2()->GetCurrentScreen() ? 400 : 320) - (pos.x * 2);
|
||||
size.x = RenderD7::R2()->GetCurrentScreenSize().x - (pos.x * 2);
|
||||
if (size.y == 0) size.y = (max_entrys * 15);
|
||||
UI7CtxCursorMove(size);
|
||||
ui7_ctx->cm->ctrl->AddObj();
|
||||
@ -1146,6 +1165,7 @@ void SameLine() {
|
||||
if (!UI7CtxValidate()) return;
|
||||
if (!UI7CtxInMenu()) return;
|
||||
ui7_ctx->cm->ctrl->NewRow();
|
||||
ui7_ctx->cm->bslp = ui7_ctx->cm->lszs;
|
||||
ui7_ctx->cm->cursor = ui7_ctx->cm->slc;
|
||||
}
|
||||
|
||||
@ -1184,19 +1204,19 @@ UI7DrawList::Ref GetBackgroundList() {
|
||||
|
||||
UI7DrawList::Ref Menu::GetBackgroundList() {
|
||||
if (!UI7CtxValidate()) return nullptr;
|
||||
if(!UI7CtxInMenu()) return ui7_ctx->bdl;
|
||||
if (!UI7CtxInMenu()) return ui7_ctx->bdl;
|
||||
return ui7_ctx->cm->background;
|
||||
}
|
||||
|
||||
UI7DrawList::Ref Menu::GetList() {
|
||||
if (!UI7CtxValidate()) return nullptr;
|
||||
if(!UI7CtxInMenu()) return ui7_ctx->bdl;
|
||||
if (!UI7CtxInMenu()) return ui7_ctx->bdl;
|
||||
return ui7_ctx->cm->main;
|
||||
}
|
||||
|
||||
UI7DrawList::Ref Menu::GetForegroundList() {
|
||||
if (!UI7CtxValidate()) return nullptr;
|
||||
if(!UI7CtxInMenu()) return ui7_ctx->bdl;
|
||||
if (!UI7CtxInMenu()) return ui7_ctx->bdl;
|
||||
return ui7_ctx->cm->front;
|
||||
}
|
||||
} // namespace UI7
|
@ -387,6 +387,8 @@ Result RenderD7::Init::Main(std::string app_name) {
|
||||
rd7i_is_am_init = true;
|
||||
}
|
||||
|
||||
Hardware::Initialisize();
|
||||
|
||||
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
|
||||
atexit(C3D_Fini);
|
||||
C2D_Init((size_t)rd7_max_objects);
|
||||
@ -442,6 +444,8 @@ Result RenderD7::Init::Minimal(std::string app_name) {
|
||||
rd7i_is_am_init = true;
|
||||
}
|
||||
|
||||
Hardware::Initialisize();
|
||||
|
||||
osSetSpeedupEnable(true);
|
||||
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
|
||||
atexit(C3D_Fini);
|
||||
|
Loading…
Reference in New Issue
Block a user