Several minor changes that were changed while developing TGUI.Net

0.8
Bruno Van de Velde 2016-10-05 15:10:21 +02:00
parent e65f73a166
commit 8170a4e229
50 changed files with 300 additions and 198 deletions

View File

@ -21,10 +21,6 @@ matrix:
- $HOME/SFML-2.4.0_LINUX
- os: osx
osx_image: xcode7
before_install:
- brew update
- brew install cmake
cache:
directories:
- $HOME/SFML_OSX

View File

@ -61,7 +61,7 @@ void loadWidgets( tgui::Gui& gui )
gui.add(editBoxPassword);
// Create the login button
// Instead of "parent.width" and "parent.width", we use the shorter "&.w" and "&.h" here as an example
// Instead of "parent.width" and "parent.height", we use the shorter "&.w" and "&.h" here as an example
auto button = tgui::Button::create("Login");
button->setSize({"&.w / 2", "&.h / 6"});
button->setPosition({"&.w / 4", "&.h * 7/10"});

View File

@ -47,7 +47,7 @@ namespace tgui
SlideFromLeft = SlideToRight, ///< Slide from left to show or to the right to hide
SlideFromRight = SlideToLeft, ///< Slide from right to show or to the left to hide
SlideFromTop = SlideToBottom, ///< Slide from top to show or to the bottom to hide
SlideFromBottom = SlideToTop, ///< Slide from bottom to show or to the top to hide
SlideFromBottom = SlideToTop ///< Slide from bottom to show or to the top to hide
};
namespace priv

View File

@ -334,7 +334,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void mouseWheelMoved(int delta, int x, int y) override;
virtual void mouseWheelMoved(float delta, int x, int y) override;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal

View File

@ -152,17 +152,6 @@ namespace tgui
void draw();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the size of the container
///
/// @return Size of the container
///
/// This size will equal the size of the window.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::Vector2f getSize() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the internal container of the Gui
///

View File

@ -40,6 +40,9 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Default constructor
///
/// @param Width and height of the outline in all directions
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Outline(float size = 0) :
left (size),
@ -69,10 +72,10 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Constructor that initializes the outline
///
/// @param leftBorderWidth Width of the left border
/// @param topBorderHeight Height of the top border
/// @param rightBorderWidth Width of the right border
/// @param bottomBorderHeight Height of the bottom border
/// @param leftBorderWidth Width of the left outline
/// @param topBorderHeight Height of the top outline
/// @param rightBorderWidth Width of the right outline
/// @param bottomBorderHeight Height of the bottom outline
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Outline(float leftBorderWidth, float topBorderHeight, float rightBorderWidth, float bottomBorderHeight) :
@ -114,16 +117,16 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Width of the left border
/// Width of the left outline
float left;
/// Height of the top border
/// Height of the top outline
float top;
/// Width of the right border
/// Width of the right outline
float right;
/// Height of the bottom border
/// Height of the bottom outline
float bottom;
};

View File

@ -111,6 +111,24 @@ namespace tgui
Color getTitleColor() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the color of the background
///
/// @param color New background color
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setBackgroundColor(Color color);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the color of the background
///
/// @return Background color
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Color getBackgroundColor() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the color of the borders
///
@ -165,24 +183,6 @@ namespace tgui
float getPaddingBetweenButtons() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the color of the background
///
/// @param color New background color
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setBackgroundColor(Color color);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the color of the background
///
/// @return Background color
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Color getBackgroundColor() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the image of the title bar
///

View File

@ -192,7 +192,7 @@ namespace tgui
/// @return Id of the texture
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::string getId() const;
const sf::String& getId() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -472,7 +472,7 @@ namespace tgui
ScalingType m_scalingType = ScalingType::Normal;
bool m_loaded = false;
std::string m_id;
sf::String m_id;
std::function<void(std::shared_ptr<TextureData>)> m_copyCallback;
std::function<void(std::shared_ptr<TextureData>)> m_destructCallback;

View File

@ -438,7 +438,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void mouseWheelMoved(int delta, int x, int y);
virtual void mouseWheelMoved(float delta, int x, int y);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal

View File

@ -136,7 +136,7 @@ namespace tgui
/// @param states Render states to use for drawing
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void draw(const sf::Vertex* vertices, unsigned int vertexCount,
void draw(const sf::Vertex* vertices, std::size_t vertexCount,
sf::PrimitiveType type, const sf::RenderStates& states = sf::RenderStates::Default);

View File

@ -382,7 +382,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void mouseWheelMoved(int delta, int x, int y) override;
virtual void mouseWheelMoved(float delta, int x, int y) override;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal

View File

@ -251,8 +251,9 @@ namespace tgui
/// @code
/// childWindow->setTitleButtons(ChildWindow::TitleButtons::Minimize | ChildWindow::TitleButtons::Close);
/// @endcode
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setTitleButtons(int buttons);
void setTitleButtons(unsigned int buttons);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -261,7 +262,7 @@ namespace tgui
/// @return Which buttons are available in the title bar
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int getTitleButtons() const;
unsigned int getTitleButtons() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -351,7 +352,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void mouseWheelMoved(int delta, int x, int y) override;
virtual void mouseWheelMoved(float delta, int x, int y) override;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
@ -431,7 +432,7 @@ namespace tgui
sf::Vector2f m_maximumSize = {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()};
sf::Vector2f m_minimumSize = {0, 0};
TitleAlignment m_titleAlignment = TitleAlignment::Center;
int m_titleButtons = TitleButton::Close;
unsigned int m_titleButtons = TitleButton::Close;
std::shared_ptr<Button> m_closeButton;
std::shared_ptr<Button> m_minimizeButton;

View File

@ -471,7 +471,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void mouseWheelMoved(int delta, int x, int y) override;
virtual void mouseWheelMoved(float delta, int x, int y) override;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -83,6 +83,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct Validator
{
static TGUI_API std::string All; ///< Accept any input
static TGUI_API std::string Int; ///< Accept negative and positive integers
static TGUI_API std::string UInt; ///< Accept only positive integers
static TGUI_API std::string Float; ///< Accept decimal numbers
@ -181,7 +182,7 @@ namespace tgui
/// @return The text of the edit box
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::String getText() const;
const sf::String& getText() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -203,7 +204,7 @@ namespace tgui
/// @return The default text of the edit box
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::String getDefaultText() const;
const sf::String& getDefaultText() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -338,12 +339,19 @@ namespace tgui
///
/// @param charactersBeforeCaret The new position
///
/// Normally you will not need this function.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setCaretPosition(std::size_t charactersBeforeCaret);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns after which character the blinking cursor is currently located
///
/// @return Characters before the caret
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::size_t getCaretPosition() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Defines how the text input should look like
///

View File

@ -52,6 +52,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum class Alignment
{
Center, ///< Center the widget in the cell
UpperLeft, ///< Draw the widget in the upper left corner of the cell
Up, ///< Draw the widget at the upper side of the cell (horizontally centered)
UpperRight, ///< Draw the widget in the upper right corner of the cell
@ -59,8 +60,7 @@ namespace tgui
BottomRight, ///< Draw the widget in the bottom right corner of the cell
Bottom, ///< Draw the widget at the bottom of the cell (horizontally centered)
BottomLeft, ///< Draw the widget in the bottom left corner of the cell
Left, ///< Draw the widget at the left side of the cell (vertically centered)
Center ///< Center the widget in the cell
Left ///< Draw the widget at the left side of the cell (vertically centered)
};
@ -201,6 +201,17 @@ namespace tgui
void setWidgetBorders(std::size_t row, std::size_t column, const Borders& borders = Borders(0, 0, 0, 0));
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the borders around a widget
///
/// @param widget The widget to get the borders from
///
/// @return The borders inside the around the widget, or Borders{0} when the widget wasn't part of the grid
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Borders getWidgetBorders(const Widget::Ptr& widget) const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the borders around a widget in a specific cell of the grid
///
@ -234,6 +245,17 @@ namespace tgui
void setWidgetAlignment(std::size_t row, std::size_t column, Alignment alignment = Alignment::Center);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the alignment of a given widget
///
/// @param widget The widget to get the alignment from
///
/// @return The alignment inside the cell, or Grid::Alignment::Center when the widget wasn't part of the grid
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Alignment getWidgetAlignment(const Widget::Ptr& widget) const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the alignment of a given widget in its cell
///

View File

@ -112,6 +112,15 @@ namespace tgui
void setStartRotation(float startRotation);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the start rotation, which is the place where the value should be minimal
///
/// @return number in the interval [0,360[, for which 0 to to the right and the rotation goes counter-clockwise
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float getStartRotation() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets the end rotation, which is the place where the value should be maximal
///
@ -123,28 +132,13 @@ namespace tgui
void setEndRotation(float endRotation);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the start rotation, which is the place where the value should be minimal
///
/// @return number in the interval [0,360[, for which 0 to to the right and the rotation goes counter-clockwise
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float getStartRotation()
{
return m_startRotation;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets the end rotation, which is the place where the value should be maximal
///
/// @return number in the interval [0,360[, for which 0 to to the right and the rotation goes counter-clockwise
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float getEndRotation()
{
return m_endRotation;
}
float getEndRotation() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -164,6 +158,19 @@ namespace tgui
virtual void setMinimum(int minimum);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the value when the knob would be rotated in the direction of StartRotation
///
/// @return The current minimum value
///
/// The default minimum value is 0.
///
/// @see getStartRotation
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int getMinimum() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets the value for when the knob would be rotated in the direction of EndRotation
///
@ -181,6 +188,19 @@ namespace tgui
virtual void setMaximum(int maximum);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the value when the knob would be rotated in the direction of EndRotation
///
/// @return The current maximum value
///
/// The default maximum value is 360.
///
/// @see getEndRotation
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int getMaximum() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the current value
///
@ -195,38 +215,6 @@ namespace tgui
virtual void setValue(int value);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the value when the knob would be rotated in the direction of StartRotation
///
/// @return The current minimum value
///
/// The default minimum value is 0.
///
/// @see getStartRotation
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int getMinimum() const
{
return m_minimum;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the value when the knob would be rotated in the direction of EndRotation
///
/// @return The current maximum value
///
/// The default maximum value is 360.
///
/// @see getEndRotation
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int getMaximum() const
{
return m_maximum;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the current value
///
@ -235,10 +223,7 @@ namespace tgui
/// The default value is 0.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int getValue() const
{
return m_value;
}
int getValue() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -256,10 +241,7 @@ namespace tgui
/// @return Does the value increase when turning clockwise?
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool getClockwiseTurning()
{
return m_clockwiseTurning;
}
bool getClockwiseTurning() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -44,7 +44,7 @@ namespace tgui
/// * Optional parameters sf::String and sf::String: Name and id of the item
/// * Uses Callback member 'text' and 'itemId'
///
/// - MousePressed (left mouse went down on top of an item
/// - MousePressed (left mouse went down on top of an item)
/// * Optional parameter sf::String: Name of the item (the text that is visible)
/// * Optional parameters sf::String and sf::String: Name and id of the item
/// * Uses Callback member 'text' and 'itemId'
@ -481,7 +481,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void mouseWheelMoved(int delta, int x, int y) override;
virtual void mouseWheelMoved(float delta, int x, int y) override;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal

View File

@ -131,7 +131,7 @@ namespace tgui
/// @return Text that is being displayed inside the message box
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::String getText() const;
const sf::String& getText() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -38,9 +38,6 @@ namespace tgui
///
/// Signals:
/// - DoubleClicked (double left clicked on top of the picture)
/// * Optional parameter sf::Vector2f: Position where you clicked
/// * Uses Callback member 'mouse'
///
/// - Inherited signals from ClickableWidget
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -141,7 +138,7 @@ namespace tgui
/// Empty string when no image was loaded yet or when it was loaded directly from an sf::Texture.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::String getLoadedFilename() const;
const sf::String& getLoadedFilename() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -231,7 +231,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void mouseWheelMoved(int delta, int x, int y) override;
virtual void mouseWheelMoved(float delta, int x, int y) override;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal

View File

@ -62,10 +62,13 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Creates a new slider widget
///
/// @param minimum The minimum value of the slider
/// @param maximum The maximum value of the slider
///
/// @return The new slider
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static Slider::Ptr create();
static Slider::Ptr create(int minimum = 0, int maximum = 10);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -218,7 +221,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void mouseWheelMoved(int delta, int x, int y) override;
virtual void mouseWheelMoved(float delta, int x, int y) override;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal

View File

@ -132,7 +132,7 @@ namespace tgui
/// @return The text that is currently inside the text box
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::String getText() const;
const sf::String& getText() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -268,7 +268,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void mouseWheelMoved(int delta, int x, int y) override;
virtual void mouseWheelMoved(float delta, int x, int y) override;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal

View File

@ -548,13 +548,13 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Container::mouseWheelMoved(int delta, int x, int y)
void Container::mouseWheelMoved(float delta, int x, int y)
{
sf::Event event;
event.type = sf::Event::MouseWheelMoved;
event.mouseWheel.delta = delta;
event.mouseWheel.x = static_cast<int>(x);
event.mouseWheel.y = static_cast<int>(y);
event.type = sf::Event::MouseWheelScrolled;
event.mouseWheelScroll.delta = delta;
event.mouseWheelScroll.x = static_cast<int>(x);
event.mouseWheelScroll.y = static_cast<int>(y);
// Let the event manager handle the event
handleEvent(event);
@ -806,16 +806,16 @@ namespace tgui
}
// Check for mouse wheel scrolling
else if (event.type == sf::Event::MouseWheelMoved)
else if ((event.type == sf::Event::MouseWheelScrolled) && (event.mouseWheelScroll.wheel == sf::Mouse::Wheel::VerticalWheel))
{
// Find the widget under the mouse
Widget::Ptr widget = mouseOnWhichWidget({static_cast<float>(event.mouseWheel.x), static_cast<float>(event.mouseWheel.y)});
Widget::Ptr widget = mouseOnWhichWidget({static_cast<float>(event.mouseWheelScroll.x), static_cast<float>(event.mouseWheelScroll.y)});
if (widget != nullptr)
{
// Send the event to the widget
widget->mouseWheelMoved(event.mouseWheel.delta,
static_cast<int>(event.mouseWheel.x - widget->getPosition().x),
static_cast<int>(event.mouseWheel.y - widget->getPosition().y));
widget->mouseWheelMoved(event.mouseWheelScroll.delta,
static_cast<int>(event.mouseWheelScroll.x - widget->getPosition().x),
static_cast<int>(event.mouseWheelScroll.y - widget->getPosition().y));
return true;
}

View File

@ -152,7 +152,7 @@ namespace tgui
// Check if the event has something to do with the mouse
if ((event.type == sf::Event::MouseMoved) || (event.type == sf::Event::MouseButtonPressed)
|| (event.type == sf::Event::MouseButtonReleased) || (event.type == sf::Event::MouseWheelMoved))
|| (event.type == sf::Event::MouseButtonReleased) || (event.type == sf::Event::MouseWheelScrolled))
{
sf::Vector2f mouseCoords;
@ -175,11 +175,11 @@ namespace tgui
break;
}
case sf::Event::MouseWheelMoved:
case sf::Event::MouseWheelScrolled:
{
mouseCoords = m_window->mapPixelToCoords({event.mouseWheel.x, event.mouseWheel.y}, m_view);
event.mouseWheel.x = static_cast<int>(mouseCoords.x + 0.5f);
event.mouseWheel.y = static_cast<int>(mouseCoords.y + 0.5f);
mouseCoords = m_window->mapPixelToCoords({event.mouseWheelScroll.x, event.mouseWheelScroll.y}, m_view);
event.mouseWheelScroll.x = static_cast<int>(mouseCoords.x + 0.5f);
event.mouseWheelScroll.y = static_cast<int>(mouseCoords.y + 0.5f);
break;
}
@ -273,15 +273,6 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::Vector2f Gui::getSize() const
{
assert(m_window != nullptr);
return sf::Vector2f{m_window->getSize()};
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
GuiContainer::Ptr Gui::getContainer() const
{
return m_container;

View File

@ -823,6 +823,9 @@ namespace tgui
if (closingBracePos == std::string::npos)
return; // No matching close brace found
/// TODO: commaPos may find wrong comma when x or y expression is e.g. "min(1,2)"
/// Neither the first not the last comma is guarenteed to be the correct one
// There have to be two components
auto commaPos = expression.find(',', openingBracePos + 1);
if ((commaPos > closingBracePos) || (expression.find(',', commaPos + 1) < closingBracePos))

View File

@ -160,7 +160,7 @@ namespace tgui
std::string serializeTexture(ObjectConverter&& value)
{
Texture texture = value.getTexture();
if (texture.getId().empty())
if (texture.getId().isEmpty())
return "None";
std::string result = "\"" + texture.getId() + "\"";

View File

@ -57,6 +57,9 @@ namespace tgui
{
auto& renderer = pair.second;
/// TODO: Exceptions should not be used for such situations!
/// Add a function to ThemeLoader that lists which sections exist.
// Try to load the new renderer
const std::map<sf::String, sf::String>* properties;
try
@ -97,19 +100,19 @@ namespace tgui
std::shared_ptr<RendererData> Theme::getRenderer(const std::string& id)
{
std::string lowercaseSecondart = toLower(id);
std::string lowercaseSecondary = toLower(id);
// If we already have this renderer in cache then just return it
auto it = m_renderers.find(lowercaseSecondart);
auto it = m_renderers.find(lowercaseSecondary);
if (it != m_renderers.end())
return it->second;
m_renderers[lowercaseSecondart] = std::make_shared<RendererData>();
auto& properties = m_themeLoader->load(m_primary, lowercaseSecondart);
m_renderers[lowercaseSecondary] = std::make_shared<RendererData>();
auto& properties = m_themeLoader->load(m_primary, lowercaseSecondary);
for (const auto& property : properties)
m_renderers[lowercaseSecondart]->propertyValuePairs[property.first] = ObjectConverter(property.second);
m_renderers[lowercaseSecondary]->propertyValuePairs[property.first] = ObjectConverter(property.second);
return m_renderers[lowercaseSecondart];
return m_renderers[lowercaseSecondary];
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -194,6 +194,8 @@ namespace tgui
}
}
/// TODO: Signals?
/// TODO: Separate renderer section?
else if (toLower(childNode->name) == "renderer")
{

View File

@ -99,7 +99,11 @@ namespace tgui
void SignalWidgetBase::disconnectAll(const std::string& signalName)
{
for (const auto& name : extractSignalNames(signalName))
m_signals.at(toLower(name)).disconnectAll();
{
auto it = m_signals.find(toLower(name));
if (it != m_signals.end())
it->second.disconnectAll();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -168,7 +168,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::string Texture::getId() const
const sf::String& Texture::getId() const
{
return m_id;
}
@ -194,8 +194,6 @@ namespace tgui
m_size.x = std::max(size.x, 0.f);
m_size.y = std::max(size.y, 0.f);
setOrigin(std::min(m_size.x, m_size.y) / 2.0f, std::min(m_size.x, m_size.y) / 2.0f);
if (m_loaded)
updateVertices();
}
@ -574,7 +572,15 @@ namespace tgui
void Texture::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform.translate(getOrigin());
// A rotation can cause the image to be shifted, so we move it upfront so that it ends at the correct location
if (getRotation() != 0)
{
sf::Vector2f pos = {getTransform().transformRect(sf::FloatRect({}, getSize())).left,
getTransform().transformRect(sf::FloatRect({}, getSize())).top};
states.transform.translate(getPosition() - pos);
}
states.transform *= getTransform();
if (m_loaded)

View File

@ -55,7 +55,7 @@ namespace
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
namespace tgui
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -623,7 +623,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Widget::mouseWheelMoved(int, int, int)
void Widget::mouseWheelMoved(float, int, int)
{
}

View File

@ -106,7 +106,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Canvas::draw(const sf::Vertex* vertices, unsigned int vertexCount, sf::PrimitiveType type, const sf::RenderStates& states)
void Canvas::draw(const sf::Vertex* vertices, std::size_t vertexCount, sf::PrimitiveType type, const sf::RenderStates& states)
{
m_renderTexture.draw(vertices, vertexCount, type, states);
}

View File

@ -370,7 +370,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ChatBox::mouseWheelMoved(int delta, int, int)
void ChatBox::mouseWheelMoved(float delta, int, int)
{
if (m_scroll.getLowValue() < m_scroll.getMaximum())
m_scroll.mouseWheelMoved(delta, 0, 0);

View File

@ -118,7 +118,7 @@ namespace tgui
m_text.setStyle(getRenderer()->getTextStyle());
m_callback.checked = true;
sendSignal("Checked", m_checked);
sendSignal("Checked", static_cast<int>(m_checked));
}
}
@ -134,7 +134,7 @@ namespace tgui
m_text.setStyle(getRenderer()->getTextStyle());
m_callback.checked = false;
sendSignal("Unchecked", m_checked);
sendSignal("Unchecked", static_cast<int>(m_checked));
}
}
@ -251,7 +251,7 @@ namespace tgui
const float pi = 3.14159265358979f;
// Set the clipping for all draw calls that happen until this clipping object goes out of scope
Clipping clipping{target, states, {borders.left, borders.top}, getInnerSize()};
Clipping clipping{target, states, {}, getInnerSize()};
sf::Vector2f size = getInnerSize();

View File

@ -255,7 +255,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ChildWindow::setTitleButtons(int buttons)
void ChildWindow::setTitleButtons(unsigned int buttons)
{
m_titleButtons = buttons;
@ -294,7 +294,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int ChildWindow::getTitleButtons() const
unsigned int ChildWindow::getTitleButtons() const
{
return m_titleButtons;
}
@ -549,7 +549,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ChildWindow::mouseWheelMoved(int delta, int x, int y)
void ChildWindow::mouseWheelMoved(float delta, int x, int y)
{
sf::Vector2f offset = getChildWidgetsOffset();
Container::mouseWheelMoved(delta, static_cast<int>(x - offset.x), static_cast<int>(y - offset.y));

View File

@ -51,6 +51,7 @@ namespace tgui
getRenderer()->setBorders({2});
getRenderer()->setPadding({2, 0, 0, 0});
getRenderer()->setBackgroundColor({245, 245, 245});
getRenderer()->setTextColor(sf::Color::Black);
getRenderer()->setArrowBackgroundColor({245, 245, 245});
getRenderer()->setArrowBackgroundColorHover(sf::Color::White);
getRenderer()->setArrowColor({60, 60, 60});
@ -428,7 +429,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ComboBox::mouseWheelMoved(int delta, int, int)
void ComboBox::mouseWheelMoved(float delta, int, int)
{
// Only act to scrolling when the list is not being shown
if (!m_listBox->isVisible())
@ -436,7 +437,7 @@ namespace tgui
// Check if you are scrolling down
if (delta < 0)
{
// select the next item
// Select the next item
if (static_cast<std::size_t>(m_listBox->getSelectedItemIndex() + 1) < m_listBox->getItemCount())
{
m_listBox->setSelectedItemByIndex(static_cast<std::size_t>(m_listBox->getSelectedItemIndex() + 1));
@ -445,7 +446,7 @@ namespace tgui
}
else // You are scrolling up
{
// select the previous item
// Select the previous item
if (m_listBox->getSelectedItemIndex() > 0)
{
m_listBox->setSelectedItemByIndex(static_cast<std::size_t>(m_listBox->getSelectedItemIndex() - 1));

View File

@ -36,6 +36,7 @@ namespace tgui
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::string EditBox::Validator::All = ".*";
std::string EditBox::Validator::Int = "[+-]?[0-9]*";
std::string EditBox::Validator::UInt = "[0-9]*";
std::string EditBox::Validator::Float = "[+-]?[0-9]*\\.?[0-9]*";
@ -223,7 +224,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::String EditBox::getText() const
const sf::String& EditBox::getText() const
{
return m_text;
}
@ -237,7 +238,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::String EditBox::getDefaultText() const
const sf::String& EditBox::getDefaultText() const
{
return m_defaultText.getString();
}
@ -430,6 +431,13 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::size_t EditBox::getCaretPosition() const
{
return m_selEnd;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void EditBox::setInputValidator(const std::string& regex)
{
m_regexString = regex;

View File

@ -274,6 +274,23 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Borders Grid::getWidgetBorders(const Widget::Ptr& widget) const
{
// Find the widget in the grid
for (std::size_t row = 0; row < m_gridWidgets.size(); ++row)
{
for (std::size_t col = 0; col < m_gridWidgets[row].size(); ++col)
{
if (m_gridWidgets[row][col] == widget)
return getWidgetBorders(row, col);
}
}
return {};
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Borders Grid::getWidgetBorders(std::size_t row, std::size_t col) const
{
if (((row < m_gridWidgets.size()) && (col < m_gridWidgets[row].size())) && (m_gridWidgets[row][col] != nullptr))
@ -384,6 +401,22 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Grid::Alignment Grid::getWidgetAlignment(const Widget::Ptr& widget) const
{
for (std::size_t row = 0; row < m_gridWidgets.size(); ++row)
{
for (std::size_t col = 0; col < m_gridWidgets[row].size(); ++col)
{
if (m_gridWidgets[row][col] == widget)
return getWidgetAlignment(row, col);
}
}
return Alignment::Center;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Grid::Alignment Grid::getWidgetAlignment(std::size_t row, std::size_t col) const
{
if (((row < m_gridWidgets.size()) && (col < m_gridWidgets[row].size())) && (m_gridWidgets[row][col] != nullptr))

View File

@ -105,6 +105,13 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float Knob::getStartRotation() const
{
return m_startRotation;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Knob::setEndRotation(float endRotation)
{
while (endRotation >= 360)
@ -120,6 +127,13 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float Knob::getEndRotation() const
{
return m_endRotation;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Knob::setMinimum(int minimum)
{
if (m_minimum != minimum)
@ -142,6 +156,13 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int Knob::getMinimum() const
{
return m_minimum;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Knob::setMaximum(int maximum)
{
if (m_maximum != maximum)
@ -167,6 +188,13 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int Knob::getMaximum() const
{
return m_maximum;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Knob::setValue(int value)
{
if (m_value != value)
@ -190,6 +218,13 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int Knob::getValue() const
{
return m_value;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Knob::setClockwiseTurning(bool clockwise)
{
m_clockwiseTurning = clockwise;
@ -200,6 +235,13 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Knob::getClockwiseTurning() const
{
return m_clockwiseTurning;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Knob::mouseOnWidget(sf::Vector2f pos) const
{
// Check if the mouse is on top of the widget

View File

@ -603,7 +603,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ListBox::mouseWheelMoved(int delta, int x, int y)
void ListBox::mouseWheelMoved(float delta, int x, int y)
{
if (m_scroll.isShown())
{

View File

@ -127,7 +127,7 @@ namespace tgui
pos.x += m_menus[i].text.getSize().x + 2 * getRenderer()->getDistanceToSide();
}
// could not find the menu
// Could not find the menu
return false;
}

View File

@ -130,7 +130,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::String MessageBox::getText() const
const sf::String& MessageBox::getText() const
{
return m_label->getText();
}

View File

@ -82,7 +82,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::String Picture::getLoadedFilename() const
const sf::String& Picture::getLoadedFilename() const
{
return m_texture.getId();
}

View File

@ -126,7 +126,7 @@ namespace tgui
m_text.setStyle(getRenderer()->getTextStyle());
m_callback.checked = true;
sendSignal("Checked", m_checked);
sendSignal("Checked", static_cast<int>(m_checked));
}
}
@ -142,7 +142,7 @@ namespace tgui
m_text.setStyle(getRenderer()->getTextStyle());
m_callback.checked = false;
sendSignal("Unchecked", m_checked);
sendSignal("Unchecked", static_cast<int>(m_checked));
}
}

View File

@ -190,7 +190,6 @@ namespace tgui
}
// Recalculate the position of the track, thumb and arrows
updateThumbPosition();
if (m_verticalScroll)
{
m_arrowDown.left = 0;
@ -207,6 +206,7 @@ namespace tgui
m_track.left = m_arrowUp.width;
m_track.top = 0;
}
updateThumbPosition();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -631,7 +631,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Scrollbar::mouseWheelMoved(int delta, int x, int y)
void Scrollbar::mouseWheelMoved(float delta, int x, int y)
{
if (static_cast<int>(m_value) - static_cast<int>(delta * m_scrollAmount) < 0)
setValue(0);

View File

@ -56,9 +56,14 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Slider::Ptr Slider::create()
Slider::Ptr Slider::create(int minimum, int maximum)
{
return std::make_shared<Slider>();
auto slider = std::make_shared<Slider>();
slider->setMinimum(minimum);
slider->setMaximum(maximum);
return slider;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -354,7 +359,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Slider::mouseWheelMoved(int delta, int, int)
void Slider::mouseWheelMoved(float delta, int, int)
{
if (m_value - delta < m_minimum)
setValue(m_minimum);

View File

@ -22,7 +22,6 @@
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <TGUI/Widgets/SpinButton.hpp>
#include <SFML/Graphics/ConvexShape.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
@ -300,6 +299,9 @@ namespace tgui
{
value.getTexture().setSize(getArrowSize());
value.getTexture().setOpacity(getRenderer()->getOpacity());
if (!m_verticalScroll)
value.getTexture().setRotation(-90);
}
else if (property == "opacity")
{
@ -408,7 +410,7 @@ namespace tgui
if (spaceBetweenArrows > 0)
{
drawRectangleShape(target, states, {spaceBetweenArrows, arrowSize.y}, getRenderer()->getBorderColor());
drawRectangleShape(target, states, {spaceBetweenArrows, arrowSize.x}, getRenderer()->getBorderColor());
states.transform.translate({spaceBetweenArrows, 0});
}
}

View File

@ -118,7 +118,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::String TextBox::getText() const
const sf::String& TextBox::getText() const
{
return m_text;
}
@ -853,7 +853,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void TextBox::mouseWheelMoved(int delta, int, int)
void TextBox::mouseWheelMoved(float delta, int, int)
{
if (m_verticalScroll.isShown())
{

View File

@ -73,9 +73,9 @@ install(TARGETS tests
BUNDLE DESTINATION ${INSTALL_MISC_DIR}/tests/ COMPONENT tests)
# Install the tests
install(DIRECTORY "${CMAKE_SOURCE_DIR}/tests/"
DESTINATION "${INSTALL_MISC_DIR}/tests/"
install(DIRECTORY "${CMAKE_SOURCE_DIR}/tests/resources"
DESTINATION "${INSTALL_MISC_DIR}/tests"
COMPONENT tests)
install(FILES "${CMAKE_SOURCE_DIR}/widgets/Black.png" "${CMAKE_SOURCE_DIR}/widgets/Black.txt"
DESTINATION "${INSTALL_MISC_DIR}/tests/resources/"
install(DIRECTORY "${CMAKE_SOURCE_DIR}/widgets/"
DESTINATION "${INSTALL_MISC_DIR}/tests/resources"
COMPONENT tests)

View File

@ -339,6 +339,7 @@ TEST_CASE("[Layouts]") {
REQUIRE(Layout("range(10, 20, 5)").getValue() == 10);
REQUIRE(Layout("range(1, 4, 2, 3)").getValue() == 0);
REQUIRE(Layout("min(5, 3) + range(10, 20, 12) * 2").getValue() == 27);
//REQUIRE(Layout2d("min(8, 2, 5), max(7, 12").getValue() == sf::Vector2f(2, 12)); // TODO
REQUIRE(Layout("1 < 2 ? 5 : 6").getValue() == 5);
REQUIRE(Layout("1 == 2 ? 5 : 6").getValue() == 6);