Skip to content

Commit 44a8c82

Browse files
committed
Merge changes from SFGUI++ with current master.
2 parents 5f96363 + 4775e91 commit 44a8c82

18 files changed

+1467
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.idea
12
*.a
23
*.o
34
*.os

CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ option( SFGUI_BUILD_EXAMPLES "Build examples."
2020
option( SFGUI_BUILD_DOC "Generate API documentation." OFF)
2121
option( SFGUI_INCLUDE_FONT "Include default font in library (DejaVuSans)." ON)
2222
option( SFML_STATIC_LIBRARIES "Do you want to link SFML statically?" OFF)
23+
option( SFGUI_BOOST_FILESYSTEM_SUPPORT "Do you want SFGUI to support Boost.FileSystem? (enable FilePickerDialog widget)" OFF)
2324

2425

2526
# Find packages.
2627
find_package( OpenGL REQUIRED )
2728
find_package( SFML 2.5 REQUIRED COMPONENTS graphics window system )
2829

30+
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/SFGUI/Config.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/SFGUI/Config.hpp)
31+
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
32+
2933
set( INCLUDE_PATH "${PROJECT_SOURCE_DIR}/include/" )
3034
set( SOURCE_PATH "${PROJECT_SOURCE_DIR}/src/" )
3135

@@ -59,6 +63,11 @@ endif()
5963

6064
target_link_libraries( ${TARGET} PUBLIC sfml-graphics sfml-window sfml-system ${OPENGL_gl_LIBRARY} )
6165

66+
# Link to Boost.FileSystem if enabled
67+
if( SFGUI_BOOST_FILESYSTEM_SUPPORT )
68+
target_link_libraries( sfgui ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} )
69+
endif()
70+
6271
# Tell the compiler to export when necessary.
6372
set_target_properties( ${TARGET} PROPERTIES DEFINE_SYMBOL SFGUI_EXPORTS )
6473

@@ -115,7 +124,7 @@ elseif( APPLE )
115124
IMPORTED_LOCATION "${COREFOUNDATION_LIBRARY}"
116125
INTERFACE_INCLUDE_DIRECTORIES "/System/Library/Frameworks/CoreFoundation.framework/Headers"
117126
)
118-
127+
119128
target_link_libraries( ${TARGET} PUBLIC CoreFoundation )
120129
set( SHARE_PATH "${CMAKE_INSTALL_PREFIX}/share/SFGUI" )
121130
set( LIB_PATH "lib" )
@@ -165,6 +174,11 @@ install(
165174
DESTINATION include
166175
)
167176

177+
install(
178+
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include
179+
DESTINATION .
180+
)
181+
168182
install(
169183
FILES README.md AUTHORS.md LICENSE.md FONT.LICENSE.md CHANGELOG.md
170184
DESTINATION "${SHARE_PATH}"

examples/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ build_example( "ProgressBar" "ProgressBar.cpp" )
3838
build_example( "SpinButton" "SpinButton.cpp" )
3939
build_example( "Canvas" "Canvas.cpp" )
4040
build_example( "CustomWidget" "CustomWidget.cpp" )
41+
build_example( "ListBox" "ListBox.cpp" )
4142
build_example( "SFGUI-Test" "Test.cpp" )
4243

44+
if( SFGUI_BOOST_FILESYSTEM_SUPPORT )
45+
build_example( "FilePickerDialog" "FilePickerDialog.cpp" )
46+
include_directories( SYSTEM ${Boost_INCLUDE_DIR} )
47+
target_link_libraries( FilePickerDialog ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} )
48+
endif()
49+
4350
# Copy data directory to build cache directory to be able to run examples from
4451
# there. Useful for testing stuff.
4552
# Don't try to copy if the directories are the same.
@@ -49,13 +56,13 @@ if( NOT ( "${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}" ) )
4956
COMMAND "${CMAKE_COMMAND}"
5057
ARGS -E copy_directory "${PROJECT_SOURCE_DIR}/examples/data" "${PROJECT_BINARY_DIR}/examples/data"
5158
)
52-
59+
5360
add_custom_command(
5461
TARGET "Image"
5562
COMMAND "${CMAKE_COMMAND}"
5663
ARGS -E copy_directory "${PROJECT_SOURCE_DIR}/examples/data" "${PROJECT_BINARY_DIR}/examples/data"
5764
)
58-
65+
5966
add_custom_command(
6067
TARGET "Canvas"
6168
COMMAND "${CMAKE_COMMAND}"

examples/CustomWidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class MyCustomWidget : public sfg::Widget {
9696
5.f,
9797
inverted_color,
9898
background_color,
99-
20.f
99+
20
100100
)
101101
);
102102

@@ -120,7 +120,7 @@ class MyCustomWidget : public sfg::Widget {
120120
255
121121
),
122122
inner_border_color,
123-
20.f
123+
20
124124
)
125125
);
126126

examples/FilePickerDialog.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Always include the necessary header files.
2+
// Including SFGUI/Widgets.hpp includes everything
3+
// you can possibly need automatically.
4+
#include <SFGUI/SFGUI.hpp>
5+
#include <SFGUI/Widgets.hpp>
6+
7+
#include <SFML/Graphics.hpp>
8+
9+
int main() {
10+
// Create the main SFML window
11+
sf::RenderWindow app_window( sf::VideoMode( 800, 600 ), "SFGUI Window Example", sf::Style::Titlebar | sf::Style::Close );
12+
13+
// We have to do this because we don't use SFML to draw.
14+
app_window.resetGLStates();
15+
16+
// Create an SFGUI. This is required before doing anything with SFGUI.
17+
sfg::SFGUI sfgui;
18+
19+
// Create our main SFGUI window
20+
21+
// Almost everything in SFGUI is handled through smart pointers
22+
// for automatic resource management purposes. You create them
23+
// and they will automatically be destroyed when the time comes.
24+
25+
// Creation of widgets is always done with it's Create() method
26+
// which will return a smart pointer owning the new widget.
27+
auto window = sfg::FilePickerDialog::Create( "/home/victor" );
28+
29+
// Here we can set the window's title bar text.
30+
window->SetTitle( "A really really really really long title" );
31+
32+
window->GetSignal( sfg::FilePickerDialog::OnCancel ).Connect(
33+
[]()
34+
{
35+
std::cout << "Path selection cancelled !" << std::endl;
36+
}
37+
);
38+
window->GetSignal( sfg::FilePickerDialog::OnOk ).Connect(
39+
[window]()
40+
{
41+
std::cout << "Selected path : \"" << window->GetSelectedPath().toAnsiString() << "\"" << std::endl;
42+
}
43+
);
44+
45+
// For more things to set around the window refer to the
46+
// API documentation.
47+
48+
// Start the game loop
49+
while ( app_window.isOpen() ) {
50+
// Process events
51+
sf::Event event;
52+
53+
while ( app_window.pollEvent( event ) ) {
54+
// Every frame we have to send SFML events to the window
55+
// to enable user interactivity. Without doing this your
56+
// GUI is nothing but a big colorful picture ;)
57+
window->HandleEvent( event );
58+
59+
// Close window : exit
60+
if ( event.type == sf::Event::Closed ) {
61+
app_window.close();
62+
}
63+
}
64+
65+
// Update the GUI, note that you shouldn't normally
66+
// pass 0 seconds to the update method.
67+
window->Update( 0.f );
68+
69+
// Clear screen
70+
app_window.clear();
71+
72+
// After drawing the rest of your game, you have to let the GUI
73+
// render itself. If you don't do this you will never be able
74+
// to see it ;)
75+
sfgui.Display( app_window );
76+
77+
// NOTICE
78+
// Because the window doesn't have any children it will shrink to
79+
// it's minimum size of (0,0) resulting in you not seeing anything
80+
// except the title bar text ;) Don't worry, in the Label example
81+
// you'll get to see more.
82+
83+
// Update the window
84+
app_window.display();
85+
}
86+
87+
return EXIT_SUCCESS;
88+
}

examples/ListBox.cpp

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// Always include the necessary header files.
2+
// Including SFGUI/Widgets.hpp includes everything
3+
// you can possibly need automatically.
4+
#include <SFGUI/SFGUI.hpp>
5+
#include <SFGUI/Widgets.hpp>
6+
7+
#include <SFML/Graphics.hpp>
8+
9+
int main() {
10+
sfg::SFGUI sfgui;
11+
sf::RenderWindow window(sf::VideoMode(800, 600), "ListBox Example");
12+
window.setVerticalSyncEnabled(true);
13+
window.setFramerateLimit(30);
14+
15+
sf::Image firstImage;
16+
firstImage.loadFromFile("data/add.png");
17+
18+
sf::Image secondImage;
19+
secondImage.loadFromFile("data/delete.png");
20+
21+
sfg::Desktop desktop;
22+
23+
auto window1 = sfg::Window::Create();
24+
window1->SetTitle( "ListBox with ItemTextPolicy::RESIZE_LISTBOX" );
25+
26+
auto box1 = sfg::Box::Create( sfg::Box::Orientation::VERTICAL );
27+
box1->SetSpacing( 5.f );
28+
box1->PackEnd( sfg::Label::Create( "The minimum width\nof this ListBox\ncorresponds to the largest\nitem's text width." ), false, true );
29+
30+
auto listbox1 = sfg::ListBox::Create();
31+
listbox1->AppendItem( "This is the first item" );
32+
listbox1->AppendItem( "Second item" );
33+
listbox1->AppendItem( "Third item which is a bit large" );
34+
listbox1->AppendItem( "Fourth item" );
35+
listbox1->AppendItem( "Fifth item" );
36+
listbox1->AppendItem( "Sixth item" );
37+
listbox1->AppendItem( "Last one !" );
38+
box1->PackEnd( listbox1 );
39+
listbox1->SetImagesSize(sf::Vector2f(32.f, 32.f));
40+
41+
window1->Add( box1 );
42+
43+
auto window2 = sfg::Window::Create();
44+
window2->SetTitle( "ListBox with ItemTextPolicy::SHRINK" );
45+
46+
auto box2 = sfg::Box::Create( sfg::Box::Orientation::VERTICAL );
47+
box2->SetSpacing( 5.f );
48+
auto label2 = sfg::Label::Create( "The items' texts\nare shrinked if the\nListBox is not big\nenough." );
49+
box2->PackEnd( label2, false, true );
50+
51+
auto listbox2 = sfg::ListBox::Create();
52+
listbox2->AppendItem( "This is the first item (long text)" );
53+
listbox2->AppendItem( "Second item", firstImage );
54+
listbox2->AppendItem( "Third item which is very long !", secondImage );
55+
listbox2->AppendItem( "Fourth item" );
56+
listbox2->AppendItem( "Fifth item" );
57+
listbox2->AppendItem( "Sixth item, again it's too large !" );
58+
listbox2->AppendItem( "Last one !" );
59+
listbox2->SetItemTextPolicy( sfg::ListBox::ItemTextPolicy::SHRINK );
60+
box2->PackEnd( listbox2 );
61+
listbox2->SetImagesSize(sf::Vector2f(32.f, 32.f));
62+
63+
window2->Add( box2 );
64+
65+
auto window3 = sfg::Window::Create();
66+
window3->SetTitle( "ListBox with ItemTextPolicy::SHRINK" );
67+
68+
auto box3 = sfg::Box::Create( sfg::Box::Orientation::VERTICAL );
69+
box3->SetSpacing( 5.f );
70+
auto label3 = sfg::Label::Create( "You can select multiple\nitems in this ListBox." );
71+
box3->PackEnd( label3, false, true );
72+
73+
auto listbox3 = sfg::ListBox::Create();
74+
listbox3->AppendItem( "First item" );
75+
listbox3->AppendItem( "Second item" );
76+
listbox3->AppendItem( "Third item" );
77+
listbox3->AppendItem( "Fourth item" );
78+
listbox3->AppendItem( "Fifth item" );
79+
listbox3->AppendItem( "Sixth item" );
80+
listbox3->AppendItem( "Last one !" );
81+
listbox3->SetSelectionMode( sfg::ListBox::SelectionMode::MULTI_SELECTION );
82+
listbox3->SetSelection( {1, 3, 4, 5} );
83+
box3->PackEnd( listbox3 );
84+
85+
window3->Add( box3 );
86+
87+
desktop.Add( window1 );
88+
desktop.Add( window2 );
89+
desktop.Add( window3 );
90+
91+
sf::Vector2f windowSize( static_cast<float>( window.getSize().x ), static_cast<float>( window.getSize().y ) );
92+
93+
window2->SetPosition(sf::Vector2f(windowSize.x/2.f - window2->GetRequisition().x/2.f, windowSize.y/2.f - window2->GetRequisition().y/2.f));
94+
window3->SetPosition(sf::Vector2f(windowSize.x - window3->GetRequisition().x - 100.f, windowSize.y - window3->GetRequisition().y - 100.f));
95+
96+
sf::Event event;
97+
sf::Clock clock;
98+
99+
window.resetGLStates();
100+
101+
int i = 0;
102+
103+
while (window.isOpen())
104+
{
105+
while (window.pollEvent(event))
106+
{
107+
desktop.HandleEvent( event );
108+
switch(event.type)
109+
{
110+
case sf::Event::Closed:
111+
window.close();
112+
break;
113+
case sf::Event::KeyPressed:
114+
if( event.key.code == sf::Keyboard::R ) {
115+
listbox3->RemoveItem(2);
116+
} else if( event.key.code == sf::Keyboard::I ) {
117+
listbox3->InsertItem(3, "Inserted item #" + std::to_string(i));
118+
++i;
119+
} else if( event.key.code == sf::Keyboard::A) {
120+
listbox3->AppendItem("Appended item #" + std::to_string(i));
121+
++i;
122+
} else if( event.key.code == sf::Keyboard::P) {
123+
listbox3->PrependItem("Prepended item #" + std::to_string(i));
124+
++i;
125+
}
126+
break;
127+
default:
128+
break;
129+
}
130+
}
131+
desktop.Update( clock.restart().asSeconds() );
132+
window.clear();
133+
sfgui.Display( window );
134+
window.display();
135+
}
136+
137+
return 0;
138+
}

include/SFGUI/Config.hpp renamed to include/SFGUI/Config.hpp.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@
3535
#define SFGUI_DEBUG
3636
#include <iostream> // XXX Only for debugging purposes.
3737
#endif
38+
39+
#cmakedefine SFGUI_BOOST_FILESYSTEM_SUPPORT

include/SFGUI/Engine.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Notebook;
4040
class Spinner;
4141
class ComboBox;
4242
class SpinButton;
43+
class ListBox;
4344

4445
class Selector;
4546
class RenderQueue;
@@ -164,6 +165,12 @@ class SFGUI_API Engine {
164165
*/
165166
virtual std::unique_ptr<RenderQueue> CreateSpinButtonDrawable( std::shared_ptr<const SpinButton> spinbutton ) const = 0;
166167

168+
/** Create drawable for listbox widgets.
169+
* @param listbox Widget.
170+
* @return New drawable object (unmanaged memory!).
171+
*/
172+
virtual std::unique_ptr<RenderQueue> CreateListBoxDrawable( std::shared_ptr<const ListBox> listbox ) const = 0;
173+
167174
/** Get maximum line height.
168175
* @param font Font.
169176
* @param font_size Font size.

include/SFGUI/Engines/BREW.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class SFGUI_API BREW : public Engine {
4343
std::unique_ptr<RenderQueue> CreateSpinnerDrawable( std::shared_ptr<const Spinner> spinner ) const override;
4444
std::unique_ptr<RenderQueue> CreateComboBoxDrawable( std::shared_ptr<const ComboBox> combo_box ) const override;
4545
std::unique_ptr<RenderQueue> CreateSpinButtonDrawable( std::shared_ptr<const SpinButton> spinbutton ) const override;
46+
std::unique_ptr<RenderQueue> CreateListBoxDrawable( std::shared_ptr<const ListBox> listbox ) const override;
4647

4748
private:
4849
static std::unique_ptr<RenderQueue> CreateBorder( const sf::FloatRect& rect, float border_width, const sf::Color& light_color, const sf::Color& dark_color );

include/SFGUI/Entry.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class SFGUI_API Entry : public Widget {
8989

9090
// Signals.
9191
static Signal::SignalID OnTextChanged; //!< Fired when the text changes.
92+
static Signal::SignalID OnReturnPressed; //!< Fired when enter is pressed.
9293

9394
protected:
9495
/** Ctor.

0 commit comments

Comments
 (0)