Fix some Typenames
Add Sound to RD7 Namespace
Add Line to Render2
Fix scrollbar dragging
This commit is contained in:
2024-06-30 15:43:48 +02:00
parent 570d7f17fb
commit 410d6bf919
8 changed files with 64 additions and 17 deletions

View File

@ -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()) {

View File

@ -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);
}

View File

@ -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;

View File

@ -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);

View File

@ -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) {