Skip to content

Commit

Permalink
Updating Layout and other small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Neko-Box-Coder committed Oct 27, 2023
1 parent 2080d57 commit 1294b94
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 34 deletions.
1 change: 1 addition & 0 deletions Include/ssGUI/DataClasses/ImageFormat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace ssGUI
bool HasAlpha = true;

//var: PreMultipliedAlpha
//If this image has pre-multiplied alpha, this means that the color values are already multiplied with the alpha value.
bool PreMultipliedAlpha = false;

//var: IndexR
Expand Down
7 changes: 7 additions & 0 deletions Include/ssGUI/Extensions/Layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ namespace Extensions
//If a GUI Object is excluded, it will be ignored
virtual void UnexcludeObject(ssGUI::GUIObject* obj);

//function: ForceUpdateLayout
//Forces layout to be updated early, and it will not be updated again by <Internal_Update>
virtual void ForceUpdateLayout( ssGUI::Backend::BackendSystemInputInterface* inputInterface,
ssGUI::InputStatus& currentInputStatus,
ssGUI::InputStatus& lastInputStatus,
ssGUI::GUIObject* mainWindow);

//function: Internal_OnRecursiveChildAdded
//(Internal ssGUI function) Listener function when a child is being added
virtual void Internal_OnRecursiveChildAdded(ssGUI::GUIObject* child);
Expand Down
10 changes: 8 additions & 2 deletions Include/ssGUI/HelperClasses/ImageUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ namespace ssGUI
if(format.IndexA < 0)
{
//If we are outputing RGBA
//TODO: This behavior is misleading, there should be a flag for sepecifying if the mono pixels are outputing to RGB pixels as opaque RGBA image or
// outputing to alpha channel of RGBA image with RGB channels being white
if(outputFormat.IndexA >= 0)
{
conversionFunc = [&](InputChannelType const* curPixelPtr, int x, int y)
Expand All @@ -149,6 +151,7 @@ namespace ssGUI
};
}
//If we are outputing RGB
//TODO: This is wrong since we are just setting the RGB channels to white without using the mono pixels
else
{
conversionFunc = [&](InputChannelType const* curPixelPtr, int x, int y)
Expand Down Expand Up @@ -219,8 +222,10 @@ namespace ssGUI
//RGB
else
{
//If the input RGB image has alpha
if(format.HasAlpha)
{
//If the input image doesn't have pre-multiplied alpha, we can just copy the pixels
if(!format.PreMultipliedAlpha)
{
//If we are outputing RGBA
Expand All @@ -245,6 +250,7 @@ namespace ssGUI
};
}
}
//If the input image has pre-multiplied alpha, we need to get the original color values
else
{
//If we are outputing RGBA
Expand Down Expand Up @@ -280,7 +286,7 @@ namespace ssGUI
//If the input RGB image doesn't have alpha
else
{
//If we are outputing RGBA
//If we are outputing RGBA, we just set the alpha to max
if(outputFormat.IndexA >= 0)
{
conversionFunc = [&](InputChannelType const* curPixelPtr, int x, int y)
Expand Down Expand Up @@ -347,7 +353,7 @@ namespace ssGUI
inImg = monoImgPtr;\
}

public:
public:
static bool ConvertToRGBA32(void* outImg, void const * inImg, ssGUI::ImageFormat format,
glm::ivec2 imageSize)
{
Expand Down
68 changes: 41 additions & 27 deletions Src/ssGUI/Extensions/Layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ namespace Extensions

Container->StashChildrenIterator();
Container->MoveChildrenIteratorToFirst();

ssGUI::Window* lastWindowChild = nullptr;
while(!Container->IsChildrenIteratorEnd())
{
ssGUIObjectIndex currentChildIndex = CurrentObjectsReferences.GetObjectIndex(Container->GetCurrentChild());
Expand All @@ -195,7 +197,8 @@ namespace Extensions
continue;
}

if(Container->GetCurrentChild()->GetType() != ssGUI::Enums::GUIObjectType::WINDOW)
if( Container->GetCurrentChild()->GetType() != ssGUI::Enums::GUIObjectType::WINDOW ||
!Container->GetCurrentChild()->IsEnabled())
{
Container->MoveChildrenIteratorNext();
continue;
Expand Down Expand Up @@ -231,10 +234,7 @@ namespace Extensions
windowP->SetResizeType(ssGUI::Enums::ResizeType::BOTTOM);
}

//last element
if(Container->IsChildrenIteratorLast())
windowP->SetResizeType(ssGUI::Enums::ResizeType::NONE);

lastWindowChild = windowP;
windowP->SetOnTopWhenFocused(false);
}

Expand All @@ -250,6 +250,14 @@ namespace Extensions

Container->MoveChildrenIteratorNext();
}

//last element of the layout shouldn't be resized so that the container can be resized
if(IsOverrideChildrenResizeTypeAndOnTop() && lastWindowChild != nullptr)
{
if(Container->IsChildrenIteratorLast())
lastWindowChild->SetResizeType(ssGUI::Enums::ResizeType::NONE);
}

Container->PopChildrenIterator();
}

Expand All @@ -268,7 +276,7 @@ namespace Extensions
{
ssGUIObjectIndex childIndex = CurrentObjectsReferences.GetObjectIndex(Container->GetCurrentChild());

if(childIndex != -1 && ObjectsToExclude.find(childIndex) != ObjectsToExclude.end())
if((childIndex != -1 && ObjectsToExclude.find(childIndex) != ObjectsToExclude.end()) || !Container->GetCurrentChild()->IsEnabled())
{
Container->MoveChildrenIteratorNext();
continue;
Expand All @@ -294,7 +302,8 @@ namespace Extensions
while(!Container->IsChildrenIteratorEnd())
{
ssGUIObjectIndex currentChildIndex = CurrentObjectsReferences.GetObjectIndex(Container->GetCurrentChild());
if(currentChildIndex != -1 && ObjectsToExclude.find(currentChildIndex) != ObjectsToExclude.end())
if( (currentChildIndex != -1 && ObjectsToExclude.find(currentChildIndex) != ObjectsToExclude.end()) ||
!Container->GetCurrentChild()->IsEnabled())
{
Container->MoveChildrenIteratorNext();
continue;
Expand Down Expand Up @@ -342,15 +351,8 @@ namespace Extensions
maxMinY += GetPadding() * 2;
}

//Check if we want to use container's min max or children's min max
maxMinY = maxMinY > Container->GetMinSize().y ? maxMinY : Container->GetMinSize().y;
minMaxY = minMaxY < Container->GetMaxSize().y ? minMaxY : Container->GetMaxSize().y;

if(IsCoverFullLength())
{
minSizeTotalX = minSizeTotalX > Container->GetMinSize().x ? minSizeTotalX : Container->GetMinSize().x;
maxSizeTotalX = maxSizeTotalX < Container->GetMaxSize().x ? maxSizeTotalX : Container->GetMaxSize().x;

Container->SetMinSize(glm::vec2(minSizeTotalX, maxMinY));
Container->SetMaxSize(glm::vec2(maxSizeTotalX, minMaxY));
}
Expand All @@ -372,7 +374,8 @@ namespace Extensions
while(!Container->IsChildrenIteratorEnd())
{
ssGUIObjectIndex currentChildIndex = CurrentObjectsReferences.GetObjectIndex(Container->GetCurrentChild());
if(currentChildIndex != -1 && ObjectsToExclude.find(currentChildIndex) != ObjectsToExclude.end())
if( (currentChildIndex != -1 && ObjectsToExclude.find(currentChildIndex) != ObjectsToExclude.end()) ||
!Container->GetCurrentChild()->IsEnabled())
{
Container->MoveChildrenIteratorNext();
continue;
Expand Down Expand Up @@ -416,15 +419,8 @@ namespace Extensions
minMaxX += GetPadding() * 2;
maxMinX += GetPadding() * 2;

//Check if we want to use container's min max or children's min max
maxMinX = maxMinX > Container->GetMinSize().x ? maxMinX : Container->GetMinSize().x;
minMaxX = minMaxX < Container->GetMaxSize().x ? minMaxX : Container->GetMaxSize().x;

if(IsCoverFullLength())
{
minSizeTotalY = minSizeTotalY > Container->GetMinSize().y ? minSizeTotalY : Container->GetMinSize().y;
maxSizeTotalY = maxSizeTotalY < Container->GetMaxSize().y ? maxSizeTotalY : Container->GetMaxSize().y;

Container->SetMinSize(glm::vec2(maxMinX, minSizeTotalY));
Container->SetMaxSize(glm::vec2(minMaxX, maxSizeTotalY));
}
Expand All @@ -443,7 +439,7 @@ namespace Extensions
for(auto it : SpecialObjectsToExclude)
{
//Don't need to hold reference for it as it is not a child
if(CurrentObjectsReferences.GetObjectReference(it) == nullptr ||
if( CurrentObjectsReferences.GetObjectReference(it) == nullptr ||
CurrentObjectsReferences.GetObjectReference(it)->GetParent() != Container)
{
objsToRemove.push_back(it);
Expand Down Expand Up @@ -507,7 +503,8 @@ namespace Extensions
ssGUIObjectIndex childIndex = CurrentObjectsReferences.GetObjectIndex(Container->GetCurrentChild());

//Don't update the objects if excluded
if(childIndex != -1 && ObjectsToExclude.find(childIndex) != ObjectsToExclude.end())
if((childIndex != -1 && ObjectsToExclude.find(childIndex) != ObjectsToExclude.end()) ||
!Container->GetCurrentChild()->IsEnabled())
{
Container->MoveChildrenIteratorNext();
continue;
Expand Down Expand Up @@ -535,7 +532,8 @@ namespace Extensions
{
ssGUIObjectIndex childIndex = CurrentObjectsReferences.GetObjectIndex(Container->GetCurrentChild());

if(childIndex != -1 && ObjectsToExclude.find(childIndex) != ObjectsToExclude.end())
if( (childIndex != -1 && ObjectsToExclude.find(childIndex) != ObjectsToExclude.end()) ||
!Container->GetCurrentChild()->IsEnabled())
{
Container->MoveChildrenIteratorNext();
continue;
Expand Down Expand Up @@ -607,7 +605,8 @@ namespace Extensions
{
ssGUIObjectIndex childIndex = CurrentObjectsReferences.GetObjectIndex(Container->GetCurrentChild());

if(childIndex != -1 && ObjectsToExclude.find(childIndex) != ObjectsToExclude.end())
if( (childIndex != -1 && ObjectsToExclude.find(childIndex) != ObjectsToExclude.end()) ||
!Container->GetCurrentChild()->IsEnabled())
{
Container->MoveChildrenIteratorPrevious();
continue;
Expand Down Expand Up @@ -673,7 +672,8 @@ namespace Extensions
{
ssGUIObjectIndex childIndex = CurrentObjectsReferences.GetObjectIndex(Container->GetCurrentChild());

if(childIndex != -1 && ObjectsToExclude.find(childIndex) != ObjectsToExclude.end())
if( (childIndex != -1 && ObjectsToExclude.find(childIndex) != ObjectsToExclude.end()) ||
!Container->GetCurrentChild()->IsEnabled())
{
Container->MoveChildrenIteratorNext();
continue;
Expand Down Expand Up @@ -721,6 +721,7 @@ namespace Extensions
void Layout::SetHorizontalLayout(bool horizontal)
{
HorizontalLayout = horizontal;
UpdateChildrenResizeTypesAndOnTop();
}

void Layout::AddPreferredSizeMultiplier(float sizeMultiplier)
Expand Down Expand Up @@ -780,6 +781,7 @@ namespace Extensions
void Layout::SetReverseOrder(bool reverseOrder)
{
ReverseOrder = reverseOrder;
UpdateChildrenResizeTypesAndOnTop();
}

bool Layout::IsCoverFullLength() const
Expand Down Expand Up @@ -952,6 +954,15 @@ namespace Extensions
}
}

void Layout::ForceUpdateLayout( ssGUI::Backend::BackendSystemInputInterface* inputInterface,
ssGUI::InputStatus& currentInputStatus,
ssGUI::InputStatus& lastInputStatus,
ssGUI::GUIObject* mainWindow)
{
Updated = false;
Internal_Update(false, inputInterface, currentInputStatus, lastInputStatus, mainWindow);
}

void Layout::Internal_OnRecursiveChildAdded(ssGUI::GUIObject* child)
{
ssGUI_LOG_FUNC();
Expand Down Expand Up @@ -1158,6 +1169,9 @@ namespace Extensions
if(DisableChildrenResizing)
DisableChildrenResizingInUpdate();

if(IsOverrideChildrenResizeTypeAndOnTop())
UpdateChildrenResizeTypesAndOnTop();

//Set all children's width and get all children pos and size and min size
std::vector<float> childrenPos;
std::vector<float> childrenSize;
Expand Down
12 changes: 7 additions & 5 deletions Src/ssGUI/Extensions/Shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ namespace Extensions

glm::vec2 curLineNormalized;
glm::vec2 perpendcularVector;
startThickness /= 2.f;
endThickness /= 2.f;

//Special case of checking of the line has any length
if(curLine.x == 0 && curLine.y == 0)
Expand Down Expand Up @@ -150,11 +152,11 @@ namespace Extensions
targetShape.Colors.push_back(endColor);

targetShape.Type = ShapeType::LINE;
targetShape.Data.Line.StartPos = start;
targetShape.Data.Line.StartSize = startThickness;
targetShape.Data.Line.StartColor = startColor;
targetShape.Data.Line.EndPos = end;
targetShape.Data.Line.EndSize = endThickness;
targetShape.Data.Line.StartPos = start;
targetShape.Data.Line.StartSize = startThickness;
targetShape.Data.Line.StartColor = startColor;
targetShape.Data.Line.EndPos = end;
targetShape.Data.Line.EndSize = endThickness;
targetShape.Data.Line.EndColor = endColor;

targetShape.BehindGUI = behindGUIObject;
Expand Down

0 comments on commit 1294b94

Please sign in to comment.