renderd7/rd7tf/source/scene.cpp
tobid7 ec8743417d Changes:
Make Timer SmartCtor
ClangFormat
Reactivate Graphical Error Screen
Fix Logger
Fix Image Rendering
2024-06-15 15:12:06 +02:00

139 lines
4.5 KiB
C++

/**
* 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 "scene.hpp"
#include <cmath>
static float MakeOffset(float x) {
float y = cos(x) * 42;
return y - floor(y);
}
static void Wave(int index, R7Vec2 position, R7Vec2 size, float time,
bool dbg) {
float offset = MakeOffset(index) * 62;
float x_position =
position.x + size.x / 8 * ((index % 11) - 1) + cos(offset + time) * 10;
float y_position = position.y + size.y / 8 * (index / 11) + 40 +
sin(offset + time) * 10 + 30;
float color_effect = 1 - exp(-(index / 11) / 3.0f);
// As this is 3ds dont go out of the box
int shrink = 0;
if (y_position >= position.y + size.y - 90) {
shrink = y_position - (position.y + size.y - 90);
}
// Just to make sure...
y_position = std::min(y_position, position.y + size.y - (90 - shrink));
RD7::R2()->AddTriangle(
R7Vec2(x_position, y_position),
R7Vec2(x_position + 300, y_position + (90 - shrink)),
R7Vec2(x_position - 300, y_position + (90 - shrink)),
RD7::Color::RGBA(.94f - .17f * color_effect, .61f - .25f * color_effect,
.36f + .38f * color_effect)
.toRGBA());
}
void DrawWave(R7Vec2 position, R7Vec2 size, float time, bool dbg) {
RD7::R2()->AddRect(position, size, 0xff64c9fd);
int i = 0;
for (; i < 44; i++) Wave(i, position, size, time, dbg);
}
R7Vec2 testv2 = R7Vec2(48, 48);
std::vector<int*> img;
void display_icon(void* v, R7Vec2 p) {
UI7::Menu::GetList()->AddRectangle(p, testv2, 0xff00ffff);
}
Sample::Sample() {
auto ti = new int;
ti[0] = 0;
for (int i = 0; i < 256; i++) {
img.push_back(ti);
}
}
Sample::~Sample() {
delete img[0];
// Here you can clear your data
}
void Sample::Draw() const {
// Draw Things to Screen:
// Step 1 -> Select Screen
RD7::R2()->OnScreen(R2Screen_Top);
// Step 2 -> Draw Things
// The hbloader Triangle Wave
DrawWave(R7Vec2(0, 0), R7Vec2(400, 240), RD7::GetTime(), debug_background);
if (UI7::BeginMenu("RenderD7 Test Framework")) {
if (state == State_Menu) {
UI7::Label("SZS: " + std::to_string(img.size()));
UI7::Grid("Images", R7Vec2(390, 180), testv2, display_icon,
(void**)&img[0], img.size());
}
UI7::EndMenu();
}
RD7::R2()->OnScreen(R2Screen_Bottom);
if (UI7::BeginMenu("Control Center")) {
if (state == State_Menu) {
if (UI7::Button("RenderD7 Settings"))
shared_requests[1U] = 1U; // Request a Toggle
UI7::SameLine();
if (UI7::Button("Test Message"))
shared_requests[2U] = 1U; // Request Test Msg
UI7::Checkbox("Debug BG", debug_background);
UI7::SameLine();
UI7::Checkbox("RD7-Debug", rd7_debugging);
UI7::SameLine();
UI7::Checkbox("UI7-Debug", UI7::IsDebugging());
UI7::InputText("Search", search__, "Tap Here");
if (UI7::Button("def")) txt_size = 0.5;
UI7::Label("GridControl: ");
if (UI7::Button("icn++")) testv2 += R7Vec2(1, 1);
UI7::SameLine();
if (UI7::Button("icn--")) testv2 -= R7Vec2(1, 1);
}
UI7::EndMenu();
}
}
void Sample::Logic() {
for (const auto& it : shared_requests) {
if (it.first == 1U) {
if (it.second) RD7::LoadSettings();
} else if (it.first == 2U) {
if (it.second)
RD7::PushMessage(RD7::Message("Test Message",
"Button Bressed\nBest Msg Handler..."));
} else if (it.first == 3U) {
state = (State)it.second;
}
}
if (d7_hDown & KEY_UP && sel > 0) sel--;
if (d7_hDown & KEY_DOWN && sel < ((int)files.size() - 1)) sel++;
// Make sure to clear after processing!!!;
shared_requests.clear();
if (d7_hDown & KEY_B) debug_background = !debug_background;
}