MCPcopy Create free account
hub / github.com/Cpasjuste/pplay / Menu

Method Menu

src/menus/menu.cpp:39–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39Menu::Menu(Main *m, const c2d::FloatRect &rect, const std::string &_title,
40 const std::vector<MenuItem> &items, bool left) : RectangleShape(rect) {
41 main = m;
42
43 Menu::setFillColor(COLOR_BG);
44 Menu::setAlpha(245);
45 Menu::setOutlineColor(Color::GrayLight);
46 Menu::setOutlineThickness(main->getScaling().y * 2);
47
48 // highlight
49 highlight = new Highlight({Menu::getSize().x, BUTTON_HEIGHT * main->getScaling().y});
50 highlight->setOrigin(Origin::Left);
51 highlight->setPosition(0, 200 * main->getScaling().y);
52 Menu::add(highlight);
53
54 // title
55 title = new Text(_title, main->getFontSize(Main::FontSize::Big), main->getFont());
56 title->setStyle(Text::Underlined);
57 title->setPosition(main->getScaled(32, 32));
58 title->setFillColor(COLOR_FONT);
59 Menu::add(title);
60
61 // options
62 FloatRect top = {0, 200 * main->getScaling().y,
63 Menu::getSize().x, BUTTON_HEIGHT * main->getScaling().y};
64 FloatRect bottom = {0, Menu::getSize().y - (32 * main->getScaling().y),
65 Menu::getSize().x, BUTTON_HEIGHT * main->getScaling().y};
66
67 for (auto &item: items) {
68 if (item.position == MenuItem::Position::Top) {
69 auto *option = new MenuButton(main, item, top);
70 add(option);
71 buttons.push_back(option);
72 top.top += 64 * main->getScaling().y;
73 } else {
74 auto *option = new MenuButton(main, item, bottom);
75 Menu::add(option);
76 buttons.push_back(option);
77 bottom.top -= 64 * main->getScaling().y;
78 }
79 }
80
81 // tween!
82 if (left) {
83 Menu::add(new TweenPosition({-rect.width, 0}, {0, 0}, 0.2f));
84 } else {
85 Menu::add(new TweenPosition({main->getSize().x, 0},
86 {main->getSize().x - Menu::getSize().x, 0}, 0.2f));
87 }
88}
89
90bool Menu::onInput(c2d::Input::Player *players) {
91 unsigned int keys = players[0].keys;

Callers

nothing calls this directly

Calls 5

getScalingMethod · 0.80
getFontSizeMethod · 0.80
getFontMethod · 0.80
getScaledMethod · 0.80
setFillColorMethod · 0.45

Tested by

no test coverage detected