Changes:
Fix some Typenames Add Sound to RD7 Namespace Add Line to Render2 Fix scrollbar dragging
This commit is contained in:
parent
570d7f17fb
commit
410d6bf919
@ -25,10 +25,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define UNPACK_RGBA(col) (uint8_t)(col >> 24), (col >> 16), (col >> 8), (col)
|
||||
#define UNPACK_BGRA(col) (uint8_t)(col >> 8), (col >> 16), (col >> 24), (col)
|
||||
#define UNPACK_RGBA(col) (unsigned char)(col >> 24), (col >> 16), (col >> 8), (col)
|
||||
#define UNPACK_BGRA(col) (unsigned char)(col >> 8), (col >> 16), (col >> 24), (col)
|
||||
|
||||
inline uint32_t RGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) {
|
||||
inline unsigned int RGBA8(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255) {
|
||||
return (r | g << 8 | b << 16 | a << 24);
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ class RGBA {
|
||||
/// @param g
|
||||
/// @param b
|
||||
/// @param a
|
||||
RGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
|
||||
RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
|
||||
: m_r(r), m_g(g), m_b(b), m_a(a) {}
|
||||
/// @brief Construct
|
||||
/// @param r
|
||||
@ -201,7 +201,7 @@ class RGBA {
|
||||
return (luminance() >= 0.5);
|
||||
}
|
||||
|
||||
uint8_t m_r = 0, m_g = 0, m_b = 0, m_a = 0;
|
||||
unsigned char m_r = 0, m_g = 0, m_b = 0, m_a = 0;
|
||||
};
|
||||
std::string RGBA2Hex(unsigned int c32);
|
||||
/// @brief Convert RGB to Hex
|
||||
@ -214,6 +214,6 @@ std::string RGB2Hex(int r, int g, int b);
|
||||
/// @param color
|
||||
/// @param a
|
||||
/// @return Color32
|
||||
uint32_t Hex(const std::string &color, uint8_t a = 255);
|
||||
unsigned int Hex(const std::string &color, unsigned char a = 255);
|
||||
} // namespace Color
|
||||
} // namespace RenderD7
|
||||
|
@ -58,7 +58,7 @@ class R2Base {
|
||||
Image::Ref img; //< Image Reference
|
||||
Sprite::Ref spr; //< Sprite Reference
|
||||
// 0 = skip, 1 = rect, 2 = tri, 3 = text,
|
||||
// 4 = image, 5 = sprite
|
||||
// 4 = image, 5 = sprite, 6 = Line
|
||||
int type; //< Command Type
|
||||
bool lined = false; //< Draw Lined Rect/Tri
|
||||
// Text Specific
|
||||
@ -97,6 +97,8 @@ class R2Base {
|
||||
RD7TextFlags flags = 0, R7Vec2 tmb = R7Vec2());
|
||||
void AddImage(R7Vec2 pos, Image::Ref img);
|
||||
void AddSprite(Sprite::Ref spr);
|
||||
void AddLine(R7Vec2 pos_a, R7Vec2 pos_b, RD7Color clr, int t = 1);
|
||||
void AddLine(R7Vec2 pos_a, R7Vec2 pos_b, unsigned int clr, int t = 1);
|
||||
|
||||
private:
|
||||
const float default_text_size = 0.5f;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <renderd7/smart_ctor.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace RenderD7 {
|
||||
/** Sound Class */
|
||||
class Sound {
|
||||
public:
|
||||
@ -49,3 +50,4 @@ class Sound {
|
||||
/// \param chnl Channel of the sound
|
||||
int chnl;
|
||||
};
|
||||
} // namespace RenderD7
|
@ -225,7 +225,7 @@ void RenderD7::ThemeSet(RenderD7::Theme::Ref theme) {
|
||||
rd7i_active_theme = theme;
|
||||
}
|
||||
|
||||
uint32_t RenderD7::Color::Hex(const std::string& color, uint8_t a) {
|
||||
unsigned int RenderD7::Color::Hex(const std::string& color, uint8_t a) {
|
||||
if (color.length() < 7 ||
|
||||
std::find_if(color.begin() + 1, color.end(),
|
||||
[](char c) { return !std::isxdigit(c); }) != color.end()) {
|
||||
|
@ -381,12 +381,12 @@ void Ovl_Metrik::Draw(void) const {
|
||||
// Force Bottom (Debug Touchpos)
|
||||
R2()->OnScreen(R2Screen_Bottom);
|
||||
if (Hid::IsEvent("touch", Hid::Held)) {
|
||||
/*R2()->AddLine(R7Vec2(Hid::GetTouchPosition().x, 0),
|
||||
R2()->AddLine(R7Vec2(Hid::GetTouchPosition().x, 0),
|
||||
R7Vec2(Hid::GetTouchPosition().x, 240),
|
||||
RenderD7::Color::Hex("#ff0000"));
|
||||
R2()->AddLine(R7Vec2(0, Hid::GetTouchPosition().y),
|
||||
R7Vec2(320, Hid::GetTouchPosition().y),
|
||||
RenderD7::Color::Hex("#ff0000"));*/
|
||||
RenderD7::Color::Hex("#ff0000"));
|
||||
}
|
||||
R2()->SetTextSize(tmp_txt);
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ R7Vec2 R2Base::GetCurrentScreenSize() {
|
||||
// Main Processing of Draw Calls
|
||||
void R2Base::Process() {
|
||||
for (auto& it : this->commands) {
|
||||
if (it->type <= 0 || it->type > 5) {
|
||||
if (it->type <= 0 || it->type > 6) {
|
||||
// Skip
|
||||
continue;
|
||||
}
|
||||
@ -209,6 +209,8 @@ void R2Base::Process() {
|
||||
} else if (it->type == 5) {
|
||||
// TODO: Move the Draw Func into this API
|
||||
it->spr->Draw();
|
||||
} else if (it->type == 6) {
|
||||
C2D_DrawLine(it->pos.x, it->pos.y, it->clr, it->pszs.x, it->pszs.y, it->clr, it->ap.x, 0.5f);
|
||||
}
|
||||
}
|
||||
this->commands.clear();
|
||||
@ -246,6 +248,40 @@ void R2Base::AddRect(R7Vec2 pos, R7Vec2 size, unsigned int clr) {
|
||||
this->commands.push_back(cmd);
|
||||
}
|
||||
|
||||
void R2Base::AddLine(R7Vec2 pos_a, R7Vec2 pos_b, RD7Color clr, int t) {
|
||||
auto cmd = R2Cmd::New();
|
||||
cmd->pos = pos_a;
|
||||
cmd->pszs = pos_b;
|
||||
cmd->ap.x = t;
|
||||
cmd->clr = RenderD7::ThemeActive()->Get(clr);
|
||||
cmd->type = 6; // Line
|
||||
// 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::AddLine(R7Vec2 pos_a, R7Vec2 pos_b, unsigned int clr, int t) {
|
||||
auto cmd = R2Cmd::New();
|
||||
cmd->pos = pos_a;
|
||||
cmd->pszs = pos_b;
|
||||
cmd->ap.x = t;
|
||||
cmd->clr = clr;
|
||||
cmd->type = 6; // Line
|
||||
// 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) {
|
||||
auto cmd = R2Cmd::New();
|
||||
cmd->pos = pos0;
|
||||
|
@ -41,6 +41,7 @@ typedef struct _WavHeader {
|
||||
} WavHeader;
|
||||
static_assert(sizeof(WavHeader) == 44, "WavHeader size is not 44 bytes.");
|
||||
|
||||
using namespace RenderD7;
|
||||
Sound::Sound(const string &path, int channel, bool toloop) {
|
||||
if (rd7i_is_ndsp) {
|
||||
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
|
||||
|
@ -448,12 +448,16 @@ void UI7CtxEndMenu() {
|
||||
static_cast<float>(ui7_ctx->cm->ms.y));
|
||||
// Create Real Slider Height
|
||||
int slider_rh = d7min(d7max(slider_h, (float)lszs), (float)(szs - 4));
|
||||
auto slider_clr = RD7Color_Button;
|
||||
// Process Slider Dragging
|
||||
/// TODO: Optimize
|
||||
if(RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Held)) {
|
||||
if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Held)) {
|
||||
auto tp = RenderD7::Hid::GetTouchPosition();
|
||||
if(UI7::InBox(tp, R7Vec2(sw-10, tsp), R7Vec2(8, szs))) {
|
||||
ui7_ctx->cm->scrolling_offset = ((tp.y-tsp)/szs)*(ui7_ctx->cm->ms.y-240);
|
||||
if (UI7::InBox(tp, R7Vec2(sw - 10, tsp), R7Vec2(8, szs))) {
|
||||
slider_clr = RD7Color_ButtonHovered;
|
||||
ui7_ctx->cm->scrolling_offset = d7max(
|
||||
0.f, d7min(ui7_ctx->cm->ms.y - 240,
|
||||
((tp.y - tsp) / szs) * (ui7_ctx->cm->ms.y - 240)));
|
||||
}
|
||||
}
|
||||
// Calculate Slider Position
|
||||
@ -469,8 +473,7 @@ void UI7CtxEndMenu() {
|
||||
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),
|
||||
R7Vec2(slider_w, slider_rh),
|
||||
RD7Color_Selector);
|
||||
R7Vec2(slider_w, slider_rh), slider_clr);
|
||||
}
|
||||
}
|
||||
// Debug Print Menu Values
|
||||
@ -840,7 +843,10 @@ bool BeginMenu(const std::string &title, R7Vec2 size, UI7MenuFlags flags) {
|
||||
}
|
||||
if (RenderD7::Hid::IsEvent("touch", RenderD7::Hid::Held)) {
|
||||
// Set modifier
|
||||
if(!InBox(np, R7Vec2(RenderD7::R2()->GetCurrentScreenSize().x - 8 - 5, 5 + ui7_ctx->cm->tbh), R7Vec2(8, 240 - ui7_ctx->cm->tbh - 10))) {
|
||||
if (!InBox(np,
|
||||
R7Vec2(RenderD7::R2()->GetCurrentScreenSize().x - 8 - 5,
|
||||
5 + ui7_ctx->cm->tbh),
|
||||
R7Vec2(8, 240 - ui7_ctx->cm->tbh - 10))) {
|
||||
// Check if and do nothing if the scrolling ofset goes out of screen
|
||||
if (ui7_ctx->cm->scrolling_offset < ui7_ctx->cm->ms.y - 200 &&
|
||||
ui7_ctx->cm->scrolling_offset > -40) {
|
||||
|
Loading…
Reference in New Issue
Block a user