Working on FPSGraph, built with temp-fixed JGL.
This commit is contained in:
@@ -41,7 +41,6 @@ CPMAddPackage(
|
||||
URL https://git.redacted.cc/maxine/mcolor/archive/Release-1.zip
|
||||
)
|
||||
|
||||
|
||||
CPMAddPackage(
|
||||
NAME Event
|
||||
URL https://git.redacted.cc/josh/Event/archive/Release-12.zip
|
||||
@@ -64,7 +63,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME JGL
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-56.zip
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-58.zip
|
||||
)
|
||||
|
||||
target_include_directories(JUI PUBLIC ${Event_SOURCE_DIR}/include)
|
||||
|
@@ -9,8 +9,6 @@ namespace JUI {
|
||||
Color4 color;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class FpsGraph : public JUI::ImageRect
|
||||
{
|
||||
public:
|
||||
@@ -19,27 +17,26 @@ namespace JUI {
|
||||
J2D::Begin(canvas, nullptr, true);
|
||||
|
||||
|
||||
|
||||
DataPoint prev = data[0];
|
||||
for (auto& data_pt : data) {
|
||||
|
||||
//J2D::DrawGradientLine(prev.color, data_pt.color, prev.pos, data_pt.pos, 1);
|
||||
J2D::DrawLine(data_pt.color, data_pt.pos, {data_pt.pos.x, GetAbsoluteSize().y }, 1);
|
||||
J2D::DrawLine(data_pt.color, data_pt.pos, {data_pt.pos.x, graph_height }, 1);
|
||||
|
||||
prev = data_pt;
|
||||
}
|
||||
float target_line_height = (1.f / 60.f) * 1000;
|
||||
J2D::DrawString(Colors::Black, "60 FPS / 16.7ms (Target)", 0, 100 - target_line_height, 10, 1.f);
|
||||
J2D::DrawLine(Colors::White, {0, 100 - target_line_height}, {GetAbsoluteSize().x, 100 - target_line_height}, 1);
|
||||
float target_line_height = (1.f / 60.f) * y_axis_scale;
|
||||
J2D::DrawString(Colors::Black, "60 FPS / 16.7ms (Target)", 0, graph_height - target_line_height, 10, 1.f);
|
||||
J2D::DrawLine(Colors::White, {0, graph_height - target_line_height}, {GetAbsoluteSize().x, graph_height - target_line_height}, 1);
|
||||
J2D::End();
|
||||
}
|
||||
|
||||
FpsGraph() : JUI::ImageRect() {
|
||||
for (int i = 0; i < 500; i++) {
|
||||
for (int i = 0; i < sample_history; i++) {
|
||||
Plot({i / 1.f, 0.f}, Colors::Black);
|
||||
}
|
||||
|
||||
canvas = new JGL::RenderTarget({500, 100});
|
||||
canvas = new JGL::RenderTarget(Vector2i(graph_width, graph_height));
|
||||
|
||||
RenderDataPoints();
|
||||
|
||||
@@ -47,8 +44,6 @@ namespace JUI {
|
||||
};
|
||||
explicit FpsGraph(Widget* parent) : FpsGraph() {
|
||||
Parent(parent);
|
||||
|
||||
|
||||
}
|
||||
void Plot(const Vector2& pt, const Color4& col) {
|
||||
data.push_back(DataPoint{ pt, col });
|
||||
@@ -62,19 +57,19 @@ namespace JUI {
|
||||
}
|
||||
|
||||
Color4 color = Colors::Green;
|
||||
if (delta > 1e-3f)
|
||||
if (delta > 1.f/120.f)
|
||||
color = Colors::Blue;
|
||||
if (delta > 1e-2f)
|
||||
if (delta > 1.f/60.f)
|
||||
color = Colors::Yellow;
|
||||
if (delta > 1e-1f)
|
||||
if (delta > 1.f/30.f)
|
||||
color = Colors::Red;
|
||||
if (delta > 1e+1f)
|
||||
if (delta > 1.f/15.f)
|
||||
color = Colors::Purples::Magenta;
|
||||
if (delta > 1e+2f)
|
||||
if (delta > 1.f/5.f)
|
||||
color = Colors::Black;
|
||||
|
||||
|
||||
Plot({(data.size()-1.f), 100 - (delta*1000)}, color);
|
||||
Plot({(data.size()-1.f), graph_height - (delta*y_axis_scale)}, color);
|
||||
|
||||
RenderDataPoints();
|
||||
Content(canvas);
|
||||
@@ -83,7 +78,37 @@ namespace JUI {
|
||||
std::vector<DataPoint> data;
|
||||
JGL::RenderTarget* canvas;
|
||||
|
||||
|
||||
float graph_height = 50;
|
||||
float graph_width = 500;
|
||||
float sample_history = 500;
|
||||
float y_axis_scale = 600;
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
class FpsGraphWindow : public JUI::Window
|
||||
{
|
||||
public:
|
||||
FpsGraphWindow() : Window()
|
||||
{
|
||||
Name("FPSGraphWindow");
|
||||
Title("FPS Graph");
|
||||
|
||||
|
||||
data_graph = new FpsGraph(this->Content());
|
||||
|
||||
}
|
||||
|
||||
explicit FpsGraphWindow(Widget* parent) : FpsGraphWindow()
|
||||
{
|
||||
this->Parent(parent);
|
||||
}
|
||||
protected:
|
||||
FpsGraph* data_graph;
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
4
main.cpp
4
main.cpp
@@ -376,11 +376,11 @@ JUI::Scene* CreateScene() {
|
||||
auto* graph_window = new JUI::Window(root);
|
||||
graph_window->Name("Graph Window");
|
||||
graph_window->Title("Graph Window");
|
||||
graph_window->Size({500_px, 100_px});
|
||||
graph_window->Size({500_px, 50_px});
|
||||
|
||||
auto* graph = new JUI::FpsGraph(graph_window->Content());
|
||||
graph->Name("Graph");
|
||||
graph->Size({500_px, 100_px});
|
||||
graph->Size({500_px, 50_px});
|
||||
|
||||
auto* colorpicker_wnd = new JUI::Window(root);
|
||||
colorpicker_wnd->Name("Slider ColorPicker");
|
||||
|
@@ -86,7 +86,7 @@ void TextBase::Draw(const Vector2& abs_pos, const Vector2& abs_size, const std::
|
||||
if (content == this->content) {
|
||||
// if Render Target needs updating.
|
||||
if (state_redraw) {
|
||||
text_canvas->Resize({(int) bounds.x+20, (int) bounds.y});
|
||||
text_canvas->Resize({(int) bounds.x, (int) bounds.y});
|
||||
J2D::Begin(text_canvas, nullptr, true);
|
||||
//J2D::FillRect(Colors::Red, {0,0}, bounds);
|
||||
J2D::DrawString(color, content, 0, 0, size, scale, this->font);
|
||||
@@ -102,9 +102,6 @@ void TextBase::Draw(const Vector2& abs_pos, const Vector2& abs_size, const std::
|
||||
use_render_target ? J2D::DrawRenderTarget(text_canvas, {align_x, align_y})
|
||||
: J2D::DrawString(color, content, align_x, align_y, size, scale, this->font);
|
||||
//J2D::End();
|
||||
|
||||
Vector2 bounds2 = this->font.MeasureString(content, this->text_size);
|
||||
JGL::J2D::OutlineRect(Colors::Red, text_pos, bounds2);
|
||||
}
|
||||
|
||||
void TextBase::Draw(const Vector2& abs_pos, const Vector2& abs_size) {
|
||||
|
Reference in New Issue
Block a user