Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/TGUI/Backend/Font/BackendFont.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ namespace tgui
///
/// Calling this function with the same parameters results in the same id, while other parameters result in another id.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD std::uint64_t constructGlyphKey(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness) const;
TGUI_NODISCARD static std::uint64_t constructGlyphKey(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
protected:
Expand Down
8 changes: 4 additions & 4 deletions include/TGUI/Backend/Renderer/BackendText.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helper function used by updateVertices to add vertices for a glyph
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void addGlyphQuad(std::vector<Vertex>& vertices, Vector2f position, const Vertex::Color& color,
const FontGlyph& glyph, float fontScale, float italicShear);
static void addGlyphQuad(std::vector<Vertex>& vertices, Vector2f position, const Vertex::Color& color,
const FontGlyph& glyph, float fontScale, float italicShear);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helper function used by updateVertices to add vertices for a line
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void addLine(std::vector<Vertex>& vertices, float lineLength, float lineTop, const Vertex::Color& color,
float offset, float thickness, float outlineThickness, float fontScale);
static void addLine(std::vector<Vertex>& vertices, float lineLength, float lineTop, const Vertex::Color& color,
float offset, float thickness, float outlineThickness, float fontScale);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
protected:
Expand Down
2 changes: 1 addition & 1 deletion include/TGUI/Backend/Window/BackendGui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ namespace tgui
// The key parameter should be a value from Numpad0 to Numpad9 and the output is the key code that corresponds to the
// wanted functionality (e.g. for Numpad0 we return the Insert key). Unknown is returned for Numpad5.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Event::KeyboardKey translateKeypadKey(Event::KeyboardKey key);
static Event::KeyboardKey translateKeypadKey(Event::KeyboardKey key);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public:
Expand Down
2 changes: 1 addition & 1 deletion include/TGUI/Backend/Window/SFML/BackendSFML.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helper function to create a system cursor
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD std::unique_ptr<sf::Cursor> createSystemCursor(Cursor::Type type);
TGUI_NODISCARD static std::unique_ptr<sf::Cursor> createSystemCursor(Cursor::Type type);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helper function to update the mouse cursors on all attached guis
Expand Down
2 changes: 1 addition & 1 deletion include/TGUI/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Transform the mouse position for the child widget based its origin, rotation and scaling.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD Vector2f transformMousePos(const Widget::Ptr& widget, Vector2f mousePos) const;
TGUI_NODISCARD static Vector2f transformMousePos(const Widget::Ptr& widget, Vector2f mousePos) ;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Finishes adding a widget to the container
Expand Down
31 changes: 10 additions & 21 deletions include/TGUI/RendererDefines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
if (it != m_data->propertyValuePairs.end()) \
return it->second.getOutline(); \
else \
return {}; \
return {}; \
} \
void CLASS::set##NAME(const tgui::Outline& outline) \
{ \
Expand All @@ -51,8 +50,7 @@
const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
if (it != m_data->propertyValuePairs.end()) \
return it->second.getColor(); \
else \
return DEFAULT; \
return DEFAULT; \
} \
void CLASS::set##NAME(tgui::Color color) \
{ \
Expand All @@ -67,8 +65,7 @@
const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
if (it != m_data->propertyValuePairs.end()) \
return it->second.getTextStyle(); \
else \
return DEFAULT; \
return DEFAULT; \
} \
void CLASS::set##NAME(tgui::TextStyles style) \
{ \
Expand All @@ -83,8 +80,7 @@
const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
if (it != m_data->propertyValuePairs.end()) \
return it->second.getNumber(); \
else \
return DEFAULT; \
return DEFAULT; \
}

#define TGUI_RENDERER_PROPERTY_NUMBER(CLASS, NAME, DEFAULT) \
Expand All @@ -102,8 +98,7 @@
const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
if (it != m_data->propertyValuePairs.end()) \
return it->second.getBool(); \
else \
return DEFAULT; \
return DEFAULT; \
}

#define TGUI_RENDERER_PROPERTY_BOOL(CLASS, NAME, DEFAULT) \
Expand All @@ -121,11 +116,8 @@
const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
if (it != m_data->propertyValuePairs.end()) \
return it->second.getTexture(); \
else \
{ \
m_data->propertyValuePairs[tgui::String(#NAME)] = {tgui::Texture{}}; \
return m_data->propertyValuePairs[tgui::String(#NAME)].getTexture(); \
} \
m_data->propertyValuePairs[tgui::String(#NAME)] = {tgui::Texture{}}; \
return m_data->propertyValuePairs[tgui::String(#NAME)].getTexture(); \
} \
void CLASS::set##NAME(const tgui::Texture& texture) \
{ \
Expand All @@ -140,12 +132,9 @@
const auto it = m_data->propertyValuePairs.find(tgui::String(#NAME)); \
if (it != m_data->propertyValuePairs.end()) \
return it->second.getRenderer(); \
else \
{ \
const auto& renderer = tgui::Theme::getDefault()->getRendererNoThrow(RENDERER); \
m_data->propertyValuePairs[tgui::String(#NAME)] = {renderer ? renderer : (DEFAULT)}; \
return renderer; \
} \
const auto& renderer = tgui::Theme::getDefault()->getRendererNoThrow(RENDERER); \
m_data->propertyValuePairs[tgui::String(#NAME)] = {renderer ? renderer : (DEFAULT)}; \
return renderer; \
} \
void CLASS::set##NAME(std::shared_ptr<tgui::RendererData> renderer) \
{ \
Expand Down
4 changes: 2 additions & 2 deletions include/TGUI/SignalManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD std::pair<Delegate, DelegateEx> makeSignal(const Delegate&);
TGUI_NODISCARD static std::pair<Delegate, DelegateEx> makeSignal(const Delegate&);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TGUI_NODISCARD std::pair<Delegate, DelegateEx> makeSignalEx(const DelegateEx&);
TGUI_NODISCARD static std::pair<Delegate, DelegateEx> makeSignalEx(const DelegateEx&);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Function that is called each time new signal is created with it id
Expand Down
2 changes: 1 addition & 1 deletion include/TGUI/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ namespace tgui
void resize(std::size_t count, char16_t ch);
void resize(std::size_t count, char32_t ch);

void swap(String& other);
void swap(String& other) noexcept;

TGUI_NODISCARD bool contains(char c) const noexcept;
TGUI_NODISCARD bool contains(wchar_t c) const noexcept;
Expand Down
2 changes: 1 addition & 1 deletion src/Backend/Font/BackendFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace tgui

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

std::uint64_t BackendFont::constructGlyphKey(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness) const
std::uint64_t BackendFont::constructGlyphKey(char32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness)
{
// Create a unique key for every character.
// Technically it would be possible to specify character sizes and outline thicknesses that can't uniquely be mapped
Expand Down
11 changes: 3 additions & 8 deletions src/Backend/Renderer/BackendRenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <TGUI/Backend/Renderer/BackendText.hpp>
#include <TGUI/Widget.hpp>

#include <algorithm>
#include <array>
#include <cmath>

Expand Down Expand Up @@ -455,10 +456,7 @@ namespace tgui
float radius, const Borders& borders, const Color& borderColor)
{
// Radius can never be larger than half the width or height
if (radius > size.x / 2)
radius = size.x / 2;
if (radius > size.y / 2)
radius = size.y / 2;
radius = std::min({radius, size.x / 2, size.y / 2});

const unsigned int nrCornerPoints = std::max(1u, static_cast<unsigned int>(std::ceil(radius * 2)));
const std::vector<Vector2f>& outerPoints = drawRoundedRectHelperGetPoints(nrCornerPoints, size, radius, 0);
Expand All @@ -468,10 +466,7 @@ namespace tgui
{
radius = std::max(0.f, radius - borderWidth);
const Vector2f innerSize = {std::max(0.f, size.x - 2*borderWidth), std::max(0.f, size.y - 2*borderWidth)};
if (radius > innerSize.x / 2)
radius = innerSize.x / 2;
if (radius > innerSize.y / 2)
radius = innerSize.y / 2;
radius = std::min({radius, innerSize.x / 2, innerSize.y / 2});

const std::vector<Vector2f>& innerPoints = drawRoundedRectHelperGetPoints(nrCornerPoints, innerSize, radius, borderWidth);

Expand Down
8 changes: 4 additions & 4 deletions src/Backend/Renderer/BackendText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <TGUI/Backend/Renderer/BackendText.hpp>

#include <algorithm>
#include <cmath>

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -193,8 +194,7 @@ namespace tgui
if (!m_font)
return {};

if (index > m_string.length())
index = m_string.length();
index = std::min(index, m_string.length());

const bool isBold = static_cast<unsigned int>(m_style) & TextStyle::Bold;
const float whitespaceWidth = m_font->getGlyph(U' ', m_characterSize, isBold).advance;
Expand Down Expand Up @@ -376,8 +376,8 @@ namespace tgui
{
const auto& glyph = m_font->getGlyph(curChar, m_characterSize, isBold, m_outlineThickness);

float top = glyph.bounds.top;
float right = glyph.bounds.left + glyph.bounds.width;
const float top = glyph.bounds.top;
const float right = glyph.bounds.left + glyph.bounds.width;

// Add the outline glyph to the vertices
addGlyphQuad(*m_outlineVertices, {x, y}, vertexOutlineColor, glyph, fontScale, italicShear);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace tgui
if (clippingRequired)
addClippingLayer(transformedStates, {{visibleRect.left, visibleRect.top}, {visibleRect.width, visibleRect.height}});

std::shared_ptr<BackendTexture> texture = sprite.getTexture().getData()->backendTexture;
const std::shared_ptr<BackendTexture> texture = sprite.getTexture().getData()->backendTexture;

sf::RenderStates sfStates = convertRenderStates(transformedStates, texture);
TGUI_ASSERT(std::dynamic_pointer_cast<BackendTextureSFML>(sprite.getTexture().getData()->backendTexture), "BackendRenderTargetSFML::drawSprite requires backend texture of type BackendTextureSFML");
Expand Down
3 changes: 1 addition & 2 deletions src/Backend/Renderer/SFML-Graphics/CanvasSFML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ namespace tgui
{
if (canvas)
return std::static_pointer_cast<CanvasSFML>(canvas->clone());
else
return nullptr;
return nullptr;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 3 additions & 4 deletions src/Backend/Window/Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ namespace tgui
{
if (m_fontBackend)
return {static_cast<const unsigned char*>(defaultFontBytes), sizeof(defaultFontBytes)};
else
return {};
return {};
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -131,9 +130,9 @@ namespace tgui
sprite->updateVertices();

// Update the size of all texts in all widgets
for (auto& gui : m_guis)
for (const auto& gui : m_guis)
{
for (auto& widget : gui->getWidgets())
for (const auto& widget : gui->getWidgets())
widget->updateTextSize();
}
}
Expand Down
28 changes: 12 additions & 16 deletions src/Backend/Window/BackendGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,23 @@ namespace tgui

if (event.type == Event::Type::MouseMoved)
return m_container->processMouseMoveEvent(mouseCoords);
else if (event.type == Event::Type::MouseWheelScrolled)
if (event.type == Event::Type::MouseWheelScrolled)
{
if (m_container->processScrollEvent(event.mouseWheel.delta, mouseCoords, false))
return true;

// Even if no scrollbar moved, we will still absorb the scroll event when the mouse is on top of a widget
return m_container->getWidgetAtPos(mouseCoords, false) != nullptr;
}
else if (event.type == Event::Type::MouseButtonPressed)
if (event.type == Event::Type::MouseButtonPressed)
return m_container->processMousePressEvent(event.mouseButton.button, mouseCoords);
else // if (event.type == Event::Type::MouseButtonReleased)
{
const bool eventHandled = m_container->processMouseReleaseEvent(event.mouseButton.button, mouseCoords);
if (event.mouseButton.button == Event::MouseButton::Left)
m_container->leftMouseButtonNoLongerDown();
else if (event.mouseButton.button == Event::MouseButton::Right)
m_container->rightMouseButtonNoLongerDown();
return eventHandled;
}
// if (event.type == Event::Type::MouseButtonReleased)
const bool eventHandled = m_container->processMouseReleaseEvent(event.mouseButton.button, mouseCoords);
if (event.mouseButton.button == Event::MouseButton::Left)
m_container->leftMouseButtonNoLongerDown();
else if (event.mouseButton.button == Event::MouseButton::Right)
m_container->rightMouseButtonNoLongerDown();
return eventHandled;
}
case Event::Type::KeyPressed:
{
Expand All @@ -178,8 +176,7 @@ namespace tgui

return true;
}
else
return m_container->processKeyPressEvent(event.key);
return m_container->processKeyPressEvent(event.key);
}
case Event::Type::TextEntered:
{
Expand Down Expand Up @@ -271,8 +268,7 @@ namespace tgui
{
if (m_container->getInheritedFont())
return m_container->getInheritedFont();
else
return Font::getGlobalFont();
return Font::getGlobalFont();
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -556,7 +552,7 @@ namespace tgui
if (m_tooltipTime >= ToolTip::getInitialDelay())
{
const Vector2f lastMousePos = mapPixelToCoords(m_lastMousePos);
Widget::Ptr tooltip = m_container->askToolTip(lastMousePos);
const Widget::Ptr tooltip = m_container->askToolTip(lastMousePos);
if (tooltip)
{
m_visibleToolTip = tooltip;
Expand Down
3 changes: 1 addition & 2 deletions src/Backend/Window/SFML/BackendGuiSFML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ namespace tgui
Optional<Duration> duration = Timer::getNextScheduledTime();
if (duration && (*duration < std::chrono::milliseconds(10)))
return *duration;
else
return Duration{std::chrono::milliseconds(10)};
return Duration{std::chrono::milliseconds(10)};
};

setDrawingUpdatesTime(false);
Expand Down
3 changes: 1 addition & 2 deletions src/Backend/Window/SFML/BackendSFML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ namespace tgui
auto cursor = sf::Cursor::createFromSystem(typeSFML);
if (cursor)
return std::make_unique<sf::Cursor>(std::move(*cursor));
else
return nullptr;
return nullptr;
#else
auto cursor = std::make_unique<sf::Cursor>();
if (cursor->loadFromSystem(typeSFML))
Expand Down
2 changes: 1 addition & 1 deletion src/Base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace tgui

unsigned int val = 0;
int valShift = -8;
for (char c : data)
for (const char c : data)
{
const std::uint8_t tableIndex = base64InverseCharactersTable[static_cast<std::uint8_t>(c)]; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)

Expand Down
10 changes: 4 additions & 6 deletions src/Components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,10 @@ namespace dev
{
if ((pos.x < m_borders.getLeft()) || (pos.y < m_borders.getTop()) || (pos.x >= m_borders.getLeft() + m_clientSize.x) || (pos.y >= m_borders.getTop() + m_clientSize.y))
return false;
else
return m_sprite.isTransparentPixel(pos - m_borders.getOffset());
return m_sprite.isTransparentPixel(pos - m_borders.getOffset());
}
else /// TODO: Perform check when using rounded corners
return false;
/// TODO: Perform check when using rounded corners
return false;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -849,8 +848,7 @@ namespace dev
{
if (transparentTexture && m_sprite.isSet()) /// TODO: transparentTexture should be option on Texture (similar to Smooth) instead of a parameter
return m_sprite.isTransparentPixel(pos);
else
return false;
return false;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading