ClipsDescendants functionality.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
namespace JUI
|
||||
{
|
||||
class RectBase {
|
||||
|
||||
public:
|
||||
protected:
|
||||
};
|
||||
}
|
@@ -26,15 +26,16 @@ namespace JUI {
|
||||
void Update(float delta) override;
|
||||
bool IsMouseInside() const;
|
||||
|
||||
Color4 GetBGColor() const { return bg_color; }
|
||||
Color4 GetBorderColor() const { return border_color;}
|
||||
float GetBorderWidth() const { return border_width;}
|
||||
Color4 GetBGColor() const;
|
||||
Color4 GetBorderColor() const;
|
||||
float GetBorderWidth() const;
|
||||
|
||||
bool GetClipsDescendants() const;
|
||||
|
||||
void SetBGColor(const Color4& col) { bg_color = col;}
|
||||
void SetBorderColor(const Color4& col) { border_color = col;}
|
||||
void SetBorderWidth(float w) {border_width = w;}
|
||||
|
||||
void SetClipsDescendants(bool clipping);
|
||||
void SetBGColor(const Color4& col);
|
||||
void SetBorderColor(const Color4& col);
|
||||
void SetBorderWidth(float w);
|
||||
|
||||
void SetCornerRounding(float radius);
|
||||
void SetCornerRounding(float tlRadius, float trRadius, float blRadius, float brRadius);
|
||||
@@ -44,10 +45,7 @@ namespace JUI {
|
||||
void SetCornerRoundingBR(float radius);
|
||||
|
||||
|
||||
void SetBorderStyling(const Color4& color, float width) {
|
||||
SetBorderColor(color);
|
||||
SetBorderWidth(width);
|
||||
}
|
||||
void SetBorderStyling(const Color4& color, float width);
|
||||
protected:
|
||||
float border_width = 1.f;
|
||||
Color4 bg_color = {128,128,128, 255};
|
||||
|
2
main.cpp
2
main.cpp
@@ -31,7 +31,7 @@ JUI::Scene* CreateScene() {
|
||||
element->SetBGColor({0,64,0});
|
||||
auto size = UDim2(64, 64, 0, 0);
|
||||
element->SetSize({0, 0, 0.5f, 0.5f});
|
||||
|
||||
element->SetClipsDescendants(true);
|
||||
|
||||
Text* text = new Text(element);
|
||||
text->SetContent("YO MAMA");
|
||||
|
@@ -18,24 +18,41 @@ namespace JUI {
|
||||
|
||||
auto root_size = GetFamilyTreeRoot()->GetAbsoluteSize();
|
||||
|
||||
GLint *old_scissor_bounds;
|
||||
bool clip_was_enabled;
|
||||
// TODO: Re-enable clipping
|
||||
|
||||
if (clips_descendants) {
|
||||
clip_was_enabled = glIsEnabled(GL_SCISSOR_TEST);
|
||||
if (clip_was_enabled)
|
||||
glGetIntegerv(GL_SCISSOR_BOX, old_scissor_bounds);
|
||||
|
||||
float presumed_screen_height = 600;
|
||||
glScissor(abs_pos.x, presumed_screen_height-abs_size.y-abs_pos.y, abs_size.x, abs_size.y);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
// Background rect
|
||||
//J2D::FillRoundedRect(bg_color, abs_pos, abs_size, corner_rounding_radius);
|
||||
|
||||
J2D::Begin();
|
||||
J2D::FillRect(bg_color, abs_pos, abs_size);
|
||||
// Outline rect
|
||||
if (corner_rounding_radius >= 0)
|
||||
J2D::OutlineRect(border_color, abs_pos, abs_size);
|
||||
|
||||
// Outline rect
|
||||
if (corner_rounding_radius >= 0)
|
||||
J2D::OutlineRect(border_color, abs_pos, abs_size);
|
||||
J2D::End();
|
||||
//J2D::OutlineRoundedRect(bg_color, abs_pos, abs_size, corner_rounding_radius, border_width);
|
||||
|
||||
|
||||
// Draw Child Elements with scissor clipping still active
|
||||
Widget::Draw();
|
||||
// TODO: Return clip to previous state
|
||||
|
||||
// Returns clip to previous state
|
||||
if (clips_descendants)
|
||||
{
|
||||
//glScissor(old_scissor_bounds[0], old_scissor_bounds[1], old_scissor_bounds[2], old_scissor_bounds[3]);
|
||||
|
||||
if (!clip_was_enabled) {}
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
}
|
||||
|
||||
J2D::End();
|
||||
}
|
||||
@@ -45,6 +62,27 @@ namespace JUI {
|
||||
Widget::Update(delta);
|
||||
}
|
||||
|
||||
bool Rect::GetClipsDescendants() const { return clips_descendants;}
|
||||
|
||||
void Rect::SetClipsDescendants(bool clipping) { clips_descendants = clipping;}
|
||||
|
||||
void Rect::SetBGColor(const Color4 &col) { bg_color = col;}
|
||||
|
||||
void Rect::SetBorderColor(const Color4 &col) { border_color = col;}
|
||||
|
||||
void Rect::SetBorderWidth(float w) {border_width = w;}
|
||||
|
||||
float Rect::GetBorderWidth() const { return border_width;}
|
||||
|
||||
Color4 Rect::GetBorderColor() const { return border_color;}
|
||||
|
||||
Color4 Rect::GetBGColor() const { return bg_color; }
|
||||
|
||||
void Rect::SetBorderStyling(const Color4 &color, float width) {
|
||||
SetBorderColor(color);
|
||||
SetBorderWidth(width);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user