Giter Site home page Giter Site logo

paradoxzero / gamemenu-cpp Goto Github PK

View Code? Open in Web Editor NEW
28.0 4.0 8.0 981 KB

A c++ library based on sfml which can be used to create old school UI menu for sfml based software.

License: MIT License

C++ 76.94% CMake 23.06%
cpp-library beginner-friendly beginner-project graphical-interface

gamemenu-cpp's Introduction

GameMenu

Codacy Badge License: MIT Language (C++) Build Status

This is a C++ library to help create Menu UI for games based of sfml. It provides simple and direct pathways to create Menu, add action to it etc.

How to use?

The main purpose of the library is to make creation of menu's in games easy. This achieves it by dividing the Menu into two parts:

  • UI - Options to display
  • Function - The action to perform

To use the library

  • First Need to decide the menu items, ie the options available (eg Start, Exit, Highscore etc)

  • Create A vector of game_menu::MenuItem. Which contains the title of the item and Action it will perform.

  • Now create a style. gmenu::Style

    • It requires two paramenters ( sf::Font ) to initialize.
    • gmenu::Style can be used to define the look of the menu.
     game_menu::Style style {
         .ItemFont = &font,
         .TitleFont = &font,
         .TitleFontSize = 36,
         .ItemFontSize = 24,
         .MenuTitleScaleFactor = 1,
         .MenuItemScaleFactor = 1.5,
         .ColorScheme = {
           .TitleColor = 0xFFFFFF,
           .ItemColor = 0xFFFFFF,
           .SelectedColor = 0xFF22F1
         },
         .PaddingTitle = {
           .top = 100,
           .left = 0,
         },
         .PaddingItems = {
           .top = 40,
         },
         .TitleAlign = game_menu::Align::Center,
         .ItemAlign = game_menu::Align::Center
       };
  • Now create an context of Menu:

    auto menu_ptr = create_menu_context(w, config);
      std::unique_ptr<game_menu::MENU, decltype(&menu_destroy_context)> menu(menu_ptr, &menu_destroy_context);
  • Now integrate the event handling and render into the event loop -

    while (w.pollEvent(event)) {
			if (event.type == sf::Event::Closed) {
				is_exit_requested = true;
			}
			menu_handle_event(menu.get(), event);
		}
		w.clear();
		menu_render(menu.get());
		w.display();

Dependencies

Installing

Install via cmake's FetchContent script -

FetchContent_Declare(game_menu
    GIT_REPOSITORY https://github.com/ParadoxZero/GameMenu-cpp.git
    GIT_TAG <commit hash>
    GIT_SHALLOW TRUE
)

FetchContent_MakeAvailable(game_menu)

target_link_libraries(mygame PRIVATE game_menu)

Contributions

If you are looking to contribute, then feel free to create a pull request.

Future Possibilities

  • Mouse integration
  • Menu style system. Abiity to alter the menu apearance as per need. (Create a style object with nessary specifications, which will be passed to the Menu)
  • Sound.

gamemenu-cpp's People

Contributors

bendyson avatar codacy-badger avatar paradoxzero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gamemenu-cpp's Issues

Style object to handle the looks of menu

It should include things like:

  • Title color
  • Title Font
  • Item color
  • Item font
  • Size of title and items
  • Relative Location (Choose from Left, right, centre)
  • Background - Color or image.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.