Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Color Picker Widget #145

Merged
merged 1 commit into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions include/TGUI/Renderers/ColorPickerRenderer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// TGUI - Texus' Graphical User Interface
// Copyright (C) 2012-2020 Bruno Van de Velde (vdv_b@tgui.eu)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


#ifndef TGUI_COLOR_PICKER_RENDERER_HPP
#define TGUI_COLOR_PICKER_RENDERER_HPP


#include <TGUI/Renderers/ChildWindowRenderer.hpp>

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

namespace tgui
{
class TGUI_API ColorPickerRenderer : public ChildWindowRenderer
{
public:

using ChildWindowRenderer::ChildWindowRenderer;


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets the renderer data of the buttons which the color picker uses
///
/// @param rendererData Data about how the buttons should look
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setButton(std::shared_ptr<RendererData> rendererData);


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the renderer data of the buttons which the color picker uses
///
/// @return Data about how the buttons looks
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::shared_ptr<RendererData> getButton() const;


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets the renderer data of the labels which the color picker uses
///
/// @param rendererData Data about how the labels should look
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setLabel(std::shared_ptr<RendererData> rendererData);


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the renderer data of the labels which the color picker uses
///
/// @return Data about how the labels looks
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::shared_ptr<RendererData> getLabel() const;


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets the renderer data of the sliders which the color picker uses
///
/// @param rendererData Data about how the sliders should look
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setSlider(std::shared_ptr<RendererData> rendererData);


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the renderer data of the sliders which the color picker uses
///
/// @return Data about how the sliders looks
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::shared_ptr<RendererData> getSlider() const;


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

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

#endif // TGUI_COLOR_PICKER_RENDERER_HPP
8 changes: 8 additions & 0 deletions include/TGUI/Signal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <TGUI/Global.hpp>
#include <TGUI/Vector2f.hpp>
#include <TGUI/Animation.hpp>
#include <TGUI/Color.hpp>
#include <SFML/System/String.hpp>
#include <type_traits>
#include <functional>
Expand Down Expand Up @@ -93,6 +94,12 @@ namespace tgui
static constexpr const char* const EscapeKeyPressed = "EscapeKeyPressed"; ///< The escape key was pressed while the child window was focused. Optional parameter: pointer to the window
};

struct ColorPicker : public ChildWindow
{
static constexpr const char* const ColorChange = "ColorChanged"; ///< The color was changed. Optional parameter: color chosen
static constexpr const char* const OkPressed = "OkPressed"; ///< The ok key was pressed. Optional parameter: color chosen
};

struct ComboBox : public Widget
{
static constexpr const char* const ItemSelected = "ItemSelected"; ///< An item was selected in the combo box. Optional parameter: selected item or its index
Expand Down Expand Up @@ -458,6 +465,7 @@ namespace tgui
TGUI_SIGNAL_VALUE_DECLARATION(Float, float)
TGUI_SIGNAL_VALUE_DECLARATION(String, const sf::String&)
TGUI_SIGNAL_VALUE_DECLARATION(Vector2f, Vector2f)
TGUI_SIGNAL_VALUE_DECLARATION(Color, Color)


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
11 changes: 10 additions & 1 deletion include/TGUI/SignalImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namespace tgui
return static_cast<std::string>(*static_cast<const sf::String*>(obj));
else if constexpr (std::is_same_v<Type, sf::Vector2f>) // Signal handlers are allowed to have sf::Vector2f parameters while the signal sends tgui::Vector2f
return static_cast<sf::Vector2f>(*static_cast<const Vector2f*>(obj));
else if constexpr (std::is_same_v<Type, sf::Color>) // Signal handlers are allowed to have sf::Color parameters while the signal sends tgui::Color
return static_cast<sf::Color>(*static_cast<const Color*>(obj));
else
return *static_cast<const std::decay_t<Type>*>(obj);
}
Expand All @@ -73,7 +75,14 @@ namespace tgui
return static_cast<sf::Vector2f>(*static_cast<const Vector2f*>(obj));
}

template <typename Type, typename std::enable_if<!std::is_same<Type, std::string>::value && !std::is_same<Type, sf::Vector2f>::value>::type* = nullptr>
template <typename Type, typename std::enable_if<std::is_same<Type, sf::Color>::value>::type* = nullptr>
decltype(auto) dereference(const void* obj)
{
// Signal handlers are allowed to have sf::Vector2f parameters while the signal sends tgui::Vector2f
return static_cast<sf::Color>(*static_cast<const Color*>(obj));
}

template <typename Type, typename std::enable_if<!std::is_same<Type, std::string>::value && !std::is_same<Type, sf::Vector2f>::value && !std::is_same<Type, sf::Color>::value>::type* = nullptr>
decltype(auto) dereference(const void* obj)
{
return *static_cast<const typename std::decay<Type>::type*>(obj);
Expand Down
1 change: 1 addition & 0 deletions include/TGUI/TGUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <TGUI/Widgets/CheckBox.hpp>
#include <TGUI/Widgets/ChildWindow.hpp>
#include <TGUI/Widgets/ClickableWidget.hpp>
#include <TGUI/Widgets/ColorPicker.hpp>
#include <TGUI/Widgets/ComboBox.hpp>
#include <TGUI/Widgets/EditBox.hpp>
#include <TGUI/Widgets/Group.hpp>
Expand Down
Loading