diff --git a/src/plugin/hold/HoldDisplay.cpp b/src/plugin/hold/HoldDisplay.cpp index e1967f1dd..088900a47 100644 --- a/src/plugin/hold/HoldDisplay.cpp +++ b/src/plugin/hold/HoldDisplay.cpp @@ -98,6 +98,19 @@ namespace UKControllerPlugin { this->showHoldInformation = !this->showHoldInformation; } else if (button == "options") { this->dialogManager.OpenDialog(IDD_HOLD_PARAMS, reinterpret_cast(this)); + } else if (button == "prevhold") { + if (this->selectedPublishedHoldIndex == 0) { + return; + } + + this->selectedPublishedHoldIndex--; + } else if (button == "nexthold") { + if (this->publishedHolds.empty() || + this->selectedPublishedHoldIndex == this->publishedHolds.size() - 1) { + return; + } + + this->selectedPublishedHoldIndex++; } } @@ -120,6 +133,11 @@ namespace UKControllerPlugin { } } + unsigned int HoldDisplay::GetPublishedHoldIndex() const + { + return this->selectedPublishedHoldIndex; + } + /* Get the rectangle to render the background of the hold display */ @@ -691,8 +709,37 @@ namespace UKControllerPlugin { } // Display the published hold selection buttons + const HoldingData* hold = *std::next(this->publishedHolds.cbegin(), this->selectedPublishedHoldIndex); + + Gdiplus::Rect buttonRect = {this->windowPos.x + 5, this->titleArea.GetBottom() + 5, 20, 20}; - const HoldingData* hold = *this->publishedHolds.cbegin(); + // Left + graphics.DrawRect(buttonRect, this->sameLevelBoxPen); + graphics.DrawString(L"<", buttonRect, this->dataBrush); + radarScreen.RegisterScreenObject( + screenObjectId, + this->navaid.identifier + "/prevhold", + RECT{buttonRect.GetLeft(), buttonRect.GetTop(), buttonRect.GetRight(), buttonRect.GetBottom()}, + false); + + // Right + buttonRect.X = this->titleArea.GetRight() - 25; + graphics.DrawRect(buttonRect, this->sameLevelBoxPen); + graphics.DrawString(L">", buttonRect, this->dataBrush); + radarScreen.RegisterScreenObject( + screenObjectId, + this->navaid.identifier + "/nexthold", + RECT{buttonRect.GetLeft(), buttonRect.GetTop(), buttonRect.GetRight(), buttonRect.GetBottom()}, + false); + + // Text + buttonRect.X = this->windowPos.x + 30; + buttonRect.Width = this->titleArea.Width - 60; + graphics.DrawString( + L"Hold " + std::to_wstring(this->selectedPublishedHoldIndex + 1) + L" of " + + std::to_wstring(this->publishedHolds.size()), + buttonRect, + this->dataBrush); // Render the data graphics.DrawString(ConvertToTchar(hold->description), dataRect, this->dataBrush); diff --git a/src/plugin/hold/HoldDisplay.h b/src/plugin/hold/HoldDisplay.h index 2e7a72ccd..8fab1d317 100644 --- a/src/plugin/hold/HoldDisplay.h +++ b/src/plugin/hold/HoldDisplay.h @@ -82,6 +82,7 @@ namespace UKControllerPlugin { int GetMinimumLevel(void) const; void SetMaximumLevel(int level); void SetMinimumLevel(int level); + unsigned int GetPublishedHoldIndex() const; std::map, CompareHoldingAircraft>> MapAircraftToLevels( const std::set, CompareHoldingAircraft>& aircraft) const; bool IsInInformationMode(void) const; @@ -206,6 +207,9 @@ namespace UKControllerPlugin { // Should we display the information about the hold bool showHoldInformation = false; + // The currently selected published hold to display in the information tab + unsigned int selectedPublishedHoldIndex = 0; + // Titlebar Gdiplus::Rect titleArea = {0, 0, this->windowWidth, 15}; RECT titleRect = {0, 0, this->windowWidth, 15}; diff --git a/test/plugin/hold/HoldDisplayTest.cpp b/test/plugin/hold/HoldDisplayTest.cpp index 475856de3..a9ad68fd4 100644 --- a/test/plugin/hold/HoldDisplayTest.cpp +++ b/test/plugin/hold/HoldDisplayTest.cpp @@ -212,6 +212,34 @@ namespace UKControllerPluginTest { this->display.SaveDataToAsr(userSetting); } + TEST_F(HoldDisplayTest, ClickingPreviousAndNextHoldChangesSelectedHold) + { + this->publishedHolds.Add({1, "TIMBA", "TIMBA", 2000, 3000}); + this->publishedHolds.Add({2, "TIMBA", "TIMBA", 2000, 3000}); + this->publishedHolds.Add({3, "TIMBA", "TIMBA", 2000, 3000}); + this->publishedHolds.Add({4, "TIMBA", "TIMBA", 2000, 3000}); + + HoldDisplay display2(mockPlugin, holdManager, navaid, publishedHolds, dialogManager, addAircraftList); + + EXPECT_EQ(0, display2.GetPublishedHoldIndex()); + display2.ButtonClicked("nexthold"); + EXPECT_EQ(1, display2.GetPublishedHoldIndex()); + display2.ButtonClicked("nexthold"); + EXPECT_EQ(2, display2.GetPublishedHoldIndex()); + display2.ButtonClicked("nexthold"); + EXPECT_EQ(3, display2.GetPublishedHoldIndex()); + display2.ButtonClicked("nexthold"); + EXPECT_EQ(3, display2.GetPublishedHoldIndex()); + display2.ButtonClicked("prevhold"); + EXPECT_EQ(2, display2.GetPublishedHoldIndex()); + display2.ButtonClicked("prevhold"); + EXPECT_EQ(1, display2.GetPublishedHoldIndex()); + display2.ButtonClicked("prevhold"); + EXPECT_EQ(0, display2.GetPublishedHoldIndex()); + display2.ButtonClicked("prevhold"); + EXPECT_EQ(0, display2.GetPublishedHoldIndex()); + } + TEST_F(HoldDisplayTest, ClickingMinusDescreasesMaximumDisplayLevelUntilMinimum) { EXPECT_EQ(15000, this->display.GetMaximumLevel());