Remove MEMTRACK Flag
Replace Draw2 with Render2
Rename sound and font to uppercase
Add SMART_CTOR to Image Sprite Sound
Port Everything to R2
This commit is contained in:
tobid7 2024-06-08 21:00:40 +02:00
parent 07ed5af300
commit 5636205002
21 changed files with 878 additions and 874 deletions

View File

@ -12,14 +12,12 @@ RENDERD7_INC := RenderD7/include
# Libraries used for RenderD7 # Libraries used for RenderD7
# if you already use -lm, -lctru etc place a # before -lm # if you already use -lm, -lctru etc place a # before -lm
RENDERD7_LIBS := -lcurl -lmbedtls -lmbedx509 -lmbedcrypto -lz -lm -lcitro2dd -lcitro3d -lctru RENDERD7_LIBS := -lcurl -lmbedtls -lmbedx509 -lmbedcrypto -lz -lm -lcitro2dd -lcitro3d -lctru
RENDERD7_FLAGS := -DRENDERD7_MEMTRACK=1
``` ```
Now you need to add it to your sources and includes Now you need to add it to your sources and includes
``` ```
SOURCES := source $(RENDERD7_SRC) SOURCES := source $(RENDERD7_SRC)
INCLUDES := source $(RENDERD7_INC) INCLUDES := source $(RENDERD7_INC)
``` ```
Finally append `$(RENDERD7_FLAGS)` to your `CFLAGS`
Example from rd7tf Example from rd7tf
### Installation (0.8.0-0.9.4) (OUTDATED) ### Installation (0.8.0-0.9.4) (OUTDATED)

View File

@ -19,7 +19,6 @@
#pragma once #pragma once
#include <renderd7/Allocator.hpp> #include <renderd7/Allocator.hpp>
#include <renderd7/DrawV2.hpp>
#include <renderd7/Error.hpp> #include <renderd7/Error.hpp>
#include <renderd7/FileSystem.hpp> #include <renderd7/FileSystem.hpp>
#include <renderd7/Hid.hpp> #include <renderd7/Hid.hpp>
@ -28,13 +27,12 @@
#include <renderd7/Message.hpp> #include <renderd7/Message.hpp>
#include <renderd7/Net.hpp> #include <renderd7/Net.hpp>
#include <renderd7/Overlays.hpp> #include <renderd7/Overlays.hpp>
#include <renderd7/Sound2.hpp>
#include <renderd7/StealConsole.hpp> #include <renderd7/StealConsole.hpp>
#include <renderd7/Timer.hpp> #include <renderd7/Timer.hpp>
#include <renderd7/UI7.hpp> #include <renderd7/UI7.hpp>
#include <renderd7/global_db.hpp> #include <renderd7/global_db.hpp>
#include <renderd7/renderd7.hpp> #include <renderd7/renderd7.hpp>
#include <renderd7/sound.hpp>
#include <renderd7/swr.hpp> #include <renderd7/swr.hpp>
namespace RD7 = RenderD7; namespace RD7 = RenderD7;
namespace DV2 = RenderD7::Draw2;

View File

@ -1,76 +0,0 @@
/**
* This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <citro2d.h>
#include <renderd7/Color.hpp>
#include <renderd7/Image.hpp>
#include <renderd7/R7Vec.hpp>
#include <renderd7/font.hpp>
#define MAKEFLAG(x) (1 << x)
typedef unsigned int RD7TextFlags;
enum RD7TextFlags_ {
RD7TextFlags_None = 0, //< Align is Left and Other things are disabled
RD7TextFlags_AlignRight = MAKEFLAG(0),
RD7TextFlags_AlignMid = MAKEFLAG(1),
RD7TextFlags_Shaddow = MAKEFLAG(2), // TextBuf Killer lol (doubled Text)
RD7TextFlags_Wrap = MAKEFLAG(3),
RD7TextFlags_Short = MAKEFLAG(4),
RD7TextFlags_Scroll = MAKEFLAG(5),
};
namespace RenderD7 {
R7Vec2 GetTextDimensions(const std::string& text);
void CustomTextSize(float size);
void TextDefaultSize();
float TextGetSize();
std::string TextShort(const std::string& in, int max_len);
// Overrite TextBox Size (by default Screenwidth x Text.h)
void TextMaxBox(R7Vec2 size);
void TextDefaultBox();
void TextFont(Font::Ref fnt);
void TextFontRestore();
void TextDefaultFont();
namespace Draw2 {
void Scissor(R7Vec2 pos, R7Vec2 size);
void ScissorReset();
void Rect(R7Vec2 pos, R7Vec2 size, unsigned int color, int t = 1);
void RectFilled(R7Vec2 pos, R7Vec2 size, Color4 colors);
void RectFilledSolid(R7Vec2 pos, R7Vec2 size, unsigned int color);
// Wrapper of RectFilledSolid
inline void RFS(R7Vec2 pos, R7Vec2 size, unsigned int color) {
RectFilledSolid(pos, size, color);
}
void Line(R7Vec2 pos0, R7Vec2 pos1, unsigned int color, int t = 1);
void Triangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, Color3 colors);
void TriangleSolid(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, unsigned int color);
// Beta and Very unstable
void TriangleLined(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, unsigned int color,
int t = 1);
void Text(R7Vec2 pos, const std::string& text, RD7TextFlags flags = 0);
void TextClr(R7Vec2 pos, const std::string& text, unsigned int color,
RD7TextFlags flags = 0);
void Image(RenderD7::Image* img, const R7Vec2& pos = R7Vec2(0, 0),
const R7Vec2& scale = R7Vec2(1, 1));
} // namespace Draw2
} // namespace RenderD7

View File

@ -1,54 +1,54 @@
/** /**
* This file is part of RenderD7 * This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7 * Copyright (C) 2021-2024 NPI-D7, tobid7
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include <citro2d.h> #include <citro2d.h>
#include <fstream> #include <fstream>
#include <memory> #include <memory>
#include <renderd7/Error.hpp> #include <renderd7/Error.hpp>
#include <renderd7/smart_ctor.hpp> #include <renderd7/smart_ctor.hpp>
namespace RenderD7 { namespace RenderD7 {
class Font { class Font {
public: public:
Font() = default; Font() = default;
Font(const std::string& path) { Load(path); }; Font(const std::string& path) { Load(path); };
~Font() { Unload(); } ~Font() { Unload(); }
RD7_SMART_CTOR(Font) RD7_SMART_CTOR(Font)
void Load(const std::string& path) { void Load(const std::string& path) {
std::ifstream ft(path, std::ios::in | std::ios::binary); std::ifstream ft(path, std::ios::in | std::ios::binary);
bool io = ft.is_open(); bool io = ft.is_open();
ft.close(); ft.close();
RenderD7::InlineAssert(io, "File not Found!"); RenderD7::InlineAssert(io, "File not Found!");
fnt = C2D_FontLoad(path.c_str()); fnt = C2D_FontLoad(path.c_str());
RenderD7::InlineAssert(fnt, "Font could not be loaded!"); RenderD7::InlineAssert(fnt, "Font could not be loaded!");
} }
C2D_Font Ptr() { return fnt; } C2D_Font Ptr() { return fnt; }
void Unload() { void Unload() {
if (!fnt) return; if (!fnt) return;
C2D_FontFree(fnt); C2D_FontFree(fnt);
fnt = nullptr; fnt = nullptr;
} }
private: private:
C2D_Font fnt = nullptr; C2D_Font fnt = nullptr;
}; };
} // namespace RenderD7 } // namespace RenderD7

View File

@ -23,6 +23,7 @@
#include <renderd7/R7Vec.hpp> #include <renderd7/R7Vec.hpp>
#include <renderd7/nimg.hpp> #include <renderd7/nimg.hpp>
#include <renderd7/smart_ctor.hpp>
#include <string> #include <string>
namespace RenderD7 { namespace RenderD7 {
@ -30,14 +31,15 @@ class Image {
public: public:
Image(); Image();
~Image(); ~Image();
void load(const std::string& path); RD7_SMART_CTOR(Image)
void from_nimg(const nimg& image); void Load(const std::string& path);
void From_NIMG(const nimg& image);
C2D_Image get(); C2D_Image Get();
C2D_Image& get_ref(); C2D_Image& GetRef();
void set(const C2D_Image& i); void Set(const C2D_Image& i);
R7Vec2 get_size(); R7Vec2 GetSize();
bool loaded(); bool Loadet();
private: private:
void safe_del(); void safe_del();

View File

@ -67,6 +67,7 @@ class Ovl_Metrik : public RenderD7::Ovl {
mutable std::string mt_cmd; mutable std::string mt_cmd;
mutable std::string mt_lfr; mutable std::string mt_lfr;
mutable std::string mt_tbs; mutable std::string mt_tbs;
mutable std::string mt_mem;
// Importand Adresses // Importand Adresses
bool* i_is_enabled; bool* i_is_enabled;

View File

@ -20,25 +20,83 @@
#include <map> #include <map>
#include <renderd7/Color.hpp> #include <renderd7/Color.hpp>
#include <renderd7/Font.hpp> #include <renderd7/Font2.hpp>
#include <renderd7/R7Vec.hpp> #include <renderd7/R7Vec.hpp>
#include <renderd7/smart_ctor.hpp> #include <renderd7/smart_ctor.hpp>
#define MAKEFLAG(x) (1 << x)
typedef unsigned int RD7TextFlags;
enum RD7TextFlags_ {
RD7TextFlags_None = 0, //< Align is Left and Other things are disabled
RD7TextFlags_AlignRight = MAKEFLAG(0),
RD7TextFlags_AlignMid = MAKEFLAG(1),
RD7TextFlags_Shaddow = MAKEFLAG(2), // TextBuf Killer lol (doubled Text)
RD7TextFlags_Wrap = MAKEFLAG(3),
RD7TextFlags_Short = MAKEFLAG(4),
RD7TextFlags_Scroll = MAKEFLAG(5),
};
enum R2Screen {
R2Screen_Bottom,
R2Screen_Top,
// TopRight,
};
namespace RenderD7 { namespace RenderD7 {
class R2Base { class R2Base {
public: public:
struct R2Cmd {
R7Vec2 pos; //< Position
R7Vec2 pszs; //< Position or (TextBox) Size
R7Vec2 ap; //< Additional Pos
unsigned int clr; //< Color
bool Screen; //< TopScreen
// 0 = skip, 1 = rect, 2 = tri, 3 = text, 4 = image
int type; //< Command Type
bool lined = false; //< Draw Lined Rect/Tri
// Text Specific
RD7TextFlags flags; // Text Flags
std::string text; // Text
};
R2Base(); R2Base();
~R2Base() = default; ~R2Base() = default;
void SetFont(); RD7_SMART_CTOR(R2Base)
// Settings
void SetFont(Font::Ref fnt);
Font::Ref GetFont(); Font::Ref GetFont();
void DefaultFont(); void DefaultFont();
void DrawNextLined();
void OnScreen(R2Screen screen);
R2Screen GetCurrentScreen();
void SetTextSize(float szs);
void DefaultTextSize();
float GetTextSize();
// Processing
void Process();
R7Vec2 GetTextDimensions(const std::string& text);
// Draw Functions
void AddRect(R7Vec2 pos, R7Vec2 size, RD7Color clr);
void AddRect(R7Vec2 pos, R7Vec2 size, unsigned int clr);
void AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, RD7Color clr);
void AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, unsigned int clr);
void AddText(R7Vec2 pos, const std::string& text, RD7Color clr,
RD7TextFlags flags = 0, R7Vec2 tmb = R7Vec2());
void AddText(R7Vec2 pos, const std::string& text, unsigned int clr,
RD7TextFlags flags = 0, R7Vec2 tmb = R7Vec2());
private: private:
const float default_text_size = 0.5f; const float default_text_size = 0.5f;
float text_size = 0.5; float text_size = 0.5;
Font::Ref font[2]; Font::Ref font;
R7Vec2 max_wh;
std::map<std::string, float> ts; std::map<std::string, float> ts;
std::map<std::string, int> mln; std::map<std::string, int> mln;
bool next_lined = false;
std::vector<R2Cmd> commands;
R2Screen current_screen = R2Screen_Bottom;
}; };
} // namespace RenderD7 } // namespace RenderD7

View File

@ -1,49 +1,51 @@
/** /**
* This file is part of RenderD7 * This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7 * Copyright (C) 2021-2024 NPI-D7, tobid7
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include <3ds.h> #include <3ds.h>
#include <string> #include <renderd7/smart_ctor.hpp>
#include <string>
/** Sound Class */
class sound { /** Sound Class */
public: class Sound {
/// \brief Construct new Soundeffect public:
/// \param path Path to the .wav file /// \brief Construct new Soundeffect
/// \param channel the channel 1-23 /// \param path Path to the .wav file
/// \param toloop true:loop the sound, false: don't loop /// \param channel the channel 1-23
sound(const std::string &path, int channel = 1, bool toloop = false); /// \param toloop true:loop the sound, false: don't loop
/// @brief Deconstructor Sound(const std::string &path, int channel = 1, bool toloop = false);
~sound(); /// @brief Deconstructor
/// @brief Play the sound ~Sound();
void play(); RD7_SMART_CTOR(Sound)
/// @brief Stop the sound /// @brief Play the sound
void stop(); void Play();
/// @brief Stop the sound
private: void Stop();
/// \param dataSize Size of the filedata
u32 dataSize; private:
/// \param waveBuf For ndsp /// \param dataSize Size of the filedata
ndspWaveBuf waveBuf; u32 dataSize;
/// \param data Memmory data of the sound /// \param waveBuf For ndsp
uint8_t *data = NULL; ndspWaveBuf waveBuf;
/// \param chnl Channel of the sound /// \param data Memmory data of the sound
int chnl; uint8_t *data = NULL;
}; /// \param chnl Channel of the sound
int chnl;
};

View File

@ -23,6 +23,7 @@
#include <renderd7/Image.hpp> #include <renderd7/Image.hpp>
#include <renderd7/Sheet.hpp> #include <renderd7/Sheet.hpp>
#include <renderd7/smart_ctor.hpp>
namespace RenderD7 { namespace RenderD7 {
/// @brief Sprite Class /// @brief Sprite Class
@ -32,13 +33,14 @@ class Sprite {
Sprite() = default; Sprite() = default;
/// \brief Deconstruct Sprite /// \brief Deconstruct Sprite
~Sprite() = default; ~Sprite() = default;
RD7_SMART_CTOR(Sprite)
/// \brief Load a Sprite From SpriteSheet /// \brief Load a Sprite From SpriteSheet
/// \param sheet the Sheet to load from.(RenderD7::Sheet) /// \param sheet the Sheet to load from.(RenderD7::Sheet)
/// \param index the number of the Sprite in the Sheet /// \param index the number of the Sprite in the Sheet
void FromSheet(RenderD7::Sheet *sheet, size_t index); void FromSheet(RenderD7::Sheet *sheet, size_t index);
/// \brief Load a Sprite From SpriteSheet /// \brief Load a Sprite From SpriteSheet
/// \param img the Image to load from.(RenderD7::Image) /// \param img the Image to load from.(RenderD7::Image)
void FromImage(RenderD7::Image *img); void FromImage(RenderD7::Image::Ref img);
/// @brief Draw the Sprite /// @brief Draw the Sprite
/// @return success ? /// @return success ?
bool Draw(); bool Draw();
@ -62,16 +64,21 @@ class Sprite {
void Rotate(float speed); void Rotate(float speed);
/// @brief Get Tje Sprite's Width /// @brief Get Tje Sprite's Width
/// @return Width /// @return Width
float getWidth(); float GetWidth();
/// @brief Get the Sprite's Height /// @brief Get the Sprite's Height
/// @return Height /// @return Height
float getHeight(); float GetHeight();
/// @brief Get The Sprite's X Position /// @brief Get The Sprite's X Position
/// @return X Position /// @return X Position
float getPosX(); float GetPosX();
/// @brief Get the Sprite's Y Position /// @brief Get the Sprite's Y Position
/// @return Y Position /// @return Y Position
float getPosY(); float GetPosY();
R7Vec2 GetSize();
R7Vec2 GetPos();
void SetPos(R7Vec2 pos);
void SetScale(R7Vec2 scale);
void SetRotCenter(R7Vec2 percentage);
private: private:
/// @param tint ImageTint (unused) /// @param tint ImageTint (unused)

View File

@ -18,8 +18,9 @@
#pragma once #pragma once
#include <renderd7/DrawV2.hpp> #include <renderd7/Image.hpp>
#include <renderd7/R7Vec.hpp> #include <renderd7/R7Vec.hpp>
#include <renderd7/Render2.hpp>
#include <renderd7/smart_ctor.hpp> #include <renderd7/smart_ctor.hpp>
// UI7: The new RenderD7 UI Standart based on // UI7: The new RenderD7 UI Standart based on
@ -80,7 +81,7 @@ void Label(const std::string &label, RD7TextFlags flags = 0);
void Progressbar(float value); void Progressbar(float value);
/// @brief Draw Image in Menu /// @brief Draw Image in Menu
/// @param img Pointer f.e to RenderD7::Image2 /// @param img Pointer f.e to RenderD7::Image2
void Image(RenderD7::Image *img); void Image(RenderD7::Image::Ref img);
void BrowserList(const std::vector<std::string> &entrys, int &selection, void BrowserList(const std::vector<std::string> &entrys, int &selection,
RD7TextFlags txtflags = 0, R7Vec2 size = R7Vec2(0, 0), RD7TextFlags txtflags = 0, R7Vec2 size = R7Vec2(0, 0),
int max_entrys = 13); int max_entrys = 13);

View File

@ -40,6 +40,7 @@
#include <renderd7/Memory.hpp> #include <renderd7/Memory.hpp>
#include <renderd7/Overlays.hpp> #include <renderd7/Overlays.hpp>
#include <renderd7/Ovl.hpp> #include <renderd7/Ovl.hpp>
#include <renderd7/Render2.hpp>
#include <renderd7/ResultDecoder.hpp> #include <renderd7/ResultDecoder.hpp>
#include <renderd7/Screen.hpp> #include <renderd7/Screen.hpp>
#include <renderd7/Sheet.hpp> #include <renderd7/Sheet.hpp>
@ -67,6 +68,8 @@ extern int rd7_max_objects;
extern bool rd7_enable_scene_system; extern bool rd7_enable_scene_system;
namespace RenderD7 { namespace RenderD7 {
// Reference to the New Renderer
R2Base::Ref R2();
/// @brief Get Deltatime /// @brief Get Deltatime
/// @return Deltatime /// @return Deltatime
float GetDeltaTime(); float GetDeltaTime();

View File

@ -1,288 +0,0 @@
/**
* This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <citro2d.h>
#include <renderd7/DrawV2.hpp>
#include <renderd7/global_db.hpp>
#include <renderd7/internal_db.hpp>
const float rd7i_d7_dts = 0.5f;
float rd7i_d2_txt_size = rd7i_d7_dts;
C2D_Font rd7i_d2_fnt = nullptr;
C2D_Font rd7i_d2_fntb = nullptr;
R7Vec2 rd7i_d7_mwh = R7Vec2(0, 0);
std::map<std::string, float> rd7i_d2_ts;
std::map<std::string, int> rd7i_d2_mln;
bool rd7i_txt_init = false;
std::string GetShortedText(const std::string &in, int maxlen) {
auto textdim = RenderD7::GetTextDimensions(in);
if (textdim.x < (float)maxlen) return in;
std::string ft = "";
std::string worker = in;
if (in.find_last_of('.') != in.npos) {
ft = in.substr(in.find_last_of('.'));
worker = in.substr(0, in.find_last_of('.'));
}
maxlen -= RenderD7::GetTextDimensions(ft).x -
RenderD7::GetTextDimensions("(...)").x;
float len_mod = (float)maxlen / textdim.x;
int pos = (in.length() * len_mod) / rd7_draw2_tsm;
std::string out;
out = in.substr(0, pos);
for (size_t i = pos; i < worker.length(); i++) {
out += worker[i];
if (RenderD7::GetTextDimensions(out + "(...)" + ft).x > (float)maxlen) {
out += "(...)";
out += ft;
return out;
}
}
return ""; // Impossible to reach
}
std::string WrapText(const std ::string &in, int maxlen) {
std::string out;
std::string line;
int line_x = 0;
std::istringstream istream(in);
std::string temp;
while (istream >> temp) {
R7Vec2 dim = RenderD7::GetTextDimensions(line + temp);
if (line_x + dim.x <= maxlen) {
line += temp + ' ';
line_x += dim.x;
} else {
out += line + '\n';
line = temp + ' ';
line_x = dim.x;
}
}
out += line;
return out;
}
bool RD7I_FNT_VALID() {
if (rd7i_d2_fnt != nullptr && !rd7i_txt_init) {
rd7i_txt_init = true;
}
if (!rd7i_txt_init) {
if (rd7i_base_font != nullptr) {
rd7i_d2_fnt = rd7i_base_font;
rd7i_txt_init = true;
return true;
}
}
if (rd7i_d2_fnt != nullptr) {
return true;
} else {
rd7i_d2_fnt = rd7i_base_font;
return true;
}
// Schould never be reached
return false;
}
namespace RenderD7 {
// TODO: Fix wrong Width/Height on other fonts
R7Vec2 GetTextDimensions(const std::string &text) {
C2D_TextBufClear(rd7i_d2_dimbuf);
float w = 0, h = 0;
if (!RD7I_FNT_VALID()) return R7Vec2(w, h);
C2D_Text c2dtext;
C2D_TextFontParse(&c2dtext, rd7i_d2_fnt, rd7i_d2_dimbuf, text.c_str());
C2D_TextGetDimensions(&c2dtext, rd7i_d2_txt_size, rd7i_d2_txt_size, &w, &h);
return R7Vec2(w, h);
}
void CustomTextSize(float size) { rd7i_d2_txt_size = size; }
void TextDefaultSize() { rd7i_d2_txt_size = rd7i_d7_dts; }
void TextMaxBox(R7Vec2 size) { rd7i_d7_mwh = size; }
void TextDefaultBox() { rd7i_d7_mwh = R7Vec2(0, 0); }
void TextFont(Font::Ref fnt) {
rd7i_d2_fntb = rd7i_d2_fnt;
rd7i_d2_fnt = fnt->Ptr();
}
void TextFontRestore() {
// Create temp copy
// Restore other font
// Set other to temp
auto tmp = rd7i_d2_fnt;
rd7i_d2_fnt = rd7i_d2_fntb;
rd7i_d2_fntb = tmp;
}
void TextDefaultFont() {
rd7i_d2_fntb = rd7i_d2_fnt;
rd7i_d2_fnt = rd7i_base_font;
}
float TextGetSize() { return rd7i_d2_txt_size; }
std::string TextShort(const std::string &in, int max_len) {
return GetShortedText(in, max_len);
}
namespace Draw2 {
void Scissor(R7Vec2 pos, R7Vec2 size) {
// TODO: Seems not correct yet
C3D_SetScissor(GPU_SCISSOR_NORMAL, GSP_SCREEN_WIDTH - pos.y - size.y, pos.x,
GSP_SCREEN_WIDTH - pos.y, pos.x + size.x);
}
void ScissorReset() { C3D_SetScissor(GPU_SCISSOR_DISABLE, 0, 0, 0, 0); }
void Rect(R7Vec2 pos, R7Vec2 size, unsigned int color, int t) {
// 4 DrawLine Calls Lol
C2D_DrawLine(pos.x, pos.y, color, pos.x + size.x, pos.y, color, t, 1.f);
C2D_DrawLine(pos.x, pos.y, color, pos.x, pos.y + size.y, color, t, 1.f);
C2D_DrawLine(pos.x + size.x, pos.y, color, pos.x + size.x, pos.y + size.y,
color, t, 1.f);
C2D_DrawLine(pos.x, pos.y + size.y, color, pos.x + size.x, pos.y + size.y,
color, t, 1.f);
}
void RectFilled(R7Vec2 pos, R7Vec2 size, Color4 colors) {
C2D_DrawRectangle(pos.x, pos.y, 0.5f, size.x, size.y, colors.color0,
colors.color1, colors.color2, colors.color3);
}
void RectFilledSolid(R7Vec2 pos, R7Vec2 size, unsigned int color) {
C2D_DrawRectSolid(pos.x, pos.y, 0.5f, size.x, size.y, color);
}
void Line(R7Vec2 pos0, R7Vec2 pos1, unsigned int color, int t) {
C2D_DrawLine(pos0.x, pos0.y, color, pos1.x, pos1.y, color, t, 1.f);
}
void Triangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, Color3 colors) {
C2D_DrawTriangle(pos0.x, pos0.y, colors.color0, pos1.x, pos1.y, colors.color1,
pos2.x, pos2.y, colors.color2, 0.5f);
}
void TriangleSolid(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, unsigned int color) {
C2D_DrawTriangle(pos0.x, pos0.y, color, pos1.x, pos1.y, color, pos2.x, pos2.y,
color, 0.5f);
}
void TriangleLined(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, unsigned int color,
int t) {
// 3 Line Cqalls lol more efficient than Rect
C2D_DrawLine(pos0.x, pos0.y, color, pos1.x, pos1.y, color, t, 1.f);
C2D_DrawLine(pos0.x, pos0.y, color, pos2.x, pos2.y, color, t, 1.f);
C2D_DrawLine(pos1.x, pos1.y, color, pos2.x, pos2.y, color, t, 1.f);
}
void Text(R7Vec2 pos, const std::string &text, RD7TextFlags flags) {
TextClr(pos, text, RenderD7::ThemeActive()->Get(RD7Color_Text), flags);
}
void TextClr(R7Vec2 pos, const std::string &text, unsigned int color,
RD7TextFlags flags) {
// The Start of the C2D Text Hell
if (!RD7I_FNT_VALID()) return;
// Check if Theme Loadet
if (!ThemeActive()) return;
// little patch for a freeze
if (text.length() < 1) return;
// Variables
bool updated_mwh = false;
if (rd7i_d7_mwh.x == 0.0f) {
rd7i_d7_mwh.x = rd7i_current_screen ? 400 : 320;
updated_mwh = true;
}
if (rd7i_d7_mwh.y == 0.0f) {
rd7i_d7_mwh.y = 240;
updated_mwh = true;
}
std::string edit_text = text;
if (edit_text.substr(text.length() - 1) != "\n")
edit_text.append("\n"); // Add \n to end if not exist
int line = 0;
if (flags & RD7TextFlags_Wrap)
edit_text = WrapText(text, rd7i_d7_mwh.x - pos.x);
while (edit_text.find('\n') != edit_text.npos) {
std::string current_line = edit_text.substr(0, edit_text.find('\n'));
if (flags & RD7TextFlags_Short)
current_line = GetShortedText(current_line, rd7i_d7_mwh.x - pos.x);
R7Vec2 newpos = pos;
// Check Flags
R7Vec2 dim = GetTextDimensions(current_line);
if (flags & RD7TextFlags_AlignRight)
newpos.x = newpos.x - GetTextDimensions(current_line).x;
if (flags & RD7TextFlags_AlignMid) // Offset by inpos
newpos.x = (rd7i_d7_mwh.x * 0.5) - (dim.x * 0.5) + pos.x;
if (flags & RD7TextFlags_Scroll) { // Scroll Text
if (newpos.x + dim.x > rd7i_d7_mwh.x - newpos.x - 10) {
if (rd7i_d2_ts.find(current_line) == rd7i_d2_ts.end())
rd7i_d2_ts[current_line] = 0;
if (rd7i_d2_mln.find(current_line) == rd7i_d2_mln.end())
rd7i_d2_mln[current_line] =
GetShortedText(current_line, rd7i_d7_mwh.x - newpos.x).length();
rd7i_d2_ts[current_line] += rd7i_dtm * 6;
if ((int)rd7i_d2_ts[current_line] >= (int)current_line.length()) {
rd7i_d2_ts[current_line] = 0.0f;
}
std::string bcl = current_line;
current_line = current_line.substr((int)rd7i_d2_ts[current_line],
rd7i_d2_mln[current_line]);
if (newpos.x + GetTextDimensions(current_line).x <
rd7i_d7_mwh.x - newpos.x)
current_line +=
"|" + bcl.substr(0, rd7i_d2_ts[bcl] - (int)current_line.length());
}
}
if (rd7_debugging) {
RenderD7::Draw2::Rect(newpos, dim, RenderD7::Color::Hex("#ff0000"));
}
C2D_Text c2dtext;
C2D_TextFontParse(&c2dtext, rd7i_d2_fnt, rd7i_text_buffer,
current_line.c_str());
C2D_TextOptimize(&c2dtext);
if (flags & RD7TextFlags_Shaddow) // performance Killer xd
C2D_DrawText(&c2dtext, C2D_WithColor, newpos.x + 1 + (dim.y * line),
newpos.y + 1, 0.5, rd7i_d2_txt_size, rd7i_d2_txt_size,
RenderD7::ThemeActive()->Get(RD7Color_TextDisabled));
C2D_DrawText(&c2dtext, C2D_WithColor, newpos.x, newpos.y + (dim.y * line),
0.5, rd7i_d2_txt_size, rd7i_d2_txt_size, color);
edit_text = edit_text.substr(edit_text.find('\n') + 1);
line++;
}
if (updated_mwh) rd7i_d7_mwh = R7Vec2(0, 0);
}
void Image(RenderD7::Image *img, const R7Vec2 &pos, const R7Vec2 &scale) {
if (img->loaded())
C2D_DrawImageAt(img->get(), pos.x, pos.y, 0.5f, nullptr, scale.x, scale.y);
}
} // namespace Draw2
} // namespace RenderD7

View File

@ -111,7 +111,7 @@ Image::Image() {
Image::~Image() { safe_del(); } Image::~Image() { safe_del(); }
void Image::load(const std::string &path) { void Image::Load(const std::string &path) {
// Make sure to cleanup // Make sure to cleanup
safe_del(); safe_del();
ld = false; ld = false;
@ -149,7 +149,7 @@ void Image::load(const std::string &path) {
ld = true; ld = true;
} }
void Image::from_nimg(const nimg &image) { void Image::From_NIMG(const nimg &image) {
// Make sure to cleanup // Make sure to cleanup
safe_del(); safe_del();
ld = false; ld = false;
@ -164,15 +164,15 @@ void Image::from_nimg(const nimg &image) {
ld = true; ld = true;
} }
C2D_Image Image::get() { return img; } C2D_Image Image::Get() { return img; }
C2D_Image &Image::get_ref() { return img; } C2D_Image &Image::GetRef() { return img; }
void Image::set(const C2D_Image &i) { void Image::Set(const C2D_Image &i) {
safe_del(); safe_del();
img = i; img = i;
} }
R7Vec2 Image::get_size() { R7Vec2 Image::GetSize() {
if (!img.subtex) return R7Vec2(0, 0); if (!img.subtex) return R7Vec2(0, 0);
return R7Vec2(img.subtex->width, img.subtex->height); return R7Vec2(img.subtex->width, img.subtex->height);
} }
@ -182,5 +182,5 @@ void Image::safe_del() {
if (img.tex != nullptr) delete img.tex; if (img.tex != nullptr) delete img.tex;
} }
bool Image::loaded() { return ld; } bool Image::Loadet() { return ld; }
} // namespace RenderD7 } // namespace RenderD7

View File

@ -24,7 +24,6 @@ static RenderD7::Memory::memory_metrics metrics;
bool rd7_enable_memtrack; bool rd7_enable_memtrack;
#ifdef RENDERD7_MEMTRACK
void *operator new(size_t size) { void *operator new(size_t size) {
void *ptr = malloc(size); void *ptr = malloc(size);
if (rd7_enable_memtrack) metrics.t_TotalAllocated += size; if (rd7_enable_memtrack) metrics.t_TotalAllocated += size;
@ -41,24 +40,27 @@ int total_size = 0;
std::map<void *, size_t> sizes; std::map<void *, size_t> sizes;
void *operator new[](size_t size) { void *operator new[](size_t size) {
if (rd7_enable_memtrack) allocations++;
if (rd7_enable_memtrack) total_size += size;
void *ptr = malloc(size); void *ptr = malloc(size);
if (rd7_enable_memtrack) sizes[ptr] = size; if (rd7_enable_memtrack) {
if (rd7_enable_memtrack) metrics.t_TotalAllocated += size; allocations++;
total_size += size;
sizes[ptr] = size;
metrics.t_TotalAllocated += size;
}
return ptr; return ptr;
} }
void operator delete[](void *ptr) { void operator delete[](void *ptr) {
if (rd7_enable_memtrack) allocations--; if (rd7_enable_memtrack) {
if (rd7_enable_memtrack) total_size -= sizes[ptr]; allocations--;
if (rd7_enable_memtrack) metrics.t_TotalFreed += sizes[ptr]; total_size -= sizes[ptr];
if (rd7_enable_memtrack) sizes.erase(ptr); metrics.t_TotalFreed += sizes[ptr];
sizes.erase(ptr);
}
free(ptr); free(ptr);
} }
#endif
namespace RenderD7 { namespace RenderD7 {
namespace Memory { namespace Memory {

View File

@ -19,9 +19,9 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <renderd7/Color.hpp> #include <renderd7/Color.hpp>
#include <renderd7/DrawV2.hpp> // Update to Draw2
#include <renderd7/Message.hpp> #include <renderd7/Message.hpp>
#include <renderd7/Screen.hpp> #include <renderd7/Screen.hpp>
#include <renderd7/renderd7.hpp>
#include <vector> #include <vector>
extern bool rd7_debugging; extern bool rd7_debugging;
@ -45,10 +45,10 @@ namespace RenderD7 {
float GetDeltaTime(); // Extern from renderd7.cpp float GetDeltaTime(); // Extern from renderd7.cpp
void ProcessMessages() { void ProcessMessages() {
float tmp_txt = RenderD7::TextGetSize(); float tmp_txt = R2()->GetTextSize();
RenderD7::TextDefaultSize(); R2()->DefaultTextSize();
// Draw in ovl mode // Draw in ovl mode
RenderD7::OnScreen(Top); R2()->OnScreen(R2Screen_Top);
float fol = anim_len - fade_outs; float fol = anim_len - fade_outs;
std::reverse(msg_lst.begin(), msg_lst.end()); std::reverse(msg_lst.begin(), msg_lst.end());
for (size_t i = 0; i < msg_lst.size(); i++) { for (size_t i = 0; i < msg_lst.size(); i++) {
@ -65,23 +65,17 @@ void ProcessMessages() {
200 - (float(msg_lst[i]->animationframe - fade_outs) / fol) * 200; 200 - (float(msg_lst[i]->animationframe - fade_outs) / fol) * 200;
} }
// Wtf is this function lol // Wtf is this function lol
RenderD7::ThemeActive()->Set( auto bgc = RenderD7::Color::RGBA(RD7Color_MessageBackground)
RD7Color_MessageBackground, .changeA(new_alpha)
RenderD7::Color::RGBA(RD7Color_MessageBackground) .toRGBA();
.changeA(new_alpha) auto tc =
.toRGBA()); RenderD7::Color::RGBA(RD7Color_Text2).changeA(new_alpha).toRGBA();
RenderD7::ThemeActive()->Set( R2()->AddRect(pos, R7Vec2(150, 50), bgc);
RD7Color_Text, R2()->AddText(pos + R7Vec2(5, 1), msg_lst[i]->title, tc);
RenderD7::Color::RGBA(RD7Color_Text2).changeA(new_alpha).toRGBA()); R2()->AddText(pos + R7Vec2(5, 17), msg_lst[i]->message, tc);
RenderD7::Draw2::RFS(
pos, R7Vec2(150, 50),
RenderD7::ThemeActive()->Get(RD7Color_MessageBackground));
RenderD7::Draw2::Text(pos + R7Vec2(5, 1), msg_lst[i]->title);
RenderD7::Draw2::Text(pos + R7Vec2(5, 17), msg_lst[i]->message);
if (rd7_debugging) if (rd7_debugging)
RenderD7::Draw2::Text(pos + R7Vec2(155, 1), R2()->AddText(pos + R7Vec2(155, 1),
std::to_string(msg_lst[i]->animationframe)); std::to_string(msg_lst[i]->animationframe), tc);
RenderD7::ThemeActive()->UndoAll();
// Why Frameadd? because Message uses int as frame and // Why Frameadd? because Message uses int as frame and
// It seems that lower 0.5 will be rounded to 0 // It seems that lower 0.5 will be rounded to 0
// Why not replace int with float ? // Why not replace int with float ?
@ -103,7 +97,7 @@ void ProcessMessages() {
// ReReverse ?? lol // ReReverse ?? lol
// Cause otherwise the Toasts will swap // Cause otherwise the Toasts will swap
std::reverse(msg_lst.begin(), msg_lst.end()); std::reverse(msg_lst.begin(), msg_lst.end());
RenderD7::CustomTextSize(tmp_txt); R2()->SetTextSize(tmp_txt);
} }
void PushMessage(const Message &msg) { void PushMessage(const Message &msg) {

View File

@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <renderd7/DrawV2.hpp>
#include <renderd7/FunctionTrace.hpp> #include <renderd7/FunctionTrace.hpp>
#include <renderd7/Hid.hpp> #include <renderd7/Hid.hpp>
#include <renderd7/Overlays.hpp> #include <renderd7/Overlays.hpp>
@ -286,22 +285,22 @@ namespace RenderD7 {
Ovl_Ftrace::Ovl_Ftrace(bool* is_enabled) { i_is_enabled = is_enabled; } Ovl_Ftrace::Ovl_Ftrace(bool* is_enabled) { i_is_enabled = is_enabled; }
void Ovl_Ftrace::Draw(void) const { void Ovl_Ftrace::Draw(void) const {
float tmp_txt = RenderD7::TextGetSize(); float tmp_txt = R2()->GetTextSize();
RenderD7::TextDefaultSize(); R2()->DefaultTextSize();
RenderD7::OnScreen(Top); R2()->OnScreen(R2Screen_Top);
RenderD7::Color::RGBA bg(RD7Color_Background); RenderD7::Color::RGBA bg(RD7Color_Background);
bg.changeA(150); bg.changeA(150);
RenderD7::Draw2::RFS(R7Vec2(0, 0), R7Vec2(400, 20), bg.toRGBA()); R2()->AddRect(R7Vec2(0, 0), R7Vec2(400, 20), bg.toRGBA());
std::vector<RenderD7::Ftrace::FTRes> dt; std::vector<RenderD7::Ftrace::FTRes> dt;
for (auto const& it : RenderD7::Ftrace::rd7_traces) for (auto const& it : RenderD7::Ftrace::rd7_traces)
if (it.second.is_ovl && dt.size() < 10) dt.push_back(it.second); if (it.second.is_ovl && dt.size() < 10) dt.push_back(it.second);
for (size_t i = 0; i < (dt.size() < 10 ? dt.size() : 10); i++) { for (size_t i = 0; i < (dt.size() < 10 ? dt.size() : 10); i++) {
RenderD7::Draw2::Text(R7Vec2(5, 30 + i * 15), dt[i].func_name); R2()->AddText(R7Vec2(5, 30 + i * 15), dt[i].func_name, RD7Color_Text);
RenderD7::Draw2::Text(R7Vec2(295, 30 + i * 15), R2()->AddText(R7Vec2(295, 30 + i * 15), RenderD7::MsTimeFmt(dt[i].time_of),
RenderD7::MsTimeFmt(dt[i].time_of)); RD7Color_Text);
} }
RenderD7::CustomTextSize(tmp_txt); R2()->SetTextSize(tmp_txt);
} }
void Ovl_Ftrace::Logic() { void Ovl_Ftrace::Logic() {
@ -318,16 +317,12 @@ Ovl_Metrik::Ovl_Metrik(bool* is_enabled, bool* screen, uint32_t* mt_color,
} }
void Ovl_Metrik::Draw(void) const { void Ovl_Metrik::Draw(void) const {
float tmp_txt = RenderD7::TextGetSize(); float tmp_txt = R2()->GetTextSize();
RenderD7::TextDefaultSize(); R2()->DefaultTextSize();
if (i_screen[0]) { R2()->OnScreen(i_screen[0] ? R2Screen_Bottom : R2Screen_Top);
RenderD7::OnScreen(Bottom);
} else {
RenderD7::OnScreen(Top);
}
std::string info = std::string info =
"RenderD7 " + std::string(RENDERD7VSTRING) + " Debug Overlay"; "RenderD7 " + std::string(RENDERD7VSTRING) + " Debug Overlay";
float dim_y = RenderD7::GetTextDimensions(info).y; float dim_y = R2()->GetTextDimensions(info).y;
float infoy = 240 - dim_y; float infoy = 240 - dim_y;
mt_fps = "FPS: " + RenderD7::GetFramerate(); mt_fps = "FPS: " + RenderD7::GetFramerate();
if (rd7i_idb_running) mt_fps += " IDB -> ON"; if (rd7i_idb_running) mt_fps += " IDB -> ON";
@ -346,41 +341,54 @@ void Ovl_Metrik::Draw(void) const {
mt_tbs = mt_tbs =
"TextBuf: " + std::to_string(C2D_TextBufGetNumGlyphs(rd7i_text_buffer)) + "TextBuf: " + std::to_string(C2D_TextBufGetNumGlyphs(rd7i_text_buffer)) +
"/4096"; "/4096";
RenderD7::Draw2::RFS(R7Vec2(0, 0), RenderD7::GetTextDimensions(mt_fps), if (rd7_enable_memtrack)
i_mt_color[0]); mt_mem = "Mem: " + RenderD7::FormatBytes(RenderD7::Memory::GetCurrent()) +
RenderD7::Draw2::RFS(R7Vec2(0, 50), RenderD7::GetTextDimensions(mt_cpu), " | " +
i_mt_color[0]); RenderD7::FormatBytes(RenderD7::Memory::GetTotalAllocated()) +
RenderD7::Draw2::RFS(R7Vec2(0, 50 + dim_y * 1), " | " + RenderD7::FormatBytes(RenderD7::Memory::GetTotalFreed());
RenderD7::GetTextDimensions(mt_gpu), i_mt_color[0]); R2()->AddRect(R7Vec2(0, 0), R2()->GetTextDimensions(mt_fps),
RenderD7::Draw2::RFS(R7Vec2(0, 50 + dim_y * 2), (unsigned int)i_mt_color[0]);
RenderD7::GetTextDimensions(mt_cmd), i_mt_color[0]); R2()->AddRect(R7Vec2(0, 50), R2()->GetTextDimensions(mt_cpu),
RenderD7::Draw2::RFS(R7Vec2(0, 50 + dim_y * 3), (unsigned int)i_mt_color[0]);
RenderD7::GetTextDimensions(mt_lfr), i_mt_color[0]); R2()->AddRect(R7Vec2(0, 50 + dim_y * 1), R2()->GetTextDimensions(mt_gpu),
RenderD7::Draw2::RFS(R7Vec2(0, 50 + dim_y * 4), (unsigned int)i_mt_color[0]);
RenderD7::GetTextDimensions(mt_tbs), i_mt_color[0]); R2()->AddRect(R7Vec2(0, 50 + dim_y * 2), R2()->GetTextDimensions(mt_cmd),
RenderD7::Draw2::RFS(R7Vec2(0, infoy), RenderD7::GetTextDimensions(info), (unsigned int)i_mt_color[0]);
i_mt_color[0]); R2()->AddRect(R7Vec2(0, 50 + dim_y * 3), R2()->GetTextDimensions(mt_lfr),
RenderD7::ThemeActive()->Set(RD7Color_Text, i_txt_color[0]); (unsigned int)i_mt_color[0]);
RenderD7::Draw2::Text(R7Vec2(0, 0), mt_fps); R2()->AddRect(R7Vec2(0, 50 + dim_y * 4), R2()->GetTextDimensions(mt_tbs),
RenderD7::Draw2::Text(R7Vec2(0, 50), mt_cpu); (unsigned int)i_mt_color[0]);
RenderD7::Draw2::Text(R7Vec2(0, 50 + dim_y * 1), mt_gpu); if (rd7_enable_memtrack)
RenderD7::Draw2::Text(R7Vec2(0, 50 + dim_y * 2), mt_cmd); R2()->AddRect(R7Vec2(0, 50 + dim_y * 5), R2()->GetTextDimensions(mt_mem),
RenderD7::Draw2::Text(R7Vec2(0, 50 + dim_y * 3), mt_lfr); (unsigned int)i_mt_color[0]);
RenderD7::Draw2::Text(R7Vec2(0, 50 + dim_y * 4), mt_tbs); R2()->AddRect(R7Vec2(0, infoy), R2()->GetTextDimensions(info),
RenderD7::Draw2::Text(R7Vec2(0, infoy), info); (unsigned int)i_mt_color[0]);
RenderD7::ThemeActive()->Undo(); R2()->AddText(R7Vec2(0, 0), mt_fps, (unsigned int)i_txt_color[0]);
R2()->AddText(R7Vec2(0, 50), mt_cpu, (unsigned int)i_txt_color[0]);
R2()->AddText(R7Vec2(0, 50 + dim_y * 1), mt_gpu,
(unsigned int)i_txt_color[0]);
R2()->AddText(R7Vec2(0, 50 + dim_y * 2), mt_cmd,
(unsigned int)i_txt_color[0]);
R2()->AddText(R7Vec2(0, 50 + dim_y * 3), mt_lfr,
(unsigned int)i_txt_color[0]);
R2()->AddText(R7Vec2(0, 50 + dim_y * 4), mt_tbs,
(unsigned int)i_txt_color[0]);
if (rd7_enable_memtrack)
R2()->AddText(R7Vec2(0, 50 + dim_y * 5), mt_mem,
(unsigned int)i_txt_color[0]);
R2()->AddText(R7Vec2(0, infoy), info, (unsigned int)i_txt_color[0]);
// Force Bottom (Debug Touchpos) // Force Bottom (Debug Touchpos)
RenderD7::OnScreen(Bottom); R2()->OnScreen(R2Screen_Bottom);
if (Hid::IsEvent("touch", Hid::Held)) { if (Hid::IsEvent("touch", Hid::Held)) {
RenderD7::Draw2::Line(R7Vec2(Hid::GetTouchPosition().x, 0), /*R2()->AddLine(R7Vec2(Hid::GetTouchPosition().x, 0),
R7Vec2(Hid::GetTouchPosition().x, 240), R7Vec2(Hid::GetTouchPosition().x, 240),
RenderD7::Color::Hex("#ff0000")); RenderD7::Color::Hex("#ff0000"));
RenderD7::Draw2::Line(R7Vec2(0, Hid::GetTouchPosition().y), R2()->AddLine(R7Vec2(0, Hid::GetTouchPosition().y),
R7Vec2(320, Hid::GetTouchPosition().y), R7Vec2(320, Hid::GetTouchPosition().y),
RenderD7::Color::Hex("#ff0000")); RenderD7::Color::Hex("#ff0000"));*/
} }
RenderD7::CustomTextSize(tmp_txt); R2()->SetTextSize(tmp_txt);
} }
void Ovl_Metrik::Logic() { void Ovl_Metrik::Logic() {
@ -406,8 +414,8 @@ Ovl_Keyboard::~Ovl_Keyboard() {
} }
void Ovl_Keyboard::Draw(void) const { void Ovl_Keyboard::Draw(void) const {
float tmp_txt = RenderD7::TextGetSize(); float tmp_txt = R2()->GetTextSize();
RenderD7::TextDefaultSize(); R2()->DefaultTextSize();
if (ft3 > 5) RenderD7::Hid::Unlock(); if (ft3 > 5) RenderD7::Hid::Unlock();
auto key_table = auto key_table =
(type == RD7Keyboard_Numpad) ? keyboard_layout_num : keyboard_layout; (type == RD7Keyboard_Numpad) ? keyboard_layout_num : keyboard_layout;
@ -415,23 +423,18 @@ void Ovl_Keyboard::Draw(void) const {
key_table = keyboard_layout_caps; key_table = keyboard_layout_caps;
else if (mode == 2) else if (mode == 2)
key_table = keyboard_layout_shift; key_table = keyboard_layout_shift;
RenderD7::OnScreen(Top); R2()->OnScreen(R2Screen_Top);
RenderD7::Draw2::RFS( R2()->AddRect(R7Vec2(0, 0), R7Vec2(400, 240),
R7Vec2(0, 0), R7Vec2(400, 240), RenderD7::Color::RGBA(RD7Color_FrameBg).changeA(150).toRGBA());
RenderD7::Color::RGBA(RD7Color_FrameBg).changeA(150).toRGBA()); R2()->OnScreen(R2Screen_Bottom);
RenderD7::OnScreen(Bottom); R2()->AddRect(R7Vec2(0, 0), R7Vec2(320, 112),
RenderD7::Draw2::RFS( RenderD7::Color::RGBA(RD7Color_FrameBg).changeA(150).toRGBA());
R7Vec2(0, 0), R7Vec2(320, 112), R2()->AddRect(R7Vec2(0, 112), R7Vec2(320, 128), RD7Color_FrameBg);
RenderD7::Color::RGBA(RD7Color_FrameBg).changeA(150).toRGBA()); R2()->AddRect(R7Vec2(0, 112), R7Vec2(320, 20), RD7Color_Header);
RenderD7::Draw2::RFS(R7Vec2(0, 112), R7Vec2(320, 128), R2()->AddText(R7Vec2(5, 114), "> " + *typed_text,
RenderD7::ThemeActive()->Get(RD7Color_FrameBg)); RenderD7::ThemeActive()->AutoText(RD7Color_Header));
RenderD7::Draw2::RFS(R7Vec2(0, 112), R7Vec2(320, 20),
RenderD7::ThemeActive()->Get(RD7Color_Header));
RenderD7::ThemeActive()->TextBy(RD7Color_Header);
RenderD7::Draw2::Text(R7Vec2(5, 114), "> " + *typed_text);
RenderD7::ThemeActive()->Undo();
for (auto const& it : key_table) { for (auto const& it : key_table) {
R7Vec2 txtdim = RenderD7::GetTextDimensions(it.disp); R7Vec2 txtdim = R2()->GetTextDimensions(it.disp);
R7Vec2 txtpos = R7Vec2(it.pos.x + it.size.x * 0.5 - txtdim.x * 0.5, R7Vec2 txtpos = R7Vec2(it.pos.x + it.size.x * 0.5 - txtdim.x * 0.5,
it.pos.y + it.size.y * 0.5 - txtdim.y * 0.5); it.pos.y + it.size.y * 0.5 - txtdim.y * 0.5);
RD7Color btn = RD7Color_Button; RD7Color btn = RD7Color_Button;
@ -466,13 +469,11 @@ void Ovl_Keyboard::Draw(void) const {
UI7_InBox(RenderD7::Hid::GetTouchPosition(), it.pos, it.size)) { UI7_InBox(RenderD7::Hid::GetTouchPosition(), it.pos, it.size)) {
btn = RD7Color_ButtonHovered; btn = RD7Color_ButtonHovered;
} }
RenderD7::Draw2::RFS(it.pos, it.size, RenderD7::ThemeActive()->Get(btn)); R2()->AddRect(it.pos, it.size, btn);
RenderD7::ThemeActive()->TextBy(btn); R2()->AddText(txtpos, it.disp, RenderD7::ThemeActive()->AutoText(btn));
RenderD7::Draw2::Text(txtpos, it.disp);
RenderD7::ThemeActive()->Undo();
} }
if (ft3 > 5) RenderD7::Hid::Lock(); if (ft3 > 5) RenderD7::Hid::Lock();
RenderD7::CustomTextSize(tmp_txt); R2()->SetTextSize(tmp_txt);
} }
void Ovl_Keyboard::Logic() { void Ovl_Keyboard::Logic() {

View File

@ -1,7 +1,260 @@
/**
* This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <citro2d.h>
#include <renderd7/Render2.hpp> #include <renderd7/Render2.hpp>
#include <renderd7/internal_db.hpp>
namespace RenderD7 { namespace RenderD7 {
R2Base::R2Base() { R2Base::R2Base() { this->font = Font::New(); }
for (int i = 0; i < 2; i++) this->font[i] = Font::New();
void R2Base::SetFont(Font::Ref fnt) {
if (!fnt) return;
this->font = fnt;
} }
Font::Ref R2Base::GetFont() { return this->font; }
void R2Base::DefaultFont() { this->font->Unload(); }
void R2Base::DrawNextLined() { this->next_lined = true; }
void R2Base::OnScreen(R2Screen screen) {
if (screen < 0 || screen > R2Screen_Top) return;
this->current_screen = screen;
}
void R2Base::SetTextSize(float szs) { text_size = szs; }
void R2Base::DefaultTextSize() { text_size = default_text_size; }
float R2Base::GetTextSize() { return text_size; }
R2Screen R2Base::GetCurrentScreen() { return current_screen; }
R7Vec2 R2Base::GetTextDimensions(const std::string& text) {
C2D_TextBufClear(rd7i_d2_dimbuf);
float w = 0, h = 0;
C2D_Text c2dtext;
C2D_TextFontParse(&c2dtext, font->Ptr(), rd7i_d2_dimbuf, text.c_str());
C2D_TextGetDimensions(&c2dtext, this->text_size, this->text_size, &w, &h);
return R7Vec2(w, h);
}
// Main Processing of Draw Calls
void R2Base::Process() {
for (auto& it : this->commands) {
if (it.type <= 0 || it.type > 3) {
// Skip
continue;
}
C2D_SceneBegin(it.Screen ? rd7_top : rd7_bottom);
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.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);
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);
} else {
C2D_DrawRectSolid(it.pos.x, it.pos.y, 0.5, it.pszs.x, it.pszs.y,
it.clr);
}
} 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,
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);
} 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);
}
} else if (it.type == 3) {
// Text
// little patch for a freeze
if (it.text.length() < 1) continue;
if (it.pszs.x == 0.0f) {
it.pszs.x = it.Screen == R2Screen_Top ? 400 : 320;
}
if (it.pszs.y == 0.0f) {
it.pszs.y = 240;
}
std::string edit_text = it.text;
if (edit_text.substr(it.text.length() - 1) != "\n")
edit_text.append("\n"); // Add \n to end if not exist
int line = 0;
// if (it.flags & RD7TextFlags_Wrap)
// edit_text = WrapText(text, rd7i_d7_mwh.x - pos.x);
while (edit_text.find('\n') != edit_text.npos) {
std::string current_line = edit_text.substr(0, edit_text.find('\n'));
// if (it.flags & RD7TextFlags_Short)
// current_line = GetShortedText(current_line, it.pszs.x - it.pos.x);
R7Vec2 newpos = it.pos;
// Check Flags
R7Vec2 dim = this->GetTextDimensions(current_line);
if (it.flags & RD7TextFlags_AlignRight) newpos.x = newpos.x - dim.x;
if (it.flags & RD7TextFlags_AlignMid) // Offset by inpos
newpos.x = (it.pszs.x * 0.5) - (dim.x * 0.5) + it.pos.x;
if (it.flags & RD7TextFlags_Scroll) { // Scroll Text
// Look into Old Draw2 Code
// TODO: Create Code for this
}
if (rd7_debugging) {
this->DrawNextLined();
this->AddRect(newpos, dim, 0xff0000ff);
}
C2D_Text c2dtext;
C2D_TextFontParse(&c2dtext, font->Ptr(), rd7i_text_buffer,
current_line.c_str());
C2D_TextOptimize(&c2dtext);
if (it.flags & RD7TextFlags_Shaddow) // performance Killer xd
C2D_DrawText(&c2dtext, C2D_WithColor, newpos.x + 1 + (dim.y * line),
newpos.y + 1, 0.5, this->text_size, this->text_size,
RenderD7::ThemeActive()->Get(RD7Color_TextDisabled));
C2D_DrawText(&c2dtext, C2D_WithColor, newpos.x,
newpos.y + (dim.y * line), 0.5, this->text_size,
this->text_size, it.clr);
edit_text = edit_text.substr(edit_text.find('\n') + 1);
line++;
}
}
}
this->commands.clear();
}
void R2Base::AddRect(R7Vec2 pos, R7Vec2 size, RD7Color clr) {
R2Cmd cmd;
cmd.pos = pos;
cmd.pszs = size;
cmd.clr = RenderD7::ThemeActive()->Get(clr);
cmd.type = 1; // Rect
// Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true)
cmd.Screen = current_screen;
if (this->next_lined) {
cmd.lined = true;
this->next_lined = false;
}
this->commands.push_back(cmd);
}
void R2Base::AddRect(R7Vec2 pos, R7Vec2 size, unsigned int clr) {
R2Cmd cmd;
cmd.pos = pos;
cmd.pszs = size;
cmd.clr = clr;
cmd.type = 1; // Rect
// Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true)
cmd.Screen = current_screen;
if (this->next_lined) {
cmd.lined = true;
this->next_lined = false;
}
this->commands.push_back(cmd);
}
void R2Base::AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2, RD7Color clr) {
R2Cmd cmd;
cmd.pos = pos0;
cmd.pszs = pos1;
cmd.ap = pos2;
cmd.clr = RenderD7::ThemeActive()->Get(clr);
cmd.type = 2; // Triangle
// Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true)
cmd.Screen = current_screen;
if (this->next_lined) {
cmd.lined = true;
this->next_lined = false;
}
this->commands.push_back(cmd);
}
void R2Base::AddTriangle(R7Vec2 pos0, R7Vec2 pos1, R7Vec2 pos2,
unsigned int clr) {
R2Cmd cmd;
cmd.pos = pos0;
cmd.pszs = pos1;
cmd.ap = pos2;
cmd.clr = clr;
cmd.type = 2; // Triangle
// Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true)
cmd.Screen = current_screen;
if (this->next_lined) {
cmd.lined = true;
this->next_lined = false;
}
this->commands.push_back(cmd);
}
void R2Base::AddText(R7Vec2 pos, const std::string& text, RD7Color clr,
RD7TextFlags flags, R7Vec2 tmb) {
R2Cmd cmd;
cmd.pos = pos;
cmd.pszs = tmb;
cmd.clr = RenderD7::ThemeActive()->Get(clr);
cmd.flags = flags;
cmd.text = text;
cmd.type = 3; // Text
// Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true)
cmd.Screen = current_screen;
if (this->next_lined) {
cmd.lined = true;
this->next_lined = false;
}
this->commands.push_back(cmd);
}
void R2Base::AddText(R7Vec2 pos, const std::string& text, unsigned int clr,
RD7TextFlags flags, R7Vec2 tmb) {
R2Cmd cmd;
cmd.pos = pos;
cmd.pszs = tmb;
cmd.clr = clr;
cmd.flags = flags;
cmd.text = text;
cmd.type = 3; // Text
// Just assign current screen as bottom is 0 (false)
// and Top and TopRight are !0 (true)
cmd.Screen = current_screen;
if (this->next_lined) {
cmd.lined = true;
this->next_lined = false;
}
this->commands.push_back(cmd);
}
} // namespace RenderD7 } // namespace RenderD7

View File

@ -1,149 +1,150 @@
/** /**
* This file is part of RenderD7 * This file is part of RenderD7
* Copyright (C) 2021-2024 NPI-D7, tobid7 * Copyright (C) 2021-2024 NPI-D7, tobid7
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <renderd7/internal_db.hpp> #include <renderd7/Sound2.hpp>
#include <renderd7/sound.hpp> #include <renderd7/internal_db.hpp>
#include <string> #include <string>
using std::string;
using std::string;
// Reference: http://yannesposito.com/Scratch/en/blog/2010-10-14-Fun-with-wav/
typedef struct _WavHeader { // Reference: http://yannesposito.com/Scratch/en/blog/2010-10-14-Fun-with-wav/
char magic[4]; // "RIFF" typedef struct _WavHeader {
u32 totallength; // Total file length, minus 8. char magic[4]; // "RIFF"
char wavefmt[8]; // Should be "WAVEfmt " u32 totallength; // Total file length, minus 8.
u32 format; // 16 for PCM format char wavefmt[8]; // Should be "WAVEfmt "
u16 pcm; // 1 for PCM format u32 format; // 16 for PCM format
u16 channels; // Channels u16 pcm; // 1 for PCM format
u32 frequency; // Sampling frequency u16 channels; // Channels
u32 bytes_per_second; u32 frequency; // Sampling frequency
u16 bytes_by_capture; u32 bytes_per_second;
u16 bits_per_sample; u16 bytes_by_capture;
char data[4]; // "data" u16 bits_per_sample;
u32 bytes_in_data; char data[4]; // "data"
} WavHeader; u32 bytes_in_data;
static_assert(sizeof(WavHeader) == 44, "WavHeader size is not 44 bytes."); } WavHeader;
static_assert(sizeof(WavHeader) == 44, "WavHeader size is not 44 bytes.");
sound::sound(const string &path, int channel, bool toloop) {
if (rd7i_is_ndsp) { Sound::Sound(const string &path, int channel, bool toloop) {
ndspSetOutputMode(NDSP_OUTPUT_STEREO); if (rd7i_is_ndsp) {
ndspSetOutputCount(2); // Num of buffers ndspSetOutputMode(NDSP_OUTPUT_STEREO);
ndspSetOutputCount(2); // Num of buffers
// Reading wav file
std::fstream fp(path, std::ios::in | std::ios::binary); // Reading wav file
std::fstream fp(path, std::ios::in | std::ios::binary);
if (!fp.is_open()) {
printf("Could not open the WAV file: %s\n", path.c_str()); if (!fp.is_open()) {
return; printf("Could not open the WAV file: %s\n", path.c_str());
} return;
}
WavHeader wavHeader;
fp.read(reinterpret_cast<char *>(&wavHeader), sizeof(WavHeader)); WavHeader wavHeader;
size_t read = fp.tellg(); fp.read(reinterpret_cast<char *>(&wavHeader), sizeof(WavHeader));
if (read != sizeof(wavHeader)) { size_t read = fp.tellg();
// Short read. if (read != sizeof(wavHeader)) {
printf("WAV file header is too short: %s\n", path.c_str()); // Short read.
fp.close(); printf("WAV file header is too short: %s\n", path.c_str());
return; fp.close();
} return;
}
// Verify the header.
static const char RIFF_magic[4] = {'R', 'I', 'F', 'F'}; // Verify the header.
if (memcmp(wavHeader.magic, RIFF_magic, sizeof(wavHeader.magic)) != 0) { static const char RIFF_magic[4] = {'R', 'I', 'F', 'F'};
// Incorrect magic number. if (memcmp(wavHeader.magic, RIFF_magic, sizeof(wavHeader.magic)) != 0) {
printf("Wrong file format.\n"); // Incorrect magic number.
fp.close(); printf("Wrong file format.\n");
return; fp.close();
} return;
}
if (wavHeader.totallength == 0 ||
(wavHeader.channels != 1 && wavHeader.channels != 2) || if (wavHeader.totallength == 0 ||
(wavHeader.bits_per_sample != 8 && wavHeader.bits_per_sample != 16)) { (wavHeader.channels != 1 && wavHeader.channels != 2) ||
// Unsupported WAV file. (wavHeader.bits_per_sample != 8 && wavHeader.bits_per_sample != 16)) {
printf("Corrupted wav file.\n"); // Unsupported WAV file.
fp.close(); printf("Corrupted wav file.\n");
return; fp.close();
} return;
}
// Get the file size.
fp.seekg(0, std::ios::end); // Get the file size.
dataSize = fp.tellg(); fp.seekg(0, std::ios::end);
dataSize -= sizeof(WavHeader); dataSize = fp.tellg();
dataSize -= sizeof(WavHeader);
// Allocating and reading samples
data = static_cast<u8 *>(linearAlloc(dataSize)); // Allocating and reading samples
fp.seekg(44, std::ios::beg); data = static_cast<u8 *>(linearAlloc(dataSize));
fp.read(reinterpret_cast<char *>(data), dataSize); fp.seekg(44, std::ios::beg);
fp.close(); fp.read(reinterpret_cast<char *>(data), dataSize);
dataSize /= 2; // FIXME: 16-bit or stereo? fp.close();
dataSize /= 2; // FIXME: 16-bit or stereo?
// Find the right format
u16 ndspFormat; // Find the right format
if (wavHeader.bits_per_sample == 8) { u16 ndspFormat;
ndspFormat = (wavHeader.channels == 1) ? NDSP_FORMAT_MONO_PCM8 if (wavHeader.bits_per_sample == 8) {
: NDSP_FORMAT_STEREO_PCM8; ndspFormat = (wavHeader.channels == 1) ? NDSP_FORMAT_MONO_PCM8
} else { : NDSP_FORMAT_STEREO_PCM8;
ndspFormat = (wavHeader.channels == 1) ? NDSP_FORMAT_MONO_PCM16 } else {
: NDSP_FORMAT_STEREO_PCM16; ndspFormat = (wavHeader.channels == 1) ? NDSP_FORMAT_MONO_PCM16
} : NDSP_FORMAT_STEREO_PCM16;
}
ndspChnReset(channel);
ndspChnSetInterp(channel, NDSP_INTERP_NONE); ndspChnReset(channel);
ndspChnSetRate(channel, float(wavHeader.frequency)); ndspChnSetInterp(channel, NDSP_INTERP_NONE);
ndspChnSetFormat(channel, ndspFormat); ndspChnSetRate(channel, float(wavHeader.frequency));
ndspChnSetFormat(channel, ndspFormat);
// Create and play a wav buffer
memset(&waveBuf, 0, sizeof(waveBuf)); // Create and play a wav buffer
memset(&waveBuf, 0, sizeof(waveBuf));
waveBuf.data_vaddr = reinterpret_cast<u32 *>(data);
waveBuf.nsamples = dataSize / (wavHeader.bits_per_sample >> 3); waveBuf.data_vaddr = reinterpret_cast<u32 *>(data);
waveBuf.looping = toloop; waveBuf.nsamples = dataSize / (wavHeader.bits_per_sample >> 3);
waveBuf.status = NDSP_WBUF_FREE; waveBuf.looping = toloop;
chnl = channel; waveBuf.status = NDSP_WBUF_FREE;
} chnl = channel;
} }
}
sound::~sound() {
if (rd7i_is_ndsp) { Sound::~Sound() {
waveBuf.data_vaddr = 0; if (rd7i_is_ndsp) {
waveBuf.nsamples = 0; waveBuf.data_vaddr = 0;
waveBuf.looping = false; waveBuf.nsamples = 0;
waveBuf.status = 0; waveBuf.looping = false;
ndspChnWaveBufClear(chnl); waveBuf.status = 0;
ndspChnWaveBufClear(chnl);
if (data) {
linearFree(data); if (data) {
} linearFree(data);
} }
} }
}
void sound::play() {
if (rd7i_is_ndsp) { void Sound::Play() {
if (!data) return; if (rd7i_is_ndsp) {
DSP_FlushDataCache(data, dataSize); if (!data) return;
ndspChnWaveBufAdd(chnl, &waveBuf); DSP_FlushDataCache(data, dataSize);
} ndspChnWaveBufAdd(chnl, &waveBuf);
} }
}
void sound::stop() {
if (rd7i_is_ndsp) { void Sound::Stop() {
if (!data) return; if (rd7i_is_ndsp) {
ndspChnWaveBufClear(chnl); if (!data) return;
} ndspChnWaveBufClear(chnl);
} }
}

View File

@ -38,13 +38,32 @@ void RenderD7::Sprite::SetRotation(float rotation) {
void RenderD7::Sprite::Rotate(float speed) { void RenderD7::Sprite::Rotate(float speed) {
C2D_SpriteRotateDegrees(&this->sprite, speed); C2D_SpriteRotateDegrees(&this->sprite, speed);
} }
float RenderD7::Sprite::getHeight() { return this->sprite.params.pos.h; } float RenderD7::Sprite::GetHeight() { return GetSize().x; }
float RenderD7::Sprite::getWidth() { return this->sprite.params.pos.w; } float RenderD7::Sprite::GetWidth() { return GetSize().y; }
float RenderD7::Sprite::getPosX() { return this->sprite.params.pos.x; } float RenderD7::Sprite::GetPosX() { return GetPos().x; }
float RenderD7::Sprite::getPosY() { return this->sprite.params.pos.y; } float RenderD7::Sprite::GetPosY() { return GetPos().y; }
void RenderD7::Sprite::FromImage(RenderD7::Image *img) { R7Vec2 RenderD7::Sprite::GetPos() {
C2D_SpriteFromImage(&this->sprite, img->get()); return R7Vec2(this->sprite.params.pos.x, this->sprite.params.pos.y);
}
R7Vec2 RenderD7::Sprite::GetSize() {
return R7Vec2(this->sprite.params.pos.w, this->sprite.params.pos.h);
}
void RenderD7::Sprite::SetPos(R7Vec2 pos) {
C2D_SpriteSetPos(&this->sprite, pos.x, pos.y);
}
void RenderD7::Sprite::SetScale(R7Vec2 scale) {
C2D_SpriteScale(&this->sprite, scale.x, scale.y);
}
void RenderD7::Sprite::SetRotCenter(R7Vec2 percentage) {
C2D_SpriteSetCenter(&this->sprite, percentage.x, percentage.y);
}
void RenderD7::Sprite::FromImage(RenderD7::Image::Ref img) {
C2D_SpriteFromImage(&this->sprite, img->Get());
} }
void RenderD7::Sprite::SetScale(float x, float y) { void RenderD7::Sprite::SetScale(float x, float y) {

View File

@ -18,12 +18,12 @@
#include <ctime> #include <ctime>
#include <renderd7/Color.hpp> #include <renderd7/Color.hpp>
#include <renderd7/DrawV2.hpp>
#include <renderd7/Hid.hpp> #include <renderd7/Hid.hpp>
#include <renderd7/Message.hpp> #include <renderd7/Message.hpp>
#include <renderd7/Overlays.hpp> #include <renderd7/Overlays.hpp>
#include <renderd7/UI7.hpp> #include <renderd7/UI7.hpp>
#include <renderd7/internal_db.hpp> #include <renderd7/internal_db.hpp>
#include <renderd7/renderd7.hpp>
#include <unordered_map> #include <unordered_map>
template <typename T> template <typename T>
@ -39,9 +39,7 @@ inline T d7min(T a, T b) {
// As the 3ds doesn't support std::chrono // As the 3ds doesn't support std::chrono
#ifdef __3DS__ #ifdef __3DS__
/// @brief 3ds System Ticks per milli second /// @brief 3ds System Ticks per milli second
/// Already defined in FTrace ik but /// Already defined in FTrace ik
/// I Want to make UI7 and Draw2 more
/// Independent of the main RenderD7 api
#define TICKS_PER_MSEC 268111.856 #define TICKS_PER_MSEC 268111.856
#include <3ds.h> #include <3ds.h>
#define __get_time() (float)svcGetSystemTick() / (float)TICKS_PER_MSEC #define __get_time() (float)svcGetSystemTick() / (float)TICKS_PER_MSEC
@ -106,20 +104,16 @@ class DrawCmd {
if (type == DrawCmdType_Skip) { if (type == DrawCmdType_Skip) {
return; return;
} }
RenderD7::OnScreen(screen ? Top : Bottom); RenderD7::R2()->OnScreen(screen ? R2Screen_Top : R2Screen_Bottom);
if (type == DrawCmdType_Rect) { if (type == DrawCmdType_Rect) {
RenderD7::Draw2::RFS(R7Vec2(rect.x, rect.y), R7Vec2(rect.z, rect.w), clr); RenderD7::R2()->AddRect(R7Vec2(rect.x, rect.y), R7Vec2(rect.z, rect.w),
clr);
} else if (type == DrawCmdType_Triangle) { } else if (type == DrawCmdType_Triangle) {
RenderD7::Draw2::TriangleSolid(R7Vec2(rect.x, rect.y), RenderD7::R2()->AddTriangle(R7Vec2(rect.x, rect.y),
R7Vec2(rect.z, rect.w), add_coords, clr); R7Vec2(rect.z, rect.w), add_coords, clr);
} else if (type == DrawCmdType_Text) { } else if (type == DrawCmdType_Text) {
if (text_box.x || text_box.y) { RenderD7::R2()->AddText(R7Vec2(rect.x, rect.y), text, clr, text_flags,
RenderD7::TextMaxBox(text_box); text_box);
}
RenderD7::Draw2::TextClr(R7Vec2(rect.x, rect.y), text, clr, text_flags);
if (text_box.x || text_box.y) {
RenderD7::TextDefaultBox();
}
} else if (type == DrawCmdType_Debug) { } else if (type == DrawCmdType_Debug) {
Debug(); Debug();
} }
@ -127,31 +121,33 @@ class DrawCmd {
void Debug() { void Debug() {
RenderD7::OnScreen(screen ? Top : Bottom); RenderD7::OnScreen(screen ? Top : Bottom);
if (stype == DrawCmdType_Skip && type != DrawCmdType_Debug) return; if (stype == DrawCmdType_Skip && type != DrawCmdType_Debug) return;
// auto color = (clr == -1 ? ovr_clr : RenderD7::ThemeActive()->Get(clr));
if (stype == DrawCmdType_Rect) { if (stype == DrawCmdType_Rect) {
RenderD7::Draw2::TriangleLined( RenderD7::R2()->DrawNextLined();
R7Vec2(rect.x, rect.y), R7Vec2(rect.x + rect.z, rect.y), RenderD7::R2()->AddTriangle(R7Vec2(rect.x, rect.y),
R7Vec2(rect.x, rect.y + rect.w), 0xff0000ff); R7Vec2(rect.x + rect.z, rect.y),
RenderD7::Draw2::TriangleLined(R7Vec2(rect.x + rect.z, rect.y + rect.w), R7Vec2(rect.x, rect.y + rect.w), 0xff0000ff);
R7Vec2(rect.x + rect.z, rect.y), RenderD7::R2()->DrawNextLined();
R7Vec2(rect.x, rect.y + rect.w), RenderD7::R2()->AddTriangle(R7Vec2(rect.x + rect.z, rect.y + rect.w),
0xff0000ff); R7Vec2(rect.x + rect.z, rect.y),
R7Vec2(rect.x, rect.y + rect.w), 0xff0000ff);
} else if (stype == DrawCmdType_Triangle) { } else if (stype == DrawCmdType_Triangle) {
RenderD7::Draw2::TriangleLined(R7Vec2(rect.x, rect.y), RenderD7::R2()->DrawNextLined();
R7Vec2(rect.z, rect.w), add_coords, RenderD7::R2()->AddTriangle(R7Vec2(rect.x, rect.y),
0xff00ff00); R7Vec2(rect.z, rect.w), add_coords,
0xff00ff00);
} else if (stype == DrawCmdType_Text) { } else if (stype == DrawCmdType_Text) {
auto szs = RenderD7::GetTextDimensions(text); auto szs = RenderD7::R2()->GetTextDimensions(text);
if (text_flags & RD7TextFlags_AlignRight) { if (text_flags & RD7TextFlags_AlignRight) {
rect.x -= szs.x; rect.x -= szs.x;
} }
RenderD7::Draw2::TriangleLined( RenderD7::R2()->DrawNextLined();
R7Vec2(rect.x, rect.y), R7Vec2(rect.x + szs.x, rect.y), RenderD7::R2()->AddTriangle(R7Vec2(rect.x, rect.y),
R7Vec2(rect.x, rect.y + szs.y), 0xff00ffff); R7Vec2(rect.x + szs.x, rect.y),
RenderD7::Draw2::TriangleLined(R7Vec2(rect.x + szs.x, rect.y + szs.y), R7Vec2(rect.x, rect.y + szs.y), 0xff00ffff);
R7Vec2(rect.x + szs.x, rect.y), RenderD7::R2()->DrawNextLined();
R7Vec2(rect.x, rect.y + szs.y), RenderD7::R2()->AddTriangle(R7Vec2(rect.x + szs.x, rect.y + szs.y),
0xff00ffff); R7Vec2(rect.x + szs.x, rect.y),
R7Vec2(rect.x, rect.y + szs.y), 0xff00ffff);
} }
} }
RD7_SMART_CTOR(DrawCmd) RD7_SMART_CTOR(DrawCmd)
@ -469,7 +465,7 @@ float GetDeltaTime() {
bool Button(const std::string &label, R7Vec2 size) { bool Button(const std::string &label, R7Vec2 size) {
bool ret = false; bool ret = false;
if (!UI7CtxValidate()) return ret; if (!UI7CtxValidate()) return ret;
R7Vec2 textdim = RenderD7::GetTextDimensions(label); R7Vec2 textdim = RenderD7::R2()->GetTextDimensions(label);
if (size.x == 0) { if (size.x == 0) {
size.x = textdim.x + 8; size.x = textdim.x + 8;
} }
@ -509,9 +505,9 @@ bool Button(const std::string &label, R7Vec2 size) {
void Checkbox(const std::string &label, bool &c) { void Checkbox(const std::string &label, bool &c) {
if (!UI7CtxValidate()) return; if (!UI7CtxValidate()) return;
float sv = (RenderD7::TextGetSize() * 40) * 0.9; float sv = (RenderD7::R2()->GetTextSize() * 40) * 0.9;
R7Vec2 cbs = R7Vec2(sv, sv); R7Vec2 cbs = R7Vec2(sv, sv);
R7Vec2 txtdim = RenderD7::GetTextDimensions(label); R7Vec2 txtdim = RenderD7::R2()->GetTextDimensions(label);
R7Vec2 inp = cbs + R7Vec2(txtdim.x + 5, 0); R7Vec2 inp = cbs + R7Vec2(txtdim.x + 5, 0);
RD7Color bg = RD7Color_FrameBg; RD7Color bg = RD7Color_FrameBg;
@ -550,7 +546,7 @@ void Checkbox(const std::string &label, bool &c) {
void Label(const std::string &label, RD7TextFlags flags) { void Label(const std::string &label, RD7TextFlags flags) {
if (!UI7CtxValidate()) return; if (!UI7CtxValidate()) return;
R7Vec2 textdim = RenderD7::GetTextDimensions(label); R7Vec2 textdim = RenderD7::R2()->GetTextDimensions(label);
R7Vec2 pos = GetCursorPos(); R7Vec2 pos = GetCursorPos();
auto upos = pos; auto upos = pos;
// Remove some y offset cause texts have some offset // Remove some y offset cause texts have some offset
@ -564,7 +560,7 @@ void Label(const std::string &label, RD7TextFlags flags) {
return; return;
} }
float tbh = RenderD7::TextGetSize() * 40; float tbh = RenderD7::R2()->GetTextSize() * 40;
auto &list = auto &list =
(upos.y + textdim.y < tbh) ? ui7_ctx->cm->front : ui7_ctx->cm->main; (upos.y + textdim.y < tbh) ? ui7_ctx->cm->front : ui7_ctx->cm->main;
@ -601,28 +597,28 @@ void Progressbar(float value) {
} }
} }
void Image(RenderD7::Image *img) { void Image(RenderD7::Image::Ref img) {
if (!UI7CtxValidate()) return; if (!UI7CtxValidate()) return;
R7Vec2 pos = GetCursorPos(); R7Vec2 pos = GetCursorPos();
UI7CtxCursorMove(R7Vec2(img->get_size().x, img->get_size().y)); UI7CtxCursorMove(R7Vec2(img->GetSize().x, img->GetSize().y));
if (ui7_ctx->cm->enable_scrolling) { if (ui7_ctx->cm->enable_scrolling) {
R7Vec2 pb = pos; R7Vec2 pb = pos;
pos -= R7Vec2(0, ui7_ctx->cm->scrolling_offset); pos -= R7Vec2(0, ui7_ctx->cm->scrolling_offset);
if (pos.y > 240 || (pos.y + img->get_size().y < ui7_ctx->cm->tbh - 5 && if (pos.y > 240 || (pos.y + img->GetSize().y < ui7_ctx->cm->tbh - 5 &&
pb.y > ui7_ctx->cm->tbh)) pb.y > ui7_ctx->cm->tbh))
return; return;
} }
RenderD7::Draw2::Image(img, pos); // RenderD7::Draw2::Image(img, pos);
} }
void BrowserList(const std::vector<std::string> &entrys, int &selection, void BrowserList(const std::vector<std::string> &entrys, int &selection,
RD7TextFlags txtflags, R7Vec2 size, int max_entrys) { RD7TextFlags txtflags, R7Vec2 size, int max_entrys) {
if (!UI7CtxValidate()) return; if (!UI7CtxValidate()) return;
if (selection < 0) return; if (selection < 0) return;
float tmp_txt = RenderD7::TextGetSize(); float tmp_txt = RenderD7::R2()->GetTextSize();
RenderD7::TextDefaultSize(); RenderD7::R2()->DefaultTextSize();
R7Vec2 pos = GetCursorPos(); R7Vec2 pos = GetCursorPos();
if (pos.y + 15 * max_entrys > 230) max_entrys = (int)((230 - pos.y) / 15); if (pos.y + 15 * max_entrys > 230) max_entrys = (int)((230 - pos.y) / 15);
if (size.x == 0) size.x = (rd7i_current_screen ? 400 : 320) - (pos.x * 2); if (size.x == 0) size.x = (rd7i_current_screen ? 400 : 320) - (pos.x * 2);
@ -656,15 +652,15 @@ void BrowserList(const std::vector<std::string> &entrys, int &selection,
: (i % 2 == 0 ? RD7Color_List0 : RD7Color_List1)), : (i % 2 == 0 ? RD7Color_List0 : RD7Color_List1)),
txtflags | RD7TextFlags_Short, R7Vec2(size.x, 15)); txtflags | RD7TextFlags_Short, R7Vec2(size.x, 15));
} }
RenderD7::CustomTextSize(tmp_txt); RenderD7::R2()->SetTextSize(tmp_txt);
} }
void InputText(const std::string &label, std::string &text, void InputText(const std::string &label, std::string &text,
const std::string &hint) { const std::string &hint) {
if (!UI7CtxValidate()) return; if (!UI7CtxValidate()) return;
float sv = (RenderD7::TextGetSize() * 40) * 0.9; float sv = (RenderD7::R2()->GetTextSize() * 40) * 0.9;
R7Vec2 cbs = R7Vec2(144, sv); R7Vec2 cbs = R7Vec2(144, sv);
R7Vec2 txtdim = RenderD7::GetTextDimensions(label); R7Vec2 txtdim = RenderD7::R2()->GetTextDimensions(label);
R7Vec2 inp = cbs + R7Vec2(txtdim.x + 5, 0); R7Vec2 inp = cbs + R7Vec2(txtdim.x + 5, 0);
RD7Color bg = RD7Color_FrameBg; RD7Color bg = RD7Color_FrameBg;
auto id = UI7ID(label); auto id = UI7ID(label);
@ -715,7 +711,7 @@ bool BeginMenu(const std::string &title, R7Vec2 size, UI7MenuFlags flags) {
size.y = 240; size.y = 240;
} }
RD7TextFlags txtflags = 0; RD7TextFlags txtflags = 0;
float tbh = RenderD7::TextGetSize() * 40; float tbh = RenderD7::R2()->GetTextSize() * 40;
ui7_ctx->cm->tbh = tbh; ui7_ctx->cm->tbh = tbh;
if (flags & UI7MenuFlags_NoTitlebar) { if (flags & UI7MenuFlags_NoTitlebar) {
@ -840,8 +836,8 @@ void Grid(const std::string &name, const R7Vec2 &size, const R7Vec2 &entry_size,
pos += igoff; pos += igoff;
for (size_t i = 0; i < num_entrys; i++) { for (size_t i = 0; i < num_entrys; i++) {
display_func(data_array[i], pos); display_func(data_array[i], pos);
if (ui7_ctx->debugging) // if (ui7_ctx->debugging)
RenderD7::Draw2::Text(pos + R7Vec2(4, 4), std::to_string(i)); // RenderD7::Draw2::Text(pos + R7Vec2(4, 4), std::to_string(i));
if (pos.x + (entry_size.x * 2) > (cpos.x + size.x) && if (pos.x + (entry_size.x * 2) > (cpos.x + size.x) &&
pos.y + (entry_size.y * 2) > cpos.y + size.y) { pos.y + (entry_size.y * 2) > cpos.y + size.y) {
break; break;
@ -858,9 +854,9 @@ void Grid(const std::string &name, const R7Vec2 &size, const R7Vec2 &entry_size,
void ColorSelector(const std::string &label, unsigned int &color) { void ColorSelector(const std::string &label, unsigned int &color) {
if (!UI7CtxValidate()) return; if (!UI7CtxValidate()) return;
float sv = (RenderD7::TextGetSize() * 40) * 0.9; float sv = (RenderD7::R2()->GetTextSize() * 40) * 0.9;
R7Vec2 cbs = R7Vec2(sv, sv); R7Vec2 cbs = R7Vec2(sv, sv);
R7Vec2 txtdim = RenderD7::GetTextDimensions(label); R7Vec2 txtdim = RenderD7::R2()->GetTextDimensions(label);
R7Vec2 inp = cbs + R7Vec2(txtdim.x + 5, 0); R7Vec2 inp = cbs + R7Vec2(txtdim.x + 5, 0);
auto outline = auto outline =
RenderD7::Color::RGBA(color).is_light() ? 0xff000000 : 0xffffffff; RenderD7::Color::RGBA(color).is_light() ? 0xff000000 : 0xffffffff;

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <renderd7/DrawV2.hpp> // Switch to Draw2 #include <renderd7/Hid.hpp> // Integate HidApi
#include <renderd7/Hid.hpp> // Integate HidApi
#include <renderd7/Message.hpp> #include <renderd7/Message.hpp>
#include <renderd7/Overlays.hpp> #include <renderd7/Overlays.hpp>
#include <renderd7/ThemeEditor.hpp> #include <renderd7/ThemeEditor.hpp>
@ -34,6 +33,8 @@
#include <filesystem> #include <filesystem>
#include <random> #include <random>
RenderD7::R2Base::Ref rd7i_render2;
static void RD7i_ExitHook() { static void RD7i_ExitHook() {
C2D_TextBufDelete(rd7i_text_buffer); C2D_TextBufDelete(rd7i_text_buffer);
C2D_TextBufDelete(rd7i_d2_dimbuf); C2D_TextBufDelete(rd7i_d2_dimbuf);
@ -53,13 +54,21 @@ std::vector<std::string> string_to_lines(std::string input_str) {
void Npifade() { void Npifade() {
if (rd7i_fadein) { if (rd7i_fadein) {
if (rd7i_fadealpha < 255) { if (rd7i_fadealpha < 255) {
rd7i_fadealpha += 3; if ((int)rd7i_fadealpha + 3 > 255) {
rd7i_fadealpha = 255;
} else {
rd7i_fadealpha += 3;
}
} else { } else {
rd7i_fadein = false; rd7i_fadein = false;
} }
} else if (rd7i_fadeout) { } else if (rd7i_fadeout) {
if (rd7i_fadealpha > 0) { if (rd7i_fadealpha > 0) {
rd7i_fadealpha -= 3; if ((int)rd7i_fadealpha - 3 < 0) {
rd7i_fadealpha = 0;
} else {
rd7i_fadealpha -= 3;
}
} else { } else {
rd7i_fadeout = false; rd7i_fadeout = false;
} }
@ -73,12 +82,14 @@ void Npifade() {
} }
// No fade // No fade
} }
RenderD7::OnScreen(Top); /*if (rd7i_fadein || rd7i_fadeout) {
RenderD7::Draw2::RFS(R7Vec2(0, 0), R7Vec2(400, 240), RenderD7::R2()->OnScreen(RenderD7::R2Screen_Top);
((rd7i_fadealpha << 24) | 0x00000000)); RenderD7::R2()->AddRect(R7Vec2(0, 0), R7Vec2(400, 240),
RenderD7::OnScreen(Bottom); ((rd7i_fadealpha << 24) | 0x00000000));
RenderD7::Draw2::RFS(R7Vec2(0, 0), R7Vec2(320, 240), RenderD7::R2()->OnScreen(RenderD7::R2Screen_Bottom);
((rd7i_fadealpha << 24) | 0x00000000)); RenderD7::R2()->AddRect(R7Vec2(0, 0), R7Vec2(320, 240),
((rd7i_fadealpha << 24) | 0x00000000));
}*/
} }
void PushSplash() { void PushSplash() {
@ -220,6 +231,14 @@ void rd7i_init_theme() {
} }
} }
RenderD7::R2Base::Ref RenderD7::R2() {
if (!rd7i_render2) {
RenderD7::Error("Render2 Was Called before being Init!");
// return schould not be reached then
}
return rd7i_render2;
}
float RenderD7::GetDeltaTime() { return (float)rd7i_dtm; } float RenderD7::GetDeltaTime() { return (float)rd7i_dtm; }
bool RenderD7::DrawImageFromSheet(RenderD7::Sheet *sheet, size_t index, float x, bool RenderD7::DrawImageFromSheet(RenderD7::Sheet *sheet, size_t index, float x,
@ -324,9 +343,13 @@ void RenderD7::Init::Graphics() {
Top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT); Top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
TopRight = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT); TopRight = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT);
Bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT); Bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
rd7_top = Top;
rd7_bottom = Bottom;
rd7_top_right = TopRight;
rd7i_text_buffer = C2D_TextBufNew(4096); rd7i_text_buffer = C2D_TextBufNew(4096);
rd7i_d2_dimbuf = C2D_TextBufNew(4096); rd7i_d2_dimbuf = C2D_TextBufNew(4096);
rd7i_base_font = C2D_FontLoadSystem(CFG_REGION_USA); rd7i_base_font = C2D_FontLoadSystem(CFG_REGION_USA);
rd7i_render2 = R2Base::New();
} }
Result RenderD7::Init::Main(std::string app_name) { Result RenderD7::Init::Main(std::string app_name) {
@ -371,6 +394,9 @@ Result RenderD7::Init::Main(std::string app_name) {
Top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT); Top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
TopRight = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT); TopRight = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT);
Bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT); Bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
rd7_top = Top;
rd7_bottom = Bottom;
rd7_top_right = TopRight;
rd7i_text_buffer = C2D_TextBufNew(4096); rd7i_text_buffer = C2D_TextBufNew(4096);
rd7i_d2_dimbuf = C2D_TextBufNew(4096); rd7i_d2_dimbuf = C2D_TextBufNew(4096);
rd7i_base_font = C2D_FontLoadSystem(CFG_REGION_USA); rd7i_base_font = C2D_FontLoadSystem(CFG_REGION_USA);
@ -379,6 +405,7 @@ Result RenderD7::Init::Main(std::string app_name) {
rd7i_last_tm = svcGetSystemTick(); rd7i_last_tm = svcGetSystemTick();
if (rd7_do_splash) PushSplash(); if (rd7_do_splash) PushSplash();
rd7i_render2 = R2Base::New();
rd7i_init_config(); rd7i_init_config();
rd7i_init_input(); rd7i_init_input();
rd7i_init_theme(); rd7i_init_theme();
@ -421,6 +448,9 @@ Result RenderD7::Init::Minimal(std::string app_name) {
Top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT); Top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
TopRight = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT); TopRight = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT);
Bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT); Bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
rd7_top = Top;
rd7_bottom = Bottom;
rd7_top_right = TopRight;
rd7i_text_buffer = C2D_TextBufNew(4096); rd7i_text_buffer = C2D_TextBufNew(4096);
rd7i_d2_dimbuf = C2D_TextBufNew(4096); rd7i_d2_dimbuf = C2D_TextBufNew(4096);
rd7i_base_font = C2D_FontLoadSystem(CFG_REGION_USA); rd7i_base_font = C2D_FontLoadSystem(CFG_REGION_USA);
@ -432,6 +462,7 @@ Result RenderD7::Init::Minimal(std::string app_name) {
svcGetSystemInfo(&citracheck, 0x20000, 0); svcGetSystemInfo(&citracheck, 0x20000, 0);
rd7i_is_citra = citracheck ? true : false; rd7i_is_citra = citracheck ? true : false;
rd7i_render2 = R2Base::New();
rd7i_init_config(); rd7i_init_config();
rd7i_init_input(); rd7i_init_input();
rd7i_init_theme(); rd7i_init_theme();
@ -444,6 +475,7 @@ Result RenderD7::Init::Minimal(std::string app_name) {
Result RenderD7::Init::Reload() { Result RenderD7::Init::Reload() {
rd7i_graphics_on = false; rd7i_graphics_on = false;
C2D_TextBufDelete(rd7i_text_buffer); C2D_TextBufDelete(rd7i_text_buffer);
rd7i_render2 = nullptr; // Delete Render2
C2D_Fini(); C2D_Fini();
C3D_Fini(); C3D_Fini();
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
@ -452,8 +484,12 @@ Result RenderD7::Init::Reload() {
Top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT); Top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
TopRight = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT); TopRight = C2D_CreateScreenTarget(GFX_TOP, GFX_RIGHT);
Bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT); Bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
rd7_top = Top;
rd7_bottom = Bottom;
rd7_top_right = TopRight;
rd7i_text_buffer = C2D_TextBufNew(4096); rd7i_text_buffer = C2D_TextBufNew(4096);
rd7i_base_font = C2D_FontLoadSystem(CFG_REGION_USA); rd7i_base_font = C2D_FontLoadSystem(CFG_REGION_USA);
rd7i_render2 = R2Base::New();
rd7i_graphics_on = true; rd7i_graphics_on = true;
return 0; return 0;
@ -504,15 +540,16 @@ void RenderD7::FrameEnd() {
RenderD7::ProcessMessages(); RenderD7::ProcessMessages();
OvlHandler(); OvlHandler();
Npifade(); Npifade();
R2()->Process();
C3D_FrameEnd(0); C3D_FrameEnd(0);
} }
RenderD7::RSettings::RSettings() { RenderD7::RSettings::RSettings() {
// RenderD7 Settings is designed for // RenderD7 Settings is designed for
// System Font // System Font
RenderD7::TextDefaultFont(); R2()->DefaultFont();
tmp_txt = RenderD7::TextGetSize(); tmp_txt = R2()->GetTextSize();
RenderD7::TextDefaultSize(); R2()->DefaultTextSize();
RenderD7::FadeIn(); RenderD7::FadeIn();
std::fstream cfg_ldr(rd7i_config_path + "/config.rc7", std::ios::in); std::fstream cfg_ldr(rd7i_config_path + "/config.rc7", std::ios::in);
cfg_ldr >> rd7i_config; cfg_ldr >> rd7i_config;
@ -522,10 +559,7 @@ RenderD7::RSettings::RSettings() {
stateftold = rd7i_ftraced; stateftold = rd7i_ftraced;
} }
RenderD7::RSettings::~RSettings() { RenderD7::RSettings::~RSettings() { R2()->SetTextSize(tmp_txt); }
RenderD7::TextFontRestore();
RenderD7::CustomTextSize(tmp_txt);
}
std::vector<std::string> StrHelper(std::string input) { std::vector<std::string> StrHelper(std::string input) {
std::string ss(input); std::string ss(input);
@ -609,39 +643,44 @@ void RenderD7::RSettings::Draw(void) const {
} else if (m_state == RFTRACE) { } else if (m_state == RFTRACE) {
RenderD7::OnScreen(Top); RenderD7::OnScreen(Top);
RenderD7::Draw2::RFS(R7Vec2(0, 0), R7Vec2(400, 240), // Draw Top Screen Into Background DrawList
RenderD7::ThemeActive()->Get(RD7Color_Background)); UI7::GetBackgroundList()->AddRectangle(R7Vec2(0, 0), R7Vec2(400, 240),
RenderD7::Draw2::RFS(R7Vec2(0, 0), R7Vec2(400, 20), RD7Color_Background);
RenderD7::ThemeActive()->Get(RD7Color_Header)); UI7::GetBackgroundList()->AddRectangle(R7Vec2(0, 0), R7Vec2(400, 20),
RenderD7::ThemeActive()->TextBy(RD7Color_Header); RD7Color_Header);
RenderD7::Draw2::Text(R7Vec2(5, 2), "RenderD7 -> FTrace"); UI7::GetBackgroundList()->AddText(
RenderD7::Draw2::Text(R7Vec2(395, 2), RENDERD7VSTRING, R7Vec2(5, 2), "RenderD7 -> FTrace",
RD7TextFlags_AlignRight); RenderD7::ThemeActive()->AutoText(RD7Color_Header));
RenderD7::ThemeActive()->Undo(); UI7::GetBackgroundList()->AddText(
RenderD7::Draw2::RFS(R7Vec2(0, 220), R7Vec2(400, 20), R7Vec2(395, 2), RENDERD7VSTRING,
RenderD7::ThemeActive()->Get(RD7Color_Header)); RenderD7::ThemeActive()->AutoText(RD7Color_Header),
RenderD7::ThemeActive()->TextBy(RD7Color_Header); RD7TextFlags_AlignRight);
RenderD7::Draw2::Text( UI7::GetBackgroundList()->AddRectangle(
R7Vec2(0, 220), R7Vec2(400, 20),
RenderD7::ThemeActive()->Get(RD7Color_Header));
UI7::GetBackgroundList()->AddText(
R7Vec2(5, 222), R7Vec2(5, 222),
"Traces: " + std::to_string(ftrace_index + 1) + "/" + "Traces: " + std::to_string(ftrace_index + 1) + "/" +
std::to_string(RenderD7::Ftrace::rd7_traces.size())); std::to_string(RenderD7::Ftrace::rd7_traces.size()),
RenderD7::ThemeActive()->Undo(); RenderD7::ThemeActive()->AutoText(RD7Color_Header));
RenderD7::Draw2::RFS(R7Vec2(0, 20), R7Vec2(400, 20), UI7::GetBackgroundList()->AddRectangle(R7Vec2(0, 20), R7Vec2(400, 20),
RenderD7::ThemeActive()->Get(RD7Color_TextDisabled)); RD7Color_TextDisabled);
RenderD7::ThemeActive()->TextBy(RD7Color_TextDisabled); UI7::GetBackgroundList()->AddText(
RenderD7::Draw2::Text(R7Vec2(5, 22), "Function:"); R7Vec2(5, 22),
RenderD7::Draw2::Text(R7Vec2(395, 22), "Function:", RenderD7::ThemeActive()->AutoText(RD7Color_TextDisabled));
"Time (ms):", RD7TextFlags_AlignRight); UI7::GetBackgroundList()->AddText(
RenderD7::ThemeActive()->Undo(); R7Vec2(395, 22),
"Time (ms):", RenderD7::ThemeActive()->AutoText(RD7Color_TextDisabled),
RD7TextFlags_AlignRight);
// List Bg // List Bg
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++) {
if ((i % 2 == 0)) if ((i % 2 == 0))
RenderD7::Draw2::RFS(R7Vec2(0, 40 + (i) * 15), R7Vec2(400, 15), UI7::GetBackgroundList()->AddRectangle(R7Vec2(0, 40 + (i)*15),
RenderD7::ThemeActive()->Get(RD7Color_List0)); R7Vec2(400, 15), RD7Color_List0);
else else
RenderD7::Draw2::RFS(R7Vec2(0, 40 + (i) * 15), R7Vec2(400, 15), UI7::GetBackgroundList()->AddRectangle(R7Vec2(0, 40 + (i)*15),
RenderD7::ThemeActive()->Get(RD7Color_List1)); R7Vec2(400, 15), RD7Color_List1);
} }
RenderD7::Ftrace::Beg("rd7ft", "display_traces"); RenderD7::Ftrace::Beg("rd7ft", "display_traces");
@ -655,27 +694,20 @@ void RenderD7::RSettings::Draw(void) const {
ix < start_index + 10 && it != RenderD7::Ftrace::rd7_traces.end()) { ix < start_index + 10 && it != RenderD7::Ftrace::rd7_traces.end()) {
if (ix == ftrace_index) { if (ix == ftrace_index) {
_fkey__ = it->first; _fkey__ = it->first;
RenderD7::Draw2::RFS(R7Vec2(0, 40 + (ix - start_index) * 15), UI7::GetBackgroundList()->AddRectangle(
R7Vec2(400, 15), R7Vec2(0, 40 + (ix - start_index) * 15), R7Vec2(400, 15),
RenderD7::ThemeActive()->Get(RD7Color_Selector)); RD7Color_Selector);
RenderD7::ThemeActive()->TextBy(RD7Color_Header);
RenderD7::Draw2::Text(R7Vec2(5, 40 + (ix - start_index) * 15),
it->second.func_name);
RenderD7::Draw2::Text(R7Vec2(395, 40 + (ix - start_index) * 15),
RenderD7::MsTimeFmt(it->second.time_of),
RD7TextFlags_AlignRight);
RenderD7::ThemeActive()->Undo();
} else {
// Use List 0 cause no reference for screenpos
RenderD7::ThemeActive()->TextBy(RD7Color_List0);
RenderD7::Draw2::Text(R7Vec2(5, 40 + (ix - start_index) * 15),
it->second.func_name);
RenderD7::Draw2::Text(R7Vec2(395, 40 + (ix - start_index) * 15),
RenderD7::MsTimeFmt(it->second.time_of),
RD7TextFlags_AlignRight);
RenderD7::ThemeActive()->Undo();
} }
auto clr = ix == ftrace_index
? RD7Color_Selector
: (ix % 2 == 0 ? RD7Color_List0 : RD7Color_List1);
UI7::GetBackgroundList()->AddText(R7Vec2(5, 40 + (ix - start_index) * 15),
it->second.func_name,
RenderD7::ThemeActive()->AutoText(clr));
UI7::GetBackgroundList()->AddText(
R7Vec2(395, 40 + (ix - start_index) * 15),
RenderD7::MsTimeFmt(it->second.time_of),
RenderD7::ThemeActive()->AutoText(clr), RD7TextFlags_AlignRight);
++it; ++it;
++ix; ++ix;
} }