Skip to content

Commit

Permalink
Added ability to set border to be inner or outer
Browse files Browse the repository at this point in the history
  • Loading branch information
Neko-Box-Coder committed Oct 25, 2023
1 parent 929d189 commit 71105f4
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 42 deletions.
19 changes: 16 additions & 3 deletions Include/ssGUI/Extensions/Border.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ namespace Extensions
//TODO : Maybe change to private enum class. Just too lazy to do it atm :P
int8_t BorderSides; //(Internal variable) Used to identify which sides need to apply the border
//(0000 [Bottom bit] [Right bit] [Top bit] [Left bit])
bool InnerBorder; //If true, the border will be rendered inside the GUI Object
=================================================================
============================== C++ ==============================
Border::Border() : Container(nullptr),
Enabled(true),
BorderColor(0, 0, 0, 255),
BorderWidth(1),
BorderSides(15)
BorderSides(1 << 3 | 1 << 2 | 1 << 1 | 1 << 0),
InnerBorder(false)
{}
=================================================================
*/
Expand All @@ -54,9 +57,13 @@ namespace Extensions
int8_t BorderSides; //(Internal variable) Used to identify which sides need to apply the border
//(0000 [Bottom bit] [Right bit] [Top bit] [Left bit])

bool InnerBorder; //If true, the border will be rendered inside the GUI Object

virtual void DrawBorder();
virtual void ConstructRenderInfo() override;
virtual void ConstructRenderInfo(ssGUI::Backend::BackendDrawingInterface* drawingInterface, ssGUI::GUIObject* mainWindow, glm::vec2 mainWindowPositionOffset) override;
virtual void ConstructRenderInfo( ssGUI::Backend::BackendDrawingInterface* drawingInterface,
ssGUI::GUIObject* mainWindow,
glm::vec2 mainWindowPositionOffset) override;

Border();
virtual ~Border() override;
Expand Down Expand Up @@ -110,8 +117,14 @@ namespace Extensions
//function: IsBorderBottomShowing
virtual bool IsBorderBottomShowing() const;

//function: SetInnerBorder
virtual void SetInnerBorder(bool innerBorder);

//function: IsInnerBorder
virtual bool IsInnerBorder() const;

//Override from Extension
//function: SetEnabled
//function: SetEnabled
//See <Extension::SetEnabled>
virtual void SetEnabled(bool enabled) override;

Expand Down
136 changes: 97 additions & 39 deletions Src/ssGUI/Extensions/Border.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace Extensions
Enabled(true),
BorderColor(0, 0, 0, 255),
BorderWidth(1),
BorderSides(15)
BorderSides(1 << 3 | 1 << 2 | 1 << 1 | 1 << 0),
InnerBorder(false)
{}

Border::~Border()
Expand All @@ -29,7 +30,8 @@ namespace Extensions
glm::vec2 drawPosition = Container->GetGlobalPosition();

int width = GetBorderWidth();
glm::u8vec4 colour = GetBorderColor();
glm::vec2 offset = InnerBorder ? glm::vec2() : glm::vec2(width, width);
glm::u8vec4 color = GetBorderColor();

std::vector<ssGUI::DrawingEntity>& drawingEntities = Container->Extension_GetDrawingEntities();

Expand All @@ -38,15 +40,21 @@ namespace Extensions
{
ssGUI::DrawingEntity entity;
entity.EntityName = BORDER_TOP_SHAPE_NAME;
entity.Vertices.push_back(drawPosition + glm::vec2(0, 0));
entity.Vertices.push_back(drawPosition + glm::vec2(Container->GetSize().x, 0));
entity.Vertices.push_back(drawPosition + glm::vec2(Container->GetSize().x, width));
entity.Vertices.push_back(drawPosition + glm::vec2(0, width));

entity.Colors.push_back(colour);
entity.Colors.push_back(colour);
entity.Colors.push_back(colour);
entity.Colors.push_back(colour);
entity.Vertices.push_back(drawPosition - offset + glm::vec2(0, 0));
entity.Vertices.push_back( drawPosition +
glm::vec2(offset.x, -offset.y) +
glm::vec2(Container->GetSize().x, 0));

entity.Vertices.push_back( drawPosition +
glm::vec2(offset.x, -offset.y) +
glm::vec2(Container->GetSize().x, width));

entity.Vertices.push_back( drawPosition - offset + glm::vec2(0, width));

entity.Colors.push_back(color);
entity.Colors.push_back(color);
entity.Colors.push_back(color);
entity.Colors.push_back(color);

drawingEntities.push_back(entity);
}
Expand All @@ -56,15 +64,30 @@ namespace Extensions
{
ssGUI::DrawingEntity entity;
entity.EntityName = BORDER_RIGHT_SHAPE_NAME;
entity.Vertices.push_back(drawPosition + glm::vec2(Container->GetSize().x - width, (IsBorderTopShowing() ? width : 0)));
entity.Vertices.push_back(drawPosition + glm::vec2(Container->GetSize().x, (IsBorderTopShowing() ? width : 0)));
entity.Vertices.push_back(drawPosition + glm::vec2(Container->GetSize().x, Container->GetSize().y + (IsBorderBottomShowing() ? -width : 0)));
entity.Vertices.push_back(drawPosition + glm::vec2(Container->GetSize().x - width, Container->GetSize().y + (IsBorderBottomShowing() ? -width : 0)));

entity.Colors.push_back(colour);
entity.Colors.push_back(colour);
entity.Colors.push_back(colour);
entity.Colors.push_back(colour);
entity.Vertices.push_back( drawPosition +
glm::vec2(offset.x, -offset.y) +
glm::vec2( Container->GetSize().x - width,
(IsBorderTopShowing() ? width : 0)));

entity.Vertices.push_back( drawPosition +
glm::vec2(offset.x, -offset.y) +
glm::vec2( Container->GetSize().x,
(IsBorderTopShowing() ? width : 0)));

entity.Vertices.push_back( drawPosition +
offset +
glm::vec2( Container->GetSize().x,
Container->GetSize().y + (IsBorderBottomShowing() ? -width : 0)));

entity.Vertices.push_back( drawPosition +
offset +
glm::vec2( Container->GetSize().x - width,
Container->GetSize().y + (IsBorderBottomShowing() ? -width : 0)));

entity.Colors.push_back(color);
entity.Colors.push_back(color);
entity.Colors.push_back(color);
entity.Colors.push_back(color);

drawingEntities.push_back(entity);
}
Expand All @@ -74,15 +97,26 @@ namespace Extensions
{
ssGUI::DrawingEntity entity;
entity.EntityName = BORDER_BOTTOM_SHAPE_NAME;
entity.Vertices.push_back(drawPosition + glm::vec2(0, Container->GetSize().y - width));
entity.Vertices.push_back(drawPosition + glm::vec2(Container->GetSize().x, Container->GetSize().y - width));
entity.Vertices.push_back(drawPosition + glm::vec2(Container->GetSize().x, Container->GetSize().y));
entity.Vertices.push_back(drawPosition + glm::vec2(0, Container->GetSize().y));

entity.Colors.push_back(colour);
entity.Colors.push_back(colour);
entity.Colors.push_back(colour);
entity.Colors.push_back(colour);
entity.Vertices.push_back( drawPosition +
glm::vec2(-offset.x, offset.y) +
glm::vec2(0, Container->GetSize().y - width));

entity.Vertices.push_back( drawPosition +
offset +
glm::vec2(Container->GetSize().x, Container->GetSize().y - width));

entity.Vertices.push_back( drawPosition +
offset +
glm::vec2(Container->GetSize().x, Container->GetSize().y));

entity.Vertices.push_back( drawPosition +
glm::vec2(-offset.x, offset.y) +
glm::vec2(0, Container->GetSize().y));

entity.Colors.push_back(color);
entity.Colors.push_back(color);
entity.Colors.push_back(color);
entity.Colors.push_back(color);

drawingEntities.push_back(entity);
}
Expand All @@ -92,15 +126,27 @@ namespace Extensions
{
ssGUI::DrawingEntity entity;
entity.EntityName = BORDER_LEFT_SHAPE_NAME;
entity.Vertices.push_back(drawPosition + glm::vec2(0, IsBorderTopShowing() ? width : 0));
entity.Vertices.push_back(drawPosition + glm::vec2(width, IsBorderTopShowing() ? width : 0));
entity.Vertices.push_back(drawPosition + glm::vec2(width, Container->GetSize().y + (IsBorderBottomShowing() ? -width : 0)));
entity.Vertices.push_back(drawPosition + glm::vec2(0, Container->GetSize().y + (IsBorderBottomShowing() ? -width : 0)));

entity.Colors.push_back(colour);
entity.Colors.push_back(colour);
entity.Colors.push_back(colour);
entity.Colors.push_back(colour);

entity.Vertices.push_back( drawPosition -
offset +
glm::vec2(0, IsBorderTopShowing() ? width : 0));

entity.Vertices.push_back( drawPosition -
offset +
glm::vec2(width, IsBorderTopShowing() ? width : 0));

entity.Vertices.push_back( drawPosition +
glm::vec2(-offset.x, offset.y) +
glm::vec2(width,Container->GetSize().y + (IsBorderBottomShowing() ? -width : 0)));

entity.Vertices.push_back( drawPosition +
glm::vec2(-offset.x, offset.y) +
glm::vec2(0, Container->GetSize().y + (IsBorderBottomShowing() ? -width : 0)));

entity.Colors.push_back(color);
entity.Colors.push_back(color);
entity.Colors.push_back(color);
entity.Colors.push_back(color);

drawingEntities.push_back(entity);
}
Expand All @@ -111,7 +157,9 @@ namespace Extensions
DrawBorder();
}

void Border::ConstructRenderInfo(ssGUI::Backend::BackendDrawingInterface* drawingInterface, ssGUI::GUIObject* mainWindow, glm::vec2 mainWindowPositionOffset)
void Border::ConstructRenderInfo( ssGUI::Backend::BackendDrawingInterface* drawingInterface,
ssGUI::GUIObject* mainWindow,
glm::vec2 mainWindowPositionOffset)
{
ConstructRenderInfo();
}
Expand Down Expand Up @@ -184,6 +232,15 @@ namespace Extensions
return ((BorderSides & (1 << 3)) > 0);
}

void Border::SetInnerBorder(bool innerBorder)
{
InnerBorder = innerBorder;
}

bool Border::IsInnerBorder() const
{
return InnerBorder;
}

void Border::SetEnabled(bool enabled)
{
Expand Down Expand Up @@ -237,6 +294,7 @@ namespace Extensions
BorderColor = border->GetBorderColor();
BorderWidth = border->GetBorderWidth();
BorderSides = border->BorderSides;
InnerBorder = border->InnerBorder;
}

ObjectsReferences* Border::Internal_GetObjectsReferences()
Expand Down

0 comments on commit 71105f4

Please sign in to comment.