Refactoring entire render logic to support ScrollingRect, got some results, but still having issues.
This commit is contained in:
@@ -58,7 +58,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME JGL
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-49.zip
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-50.zip
|
||||
)
|
||||
|
||||
target_include_directories(JUI PUBLIC ${Event_SOURCE_DIR}/include)
|
||||
|
@@ -67,7 +67,6 @@ namespace JUI
|
||||
|
||||
void Draw(const Vector2& pos, const Vector2& size);
|
||||
void Draw(const Color4& bgColor, const Color4& fgColor, const Vector2& pos, const Vector2& size);
|
||||
|
||||
protected:
|
||||
|
||||
enum BorderMode border_mode = BorderMode::Middle;
|
||||
@@ -78,7 +77,5 @@ namespace JUI
|
||||
Color4 border_color = {192, 192, 192, 0};
|
||||
bool clips_descendants = false; // Controls if child objects can render outside of their parent's rectangle bounds.
|
||||
float corner_rounding_radius = 0.f; // Curves the rectangle corners by N degrees.
|
||||
void Draw(JGL::RenderTarget *canvas, const Color4 &bgColor, const Color4 &borderColor, const Vector2 &abs_pos,
|
||||
const Vector2 &abs_size);
|
||||
};
|
||||
}
|
@@ -297,9 +297,10 @@ namespace JUI
|
||||
|
||||
// TODO: Consider calling J2D::Begin here.
|
||||
virtual void PreDraw() {}
|
||||
// TODO: Consider calling J2D::End here.
|
||||
virtual void PostDraw() {}
|
||||
|
||||
// TODO: Consider calling J2D::End here.
|
||||
|
||||
virtual void InnerDraw() {}
|
||||
|
||||
/// Renders the widget to the current OpenGL Context using JGL.
|
||||
|
@@ -46,10 +46,10 @@ namespace JUI
|
||||
Rect::InnerDraw();
|
||||
if (checked)
|
||||
{
|
||||
J2D::Begin();
|
||||
//J2D::Begin();
|
||||
Vector2 check_padding = {2, 2};
|
||||
RectBase::Draw(check_color, check_color, GetAbsolutePosition()+check_padding, GetAbsoluteSize()-(check_padding*2));
|
||||
J2D::End();
|
||||
//J2D::End();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ namespace JUI
|
||||
if (!visible)
|
||||
return;
|
||||
|
||||
J2D::Begin();
|
||||
//J2D::Begin();
|
||||
Vector2 abs_pos = GetAbsolutePosition();
|
||||
Vector2 abs_size = GetAbsoluteSize();
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace JUI
|
||||
|
||||
}
|
||||
|
||||
J2D::End();
|
||||
//J2D::End();
|
||||
}
|
||||
protected:
|
||||
bool checked;
|
||||
|
@@ -45,10 +45,11 @@ public:
|
||||
void Draw() override;
|
||||
void Update(float delta) override
|
||||
{
|
||||
scroll += delta;
|
||||
scroll += delta*5;
|
||||
canvas->Resize(Vector2i(GetAbsoluteSize().x, GetAbsoluteSize().y));
|
||||
Rect::Update(delta);
|
||||
|
||||
canvas->Resize(Vector2i(GetAbsoluteSize().x, GetAbsoluteSize().y));
|
||||
|
||||
}
|
||||
public:
|
||||
~ScrollingRect() override { delete canvas; }
|
||||
|
10
main.cpp
10
main.cpp
@@ -135,6 +135,16 @@ JUI::Scene* CreateScene() {
|
||||
scroller->Size({100_percent, 100_percent});
|
||||
scroller->BGColor(Colors::Reds::LightCoral);
|
||||
|
||||
|
||||
auto* layout = new JUI::VerticalListLayout(scroller);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
auto* text = new JUI::TextRect(layout);
|
||||
text->Size({50_percent, 20_px});
|
||||
text->SetContent("This Dick");
|
||||
}
|
||||
|
||||
//nineslice_demo_window->Padding(1_px);
|
||||
// End Window //
|
||||
|
||||
|
@@ -6,10 +6,10 @@ using namespace JGL;
|
||||
namespace JUI
|
||||
{
|
||||
void ImageBase::Draw(const Vector2 &pos, const Vector2 &size) {
|
||||
J2D::Begin();
|
||||
//J2D::Begin();
|
||||
// TODO: Support image rotation in the widget.
|
||||
J2D::DrawSprite(*texture, pos, 0, origin, scale, image_color);
|
||||
J2D::End();
|
||||
//J2D::End();
|
||||
}
|
||||
|
||||
ImageBase::ImageBase()
|
||||
|
@@ -33,14 +33,14 @@ namespace JUI {
|
||||
Draw(bg_color, border_color, abs_pos, abs_size);
|
||||
}
|
||||
|
||||
//void RectBase::Draw(const Color4& bgColor, const Color4& borderColor, const Vector2 &abs_pos, const Vector2 &abs_size) {
|
||||
|
||||
//Draw(nullptr, bgColor, borderColor, abs_pos, abs_size);
|
||||
//}
|
||||
|
||||
void RectBase::Draw(const Color4& bgColor, const Color4& borderColor, const Vector2 &abs_pos, const Vector2 &abs_size) {
|
||||
|
||||
Draw(nullptr, bgColor, borderColor, abs_pos, abs_size);
|
||||
}
|
||||
|
||||
void RectBase::Draw(JGL::RenderTarget* canvas, const Color4& bgColor, const Color4& borderColor, const Vector2 &abs_pos, const Vector2 &abs_size) {
|
||||
|
||||
J2D::Begin(canvas, false);
|
||||
//J2D::Begin(canvas, false);
|
||||
|
||||
// Background rect
|
||||
if (corner_rounding_radius > 0)
|
||||
@@ -68,7 +68,7 @@ namespace JUI {
|
||||
}
|
||||
|
||||
|
||||
J2D::End();
|
||||
//J2D::End();
|
||||
}
|
||||
|
||||
void RectBase::BorderMode(const enum BorderMode &mode) {
|
||||
|
@@ -89,11 +89,11 @@ void TextBase::Draw(const Vector2& abs_pos, const Vector2& abs_size, const std::
|
||||
}
|
||||
|
||||
Vector2 text_pos = {align_x, align_y};
|
||||
J2D::Begin();
|
||||
//J2D::Begin();
|
||||
//J2D::OutlineRect(color, text_pos, bounds); // Draw bounding box for debugging.
|
||||
use_render_target ? J2D::DrawRenderTarget(text_canvas, {align_x, align_y})
|
||||
: J2D::DrawString(color, content, align_x, align_y, scale, size, this->set_font);
|
||||
J2D::End();
|
||||
//J2D::End();
|
||||
}
|
||||
|
||||
void TextBase::Draw(const Vector2& abs_pos, const Vector2& abs_size) {
|
||||
|
@@ -42,7 +42,7 @@ namespace JUI
|
||||
void NineSliceRect::Draw() {
|
||||
Rect::Draw();
|
||||
|
||||
JGL::J2D::Begin();
|
||||
//JGL::J2D::Begin();
|
||||
|
||||
Vector2 abs_pos = GetAbsolutePosition();
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace JUI
|
||||
JGL::J2D::DrawPartialSprite(texture, c_computed_pos, c_quad.minPoint, c_quad.maxPoint, 0, {0,0}, c_scaling);
|
||||
|
||||
|
||||
JGL::J2D::End();
|
||||
//JGL::J2D::End();
|
||||
}
|
||||
|
||||
NineSliceRect::NineSliceRect() : Rect(), ImageBase() {}
|
||||
|
@@ -44,12 +44,11 @@ namespace JUI {
|
||||
|
||||
void Rect::InnerDraw()
|
||||
{
|
||||
J2D::Begin();
|
||||
//J2D::Begin();
|
||||
RectBase::Draw(GetAbsolutePosition(), GetAbsoluteSize());
|
||||
J2D::End();
|
||||
//J2D::End();
|
||||
// Draw Child Elements with scissor clipping still active
|
||||
//Widget::DrawChildWidgets();
|
||||
|
||||
}
|
||||
|
||||
void Rect::Update(float delta) {
|
||||
|
@@ -8,7 +8,9 @@ namespace JUI {
|
||||
Vector2 Scene::GetAbsoluteSize() const { return viewport_size;}
|
||||
|
||||
void Scene::Draw() {
|
||||
Widget::Draw();
|
||||
J2D::Begin();
|
||||
Widget::Draw();
|
||||
J2D::End();
|
||||
}
|
||||
|
||||
void Scene::Update(float delta) {
|
||||
|
@@ -4,22 +4,23 @@
|
||||
using namespace JUI;
|
||||
|
||||
void ScrollingRect::RecomputeRenderTarget() {
|
||||
Rect::PreDraw();
|
||||
//
|
||||
//Rect::PreDraw();
|
||||
InnerDraw();
|
||||
Rect::PostDraw();
|
||||
//Rect::PostDraw();
|
||||
}
|
||||
|
||||
void ScrollingRect::Draw() {
|
||||
|
||||
//std::cout << "ScrollingRect::RecomputeRenderTarget " << scroll << std::endl;
|
||||
RecomputeRenderTarget();
|
||||
Rect::InnerDraw();
|
||||
J2D::Begin();
|
||||
//ScrollingRect::InnerDraw();
|
||||
//J2D::Begin();
|
||||
|
||||
//J2D::DrawRenderTarget(canvas, CanvasPosition());
|
||||
// TODO sub_texture_size would be the size of the visible area.
|
||||
J2D::DrawPartialRenderTarget(canvas, GetAbsolutePosition(), {0, scroll}, {64, 64});
|
||||
J2D::DrawPartialRenderTarget(canvas, GetAbsolutePosition(), {0, scroll}, {256, 256});//Vector2(canvas_size.x, canvas_size.y));
|
||||
|
||||
J2D::End();
|
||||
//J2D::End();
|
||||
}
|
||||
|
||||
Vector2 ScrollingRect::CanvasPosition() const {
|
||||
@@ -28,9 +29,32 @@ Vector2 ScrollingRect::CanvasPosition() const {
|
||||
|
||||
// Wouldn't inner draw actually render everything onto the RenderTarget?
|
||||
void ScrollingRect::InnerDraw() {
|
||||
//
|
||||
|
||||
|
||||
|
||||
J2D::Begin(canvas, true);
|
||||
auto saved_pos = position;
|
||||
auto* saved_parent = parent;
|
||||
auto saved_size = size;
|
||||
|
||||
// OH MY GOD
|
||||
Parent(nullptr);
|
||||
Position({0_px, 0_px});
|
||||
Size({256_px, 256_px});
|
||||
|
||||
std::cout << GetAbsolutePosition() << std::endl;
|
||||
|
||||
|
||||
Rect::InnerDraw();
|
||||
DrawChildWidgets();
|
||||
|
||||
Parent(saved_parent);
|
||||
|
||||
Size(saved_size);
|
||||
Position(saved_pos);
|
||||
J2D::End();
|
||||
|
||||
//J2D::FillRect(bg_color, {0, 0}, {64, 64});
|
||||
//RectBase::Draw(canvas,bg_color, border_color, {0, 0}, {64, 64});
|
||||
//RectBase::Draw(canvas,bg_color, border_color, {0, 70}, {64, 64});
|
||||
|
@@ -85,9 +85,9 @@ namespace JUI
|
||||
,GetAbsolutePosition().y
|
||||
};
|
||||
/// TODO: Implement internal padding on scrubber element?
|
||||
J2D::Begin();
|
||||
//J2D::Begin();
|
||||
JGL::J2D::FillRect(scrubber_color, pos, {scrubber_width, GetAbsoluteSize().y});
|
||||
J2D::End();
|
||||
//J2D::End();
|
||||
}
|
||||
|
||||
float Slider::Minimum() const { return minimum; }
|
||||
|
@@ -11,7 +11,7 @@ namespace JUI {
|
||||
|
||||
Text::~Text() {}
|
||||
Vector2 Text::GetAbsolutePosition() const {
|
||||
auto parent =this->GetParent();
|
||||
auto parent = this->GetParent();
|
||||
if (parent)
|
||||
return parent->GetAbsolutePosition();
|
||||
//return {0,0};
|
||||
|
Reference in New Issue
Block a user