Skip to content

Commit 1a58160

Browse files
committed
Update readme
1 parent de46153 commit 1a58160

File tree

1 file changed

+53
-38
lines changed

1 file changed

+53
-38
lines changed

ReadMe.md

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,55 @@ The main purpose of the library is to make creation of menu's in games easy. Thi
1414
#### To use the library
1515

1616
* First Need to decide the menu items, ie the options available (eg Start, Exit, Highscore etc)
17-
* Create A vector of `gmenu::MenuItem`. Which contains the title of the item and Action it will perform.
18-
19-
The definition of `gmenu::MenuItem` is:
20-
21-
```cpp
22-
struct MenuItem {
23-
std::shared_ptr<Action> action;
24-
std::string title;
25-
};
26-
```
17+
* Create A vector of `game_menu::MenuItem`. Which contains the title of the item and Action it will perform.
2718

28-
Here `gmenu::Action` is an abstract Class that acts as an interface.
29-
The virtual method `bool DerivedAction::start()` will be called by the Menu when that item is selected.
30-
31-
32-
* Now create a style. `gmenu::Style`
19+
* Now create a style. `gmenu::Style`
3320
* It requires two paramenters ( `sf::Font` ) to initialize.
3421
* `gmenu::Style` can be used to define the look of the menu.
3522

3623
```cpp
37-
sf::Font &TitleFont;
38-
sf::Font &ItemFont;
39-
40-
sf::Color TitleColor = sf::Color::Green;;
41-
sf::Color ItemColor = sf::Color::Red ;
42-
sf::Color Selected = sf::Color::Blue;
43-
44-
unsigned int TitleFontSize = 50;
45-
unsigned int ItemFontSize = 20;
46-
47-
float MenuItemScaleFactor = 0.25; // This determines the distance between options.
48-
49-
int layout = Layout::Default; // Bitflag, Defines the layout of menu. eg. Layout::ItemLeft| Layout::TitleCentre
50-
51-
struct {
52-
signed int top, left;
53-
} PaddingTitle, PaddingItems; // this is the padding that will extra displacement that will always be added.
24+
game_menu::Style style {
25+
.ItemFont = &font,
26+
.TitleFont = &font,
27+
.TitleFontSize = 36,
28+
.ItemFontSize = 24,
29+
.MenuTitleScaleFactor = 1,
30+
.MenuItemScaleFactor = 1.5,
31+
.ColorScheme = {
32+
.TitleColor = 0xFFFFFF,
33+
.ItemColor = 0xFFFFFF,
34+
.SelectedColor = 0xFF22F1
35+
},
36+
.PaddingTitle = {
37+
.top = 100,
38+
.left = 0,
39+
},
40+
.PaddingItems = {
41+
.top = 40,
42+
},
43+
.TitleAlign = game_menu::Align::Center,
44+
.ItemAlign = game_menu::Align::Center
45+
};
5446
```
5547
56-
* Now create an object of `gmenuMenu` which require the following parameters:
57-
* `sf::RenderWindow` : Where menu is to be created
58-
* `std::vector<gmenu::MenuItem>` : Vector containing MenuItems.
59-
* `gmenu::Style`: That defines the style.
48+
* Now create an context of `Menu`:
49+
```cpp
50+
auto menu_ptr = create_menu_context(w, config);
51+
std::unique_ptr<game_menu::MENU, decltype(&menu_destroy_context)> menu(menu_ptr, &menu_destroy_context);
52+
```
6053

61-
* Vola, your menu is ready to be used.
54+
* Now integrate the event handling and render into the event loop -
55+
```cpp
56+
while (w.pollEvent(event)) {
57+
if (event.type == sf::Event::Closed) {
58+
is_exit_requested = true;
59+
}
60+
menu_handle_event(menu.get(), event);
61+
}
62+
w.clear();
63+
menu_render(menu.get());
64+
w.display();
65+
```
6266
6367
6468
## [Screenshots!](Screenshots.md)
@@ -67,7 +71,18 @@ The main purpose of the library is to make creation of menu's in games easy. Thi
6771
* [Simple and Fast Multimedia Library](http://www.sfml-dev.org/index.php)
6872
6973
## Installing
70-
> TODO
74+
Install via cmake's FetchContent script -
75+
```cmake
76+
FetchContent_Declare(game_menu
77+
GIT_REPOSITORY https://github.com/ParadoxZero/GameMenu-cpp.git
78+
GIT_TAG <commit hash>
79+
GIT_SHALLOW TRUE
80+
)
81+
82+
FetchContent_MakeAvailable(game_menu)
83+
84+
target_link_libraries(mygame PRIVATE game_menu)
85+
```
7186

7287
## Contributions
7388
If you are looking to contribute, then feel free to create a pull request.

0 commit comments

Comments
 (0)