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

Add CMakeLists.txt and Screenshot #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ sfml-widgets-demo
# Code::Blocks
sfml-widgets.layout
sfml-widgets.depend

# CMakeFiles
CMakeFiles/*
CMakeCache.txt
Makefile
cmake_install.cmake
demo_program
34 changes: 34 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.0)
project(sfml-widgets)

###################################################################
# Option Setting
option(ENABLE_DEMO "build demo program.(Default:OFF)" OFF)

###################################################################
# import SFML library
find_package(SFML 2.5.1 COMPONENTS system window graphics)
if (SFML_FOUND)
message(STATUS "SFML_INCLUDE_DIRS: ${SFML_INCLUDE_DIR}")
message(STATUS "SFML_LIBRARIES: ${SFML_LIBRARIES}")
message(STATUS "SFML_VERSION: ${SFML_VERSION}")
endif ()

###################################################################
# Configure general build settings
set(CMAKE_CXX_STANDARD 17)

###################################################################
# Configure build for SFGraphing library
file(GLOB SFML_WIDGETS_SRC src/Gui/*.cpp src/Gui/**/*.cpp)
add_library(sfml-widgets ${SFML_WIDGETS_SRC} )
target_link_libraries(sfml-widgets PUBLIC sfml-graphics sfml-window sfml-system GL)
target_include_directories(sfml-widgets PUBLIC src/)

###################################################################
# Configure build for Sample program
if(ENABLE_DEMO)
file(GLOB DEMO_SRC demo/*.cpp)
add_executable(demo_program ${DEMO_SRC})
target_link_libraries(demo_program sfml-widgets)
endif()
38 changes: 0 additions & 38 deletions Makefile

This file was deleted.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
SFML Widgets
============


![doc/demo_program.png](doc/demo_program.png)

A simple GUI module for SFML.

- Author: Alexandre Bodelot <[email protected]>
Expand Down
46 changes: 29 additions & 17 deletions demo/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ struct Theme

int main()
{
Theme defaultTheme = {
Theme defaultTheme =
{
hex2color("#dddbde"),
"demo/texture-default.png"
"resource/texture-default.png"
};

Theme win98Theme = {
Theme win98Theme =
{
hex2color("#d4d0c8"),
"demo/texture-win98.png"
"resource/texture-win98.png"
};

// Create the main window
Expand All @@ -46,7 +48,7 @@ int main()
gui::Menu menu(app);
menu.setPosition(10, 10);

gui::Theme::loadFont("demo/tahoma.ttf");
gui::Theme::loadFont("resource/tahoma.ttf");
gui::Theme::loadTexture(defaultTheme.texturePath);
gui::Theme::textSize = 11;
gui::Theme::click.textColor = hex2color("#191B18");
Expand All @@ -68,7 +70,8 @@ int main()
// Textbox
gui::TextBox* textbox = new gui::TextBox();
textbox->setText("Hello world!");
textbox->setCallback([&]() {
textbox->setCallback([&]()
{
text.setString(textbox->getText());
text.setOrigin(text.getLocalBounds().width / 2, text.getLocalBounds().height / 2);
});
Expand All @@ -84,15 +87,17 @@ int main()
// Slider for rotation
gui::Slider* sliderRotation = new gui::Slider();
sliderRotation->setStep(1);
sliderRotation->setCallback([&]() {
sliderRotation->setCallback([&]()
{
text.setRotation(sliderRotation->getValue() * 360 / 100.f);
pbar0->setValue(sliderRotation->getValue());
});
form->addRow("Rotation", sliderRotation);

// Slider for scale
gui::Slider* sliderScale = new gui::Slider();
sliderScale->setCallback([&]() {
sliderScale->setCallback([&]()
{
float scale = 1 + sliderScale->getValue() * 2 / 100.f;
text.setScale(scale, scale);
});
Expand All @@ -105,14 +110,16 @@ int main()
opt->addItem("Green", sf::Color::Green);
opt->addItem("Yellow", sf::Color::Yellow);
opt->addItem("White", sf::Color::White);
opt->setCallback([&]() {
opt->setCallback([&]()
{
text.setFillColor(opt->getSelectedValue());
});
form->addRow("Color", opt);

// Checbkox
gui::CheckBox* checkboxBold = new gui::CheckBox();
checkboxBold->setCallback([&]() {
checkboxBold->setCallback([&]()
{
int style = text.getStyle();
if (checkboxBold->isChecked())
style |= sf::Text::Bold;
Expand All @@ -123,7 +130,8 @@ int main()
form->addRow("Bold text", checkboxBold);

gui::CheckBox* checkboxUnderlined = new gui::CheckBox();
checkboxUnderlined->setCallback([&]() {
checkboxUnderlined->setCallback([&]()
{
int style = text.getStyle();
if (checkboxUnderlined->isChecked())
style |= sf::Text::Underlined;
Expand All @@ -139,7 +147,7 @@ int main()

// Custom button
sf::Texture imgbutton;
imgbutton.loadFromFile("demo/themed-button.png");
imgbutton.loadFromFile("resource/themed-button.png");

gui::SpriteButton* customButton = new gui::SpriteButton(imgbutton, "Play");
customButton->setTextSize(20);
Expand All @@ -151,7 +159,8 @@ int main()
gui::OptionsBox<Theme>* themeBox = new gui::OptionsBox<Theme>();
themeBox->addItem("Windows 98", win98Theme);
themeBox->addItem("Default", defaultTheme);
themeBox->setCallback([&]() {
themeBox->setCallback([&]()
{
const Theme& theme = themeBox->getSelectedValue();
gui::Theme::loadTexture(theme.texturePath);
gui::Theme::windowBgColor = theme.backgroundColor;
Expand All @@ -163,7 +172,8 @@ int main()
gui::TextBox* textbox3 = new gui::TextBox(100);
textbox3->setText("Button name");
hbox2->add(textbox3);
hbox2->addButton("Create button", [&]() {
hbox2->addButton("Create button", [&]()
{
vbox->add(new gui::Button(textbox3->getText()));
});

Expand All @@ -174,17 +184,19 @@ int main()
hbox3->add(pbar);

gui::Slider* vslider = new gui::Slider(100, gui::Slider::Vertical);
vslider->setCallback([&]() {
vslider->setCallback([&]()
{
pbar->setValue(vslider->getValue());
});
hbox->add(vslider);

menu.addButton("Quit", [&]() {
menu.addButton("Quit", [&]()
{
app.close();
});

sf::Texture texture;
texture.loadFromFile("demo/sfml.png");
texture.loadFromFile("resource/sfml.png");

sf::Sprite sprite(texture);
sprite.setOrigin(texture.getSize().x / 2, texture.getSize().y / 2);
Expand Down
Binary file added doc/demo_program.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes