Skip to content

Commit

Permalink
Replace non template functions that uses string... (kwk4HP3HDr)
Browse files Browse the repository at this point in the history
Replace non template functions that uses string to template in extension (kwk4HP3HDr)
  • Loading branch information
Neko-Box-Coder committed Aug 27, 2023
1 parent 0db0233 commit b469ee7
Show file tree
Hide file tree
Showing 36 changed files with 251 additions and 272 deletions.
79 changes: 32 additions & 47 deletions Include/ssGUI/DataClasses/ExtensionManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,39 @@ namespace ssGUI

ExtensionManager(ExtensionManager const&);

ssGUI::Extensions::Extension* GetExtension(std::string extensionName);

bool IsExtensionExist(std::string extensionName) const;

void RemoveExtension(std::string extensionName);

int GetExtensionDrawOrder(std::string extensionName) const;

void ChangeExtensionDrawOrder(std::string extensionName, int order);

int GetExtensionUpdateOrder(std::string extensionName) const;

void ChangeExtensionUpdateOrder(std::string extensionName, int order);

public:
ExtensionManager();
virtual ~ExtensionManager();

virtual void SetDependentComponents(ssGUI::Renderer* renderer, ssGUI::GUIObject* obj);

//====================================================================
//Group: Adding, Getting and Removing Extension
//====================================================================

//function: AddExtension
//Adds an extension to this GUI Object. If the extension already exists, nothing will be modified.
template<typename T>
T* AddExtension()
{
if(std::is_base_of<ssGUI::Extensions::Extension, T>::value)
{
if(IsAnyExtensionExist<T>())
return GetAnyExtension<T>();
if(IsExtensionExist<T>())
return GetExtension<T>();

auto* extension = ssGUI::Factory::Create<T>();
Extensions[extension->GetExtensionName()] = extension;
Expand Down Expand Up @@ -107,15 +125,8 @@ namespace ssGUI

//function: GetExtension
//Gets the extension by the name of it. Nullptr will be returned if not found.
virtual ssGUI::Extensions::Extension* GetExtension(std::string extensionName);

//function: GetAnyExtension
//Generic version of <GetExtension>.
//It has to be a different name as template function doesn't support inheritance.
//If it had the same name, the derived version of GetExtension will "hide" the generic version of it
//and will just throw an error saying the template function is not found.
template <typename T>
T* GetAnyExtension()
T* GetExtension()
{
static_assert(std::is_base_of<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
static_assert(!std::is_same<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
Expand All @@ -128,13 +139,8 @@ namespace ssGUI

//function: IsExtensionExist
//Returns true if the extension exists on this GUI Object
virtual bool IsExtensionExist(std::string extensionName) const;

//function: IsAnyExtensionExist
//Generic version of <IsExtensionExist>.
//Reason for not having the same name can be found in <GetAnyExtension>
template <typename T>
bool IsAnyExtensionExist()
bool IsExtensionExist()
{
static_assert(std::is_base_of<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
static_assert(!std::is_same<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
Expand All @@ -143,13 +149,8 @@ namespace ssGUI

//function: RemoveExtension
//Removes the extension by the name of it
virtual void RemoveExtension(std::string extensionName);

//function: RemoveAnyExtension
//Generic version of <RemoveExtension>.
//Reason for not having the same name can be found in <GetAnyExtension>
template <typename T>
void RemoveAnyExtension()
void RemoveExtension()
{
static_assert(std::is_base_of<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
static_assert(!std::is_same<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
Expand All @@ -160,15 +161,14 @@ namespace ssGUI
//Returns the number of extensions on this GUI Object
virtual int GetExtensionsCount() const;

//====================================================================
//Group: Changing Extension Execution Order
//====================================================================

//function: GetExtensionDrawOrder
//Returns the draw order of the extension by the name of it
virtual int GetExtensionDrawOrder(std::string extensionName) const;

//function: GetAnyExtensionDrawOrder
//Generic version of <GetExtensionDrawOrder>.
//Reason for not having the same name can be found in <GetAnyExtension>
template <typename T>
int GetAnyExtensionDrawOrder()
int GetExtensionDrawOrder()
{
static_assert(std::is_base_of<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
static_assert(!std::is_same<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
Expand All @@ -177,13 +177,8 @@ namespace ssGUI

//function: ChangeExtensionDrawOrder
//Changes the draw order of the extension by the name of it
virtual void ChangeExtensionDrawOrder(std::string extensionName, int order);

//function: ChangeAnyExtensionDrawOrder
//Generic version of <ChangeExtensionDrawOrder>.
//Reason for not having the same name can be found in <GetAnyExtension>
template <typename T>
void ChangeAnyExtensionDrawOrder(int order)
void ChangeExtensionDrawOrder(int order)
{
static_assert(std::is_base_of<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
static_assert(!std::is_same<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
Expand All @@ -192,28 +187,18 @@ namespace ssGUI

//function: GetExtensionUpdateOrder
//Returns the update order of the extension by the name of it
virtual int GetExtensionUpdateOrder(std::string extensionName) const;

//function: GetAnyExtensionUpdateOrder
//Generic version of <GetExtensionUpdateOrder>.
//Reason for not having the same name can be found in <GetAnyExtension>
template <typename T>
int GetAnyExtensionUpdateOrder()
int GetExtensionUpdateOrder()
{
static_assert(std::is_base_of<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
static_assert(!std::is_same<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
return GetAnyExtensionUpdateOrder(T::EXTENSION_NAME);
return GetExtensionUpdateOrder(T::EXTENSION_NAME);
}

//function: ChangeExtensionUpdateOrder
//Changes the update order of the extension by the name of it
virtual void ChangeExtensionUpdateOrder(std::string extensionName, int order);

//function: ChangeAnyExtensionUpdateOrder
//Generic version of <ChangeExtensionUpdateOrder>.
//Reason for not having the same name can be found in <GetAnyExtension>
template <typename T>
void ChangeAnyExtensionUpdateOrder(int order)
void ChangeExtensionUpdateOrder(int order)
{
static_assert(std::is_base_of<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
static_assert(!std::is_same<ssGUI::Extensions::Extension, T>::value, "Invalid Type to get extension");
Expand Down
4 changes: 2 additions & 2 deletions Include/ssGUI/GUIObjectClasses/Checkbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace ssGUI
Checked(false)
{
SetBackgroundColor(glm::u8vec4(0, 0, 0, 255));
auto border = GetAnyExtension<ssGUI::Extensions::Border>();
auto border = GetExtension<ssGUI::Extensions::Border>();
border->SetBorderWidth(2);
border->SetBorderColor(GetBackgroundColor());
Expand Down Expand Up @@ -60,7 +60,7 @@ namespace ssGUI
break;
}
auto border = btn->GetAnyExtension<ssGUI::Extensions::Border>();
auto border = btn->GetExtension<ssGUI::Extensions::Border>();
if(border != nullptr)
border->SetBorderColor(btn->GetBackgroundColor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace ssGUI
//Swap size multiplier
SetButtonMode(ssGUI::StandardButton::Mode::BOTH);
auto layout = GetAnyExtension<ssGUI::Extensions::Layout>();
auto layout = GetExtension<ssGUI::Extensions::Layout>();
float iconMulti = layout->GetPreferredSizeMultiplier(0);
float textMulti = layout->GetPreferredSizeMultiplier(1);
layout->SetPreferredSizeMultiplier(0, textMulti);
Expand Down
6 changes: 3 additions & 3 deletions Include/ssGUI/GUIObjectClasses/CompositeClasses/MenuItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace ssGUI
{
ssGUI_LOG_FUNC();
RemoveAnyExtension<ssGUI::Extensions::BoxShadow>();
RemoveAnyExtension<ssGUI::Extensions::RoundedCorners>();
RemoveAnyExtension<ssGUI::Extensions::Outline>();
RemoveExtension<ssGUI::Extensions::BoxShadow>();
RemoveExtension<ssGUI::Extensions::RoundedCorners>();
RemoveExtension<ssGUI::Extensions::Outline>();
GetButtonTextObject()->SetNewTextFontSize(15);
GetButtonTextObject()->SetTextHorizontalAlignment(ssGUI::Enums::TextAlignmentHorizontal::LEFT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ssGUI
float diff = 50;
SetBackgroundColor(GetBackgroundColor() - glm::u8vec4(diff, diff, diff, 0));
GetKnobObject()->RemoveAnyExtension<ssGUI::Extensions::Outline>();
GetKnobObject()->RemoveExtension<ssGUI::Extensions::Outline>();
auto btn = static_cast<ssGUI::StandardButton*>(GetKnobObject());
glm::u8vec4 bgColor = GetBackgroundColor();
bgColor.a = 255;
Expand Down
2 changes: 1 addition & 1 deletion Include/ssGUI/GUIObjectClasses/CompositeClasses/Slider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace ssGUI
button->AddExtension<ssGUI::Extensions::RoundedCorners>()->SetRoundedCornersRadius(KnobSize);
button->RemoveAnyExtension<ssGUI::Extensions::Border>();
button->RemoveExtension<ssGUI::Extensions::Border>();
button->SetUserCreated(false);
button->AddExtension<ssGUI::Extensions::Outline>()->SetOutlineThickness(1.5);
button->SetParent(this, true);
Expand Down
29 changes: 16 additions & 13 deletions Include/ssGUI/GUIObjectClasses/CompositeClasses/StandardWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace ssGUI
closeButton->SetHeapAllocated(true);
closeButton->SetParent(this, true);
closeButton->SetMinSize(glm::vec2(5, 5));
closeButton->RemoveExtension(ssGUI::Extensions::Border::EXTENSION_NAME);
closeButton->RemoveExtension<ssGUI::Extensions::Border>();
//Change button shape to circle
auto shapeEx = closeButton->AddExtension<ssGUI::Extensions::Shape>();
Expand All @@ -101,7 +101,7 @@ namespace ssGUI
[circleId](ssGUI::EventInfo& info)
{
auto closeButtonObj = static_cast<ssGUI::Button*>(info.EventSource);
auto shape = static_cast<ssGUI::Extensions::Shape*>(info.EventSource->GetExtension(ssGUI::Extensions::Shape::EXTENSION_NAME));
auto shape = info.EventSource->GetExtension<ssGUI::Extensions::Shape>();
int amount = 60;
static_assert((int)ssGUI::Enums::ButtonState::COUNT == 6, "Make sure this is updated");
Expand Down Expand Up @@ -140,7 +140,7 @@ namespace ssGUI
ListenerKey, this,
[circleId](ssGUI::EventInfo& info)
{
auto shape = static_cast<ssGUI::Extensions::Shape*>(info.EventSource->GetExtension(ssGUI::Extensions::Shape::EXTENSION_NAME));
auto shape = info.EventSource->GetExtension<ssGUI::Extensions::Shape>();
shape->SetAdditionalCircle(circleId, glm::vec2(), info.EventSource->GetSize(), glm::u8vec4(255, 127, 127, 255), false);
}
);
Expand All @@ -149,13 +149,16 @@ namespace ssGUI
//Add rounded corners to window
auto rc = AddExtension<ssGUI::Extensions::RoundedCorners>();
rc->ClearTargetShapes();
rc->AddTargetVertex(0);
rc->AddTargetVertex(1);
rc->AddTargetVertex(2);
rc->AddTargetVertex(3);
rc->AddTargetVertex(4);
rc->AddTargetVertex(5);
ssGUI::TargetShape titlebarShape(ssGUI::Window::WINDOW_TITLEBAR_SHAPE_NAME);
ssGUI::TargetShape baseShape(ssGUI::Window::WINDOW_BASE_SHAPE_NAME);
rc->AddTargetVertex(titlebarShape, 0);
rc->AddTargetVertex(titlebarShape, 1);
rc->AddTargetVertex(baseShape, 0);
rc->AddTargetVertex(baseShape, 1);
rc->AddTargetVertex(baseShape, 2);
rc->AddTargetVertex(baseShape, 3);
//Make window dockable
AddExtension<ssGUI::Extensions::Dockable>();
Expand All @@ -169,9 +172,9 @@ namespace ssGUI
shadowEx->SetSizeOffset(glm::vec2(10, 10));
RemoveExtension(ssGUI::Extensions::Border::EXTENSION_NAME);
UpdateTitleText();
UpdateIconImage();
UpdateCloseButton();
UpdateTitleText(true);
UpdateIconImage(true);
UpdateCloseButton(true);
StandardWindowObjectCount++;
Expand Down
4 changes: 2 additions & 2 deletions Include/ssGUI/GUIObjectClasses/Menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ namespace ssGUI
SetSize(glm::vec2(200, GetSize().y));
AddExtension<ssGUI::Extensions::Layout>();
AddExtension<ssGUI::Extensions::Border>();
GetAnyExtension<ssGUI::Extensions::Layout>()->SetPadding(2);
GetAnyExtension<ssGUI::Extensions::Layout>()->SetSpacing(0);
GetExtension<ssGUI::Extensions::Layout>()->SetPadding(2);
GetExtension<ssGUI::Extensions::Layout>()->SetSpacing(0);
SetBackgroundColor(glm::u8vec4(150, 150, 150, 255));
AddTag(ssGUI::Tags::FLOATING);
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Examples/CloningExampleV3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main()
auto* window = mainWindow.AddChild<ssGUI::StandardWindow>();

//We don't need docking
window->RemoveAnyExtension<ssGUI::Extensions::Dockable>();
window->RemoveExtension<ssGUI::Extensions::Dockable>();
window->SetRenderSize(glm::ivec2(450, 80));
window->AddExtension<ssGUI::Extensions::Layout>();

Expand Down
2 changes: 1 addition & 1 deletion Src/Examples/DockAndLayoutExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int main()
// window.AddExtension(new ssGUI::Extensions::Layout());
// window.RemoveExtension(ssGUI::Extensions::Dockable::EXTENSION_NAME);
window.AddExtension<ssGUI::Extensions::Docker>();
// window.GetAnyExtension<ssGUI::Extensions::Layout>()->SetPadding(5);
// window.GetExtension<ssGUI::Extensions::Layout>()->SetPadding(5);
window.SetBackgroundColor(glm::u8vec4(180, 180, 180, 255));

ssGUI::StandardWindow window2;
Expand Down
22 changes: 11 additions & 11 deletions Src/Examples/ExtensionExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int main()
window.SetPosition(glm::vec2(20, 20));
window.SetMinSize(glm::vec2(100, 100));
window.SetSize(glm::vec2(325, 280));
window.RemoveAnyExtension<ssGUI::Extensions::Border>();
window.RemoveExtension<ssGUI::Extensions::Border>();
window.SetTitlebarHeight(25);
window.SetParent(&mainWindow);

Expand Down Expand Up @@ -47,12 +47,12 @@ int main()
{
if(static_cast<ssGUI::Button*>(info.Container)->GetButtonState() == ssGUI::Enums::ButtonState::CLICKED)
{
if(window.IsAnyExtensionExist<ssGUI::Extensions::Border>())
window.RemoveAnyExtension<ssGUI::Extensions::Border>();
if(window.IsExtensionExist<ssGUI::Extensions::Border>())
window.RemoveExtension<ssGUI::Extensions::Border>();
else
{
window.AddExtension<ssGUI::Extensions::Border>();
window.GetAnyExtension<ssGUI::Extensions::Border>()->SetBorderWidth(2);
window.GetExtension<ssGUI::Extensions::Border>()->SetBorderWidth(2);
}
}
}
Expand All @@ -65,8 +65,8 @@ int main()
{
if(static_cast<ssGUI::Button*>(info.Container)->GetButtonState() == ssGUI::Enums::ButtonState::CLICKED)
{
if(window.IsAnyExtensionExist<ssGUI::Extensions::BoxShadow>())
window.RemoveAnyExtension<ssGUI::Extensions::BoxShadow>();
if(window.IsExtensionExist<ssGUI::Extensions::BoxShadow>())
window.RemoveExtension<ssGUI::Extensions::BoxShadow>();
else
{
window.AddExtension<ssGUI::Extensions::BoxShadow>();
Expand All @@ -82,8 +82,8 @@ int main()
{
if(static_cast<ssGUI::Button*>(info.Container)->GetButtonState() == ssGUI::Enums::ButtonState::CLICKED)
{
if(window.IsAnyExtensionExist<ssGUI::Extensions::RoundedCorners>())
window.RemoveAnyExtension<ssGUI::Extensions::RoundedCorners>();
if(window.IsExtensionExist<ssGUI::Extensions::RoundedCorners>())
window.RemoveExtension<ssGUI::Extensions::RoundedCorners>();
else
{
auto rc = window.AddExtension<ssGUI::Extensions::RoundedCorners>();
Expand All @@ -99,7 +99,7 @@ int main()
rc->AddTargetVertex(baseShape, 2);
rc->AddTargetVertex(baseShape, 3);

window.ChangeAnyExtensionDrawOrder<ssGUI::Extensions::RoundedCorners>(0);
window.ChangeExtensionDrawOrder<ssGUI::Extensions::RoundedCorners>(0);
}
}
}
Expand All @@ -112,8 +112,8 @@ int main()
{
if(static_cast<ssGUI::Button*>(info.Container)->GetButtonState() == ssGUI::Enums::ButtonState::CLICKED)
{
if(window.IsAnyExtensionExist<ssGUI::Extensions::Outline>())
window.RemoveAnyExtension<ssGUI::Extensions::Outline>();
if(window.IsExtensionExist<ssGUI::Extensions::Outline>())
window.RemoveExtension<ssGUI::Extensions::Outline>();
else
{
auto windowOutline = window.AddExtension<ssGUI::Extensions::Outline>();
Expand Down
2 changes: 1 addition & 1 deletion Src/Examples/Playground/StandardSliderPlayground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int main()
(
[&]()
{
//auto* layout = slider->GetAnyExtension<ssGUI::Extensions::Layout>();
//auto* layout = slider->GetExtension<ssGUI::Extensions::Layout>();
//ssLOG_LINE("layout->GetPreferredSizeMultiplier(0): "<<layout->GetPreferredSizeMultiplier(0));
//ssLOG_LINE("layout->GetPreferredSizeMultiplier(1): "<<layout->GetPreferredSizeMultiplier(1));
//ssLOG_LINE("layout->GetPreferredSizeMultiplier(2): "<<layout->GetPreferredSizeMultiplier(2));
Expand Down
Loading

0 comments on commit b469ee7

Please sign in to comment.