Ported Button (without tests)
parent
1248df491c
commit
9c6e571836
|
@ -205,7 +205,7 @@ namespace tgui
|
|||
/// This function will assert when something other than a texture was saved
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const Texture& getTexture();
|
||||
Texture& getTexture();
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -95,4 +95,26 @@
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define TGUI_RENDERER_PROPERTY_GET_TEXTURE(CLASS, NAME) \
|
||||
Texture& CLASS::get##NAME() const \
|
||||
{ \
|
||||
auto it = m_data->propertyValuePairs.find(toLower(#NAME)); \
|
||||
if (it != m_data->propertyValuePairs.end()) \
|
||||
return it->second.getTexture(); \
|
||||
else \
|
||||
{ \
|
||||
m_data->propertyValuePairs[toLower(#NAME)] = {Texture{}}; \
|
||||
return m_data->propertyValuePairs[toLower(#NAME)].getTexture(); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define TGUI_RENDERER_PROPERTY_TEXTURE(CLASS, NAME) \
|
||||
TGUI_RENDERER_PROPERTY_GET_TEXTURE(CLASS, NAME) \
|
||||
void CLASS::set##NAME(const Texture& texture) \
|
||||
{ \
|
||||
setProperty(toLower(#NAME), {texture}); \
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // TGUI_RENDERER_DEFINES_HPP
|
||||
|
|
|
@ -40,8 +40,8 @@
|
|||
#include <TGUI/Loading/Theme.hpp>
|
||||
#include <TGUI/Loading/WidgetLoader.hpp>
|
||||
#include <TGUI/Loading/WidgetSaver.hpp>
|
||||
/**
|
||||
#include <TGUI/Widgets/Button.hpp>
|
||||
|
||||
#include <TGUI/Widgets/Button.hpp>/**
|
||||
#include <TGUI/Widgets/Canvas.hpp>
|
||||
#include <TGUI/Widgets/ChatBox.hpp>
|
||||
#include <TGUI/Widgets/CheckBox.hpp>
|
||||
|
|
|
@ -60,26 +60,6 @@ namespace tgui
|
|||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Button();
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Copy constructor
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Button(const Button&);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Default move constructor
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Button(Button&&) = default;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Overload of copy assignment operator
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Button& operator=(const Button&);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Default move assignment
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Button& operator=(Button&&) = default;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Makes a copy of another button
|
||||
|
@ -98,23 +78,10 @@ namespace tgui
|
|||
/// @return Temporary pointer to the renderer
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
ButtonRenderer* getRenderer() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Set the position of the widget
|
||||
///
|
||||
/// This function completely overwrites the previous position.
|
||||
/// See the move function to apply an offset based on the previous position instead.
|
||||
/// The default position of a transformable widget is (0, 0).
|
||||
///
|
||||
/// @param position New position
|
||||
///
|
||||
/// @see move, getPosition
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual void setPosition(const Layout2d& position) override;
|
||||
using Transformable::setPosition;
|
||||
ButtonRenderer* getRenderer() const
|
||||
{
|
||||
return aurora::downcast<ButtonRenderer*>(m_renderer.get());
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -127,17 +94,6 @@ namespace tgui
|
|||
using Transformable::setSize;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the full size of the button
|
||||
///
|
||||
/// The size returned by this function includes the borders.
|
||||
///
|
||||
/// @return Full size of the button
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual sf::Vector2f getFullSize() const override;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the font of the text in the widget.
|
||||
///
|
||||
|
@ -164,10 +120,7 @@ namespace tgui
|
|||
/// @return Text that is drawn on top of the button.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const sf::String& getText() const
|
||||
{
|
||||
return m_string;
|
||||
}
|
||||
const sf::String& getText() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -186,30 +139,7 @@ namespace tgui
|
|||
/// @return The current text size.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
unsigned int getTextSize() const
|
||||
{
|
||||
return m_text.getTextSize();
|
||||
}
|
||||
|
||||
/**
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the opacity of the widget.
|
||||
///
|
||||
/// @param opacity The opacity of the widget. 0 means completely transparent, while 1 (default) means fully opaque.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual void setOpacity(float opacity) override;
|
||||
*/
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the distance between the position where the widget is drawn and where the widget is placed
|
||||
///
|
||||
/// This is basically the width and height of the optional borders drawn around widgets.
|
||||
///
|
||||
/// @return Offset of the widget
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual sf::Vector2f getWidgetOffset() const override;
|
||||
unsigned int getTextSize() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -235,29 +165,15 @@ namespace tgui
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
/**
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Reload the widget
|
||||
///
|
||||
/// @param primary Primary parameter for the loader
|
||||
/// @param secondary Secondary parameter for the loader
|
||||
/// @param force Try to only change the looks of the widget and not alter the widget itself when false
|
||||
///
|
||||
/// @throw Exception when the connected theme could not create the widget
|
||||
///
|
||||
/// When primary is an empty string the built-in white theme will be used.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual void reload(const std::string& primary = "", const std::string& secondary = "", bool force = false) override;
|
||||
*/
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Makes a copy of the widget
|
||||
/// @brief Function called when one of the properties of the renderer is changed
|
||||
///
|
||||
/// @param property Lowercase name of the property that was changed
|
||||
/// @param value New value of the property
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual Widget::Ptr clone() const override
|
||||
{
|
||||
return std::make_shared<Button>(*this);
|
||||
}
|
||||
virtual void rendererChanged(const std::string& property, ObjectConverter&& value) override;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -279,7 +195,22 @@ namespace tgui
|
|||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
// Makes a copy of the widget
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual Widget::Ptr clone() const override
|
||||
{
|
||||
return std::make_shared<Button>(*this);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private:
|
||||
|
||||
void recalculateTextPosition();
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private:
|
||||
|
||||
sf::String m_string;
|
||||
Label m_text;
|
||||
|
@ -287,71 +218,16 @@ namespace tgui
|
|||
// This will store the size of the text (0 to auto-size)
|
||||
unsigned int m_textSize = 0;
|
||||
|
||||
friend class ButtonRenderer;
|
||||
friend class ChildWindow;
|
||||
// Keeps track of when setSize is called
|
||||
bool m_sizeDefined = false;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TGUI_API ButtonRenderer : public WidgetRenderer/**, public WidgetBorders*/
|
||||
class TGUI_API ButtonRenderer : public WidgetRenderer
|
||||
{
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Constructor
|
||||
///
|
||||
/// @param button The button that is connected to the renderer
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
ButtonRenderer(Button* button) : m_button{button} {}
|
||||
|
||||
/**
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Change a property of the renderer
|
||||
///
|
||||
/// @param property The property that you would like to change
|
||||
/// @param value The new serialized value that you like to assign to the property
|
||||
///
|
||||
/// @throw Exception when deserialization fails or when the widget does not have this property.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual void setProperty(std::string property, const std::string& value) override;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Change a property of the renderer
|
||||
///
|
||||
/// @param property The property that you would like to change
|
||||
/// @param value The new value that you like to assign to the property.
|
||||
/// The ObjectConverter is implicitly constructed from the possible value types.
|
||||
///
|
||||
/// @throw Exception for unknown properties or when value was of a wrong type.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual void setProperty(std::string property, ObjectConverter&& value) override;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Retrieve the value of a certain property
|
||||
///
|
||||
/// @param property The property that you would like to retrieve
|
||||
///
|
||||
/// @return The value inside a ObjectConverter object which you can extract with the correct get function or
|
||||
/// an ObjectConverter object with type ObjectConverter::Type::None when the property did not exist.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual ObjectConverter getProperty(std::string property) const override;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Get a map with all properties and their values
|
||||
///
|
||||
/// @return Property-value pairs of the renderer
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual std::map<std::string, ObjectConverter> getPropertyValuePairs() const override;
|
||||
*/
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the color of the text.
|
||||
///
|
||||
|
@ -367,33 +243,6 @@ namespace tgui
|
|||
void setTextColor(const Color& color);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the color of the text in the normal state (mouse not on button).
|
||||
///
|
||||
/// @param color New text color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setTextColorNormal(const Color& color);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the color of the text in the hover state (mouse on button, but not pressed).
|
||||
///
|
||||
/// @param color New text color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setTextColorHover(const Color& color);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the color of the text in the down state (mouse on button and left mouse button being held down).
|
||||
///
|
||||
/// @param color New text color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setTextColorDown(const Color& color);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the color of the background.
|
||||
///
|
||||
|
@ -411,6 +260,78 @@ namespace tgui
|
|||
void setBackgroundColor(const Color& color);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the size of the borders.
|
||||
///
|
||||
/// @param borders Size of the borders
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setBorders(const Borders& borders);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the size of the borders.
|
||||
///
|
||||
/// @return border size
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Borders getBorders() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the color of the text in the normal state (mouse not on button).
|
||||
///
|
||||
/// @param color New text color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setTextColorNormal(const Color& color);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the text color in the normal state (mouse not on button).
|
||||
///
|
||||
/// @return text color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
sf::Color getTextColorNormal() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the color of the text in the hover state (mouse on button, but not pressed).
|
||||
///
|
||||
/// @param color New text color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setTextColorHover(const Color& color);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the text color in the hover state (mouse on button, but not pressed).
|
||||
///
|
||||
/// @return text color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
sf::Color getTextColorHover() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the color of the text in the down state (mouse on button and left mouse button being held down).
|
||||
///
|
||||
/// @param color New text color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setTextColorDown(const Color& color);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the text color in the down state (mouse on button and left mouse button being held down).
|
||||
///
|
||||
/// @return text color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
sf::Color getTextColorDown() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the color of the background in the normal state (mouse not on button).
|
||||
///
|
||||
|
@ -422,6 +343,15 @@ namespace tgui
|
|||
void setBackgroundColorNormal(const Color& color);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the background color in the normal state (mouse not on button).
|
||||
///
|
||||
/// @return background color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
sf::Color getBackgroundColorNormal() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the color of the background in the hover state (mouse on button, but not pressed).
|
||||
///
|
||||
|
@ -433,6 +363,15 @@ namespace tgui
|
|||
void setBackgroundColorHover(const Color& color);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the background color in the hover state (mouse on button, but not pressed).
|
||||
///
|
||||
/// @return background color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
sf::Color getBackgroundColorHover() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the color of the background in the down state (mouse on button and left mouse button being held down).
|
||||
///
|
||||
|
@ -444,6 +383,15 @@ namespace tgui
|
|||
void setBackgroundColorDown(const Color& color);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the background color in the down state (mouse on button and left mouse button being held down).
|
||||
///
|
||||
/// @return background color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
sf::Color getBackgroundColorDown() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Changes the color of the borders.
|
||||
///
|
||||
|
@ -453,6 +401,15 @@ namespace tgui
|
|||
void setBorderColor(const Color& color);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Returns the color of the borders.
|
||||
///
|
||||
/// @return Border color
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
sf::Color getBorderColor() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Change the image that is displayed when the mouse is not on the button
|
||||
///
|
||||
|
@ -462,7 +419,16 @@ namespace tgui
|
|||
/// Pass an empty texture to unset the image, in this case the background color property will be used again.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setNormalTexture(const Texture& texture);
|
||||
void setTextureNormal(const Texture& texture);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Return the image that is displayed when the mouse is not on the button
|
||||
///
|
||||
/// @param normal texture
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Texture& getTextureNormal() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -473,7 +439,16 @@ namespace tgui
|
|||
/// Pass an empty texture to unset the image.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setHoverTexture(const Texture& texture);
|
||||
void setTextureHover(const Texture& texture);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Return the image that is displayed when the mouse is located on top of the button
|
||||
///
|
||||
/// @param hover texture
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Texture& getTextureHover() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -484,7 +459,16 @@ namespace tgui
|
|||
/// Pass an empty texture to unset the image.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setDownTexture(const Texture& texture);
|
||||
void setTextureDown(const Texture& texture);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Return the image that is displayed when the mouse is held down on top of the button
|
||||
///
|
||||
/// @param hover texture
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Texture& getTextureDown() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -495,48 +479,17 @@ namespace tgui
|
|||
/// Pass an empty texture to unset the image.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setFocusTexture(const Texture& texture);
|
||||
void setTextureFocused(const Texture& texture);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Draws the widget on the render target.
|
||||
/// @brief Return the image that is drawn on top of the button image when the button is focused
|
||||
///
|
||||
/// @param focused texture
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const;
|
||||
Texture& getTextureFocused() const;
|
||||
|
||||
/**
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Makes a copy of the renderer
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual std::shared_ptr<WidgetRenderer> clone(Widget* widget) override;
|
||||
*/
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
|
||||
Button* m_button;
|
||||
|
||||
sf::Color m_textColorNormal;
|
||||
sf::Color m_textColorHover;
|
||||
sf::Color m_textColorDown;
|
||||
|
||||
sf::Color m_backgroundColorNormal;
|
||||
sf::Color m_backgroundColorHover;
|
||||
sf::Color m_backgroundColorDown;
|
||||
|
||||
sf::Color m_borderColor;
|
||||
|
||||
Texture m_textureNormal;
|
||||
Texture m_textureHover;
|
||||
Texture m_textureDown;
|
||||
Texture m_textureFocused;
|
||||
|
||||
friend class Button;
|
||||
friend class ChildWindow;
|
||||
friend class ChildWindowRenderer;
|
||||
friend class MessageBox;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
};
|
||||
|
|
|
@ -154,10 +154,7 @@ namespace tgui
|
|||
/// @return Text that is currently used
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
const sf::String& getText() const
|
||||
{
|
||||
return m_string;
|
||||
}
|
||||
const sf::String& getText() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -251,7 +248,7 @@ namespace tgui
|
|||
/// The label is auto-sized by default.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual void setAutoSize(bool autoSize);
|
||||
void setAutoSize(bool autoSize);
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -260,10 +257,7 @@ namespace tgui
|
|||
/// @return Is the size of the label changed when the text changes?
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
virtual bool getAutoSize() const
|
||||
{
|
||||
return m_autoSize;
|
||||
}
|
||||
bool getAutoSize() const;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -274,7 +268,8 @@ namespace tgui
|
|||
/// This property is ignored when an exact size has been given.
|
||||
/// Pass 0 to this function to disable the maximum.
|
||||
///
|
||||
/// When the text is auto-sizing then the text will be split over several lines when its width would exceed th
|
||||
/// When the text is auto-sizing then the text will be split over several lines when its width would exceed the
|
||||
/// value passed to this function.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void setMaximumTextWidth(float maximumWidth);
|
||||
|
|
|
@ -24,7 +24,7 @@ set(TGUI_SRC
|
|||
Loading/WidgetConverter.cpp
|
||||
Loading/WidgetLoader.cpp
|
||||
Loading/WidgetSaver.cpp
|
||||
#Widgets/Button.cpp
|
||||
Widgets/Button.cpp
|
||||
#Widgets/Canvas.cpp
|
||||
#Widgets/ChatBox.cpp
|
||||
#Widgets/CheckBox.cpp
|
||||
|
|
|
@ -118,7 +118,7 @@ namespace tgui
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const Texture& ObjectConverter::getTexture()
|
||||
Texture& ObjectConverter::getTexture()
|
||||
{
|
||||
assert(m_type == Type::Texture || m_type == Type::String);
|
||||
|
||||
|
|
|
@ -60,12 +60,6 @@ namespace tgui
|
|||
{
|
||||
if (!primary.empty())
|
||||
m_themeLoader->preload(primary);
|
||||
|
||||
/** TODO: m_resourcePath?
|
||||
std::string::size_type slashPos = m_primary.find_last_of("/\\");
|
||||
if (slashPos != std::string::npos)
|
||||
m_resourcePath = m_primary.substr(0, slashPos+1);
|
||||
*/
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -78,6 +78,11 @@ namespace tgui
|
|||
// Load the file when not already in cache
|
||||
if (m_propertiesCache.find(filename) == m_propertiesCache.end())
|
||||
{
|
||||
std::string resourcePath;
|
||||
auto slashPos = filename.find_last_of("/\\");
|
||||
if (slashPos != std::string::npos)
|
||||
resourcePath = filename.substr(0, slashPos+1);
|
||||
|
||||
std::stringstream fileContents;
|
||||
readFile(filename, fileContents);
|
||||
|
||||
|
@ -94,7 +99,21 @@ namespace tgui
|
|||
throw Exception{"Unexpected result while loading theme file '" + filename + "'. Nested section encountered."};
|
||||
|
||||
for (auto& pair : child->propertyValuePairs)
|
||||
{
|
||||
// Inject relative path to the theme file into texture filenames
|
||||
if (!resourcePath.empty() && (pair.first.size() >= 7) && (toLower(pair.first.substr(0, 7)) == "texture"))
|
||||
{
|
||||
auto quotePos = pair.second->value.find('"');
|
||||
if (quotePos != std::string::npos)
|
||||
{
|
||||
///TODO: Detect absolute pathname on windows
|
||||
if ((pair.second->value.size() > quotePos + 1) && (pair.second->value[quotePos+1] != '/'))
|
||||
pair.second->value = pair.second->value.substr(0, quotePos+1) + resourcePath + pair.second->value.substr(quotePos+1);
|
||||
}
|
||||
}
|
||||
|
||||
m_propertiesCache[filename][name][toLower(pair.first)] = pair.second->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,13 +36,15 @@ namespace tgui
|
|||
Button::Button()
|
||||
{
|
||||
m_callback.widgetType = "Button";
|
||||
|
||||
addSignal<sf::String>("Pressed");
|
||||
|
||||
m_renderer = std::make_shared<ButtonRenderer>(this);
|
||||
reload();
|
||||
m_renderer = aurora::makeCopied<tgui::ButtonRenderer>();
|
||||
setRenderer(m_renderer->getData());
|
||||
|
||||
setSize(120, 30);
|
||||
getRenderer()->setBorders({2, 2, 2, 2});
|
||||
|
||||
m_sizeDefined = false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -57,45 +59,23 @@ namespace tgui
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Button::setPosition(const Layout2d& position)
|
||||
{
|
||||
Widget::setPosition(position);
|
||||
|
||||
getRenderer()->m_textureDown.setPosition(getPosition());
|
||||
getRenderer()->m_textureHover.setPosition(getPosition());
|
||||
getRenderer()->m_textureNormal.setPosition(getPosition());
|
||||
getRenderer()->m_textureFocused.setPosition(getPosition());
|
||||
|
||||
// Set the position of the text
|
||||
m_text.setPosition(getPosition().x + (getSize().x - m_text.getSize().x) * 0.5f,
|
||||
getPosition().y + (getSize().y - m_text.getSize().y) * 0.5f);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Button::setSize(const Layout2d& size)
|
||||
{
|
||||
Widget::setSize(size);
|
||||
|
||||
getRenderer()->m_textureDown.setSize(getSize());
|
||||
getRenderer()->m_textureHover.setSize(getSize());
|
||||
getRenderer()->m_textureNormal.setSize(getSize());
|
||||
getRenderer()->m_textureFocused.setSize(getSize());
|
||||
m_sizeDefined = true;
|
||||
|
||||
// Reset the texture sizes
|
||||
getRenderer()->getTextureNormal().setSize(getSize());
|
||||
getRenderer()->getTextureHover().setSize(getSize());
|
||||
getRenderer()->getTextureDown().setSize(getSize());
|
||||
getRenderer()->getTextureFocused().setSize(getSize());
|
||||
|
||||
// Recalculate the text size when auto sizing
|
||||
if (m_textSize == 0)
|
||||
setText(m_string);
|
||||
|
||||
// Recalculate the position of the images
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sf::Vector2f Button::getFullSize() const
|
||||
{
|
||||
return {getSize().x + getRenderer()->getBorders().left + getRenderer()->getBorders().right,
|
||||
getSize().y + getRenderer()->getBorders().top + getRenderer()->getBorders().bottom};
|
||||
recalculateTextPosition();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -118,8 +98,23 @@ namespace tgui
|
|||
if (m_textSize != 0)
|
||||
m_text.setTextSize(m_textSize);
|
||||
|
||||
// If the height is much bigger than the width then the text should be vertical
|
||||
if (getSize().y > getSize().x * 2)
|
||||
// Draw the text normally unless the height is more than double of the width
|
||||
if (getSize().y <= getSize().x * 2)
|
||||
{
|
||||
m_text.setText(text);
|
||||
|
||||
// Auto size the text when necessary
|
||||
if (m_textSize == 0)
|
||||
{
|
||||
unsigned int textSize = findBestTextSize(getFont(), getSize().y * 0.85f);
|
||||
m_text.setTextSize(textSize);
|
||||
|
||||
// Make the text smaller when it's too width
|
||||
if (m_text.getSize().x > (getSize().x * 0.85f))
|
||||
m_text.setTextSize(static_cast<unsigned int>(textSize * ((getSize().x * 0.85f) / m_text.getSize().x)));
|
||||
}
|
||||
}
|
||||
else // Place the text vertically
|
||||
{
|
||||
// The text is vertical
|
||||
if (!m_string.isEmpty())
|
||||
|
@ -141,62 +136,35 @@ namespace tgui
|
|||
m_text.setTextSize(static_cast<unsigned int>(textSize * getSize().y * 0.85f / m_text.getSize().y));
|
||||
}
|
||||
}
|
||||
else // The width of the button is big enough
|
||||
{
|
||||
m_text.setText(text);
|
||||
|
||||
// Auto size the text when necessary
|
||||
if (m_textSize == 0)
|
||||
{
|
||||
unsigned int textSize = findBestTextSize(getFont(), getSize().y * 0.85f);
|
||||
m_text.setTextSize(textSize);
|
||||
recalculateTextPosition();
|
||||
}
|
||||
|
||||
// Make the text smaller when it's too width
|
||||
if (m_text.getSize().x > (getSize().x * 0.85f))
|
||||
m_text.setTextSize(static_cast<unsigned int>(textSize * ((getSize().x * 0.85f) / m_text.getSize().x)));
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Set the position of the text
|
||||
m_text.setPosition(getPosition().x + (getSize().x - m_text.getSize().x) * 0.5f,
|
||||
getPosition().y + (getSize().y - m_text.getSize().y) * 0.5f);
|
||||
const sf::String& Button::getText() const
|
||||
{
|
||||
return m_string;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Button::setTextSize(unsigned int size)
|
||||
{
|
||||
// Change the text size
|
||||
m_textSize = size;
|
||||
if (size != m_textSize)
|
||||
{
|
||||
m_textSize = size;
|
||||
|
||||
// Call setText to reposition the text
|
||||
setText(m_string);
|
||||
// Call setText to reposition the text
|
||||
setText(m_string);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Button::setOpacity(float opacity)
|
||||
unsigned int Button::getTextSize() const
|
||||
{
|
||||
Widget::setOpacity(opacity);
|
||||
|
||||
getRenderer()->m_textureNormal.setColor({255, 255, 255, static_cast<sf::Uint8>(m_opacity * 255)});
|
||||
getRenderer()->m_textureHover.setColor({255, 255, 255, static_cast<sf::Uint8>(m_opacity * 255)});
|
||||
getRenderer()->m_textureDown.setColor({255, 255, 255, static_cast<sf::Uint8>(m_opacity * 255)});
|
||||
getRenderer()->m_textureFocused.setColor({255, 255, 255, static_cast<sf::Uint8>(m_opacity * 255)});
|
||||
|
||||
if (!m_mouseHover)
|
||||
m_text.setTextColor(calcColorOpacity(getRenderer()->m_textColorNormal, getOpacity()));
|
||||
else if (m_mouseHover && !m_mouseDown)
|
||||
m_text.setTextColor(calcColorOpacity(getRenderer()->m_textColorHover, getOpacity()));
|
||||
else if (m_mouseHover && m_mouseDown)
|
||||
m_text.setTextColor(calcColorOpacity(getRenderer()->m_textColorDown, getOpacity()));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sf::Vector2f Button::getWidgetOffset() const
|
||||
{
|
||||
return {getRenderer()->getBorders().left, getRenderer()->getBorders().top};
|
||||
return m_text.getTextSize();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -205,7 +173,7 @@ namespace tgui
|
|||
{
|
||||
ClickableWidget::leftMousePressed(x, y);
|
||||
|
||||
m_text.setTextColor(getRenderer()->m_textColorDown);
|
||||
m_text.getRenderer()->setTextColor(getRenderer()->getTextColorDown());
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -218,7 +186,7 @@ namespace tgui
|
|||
ClickableWidget::leftMouseReleased(x, y);
|
||||
|
||||
if (m_mouseHover)
|
||||
m_text.setTextColor(getRenderer()->m_textColorHover);
|
||||
m_text.getRenderer()->setTextColor(getRenderer()->getTextColorHover());
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -234,7 +202,7 @@ namespace tgui
|
|||
void Button::widgetFocused()
|
||||
{
|
||||
// We can't be focused when we don't have a focus image
|
||||
if (getRenderer()->m_textureFocused.isLoaded())
|
||||
if (getRenderer()->getTextureFocused().isLoaded())
|
||||
Widget::widgetFocused();
|
||||
else
|
||||
unfocus();
|
||||
|
@ -242,36 +210,80 @@ namespace tgui
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Button::reload(const std::string& primary, const std::string& secondary, bool force)
|
||||
void Button::rendererChanged(const std::string& property, ObjectConverter&& value)
|
||||
{
|
||||
getRenderer()->setBorders({2, 2, 2, 2});
|
||||
getRenderer()->setTextColorNormal({60, 60, 60});
|
||||
getRenderer()->setTextColorHover({0, 0, 0});
|
||||
getRenderer()->setTextColorDown({0, 0, 0});
|
||||
getRenderer()->setBackgroundColorNormal({245, 245, 245});
|
||||
getRenderer()->setBackgroundColorHover({255, 255, 255});
|
||||
getRenderer()->setBackgroundColorDown({255, 255, 255});
|
||||
getRenderer()->setBorderColor({0, 0, 0});
|
||||
getRenderer()->setNormalTexture({});
|
||||
getRenderer()->setHoverTexture({});
|
||||
getRenderer()->setDownTexture({});
|
||||
getRenderer()->setFocusTexture({});
|
||||
|
||||
if (m_theme && primary != "")
|
||||
if (property == "borders")
|
||||
{
|
||||
getRenderer()->setBorders({0, 0, 0, 0});
|
||||
Widget::reload(primary, secondary, force);
|
||||
|
||||
// The widget can only be focused when there is an image available for this phase
|
||||
if (getRenderer()->m_textureFocused.isLoaded())
|
||||
m_allowFocus = true;
|
||||
|
||||
if (force)
|
||||
recalculateTextPosition();
|
||||
}
|
||||
else if (property == "textcolornormal")
|
||||
{
|
||||
if (!m_mouseHover)
|
||||
m_text.getRenderer()->setTextColor(calcColorOpacity(value.getColor(), getRenderer()->getOpacity()));
|
||||
}
|
||||
else if (property == "textcolorhover")
|
||||
{
|
||||
if (m_mouseHover && !m_mouseDown)
|
||||
m_text.getRenderer()->setTextColor(calcColorOpacity(value.getColor(), getRenderer()->getOpacity()));
|
||||
}
|
||||
else if (property == "textcolordown")
|
||||
{
|
||||
if (m_mouseHover && m_mouseDown)
|
||||
m_text.getRenderer()->setTextColor(calcColorOpacity(value.getColor(), getRenderer()->getOpacity()));
|
||||
}
|
||||
else if (property == "texturenormal")
|
||||
{
|
||||
if (value.getTexture().isLoaded())
|
||||
{
|
||||
if (getRenderer()->m_textureNormal.isLoaded())
|
||||
setSize(getRenderer()->m_textureNormal.getImageSize());
|
||||
value.getTexture().setColor({255, 255, 255, static_cast<sf::Uint8>(getRenderer()->getOpacity() * 255)});
|
||||
|
||||
if (m_sizeDefined)
|
||||
value.getTexture().setSize(getSize());
|
||||
else
|
||||
setSize(value.getTexture().getSize());
|
||||
}
|
||||
}
|
||||
else if ((property == "texturehover") || (property == "texturedown"))
|
||||
{
|
||||
if (value.getTexture().isLoaded())
|
||||
{
|
||||
value.getTexture().setColor({255, 255, 255, static_cast<sf::Uint8>(getRenderer()->getOpacity() * 255)});
|
||||
value.getTexture().setSize(getSize());
|
||||
}
|
||||
}
|
||||
else if (property == "texturefocused")
|
||||
{
|
||||
if (value.getTexture().isLoaded())
|
||||
{
|
||||
value.getTexture().setColor({255, 255, 255, static_cast<sf::Uint8>(getRenderer()->getOpacity() * 255)});
|
||||
value.getTexture().setSize(getSize());
|
||||
m_allowFocus = true;
|
||||
}
|
||||
else
|
||||
m_allowFocus = false;
|
||||
}
|
||||
else if (property == "opacity")
|
||||
{
|
||||
float opacity = value.getNumber();
|
||||
getRenderer()->getTextureNormal().setColor({255, 255, 255, static_cast<sf::Uint8>(opacity * 255)});
|
||||
getRenderer()->getTextureHover().setColor({255, 255, 255, static_cast<sf::Uint8>(opacity * 255)});
|
||||
getRenderer()->getTextureDown().setColor({255, 255, 255, static_cast<sf::Uint8>(opacity * 255)});
|
||||
getRenderer()->getTextureFocused().setColor({255, 255, 255, static_cast<sf::Uint8>(opacity * 255)});
|
||||
|
||||
if (!m_mouseHover)
|
||||
m_text.getRenderer()->setTextColor(calcColorOpacity(getRenderer()->getTextColorNormal(), opacity));
|
||||
else if (m_mouseHover && !m_mouseDown)
|
||||
m_text.getRenderer()->setTextColor(calcColorOpacity(getRenderer()->getTextColorHover(), opacity));
|
||||
else if (m_mouseHover && m_mouseDown)
|
||||
m_text.getRenderer()->setTextColor(calcColorOpacity(getRenderer()->getTextColorDown(), opacity));
|
||||
}
|
||||
else if ((property != "bordercolor")
|
||||
&& (property != "backgroundcolornormal")
|
||||
&& (property != "backgroundcolorhover")
|
||||
&& (property != "backgroundcolordown"))
|
||||
{
|
||||
Widget::rendererChanged(property, std::move(value));
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -281,9 +293,9 @@ namespace tgui
|
|||
Widget::mouseEnteredWidget();
|
||||
|
||||
if (m_mouseDown)
|
||||
m_text.setTextColor(calcColorOpacity(getRenderer()->m_textColorDown, getOpacity()));
|
||||
m_text.getRenderer()->setTextColor(calcColorOpacity(getRenderer()->getTextColorDown(), getRenderer()->getOpacity()));
|
||||
else
|
||||
m_text.setTextColor(calcColorOpacity(getRenderer()->m_textColorHover, getOpacity()));
|
||||
m_text.getRenderer()->setTextColor(calcColorOpacity(getRenderer()->getTextColorHover(), getRenderer()->getOpacity()));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -292,181 +304,77 @@ namespace tgui
|
|||
{
|
||||
Widget::mouseLeftWidget();
|
||||
|
||||
m_text.setTextColor(calcColorOpacity(getRenderer()->m_textColorNormal, getOpacity()));
|
||||
m_text.getRenderer()->setTextColor(calcColorOpacity(getRenderer()->getTextColorNormal(), getRenderer()->getOpacity()));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Button::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
// Draw the background of the button
|
||||
getRenderer()->draw(target, states);
|
||||
states.transform.translate(getPosition());
|
||||
|
||||
// Check if there is a background texture
|
||||
if (getRenderer()->getTextureNormal().isLoaded())
|
||||
{
|
||||
if (m_mouseHover)
|
||||
{
|
||||
if (m_mouseDown && m_mouseHover && getRenderer()->getTextureDown().isLoaded())
|
||||
target.draw(getRenderer()->getTextureDown(), states);
|
||||
else if (getRenderer()->getTextureHover().isLoaded())
|
||||
target.draw(getRenderer()->getTextureHover(), states);
|
||||
else
|
||||
target.draw(getRenderer()->getTextureNormal(), states);
|
||||
}
|
||||
else
|
||||
target.draw(getRenderer()->getTextureNormal(), states);
|
||||
|
||||
// When the edit box is focused then draw an extra image
|
||||
if (m_focused && getRenderer()->getTextureFocused().isLoaded())
|
||||
target.draw(getRenderer()->getTextureFocused(), states);
|
||||
}
|
||||
else // There is no background texture
|
||||
{
|
||||
sf::RectangleShape background(getSize());
|
||||
background.setPosition(getPosition());
|
||||
|
||||
if (m_mouseHover)
|
||||
{
|
||||
if (m_mouseDown)
|
||||
background.setFillColor(calcColorOpacity(getRenderer()->getBackgroundColorDown(), getRenderer()->getOpacity()));
|
||||
else
|
||||
background.setFillColor(calcColorOpacity(getRenderer()->getBackgroundColorHover(), getRenderer()->getOpacity()));
|
||||
}
|
||||
else
|
||||
background.setFillColor(calcColorOpacity(getRenderer()->getBackgroundColorNormal(), getRenderer()->getOpacity()));
|
||||
|
||||
target.draw(background, states);
|
||||
}
|
||||
|
||||
// Draw the borders
|
||||
Borders borders = getRenderer()->getBorders();
|
||||
if (borders != Borders{0, 0, 0, 0})
|
||||
{
|
||||
drawBorders(target, states, borders, getPosition(), getSize(), calcColorOpacity(getRenderer()->getBorderColor(), getRenderer()->getOpacity()));
|
||||
|
||||
// Don't try to draw the text when there is no space left for it
|
||||
if ((getSize().x <= borders.left + borders.right) || (getSize().y <= borders.top + borders.bottom))
|
||||
return;
|
||||
}
|
||||
|
||||
// If the button has a text then also draw the text
|
||||
target.draw(m_text, states);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setProperty(std::string property, const std::string& value)
|
||||
void Button::recalculateTextPosition()
|
||||
{
|
||||
property = toLower(property);
|
||||
if (property == "borders")
|
||||
setBorders(Deserializer::deserialize(ObjectConverter::Type::Borders, value).getBorders());
|
||||
else if (property == "textcolor")
|
||||
setTextColor(Deserializer::deserialize(ObjectConverter::Type::Color, value).getColor());
|
||||
else if (property == "textcolornormal")
|
||||
setTextColorNormal(Deserializer::deserialize(ObjectConverter::Type::Color, value).getColor());
|
||||
else if (property == "textcolorhover")
|
||||
setTextColorHover(Deserializer::deserialize(ObjectConverter::Type::Color, value).getColor());
|
||||
else if (property == "textcolordown")
|
||||
setTextColorDown(Deserializer::deserialize(ObjectConverter::Type::Color, value).getColor());
|
||||
else if (property == "backgroundcolor")
|
||||
setBackgroundColor(Deserializer::deserialize(ObjectConverter::Type::Color, value).getColor());
|
||||
else if (property == "backgroundcolornormal")
|
||||
setBackgroundColorNormal(Deserializer::deserialize(ObjectConverter::Type::Color, value).getColor());
|
||||
else if (property == "backgroundcolorhover")
|
||||
setBackgroundColorHover(Deserializer::deserialize(ObjectConverter::Type::Color, value).getColor());
|
||||
else if (property == "backgroundcolordown")
|
||||
setBackgroundColorDown(Deserializer::deserialize(ObjectConverter::Type::Color, value).getColor());
|
||||
else if (property == "bordercolor")
|
||||
setBorderColor(Deserializer::deserialize(ObjectConverter::Type::Color, value).getColor());
|
||||
else if (property == "normalimage")
|
||||
setNormalTexture(Deserializer::deserialize(ObjectConverter::Type::Texture, value).getTexture());
|
||||
else if (property == "hoverimage")
|
||||
setHoverTexture(Deserializer::deserialize(ObjectConverter::Type::Texture, value).getTexture());
|
||||
else if (property == "downimage")
|
||||
setDownTexture(Deserializer::deserialize(ObjectConverter::Type::Texture, value).getTexture());
|
||||
else if (property == "focusedimage")
|
||||
setFocusTexture(Deserializer::deserialize(ObjectConverter::Type::Texture, value).getTexture());
|
||||
else
|
||||
WidgetRenderer::setProperty(property, value);
|
||||
Borders borders = getRenderer()->getBorders();
|
||||
m_text.setPosition(((getSize().x - borders.left - borders.right) - m_text.getSize().x) * 0.5f,
|
||||
((getSize().y - borders.top - borders.bottom) - m_text.getSize().y) * 0.5f);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setProperty(std::string property, ObjectConverter&& value)
|
||||
{
|
||||
property = toLower(property);
|
||||
|
||||
if (value.getType() == ObjectConverter::Type::Borders)
|
||||
{
|
||||
if (property == "borders")
|
||||
setBorders(value.getBorders());
|
||||
else
|
||||
return WidgetRenderer::setProperty(property, std::move(value));
|
||||
}
|
||||
else if (value.getType() == ObjectConverter::Type::Color)
|
||||
{
|
||||
if (property == "textcolor")
|
||||
setTextColor(value.getColor());
|
||||
else if (property == "textcolornormal")
|
||||
setTextColorNormal(value.getColor());
|
||||
else if (property == "textcolorhover")
|
||||
setTextColorHover(value.getColor());
|
||||
else if (property == "textcolordown")
|
||||
setTextColorDown(value.getColor());
|
||||
else if (property == "backgroundcolor")
|
||||
setBackgroundColor(value.getColor());
|
||||
else if (property == "backgroundcolornormal")
|
||||
setBackgroundColorNormal(value.getColor());
|
||||
else if (property == "backgroundcolorhover")
|
||||
setBackgroundColorHover(value.getColor());
|
||||
else if (property == "backgroundcolordown")
|
||||
setBackgroundColorDown(value.getColor());
|
||||
else if (property == "bordercolor")
|
||||
setBorderColor(value.getColor());
|
||||
else
|
||||
WidgetRenderer::setProperty(property, std::move(value));
|
||||
}
|
||||
else if (value.getType() == ObjectConverter::Type::Texture)
|
||||
{
|
||||
if (property == "normalimage")
|
||||
setNormalTexture(value.getTexture());
|
||||
else if (property == "hoverimage")
|
||||
setHoverTexture(value.getTexture());
|
||||
else if (property == "downimage")
|
||||
setDownTexture(value.getTexture());
|
||||
else if (property == "focusedimage")
|
||||
setFocusTexture(value.getTexture());
|
||||
else
|
||||
WidgetRenderer::setProperty(property, std::move(value));
|
||||
}
|
||||
else
|
||||
WidgetRenderer::setProperty(property, std::move(value));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ObjectConverter ButtonRenderer::getProperty(std::string property) const
|
||||
{
|
||||
property = toLower(property);
|
||||
|
||||
if (property == "borders")
|
||||
return m_borders;
|
||||
else if (property == "textcolor")
|
||||
return m_textColorNormal;
|
||||
else if (property == "textcolornormal")
|
||||
return m_textColorNormal;
|
||||
else if (property == "textcolorhover")
|
||||
return m_textColorHover;
|
||||
else if (property == "textcolordown")
|
||||
return m_textColorDown;
|
||||
else if (property == "backgroundcolor")
|
||||
return m_backgroundColorNormal;
|
||||
else if (property == "backgroundcolornormal")
|
||||
return m_backgroundColorNormal;
|
||||
else if (property == "backgroundcolorhover")
|
||||
return m_backgroundColorHover;
|
||||
else if (property == "backgroundcolordown")
|
||||
return m_backgroundColorDown;
|
||||
else if (property == "bordercolor")
|
||||
return m_borderColor;
|
||||
else if (property == "normalimage")
|
||||
return m_textureNormal;
|
||||
else if (property == "hoverimage")
|
||||
return m_textureHover;
|
||||
else if (property == "downimage")
|
||||
return m_textureDown;
|
||||
else if (property == "focusedimage")
|
||||
return m_textureFocused;
|
||||
else
|
||||
return WidgetRenderer::getProperty(property);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::map<std::string, ObjectConverter> ButtonRenderer::getPropertyValuePairs() const
|
||||
{
|
||||
auto pairs = WidgetRenderer::getPropertyValuePairs();
|
||||
|
||||
if (m_textureNormal.isLoaded())
|
||||
{
|
||||
pairs["NormalImage"] = m_textureNormal;
|
||||
if (m_textureHover.isLoaded())
|
||||
pairs["HoverImage"] = m_textureHover;
|
||||
if (m_textureDown.isLoaded())
|
||||
pairs["DownImage"] = m_textureDown;
|
||||
if (m_textureFocused.isLoaded())
|
||||
pairs["FocusedImage"] = m_textureFocused;
|
||||
}
|
||||
else
|
||||
{
|
||||
pairs["BackgroundColorNormal"] = m_backgroundColorNormal;
|
||||
pairs["BackgroundColorHover"] = m_backgroundColorHover;
|
||||
pairs["BackgroundColorDown"] = m_backgroundColorDown;
|
||||
}
|
||||
|
||||
pairs["TextColorNormal"] = m_textColorNormal;
|
||||
pairs["TextColorHover"] = m_textColorHover;
|
||||
pairs["TextColorDown"] = m_textColorDown;
|
||||
pairs["BorderColor"] = m_borderColor;
|
||||
pairs["Borders"] = m_borders;
|
||||
|
||||
return pairs;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setTextColor(const Color& color)
|
||||
|
@ -478,36 +386,6 @@ namespace tgui
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setTextColorNormal(const Color& color)
|
||||
{
|
||||
m_textColorNormal = color;
|
||||
|
||||
if (!m_button->m_mouseHover)
|
||||
m_button->m_text.setTextColor(calcColorOpacity(m_textColorNormal, m_button->getOpacity()));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setTextColorHover(const Color& color)
|
||||
{
|
||||
m_textColorHover = color;
|
||||
|
||||
if (m_button->m_mouseHover && !m_button->m_mouseDown)
|
||||
m_button->m_text.setTextColor(calcColorOpacity(m_textColorHover, m_button->getOpacity()));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setTextColorDown(const Color& color)
|
||||
{
|
||||
m_textColorDown = color;
|
||||
|
||||
if (m_button->m_mouseHover && m_button->m_mouseDown)
|
||||
m_button->m_text.setTextColor(calcColorOpacity(m_textColorDown, m_button->getOpacity()));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setBackgroundColor(const Color& color)
|
||||
{
|
||||
setBackgroundColorNormal(color);
|
||||
|
@ -517,162 +395,20 @@ namespace tgui
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setBackgroundColorNormal(const Color& color)
|
||||
{
|
||||
m_backgroundColorNormal = color;
|
||||
}
|
||||
TGUI_RENDERER_PROPERTY_BORDERS(ButtonRenderer, Borders, Borders(0))
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
TGUI_RENDERER_PROPERTY_COLOR(ButtonRenderer, TextColorNormal, Color(60, 60, 60))
|
||||
TGUI_RENDERER_PROPERTY_COLOR(ButtonRenderer, TextColorHover, sf::Color::Black)
|
||||
TGUI_RENDERER_PROPERTY_COLOR(ButtonRenderer, TextColorDown, sf::Color::Black)
|
||||
TGUI_RENDERER_PROPERTY_COLOR(ButtonRenderer, BackgroundColorNormal, Color(245, 245, 245))
|
||||
TGUI_RENDERER_PROPERTY_COLOR(ButtonRenderer, BackgroundColorHover, sf::Color::White)
|
||||
TGUI_RENDERER_PROPERTY_COLOR(ButtonRenderer, BackgroundColorDown, sf::Color::White)
|
||||
TGUI_RENDERER_PROPERTY_COLOR(ButtonRenderer, BorderColor, sf::Color::Black)
|
||||
|
||||
void ButtonRenderer::setBackgroundColorHover(const Color& color)
|
||||
{
|
||||
m_backgroundColorHover = color;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setBackgroundColorDown(const Color& color)
|
||||
{
|
||||
m_backgroundColorDown = color;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setBorderColor(const Color& color)
|
||||
{
|
||||
m_borderColor = color;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setNormalTexture(const Texture& texture)
|
||||
{
|
||||
m_textureNormal = texture;
|
||||
if (m_textureNormal.isLoaded())
|
||||
{
|
||||
m_textureNormal.setPosition(m_button->getPosition());
|
||||
m_textureNormal.setSize(m_button->getSize());
|
||||
m_textureNormal.setColor({255, 255, 255, static_cast<sf::Uint8>(m_button->getOpacity() * 255)});
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setHoverTexture(const Texture& texture)
|
||||
{
|
||||
m_textureHover = texture;
|
||||
if (m_textureHover.isLoaded())
|
||||
{
|
||||
m_textureHover.setPosition(m_button->getPosition());
|
||||
m_textureHover.setSize(m_button->getSize());
|
||||
m_textureHover.setColor({255, 255, 255, static_cast<sf::Uint8>(m_button->getOpacity() * 255)});
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setDownTexture(const Texture& texture)
|
||||
{
|
||||
m_textureDown = texture;
|
||||
if (m_textureDown.isLoaded())
|
||||
{
|
||||
m_textureDown.setPosition(m_button->getPosition());
|
||||
m_textureDown.setSize(m_button->getSize());
|
||||
m_textureDown.setColor({255, 255, 255, static_cast<sf::Uint8>(m_button->getOpacity() * 255)});
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::setFocusTexture(const Texture& texture)
|
||||
{
|
||||
m_textureFocused = texture;
|
||||
if (m_textureFocused.isLoaded())
|
||||
{
|
||||
m_textureFocused.setPosition(m_button->getPosition());
|
||||
m_textureFocused.setSize(m_button->getSize());
|
||||
m_textureFocused.setColor({255, 255, 255, static_cast<sf::Uint8>(m_button->getOpacity() * 255)});
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ButtonRenderer::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
// Check if there is a background texture
|
||||
if (m_textureNormal.isLoaded())
|
||||
{
|
||||
if (m_button->m_mouseHover)
|
||||
{
|
||||
if (m_button->m_mouseDown && m_button->m_mouseHover && m_textureDown.isLoaded())
|
||||
target.draw(m_textureDown, states);
|
||||
else if (m_textureHover.isLoaded())
|
||||
target.draw(m_textureHover, states);
|
||||
else
|
||||
target.draw(m_textureNormal, states);
|
||||
}
|
||||
else
|
||||
target.draw(m_textureNormal, states);
|
||||
|
||||
// When the edit box is focused then draw an extra image
|
||||
if (m_button->m_focused && m_textureFocused.isLoaded())
|
||||
target.draw(m_textureFocused, states);
|
||||
}
|
||||
else // There is no background texture
|
||||
{
|
||||
sf::RectangleShape button(m_button->getSize());
|
||||
button.setPosition(m_button->getPosition());
|
||||
|
||||
if (m_button->m_mouseHover)
|
||||
{
|
||||
if (m_button->m_mouseDown)
|
||||
button.setFillColor(calcColorOpacity(m_backgroundColorDown, m_button->getOpacity()));
|
||||
else
|
||||
button.setFillColor(calcColorOpacity(m_backgroundColorHover, m_button->getOpacity()));
|
||||
}
|
||||
else
|
||||
button.setFillColor(calcColorOpacity(m_backgroundColorNormal, m_button->getOpacity()));
|
||||
|
||||
target.draw(button, states);
|
||||
}
|
||||
|
||||
// Draw the borders around the button
|
||||
if (m_borders != Borders{0, 0, 0, 0})
|
||||
{
|
||||
sf::Vector2f position = m_button->getPosition();
|
||||
sf::Vector2f size = m_button->getSize();
|
||||
|
||||
// Draw left border
|
||||
sf::RectangleShape border({m_borders.left, size.y + m_borders.top});
|
||||
border.setPosition(position.x - m_borders.left, position.y - m_borders.top);
|
||||
border.setFillColor(calcColorOpacity(m_borderColor, m_button->getOpacity()));
|
||||
target.draw(border, states);
|
||||
|
||||
// Draw top border
|
||||
border.setSize({size.x + m_borders.right, m_borders.top});
|
||||
border.setPosition(position.x, position.y - m_borders.top);
|
||||
target.draw(border, states);
|
||||
|
||||
// Draw right border
|
||||
border.setSize({m_borders.right, size.y + m_borders.bottom});
|
||||
border.setPosition(position.x + size.x, position.y);
|
||||
target.draw(border, states);
|
||||
|
||||
// Draw bottom border
|
||||
border.setSize({size.x + m_borders.left, m_borders.bottom});
|
||||
border.setPosition(position.x - m_borders.left, position.y + size.y);
|
||||
target.draw(border, states);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::shared_ptr<WidgetRenderer> ButtonRenderer::clone(Widget* widget)
|
||||
{
|
||||
auto renderer = std::make_shared<ButtonRenderer>(*this);
|
||||
renderer->m_button = static_cast<Button*>(widget);
|
||||
return renderer;
|
||||
}
|
||||
TGUI_RENDERER_PROPERTY_TEXTURE(ButtonRenderer, TextureNormal)
|
||||
TGUI_RENDERER_PROPERTY_TEXTURE(ButtonRenderer, TextureHover)
|
||||
TGUI_RENDERER_PROPERTY_TEXTURE(ButtonRenderer, TextureDown)
|
||||
TGUI_RENDERER_PROPERTY_TEXTURE(ButtonRenderer, TextureFocused)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
|
|
@ -89,6 +89,13 @@ namespace tgui
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const sf::String& Label::getText() const
|
||||
{
|
||||
return m_string;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Label::setTextSize(unsigned int size)
|
||||
{
|
||||
if (size != m_textSize)
|
||||
|
@ -163,6 +170,13 @@ namespace tgui
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Label::getAutoSize() const
|
||||
{
|
||||
return m_autoSize;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Label::setMaximumTextWidth(float maximumWidth)
|
||||
{
|
||||
if (m_maximumTextWidth != maximumWidth)
|
||||
|
|
|
@ -25,35 +25,43 @@
|
|||
#include "../Tests.hpp"
|
||||
#include <TGUI/Widgets/Button.hpp>
|
||||
|
||||
TEST_CASE("[Button]") {
|
||||
TEST_CASE("[Button]")
|
||||
{
|
||||
tgui::Button::Ptr button = std::make_shared<tgui::Button>();
|
||||
button->setFont("resources/DroidSansArmenian.ttf");
|
||||
|
||||
SECTION("Signals") {
|
||||
SECTION("Signals")
|
||||
{
|
||||
REQUIRE_NOTHROW(button->connect("Pressed", [](){}));
|
||||
REQUIRE_NOTHROW(button->connect("Pressed", [](sf::String){}));
|
||||
}
|
||||
|
||||
SECTION("WidgetType") {
|
||||
SECTION("WidgetType")
|
||||
{
|
||||
REQUIRE(button->getWidgetType() == "Button");
|
||||
}
|
||||
|
||||
SECTION("Text") {
|
||||
SECTION("Text")
|
||||
{
|
||||
REQUIRE(button->getText() == "");
|
||||
button->setText("SomeText");
|
||||
REQUIRE(button->getText() == "SomeText");
|
||||
}
|
||||
|
||||
SECTION("TextSize") {
|
||||
SECTION("TextSize")
|
||||
{
|
||||
button->setTextSize(25);
|
||||
REQUIRE(button->getTextSize() == 25);
|
||||
}
|
||||
|
||||
SECTION("Renderer") {
|
||||
SECTION("Renderer")
|
||||
{
|
||||
auto renderer = button->getRenderer();
|
||||
|
||||
SECTION("colored") {
|
||||
SECTION("set serialized property") {
|
||||
SECTION("colored")
|
||||
{
|
||||
SECTION("set serialized property")
|
||||
{
|
||||
REQUIRE_NOTHROW(renderer->setProperty("TextColor", "rgb(10, 20, 30)"));
|
||||
REQUIRE(renderer->getProperty("TextColor").getColor() == sf::Color(10, 20, 30));
|
||||
REQUIRE(renderer->getProperty("TextColorNormal").getColor() == sf::Color(10, 20, 30));
|
||||
|
@ -76,7 +84,8 @@ TEST_CASE("[Button]") {
|
|||
REQUIRE_NOTHROW(renderer->setProperty("Borders", "(1, 2, 3, 4)"));
|
||||
}
|
||||
|
||||
SECTION("set object property") {
|
||||
SECTION("set object property")
|
||||
{
|
||||
REQUIRE_NOTHROW(renderer->setProperty("TextColor", sf::Color{10, 20, 30}));
|
||||
REQUIRE(renderer->getProperty("TextColor").getColor() == sf::Color(10, 20, 30));
|
||||
REQUIRE(renderer->getProperty("TextColorNormal").getColor() == sf::Color(10, 20, 30));
|
||||
|
@ -99,7 +108,8 @@ TEST_CASE("[Button]") {
|
|||
REQUIRE_NOTHROW(renderer->setProperty("Borders", tgui::Borders{1, 2, 3, 4}));
|
||||
}
|
||||
|
||||
SECTION("functions") {
|
||||
SECTION("functions")
|
||||
{
|
||||
renderer->setTextColor({10, 20, 30});
|
||||
REQUIRE(renderer->getProperty("TextColor").getColor() == sf::Color(10, 20, 30));
|
||||
REQUIRE(renderer->getProperty("TextColorNormal").getColor() == sf::Color(10, 20, 30));
|
||||
|
@ -121,7 +131,8 @@ TEST_CASE("[Button]") {
|
|||
renderer->setBorderColor({80, 90, 100});
|
||||
renderer->setBorders({1, 2, 3, 4});
|
||||
|
||||
SECTION("getPropertyValuePairs") {
|
||||
SECTION("getPropertyValuePairs")
|
||||
{
|
||||
auto pairs = renderer->getPropertyValuePairs();
|
||||
REQUIRE(pairs.size() == 8);
|
||||
REQUIRE(pairs["TextColorNormal"].getColor() == sf::Color(20, 30, 40));
|
||||
|
@ -145,7 +156,8 @@ TEST_CASE("[Button]") {
|
|||
REQUIRE(renderer->getProperty("Borders").getBorders() == tgui::Borders(1, 2, 3, 4));
|
||||
}
|
||||
|
||||
SECTION("textured") {
|
||||
SECTION("textured")
|
||||
{
|
||||
tgui::Texture textureNormal("resources/Black.png", {0, 64, 45, 50}, {10, 0, 25, 50});
|
||||
tgui::Texture textureHover("resources/Black.png", {45, 64, 45, 50}, {10, 0, 25, 50});
|
||||
tgui::Texture textureDown("resources/Black.png", {90, 64, 45, 50}, {10, 0, 25, 50});
|
||||
|
@ -156,27 +168,31 @@ TEST_CASE("[Button]") {
|
|||
REQUIRE(!renderer->getProperty("DownImage").getTexture().isLoaded());
|
||||
REQUIRE(!renderer->getProperty("FocusedImage").getTexture().isLoaded());
|
||||
|
||||
SECTION("set serialized property") {
|
||||
SECTION("set serialized property")
|
||||
{
|
||||
REQUIRE_NOTHROW(renderer->setProperty("NormalImage", tgui::Serializer::serialize(textureNormal)));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("HoverImage", tgui::Serializer::serialize(textureHover)));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("DownImage", tgui::Serializer::serialize(textureDown)));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("FocusedImage", tgui::Serializer::serialize(textureFocused)));
|
||||
}
|
||||
|
||||
SECTION("set object property") {
|
||||
SECTION("set object property")
|
||||
{
|
||||
REQUIRE_NOTHROW(renderer->setProperty("NormalImage", textureNormal));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("HoverImage", textureHover));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("DownImage", textureDown));
|
||||
REQUIRE_NOTHROW(renderer->setProperty("FocusedImage", textureFocused));
|
||||
}
|
||||
|
||||
SECTION("functions") {
|
||||
SECTION("functions")
|
||||
{
|
||||
renderer->setNormalTexture(textureNormal);
|
||||
renderer->setHoverTexture(textureHover);
|
||||
renderer->setDownTexture(textureDown);
|
||||
renderer->setFocusTexture(textureFocused);
|
||||
|
||||
SECTION("getPropertyValuePairs") {
|
||||
SECTION("getPropertyValuePairs")
|
||||
{
|
||||
auto pairs = renderer->getPropertyValuePairs();
|
||||
REQUIRE(pairs.size() == 9);
|
||||
REQUIRE(pairs["NormalImage"].getTexture().getData() == textureNormal.getData());
|
||||
|
@ -198,7 +214,8 @@ TEST_CASE("[Button]") {
|
|||
}
|
||||
}
|
||||
|
||||
SECTION("Saving and loading from file") {
|
||||
SECTION("Saving and loading from file")
|
||||
{
|
||||
REQUIRE_NOTHROW(button = std::make_shared<tgui::Theme>()->load("Button"));
|
||||
|
||||
auto theme = std::make_shared<tgui::Theme>("resources/Black.txt");
|
||||
|
@ -221,12 +238,9 @@ TEST_CASE("[Button]") {
|
|||
REQUIRE_NOTHROW(parent->saveWidgetsToFile("WidgetFileButton2.txt"));
|
||||
REQUIRE(compareFiles("WidgetFileButton1.txt", "WidgetFileButton2.txt"));
|
||||
|
||||
SECTION("Copying widget") {
|
||||
tgui::Button temp;
|
||||
temp = *button;
|
||||
|
||||
parent->removeAllWidgets();
|
||||
parent->add(tgui::Button::copy(std::make_shared<tgui::Button>(temp)), "ButtonName");
|
||||
SECTION("Copying widget")
|
||||
{
|
||||
copy(parent, button);
|
||||
|
||||
REQUIRE_NOTHROW(parent->saveWidgetsToFile("WidgetFileButton2.txt"));
|
||||
REQUIRE(compareFiles("WidgetFileButton1.txt", "WidgetFileButton2.txt"));
|
||||
|
|
|
@ -45,13 +45,24 @@ TEST_CASE("[ClickableWidget]")
|
|||
REQUIRE(widget->getWidgetType() == "ClickableWidget");
|
||||
}
|
||||
|
||||
SECTION("constructor")
|
||||
SECTION("Constructor")
|
||||
{
|
||||
widget = std::make_shared<tgui::ClickableWidget>(200.f, 100.f);
|
||||
REQUIRE(widget->getSize() == sf::Vector2f(200, 100));
|
||||
}
|
||||
|
||||
SECTION("events")
|
||||
SECTION("Position and Size")
|
||||
{
|
||||
widget->setPosition(40, 30);
|
||||
widget->setSize(150, 100);
|
||||
|
||||
REQUIRE(widget->getPosition() == sf::Vector2f(40, 30));
|
||||
REQUIRE(widget->getSize() == sf::Vector2f(150, 100));
|
||||
REQUIRE(widget->getFullSize() == widget->getSize());
|
||||
REQUIRE(widget->getWidgetOffset() == sf::Vector2f(0, 0));
|
||||
}
|
||||
|
||||
SECTION("Events")
|
||||
{
|
||||
unsigned int mousePressedCount = 0;
|
||||
unsigned int mouseReleasedCount = 0;
|
||||
|
|
|
@ -41,6 +41,18 @@ TEST_CASE("[Label]") {
|
|||
REQUIRE(label->getWidgetType() == "Label");
|
||||
}
|
||||
|
||||
SECTION("Position and Size")
|
||||
{
|
||||
label->setPosition(40, 30);
|
||||
label->setSize(150, 100);
|
||||
label->getRenderer()->setBorders(2);
|
||||
|
||||
REQUIRE(label->getPosition() == sf::Vector2f(40, 30));
|
||||
REQUIRE(label->getSize() == sf::Vector2f(150, 100));
|
||||
REQUIRE(label->getFullSize() == label->getSize());
|
||||
REQUIRE(label->getWidgetOffset() == sf::Vector2f(0, 0));
|
||||
}
|
||||
|
||||
SECTION("Text")
|
||||
{
|
||||
REQUIRE(label->getText() == "");
|
||||
|
@ -117,7 +129,7 @@ TEST_CASE("[Label]") {
|
|||
REQUIRE(label->getMaximumTextWidth() == 500);
|
||||
}
|
||||
|
||||
SECTION("events")
|
||||
SECTION("Events")
|
||||
{
|
||||
unsigned int mousePressedCount = 0;
|
||||
unsigned int mouseReleasedCount = 0;
|
||||
|
|
|
@ -47,7 +47,18 @@ TEST_CASE("[Panel]")
|
|||
REQUIRE(panel->getWidgetType() == "Panel");
|
||||
}
|
||||
|
||||
SECTION("events")
|
||||
SECTION("Position and Size")
|
||||
{
|
||||
panel->setPosition(40, 30);
|
||||
panel->setSize(150, 100);
|
||||
|
||||
REQUIRE(panel->getPosition() == sf::Vector2f(40, 30));
|
||||
REQUIRE(panel->getSize() == sf::Vector2f(150, 100));
|
||||
REQUIRE(panel->getFullSize() == panel->getSize());
|
||||
REQUIRE(panel->getWidgetOffset() == sf::Vector2f(0, 0));
|
||||
}
|
||||
|
||||
SECTION("Events")
|
||||
{
|
||||
unsigned int mousePressedCount = 0;
|
||||
unsigned int mouseReleasedCount = 0;
|
||||
|
|
|
@ -40,7 +40,7 @@ TEST_CASE("[Picture]")
|
|||
REQUIRE(picture->getWidgetType() == "Picture");
|
||||
}
|
||||
|
||||
SECTION("constructor")
|
||||
SECTION("Constructor")
|
||||
{
|
||||
sf::Texture texture;
|
||||
texture.loadFromFile("resources/image.png");
|
||||
|
@ -66,6 +66,17 @@ TEST_CASE("[Picture]")
|
|||
REQUIRE(picture->getSize() == sf::Vector2f(texture.getSize()));
|
||||
}
|
||||
|
||||
SECTION("Position and Size")
|
||||
{
|
||||
picture->setPosition(40, 30);
|
||||
picture->setSize(150, 100);
|
||||
|
||||
REQUIRE(picture->getPosition() == sf::Vector2f(40, 30));
|
||||
REQUIRE(picture->getSize() == sf::Vector2f(150, 100));
|
||||
REQUIRE(picture->getFullSize() == picture->getSize());
|
||||
REQUIRE(picture->getWidgetOffset() == sf::Vector2f(0, 0));
|
||||
}
|
||||
|
||||
SECTION("setTexture")
|
||||
{
|
||||
picture->setSize(50, 50);
|
||||
|
@ -109,7 +120,7 @@ TEST_CASE("[Picture]")
|
|||
REQUIRE(!picture->isSmooth());
|
||||
}
|
||||
|
||||
SECTION("events")
|
||||
SECTION("Events")
|
||||
{
|
||||
unsigned int mousePressedCount = 0;
|
||||
unsigned int mouseReleasedCount = 0;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Button {
|
||||
NormalImage : "Black.png" Part( 0, 64, 45, 50) Middle(10, 0, 25, 50);
|
||||
HoverImage : "Black.png" Part(45, 64, 45, 50) Middle(10, 0, 25, 50);
|
||||
DownImage : "Black.png" Part(90, 64, 45, 50) Middle(10, 0, 25, 50);
|
||||
TextureNormal : "Black.png" Part( 0, 64, 45, 50) Middle(10, 0, 25, 50);
|
||||
TextureHover : "Black.png" Part(45, 64, 45, 50) Middle(10, 0, 25, 50);
|
||||
TextureDown : "Black.png" Part(90, 64, 45, 50) Middle(10, 0, 25, 50);
|
||||
TextColorNormal : rgb(190, 190, 190);
|
||||
TextColorHover : rgb(250, 250, 250);
|
||||
TextColorDown : rgb(250, 250, 250);
|
||||
|
@ -91,6 +91,10 @@ MessageBox {
|
|||
TextColor : rgb(190, 190, 190);
|
||||
}
|
||||
|
||||
Panel {
|
||||
BackgroundColor : rgb(80, 80, 80);
|
||||
}
|
||||
|
||||
ProgressBar {
|
||||
BackImage : "Black.png" Part(180, 64, 90, 40) Middle(20, 0, 50, 40);
|
||||
FrontImage : "Black.png" Part(180, 108, 90, 32) Middle(16, 0, 50, 32);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Button {
|
||||
NormalImage : "Black.png" Part( 0, 64, 45, 50) Middle(10, 0, 25, 50);
|
||||
HoverImage : "Black.png" Part(45, 64, 45, 50) Middle(10, 0, 25, 50);
|
||||
DownImage : "Black.png" Part(90, 64, 45, 50) Middle(10, 0, 25, 50);
|
||||
TextureNormal : "Black.png" Part( 0, 64, 45, 50) Middle(10, 0, 25, 50);
|
||||
TextureHover : "Black.png" Part(45, 64, 45, 50) Middle(10, 0, 25, 50);
|
||||
TextureDown : "Black.png" Part(90, 64, 45, 50) Middle(10, 0, 25, 50);
|
||||
TextColorNormal : rgb(190, 190, 190);
|
||||
TextColorHover : rgb(250, 250, 250);
|
||||
TextColorDown : rgb(250, 250, 250);
|
||||
|
|
Loading…
Reference in New Issue