Skip to content
Open
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
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ build_example( "SpinButton" "SpinButton.cpp" )
build_example( "Canvas" "Canvas.cpp" )
build_example( "CustomWidget" "CustomWidget.cpp" )
build_example( "ListBox" "ListBox.cpp" )
build_example( "RichText" "RichText.cpp" )
build_example( "SFGUI-Test" "Test.cpp" )

if( SFGUI_BOOST_FILESYSTEM_SUPPORT )
Expand Down
109 changes: 109 additions & 0 deletions examples/RichText.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Always include the necessary header files.
// Including SFGUI/Widgets.hpp includes everything
// you can possibly need automatically.

// Always include the necessary header files.
// Including SFGUI/Widgets.hpp includes everything
// you can possibly need automatically.
#include <SFGUI/SFGUI.hpp>
#include <SFGUI/Widgets.hpp>

#include <SFML/Graphics.hpp>


int main()
{
// Create the main SFML window
sf::RenderWindow app_window(sf::VideoMode(800, 600), "SFGUI RichText Example", sf::Style::Titlebar | sf::Style::Close);

// We have to do this because we don't use SFML to draw.
app_window.resetGLStates();

// Create an SFGUI. This is required before doing anything with SFGUI.
sfg::SFGUI sfgui;

// Create our main SFGUI window
auto window = sfg::Window::Create();
window->SetTitle("Title");

sf::Font font;
// Load it from a file
if (!font.loadFromFile("D:\\Fafa\\Domki\\SFGUI\\SFGUI++\\build\\examples\\Debug\\sansation.ttf"))
{
return -1;
// error...
}

// Create the richtext.
auto richtext = sfg::RichText::Create();
richtext->setFont(font);

// Set the text of the richtext.
*richtext << "Default colors. " << sf::Text::Bold << sf::Color::Cyan << "This "
<< sf::Text::Italic << sf::Color::White << "is\nan\n"
<< sf::Text::Regular << sf::Color::Green << "example" << " going now very long and booooring"
<< sf::Color::White << ".\n"
<< sf::Text::Underlined << "It looks good!\n" << sf::Text::StrikeThrough
<< sfg::Outline{ sf::Color::Blue, 3.f } << "Really good!"
<< sf::Text::Italic << sf::Color::White << "start chatting below...\n";

// Create the ScrolledWindow.
auto scrolledwindow = sfg::ScrolledWindow::Create();
scrolledwindow->SetScrollbarPolicy(sfg::ScrolledWindow::VERTICAL_AUTOMATIC | sfg::ScrolledWindow::HORIZONTAL_AUTOMATIC);
scrolledwindow->AddWithViewport(richtext);
scrolledwindow->SetRequisition(sf::Vector2f(50.f, 50.f));
scrolledwindow->SetStick(sfg::ScrolledWindow::ScrollbarSticking::YES);

// Create label.
auto label = sfg::Label::Create("Type chat and enter:");
label->SetAlignment(sf::Vector2f(0,0));

// Create the Entry for adding text to richtext.
auto entry = sfg::Entry::Create("");
entry->GetSignal(sfg::Entry::OnReturnPressed).Connect([&richtext, &entry] {
*richtext << sf::Text::Bold << sf::Color::Green << "Fafa87:" << sf::Text::Regular << sf::Color::White << entry->GetText() << "\n";
entry->SetText("");
});
entry->SetRequisition(sf::Vector2f(80.f, 20.f));

// Pack both into a box.
auto box = sfg::Box::Create(sfg::Box::Orientation::VERTICAL);
box->SetSpacing(10);
box->Pack(scrolledwindow);
box->Pack(sfg::Separator::Create(), false);
box->Pack(label, false);
box->Pack(entry, false);

window->Add(box);

// Start the game loop
while (app_window.isOpen()) {
// Process events
sf::Event event;

while (app_window.pollEvent(event)) {
// Handle events
window->HandleEvent(event);

// Close window : exit
if (event.type == sf::Event::Closed) {
return EXIT_SUCCESS;
}
}

// Update the GUI, note that you shouldn't normally
// pass 0 seconds to the update method.
window->Update(0.f);

// Clear screen
app_window.clear();

// Draw the GUI
sfgui.Display(app_window);

// Update the window
app_window.display();
}

return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions examples/ScrolledWindowViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ int main() {
// Set the ScrolledWindow to always show the horizontal scrollbar
// and only show the vertical scrollbar when needed.
scrolledwindow->SetScrollbarPolicy( sfg::ScrolledWindow::HORIZONTAL_ALWAYS | sfg::ScrolledWindow::VERTICAL_AUTOMATIC );

// Set sticking ON
scrolledwindow->SetStick(sfg::ScrolledWindow::ScrollbarSticking::YES);

// Add the ScrolledWindow box to the ScrolledWindow
// and create a new viewport automatically.
Expand Down
27 changes: 23 additions & 4 deletions include/SFGUI/Adjustment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ class SFGUI_API Adjustment : public Object, public std::enable_shared_from_this<
* @param minor_step Minor change value (such as clicking on arrow button).
* @param major_step Major change value (such as clicking on the scroll area).
* @param page_size Page size (how many entries are visible / slider size).
* @param stick True if the adjustment should stick to the maximum value.
* @return Adjustment.
*/
static Ptr Create( float value = .0f, float lower = .0f, float upper = .0f, float minor_step = 1.f, float major_step = 5.f, float page_size = .0f );
static Ptr Create( float value = .0f, float lower = .0f, float upper = .0f, float minor_step = 1.f, float major_step = 5.f, float page_size = .0f, bool stick = false );

/** Assignment operator
* @param adjustment Adjustment whose values are to be assigned to this one.
Expand Down Expand Up @@ -65,6 +66,21 @@ class SFGUI_API Adjustment : public Object, public std::enable_shared_from_this<
*/
void SetUpper( float new_upper );

/** Get Adjustment stick setting
* @return Adjustment stick setting
*/
bool GetStick() const;

/** Set Adjustment stick setting
* @param new_stick new stick setting
*/
void SetStick(bool new_stick);

/** Check if value is set to maximum
* @return True is Value at Upper
*/
bool IsAtUpper() const;

/** Get Adjustment minor step
* @return Adjustment minor step
*/
Expand Down Expand Up @@ -102,8 +118,9 @@ class SFGUI_API Adjustment : public Object, public std::enable_shared_from_this<
* @param new_minor_step Minor change value (such as clicking on arrow button).
* @param new_major_step Major change value (such as clicking on the scroll area).
* @param new_page_size Page size (how many entries are visible / slider size).
* @param stick True if the adjustment should stick to the maximum value.
*/
void Configure( float new_value, float new_lower, float new_upper, float new_minor_step, float new_major_step, float new_page_size );
void Configure( float new_value, float new_lower, float new_upper, float new_minor_step, float new_major_step, float new_page_size, bool new_stick);

/** Increment current value
*/
Expand Down Expand Up @@ -132,15 +149,17 @@ class SFGUI_API Adjustment : public Object, public std::enable_shared_from_this<
* @param minor_step Minor change value (such as clicking on arrow button).
* @param major_step Major change value (such as clicking on the scroll area).
* @param page_size Page size (how many entries are visible / slider size).
* @param stick True if the adjustment should stick to the maximum value.
*/
Adjustment( float value, float lower, float upper, float minor_step, float major_step, float page_size );
Adjustment( float value, float lower, float upper, float minor_step, float major_step, float page_size, bool new_stick);

float m_value;
float m_lower;
float m_upper;
float m_minor_step;
float m_major_step;
float m_page_size;
float m_page_size;
float m_stick;
};

}
7 changes: 7 additions & 0 deletions include/SFGUI/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Spinner;
class ComboBox;
class SpinButton;
class ListBox;
class RichText;

class Selector;
class RenderQueue;
Expand Down Expand Up @@ -171,6 +172,12 @@ class SFGUI_API Engine {
*/
virtual std::unique_ptr<RenderQueue> CreateListBoxDrawable( std::shared_ptr<const ListBox> listbox ) const = 0;

/** Create drawable for richtext widgets.
* @param richtext Widget.
* @return New drawable object (unmanaged memory!).
*/
virtual std::unique_ptr<RenderQueue> CreateRichTextDrawable(std::shared_ptr<const RichText> listbox) const = 0;

/** Get maximum line height.
* @param font Font.
* @param font_size Font size.
Expand Down
3 changes: 2 additions & 1 deletion include/SFGUI/Engines/BREW.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class SFGUI_API BREW : public Engine {
std::unique_ptr<RenderQueue> CreateSpinnerDrawable( std::shared_ptr<const Spinner> spinner ) const override;
std::unique_ptr<RenderQueue> CreateComboBoxDrawable( std::shared_ptr<const ComboBox> combo_box ) const override;
std::unique_ptr<RenderQueue> CreateSpinButtonDrawable( std::shared_ptr<const SpinButton> spinbutton ) const override;
std::unique_ptr<RenderQueue> CreateListBoxDrawable( std::shared_ptr<const ListBox> listbox ) const override;
std::unique_ptr<RenderQueue> CreateListBoxDrawable( std::shared_ptr<const ListBox> listbox ) const override;
std::unique_ptr<RenderQueue> CreateRichTextDrawable( std::shared_ptr<const RichText> richtext ) const override;

private:
static std::unique_ptr<RenderQueue> CreateBorder( const sf::FloatRect& rect, float border_width, const sf::Color& light_color, const sf::Color& dark_color );
Expand Down
2 changes: 1 addition & 1 deletion include/SFGUI/ResizableImage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace sfg
if (m_KeepAspect)
{
// Use same scale for both sides of the sprite
float lowerScale = std::min(scaleX, scaleY);
float lowerScale = scaleX < scaleY ? scaleX : scaleY;

tempSprite.scale(lowerScale, lowerScale);

Expand Down
Loading