-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuBar.cpp
More file actions
84 lines (73 loc) · 2.59 KB
/
Copy pathMenuBar.cpp
File metadata and controls
84 lines (73 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// Created by jonng on 5/9/2021.
//
#include "MenuBar.h"
MenuBar::MenuBar() {
is_active = false;
the_bar.setFillColor({66,66,66});
the_bar.setPosition({0,0});
the_bar.setSize({2000.f,30.f});
the_bar.setOutlineThickness(1.f);
the_bar.setOutlineColor(sf::Color::White);
status_message = Menu::NO_STATUS;
}
void MenuBar::addMenu(Menu aMenu) {
addBack(aMenu);
if (head == tail) {
head->data.setPosition({0,0});
}
else {
tail->data.setPosition({tail->prev->data.getButtonGlobalBounds().left + tail->prev->data.getButtonGlobalBounds().width, 0});
}
}
void MenuBar::addEventHandler(sf::RenderWindow& window, sf::Event event) {
is_active = false;
Node<Menu>* activeMenu;
//Checks if any menus are open & also reads statuses
for (Node<Menu>* walker = head; walker != nullptr; walker = walker->next) {
if(walker->data.isExpanded()) {
is_active = true;
activeMenu = walker;
}
if (walker->data.getStatusMessage() < Menu::ACTIVE_STATUS_MESSAGE_COUNT)
status_message = walker->data.getStatusMessage();
}
//Allows switching to a different menu by hovering
for (Node<Menu>* walker = head; walker != nullptr; walker = walker->next) {
//Allows normal selecting and highlighting activity
walker->data.addEventHandler(window, event);
if(is_active && walker != activeMenu && walker->data.getButtonGlobalBounds().contains((sf::Vector2f)sf::Mouse::getPosition(window))) {
activeMenu = walker;
for (Node<Menu>* walker2 = head; walker2 != nullptr; walker2 = walker2->next) {
if(walker2 == activeMenu)
walker2->data.expand();
else
walker2->data.collapse();
}
}
}
}
void MenuBar::draw(RenderTarget& target, RenderStates states) const {
target.draw(the_bar);
for (Node<Menu>* walker = head; walker != nullptr; walker = walker->next) {
target.draw(walker->data);
}
}
void MenuBar::setHeight(float height) {
for (Node<Menu>* walker = head; walker != nullptr; walker = walker->next) {
walker->data.setButtonSize({walker->data.getButtonGlobalBounds().width,height});
}
the_bar.setSize({the_bar.getSize().x,height});
}
void MenuBar::resetStatusMessage() {
status_message = Menu::NO_STATUS;
for (Node<Menu>* walker = head; walker != nullptr; walker = walker->next) {
walker->data.resetStatusMessage();
}
}
Menu::StatusMessage MenuBar::getStatusMessage() {
return status_message;
}
//void MenuBar::update() {
//
//}