33#include < vector>
44#include < iostream>
55#include < string>
6+ #include < map>
7+
8+ inline constexpr float SMALL = 30 .0f ;
9+ inline constexpr float MEDIUM = 50 .0f ;
10+ inline constexpr float LARGE = 70 .0f ;
611
712const float margin = 10 .0f ;
813float topButtons;
914
15+ static const std::map<RadiusSize, float > RadiusValues = {
16+ {RadiusSize::Small, SMALL},
17+ {RadiusSize::Medium, MEDIUM},
18+ {RadiusSize::Large, LARGE}
19+ };
20+
21+ static RadiusSize labelToRadiusEnum (const std::string& label) {
22+ if (label == " S" ) return RadiusSize::Small;
23+ if (label == " M" ) return RadiusSize::Medium;
24+ if (label == " L" ) return RadiusSize::Large;
25+ return RadiusSize::None;
26+ }
27+
1028Sidebar::Sidebar (int screenHeight) :
1129 x(0 ),
1230 width(250 ),
@@ -37,6 +55,10 @@ Sidebar::Sidebar(int screenHeight) :
3755 for (int i = 0 ; i < radiusLabels.size (); ++i) {
3856 float buttonX = baseX + i * (buttonWidth + margin);
3957 radiuses.emplace_back (Rectangle{buttonX, radiusY, buttonWidth, buttonHeight}, radiusLabels[i]);
58+ if (radiusLabels[i] == " M" ) {
59+ // default value
60+ radiuses[i].isClicked = true ;
61+ }
4062 }
4163
4264 yOffset += buttonHeight + margin;
@@ -51,7 +73,7 @@ void Sidebar::draw() {
5173 DrawRectangleRoundedLinesEx (temp, 0 .2f , 1 , 5 , DARKGRAY);
5274
5375 for (const auto & button : buttons) {
54- DrawRectangleRec (button.domain , LIGHTGRAY);
76+ DrawRectangleRec (button.domain , isButtonClicked (button. getButtonLabel ()) ? GREEN : LIGHTGRAY);
5577 DrawRectangleLinesEx (button.domain , 2 , DARKGRAY);
5678 int textWidth = MeasureText (button.label .c_str (), 18 );
5779 DrawText (button.label .c_str (),
@@ -63,41 +85,47 @@ void Sidebar::draw() {
6385 DrawLineEx ({x + 3 * margin, topButtons + margin}, {(float )width - margin - margin / 2 , topButtons + margin}, 5 .0f , DARKGRAY);
6486
6587 for (const auto & button : radiuses) {
66- DrawRectangleRec (button.domain , LIGHTGRAY);
88+ DrawRectangleRec (button.domain , isButtonClicked (button. getButtonLabel ()) ? GREEN : LIGHTGRAY);
6789 DrawRectangleLinesEx (button.domain , 2 , DARKGRAY);
6890 int textWidth = MeasureText (button.label .c_str (), 18 );
6991 DrawText (button.label .c_str (),
7092 button.domain .x + (button.domain .width - textWidth) / 2 ,
7193 button.domain .y + (button.domain .height - 18 ) / 2 ,
7294 18 , BLACK);
73- }
95+ }
7496}
7597
7698void Sidebar::handleMouse (Vector2 mousePosition) {
7799 if (mousePosition.x > width || mousePosition.y > height) {
78100 return ;
79101 }
80102
81- for (auto & button : buttons) {
82- button.isClicked = false ;
83- }
84-
85103 for (auto & button : buttons) {
86104 const Rectangle& rect = button.domain ;
87- button.isClicked = false ;
88- if (mousePosition.x > rect.x && mousePosition.x < rect.x + rect.width &&
89- mousePosition.y > rect.y && mousePosition.y < rect.y + rect.height ) {
105+
106+ if (button.getButtonLabel () != " Weighted" ) {
107+ button.isClicked = false ;
108+ }
109+
110+ if (CheckCollisionPointRec (mousePosition, rect)) {
90111 std::cout << " Is In Domain of " << button.label << ' \n ' ;
91112 button.isClicked = true ;
113+ return ;
92114 }
93- }
115+ }
94116
95117 for (auto & button : radiuses) {
96118 const Rectangle& rect = button.domain ;
97- if (mousePosition. x > rect. x && mousePosition. x < rect. x + rect. width &&
98- mousePosition. y > rect. y && mousePosition. y < rect. y + rect. height ) {
119+ button. isClicked = false ;
120+ if ( CheckCollisionPointRec ( mousePosition, rect) ) {
99121 std::cout << " Is In Domain of " << button.label << ' \n ' ;
122+
123+ for (auto & b : radiuses) {
124+ b.isClicked = false ;
125+ }
126+
100127 button.isClicked = true ;
128+ return ;
101129 }
102130 }
103131}
@@ -125,8 +153,29 @@ bool Sidebar::isButtonClicked(const std::string& label) {
125153 return false ;
126154}
127155
156+ RadiusSize Sidebar::getSelectedRadiusSize () const {
157+ for (const auto & button : radiuses) {
158+ if (button.isClicked ) {
159+ return labelToRadiusEnum (button.getButtonLabel ());
160+ }
161+ }
162+
163+ return RadiusSize::None;
164+ }
165+
166+ float Sidebar::getSelectedRadius () const {
167+ RadiusSize selected = getSelectedRadiusSize ();
168+ auto it = RadiusValues.find (selected);
169+ return (it != RadiusValues.end () ? it->second : 0 .0f );
170+ }
171+
128172void Sidebar::resetClicks () {
129173 for (auto & button : radiuses) {
174+ if (button.getButtonLabel () == " M" ) {
175+ button.isClicked = true ;
176+ continue ;
177+ }
178+
130179 button.isClicked = false ;
131180 }
132181
0 commit comments