diff --git a/.gitignore b/.gitignore index c73eaa7..bfb6228 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..361f17b --- /dev/null +++ b/CMakeLists.txt @@ -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() diff --git a/Makefile b/Makefile deleted file mode 100644 index d2bf1fa..0000000 --- a/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -TARGET := sfml-widgets-demo -SRCDIR := src -SRC := $(shell find $(SRCDIR) -name "*.cpp" -type f) -OBJDIR := obj -OBJ := $(SRC:%.cpp=$(OBJDIR)/%.o) - -CC := g++ -CFLAGS := -I$(SRCDIR) -std=c++11 -pedantic -Wall -Wextra -Wshadow -Wwrite-strings -O2 -LDFLAGS := -lsfml-graphics -lsfml-window -lsfml-system -lGL - -# Demo -$(TARGET): demo/demo.cpp lib/libsfml-widgets.a - @echo "\033[1;33mlinking exec\033[0m $@" - @$(CC) $< $(CFLAGS) -L./lib -lsfml-widgets $(LDFLAGS) -o $@ - @echo "\033[1;32mDone!\033[0m" - -# Static library -lib/libsfml-widgets.a: $(OBJ) - @mkdir -p lib - @echo "\033[1;33mlinking library\033[0m $@" - @ar crvf $@ $(OBJ) - -# Library objects -$(OBJDIR)/%.o: %.cpp - @echo "\033[1;33mcompiling\033[0m $<" - @mkdir -p $(shell dirname $@) - @$(CC) $(CFLAGS) -c $< -o $@ - -clean: - @echo "\033[1;33mremoving\033[0m $(OBJDIR)" - -@rm -r lib - -@rm -r $(OBJDIR) - -mrproper: clean - @echo "\033[1;33mremoving\033[0m $(TARGET)" - -@rm $(TARGET) - -all: mrproper $(TARGET) diff --git a/README.md b/README.md index fd97713..1d1f026 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ SFML Widgets ============ + +![doc/demo_program.png](doc/demo_program.png) + A simple GUI module for SFML. - Author: Alexandre Bodelot diff --git a/demo/demo.cpp b/demo/demo.cpp index 954d92e..bfc8975 100644 --- a/demo/demo.cpp +++ b/demo/demo.cpp @@ -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 @@ -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"); @@ -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); }); @@ -84,7 +87,8 @@ 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()); }); @@ -92,7 +96,8 @@ int main() // 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); }); @@ -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; @@ -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; @@ -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); @@ -151,7 +159,8 @@ int main() gui::OptionsBox* themeBox = new gui::OptionsBox(); 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; @@ -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())); }); @@ -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); diff --git a/doc/demo_program.png b/doc/demo_program.png new file mode 100644 index 0000000..a7b2000 Binary files /dev/null and b/doc/demo_program.png differ diff --git a/demo/sfml.png b/resource/sfml.png similarity index 100% rename from demo/sfml.png rename to resource/sfml.png diff --git a/demo/tahoma.ttf b/resource/tahoma.ttf similarity index 100% rename from demo/tahoma.ttf rename to resource/tahoma.ttf diff --git a/demo/texture-default.png b/resource/texture-default.png similarity index 100% rename from demo/texture-default.png rename to resource/texture-default.png diff --git a/demo/texture-win98.png b/resource/texture-win98.png similarity index 100% rename from demo/texture-win98.png rename to resource/texture-win98.png diff --git a/demo/themed-button.png b/resource/themed-button.png similarity index 100% rename from demo/themed-button.png rename to resource/themed-button.png