From 0c836e079745f5329364a6919f6f47403eb7683b Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 17 Aug 2024 12:25:16 +0200 Subject: [PATCH] code review --- client/gui/CIntObject.cpp | 13 +++++++++---- client/gui/CIntObject.h | 1 + client/mainmenu/CHighScoreScreen.h | 2 +- client/mainmenu/CStatisticScreen.cpp | 4 +++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/client/gui/CIntObject.cpp b/client/gui/CIntObject.cpp index 5528363ef..737263d54 100644 --- a/client/gui/CIntObject.cpp +++ b/client/gui/CIntObject.cpp @@ -156,12 +156,17 @@ void CIntObject::setRedrawParent(bool on) } void CIntObject::fitToScreen(int borderWidth, bool propagate) +{ + fitToRect(Rect(Point(0, 0), GH.screenDimensions()), borderWidth, propagate); +} + +void CIntObject::fitToRect(Rect rect, int borderWidth, bool propagate) { Point newPos = pos.topLeft(); - vstd::amax(newPos.x, borderWidth); - vstd::amax(newPos.y, borderWidth); - vstd::amin(newPos.x, GH.screenDimensions().x - borderWidth - pos.w); - vstd::amin(newPos.y, GH.screenDimensions().y - borderWidth - pos.h); + vstd::amax(newPos.x, rect.x + borderWidth); + vstd::amax(newPos.y, rect.y + borderWidth); + vstd::amin(newPos.x, rect.x + rect.w - borderWidth - pos.w); + vstd::amin(newPos.y, rect.y + rect.h - borderWidth - pos.h); if (newPos != pos.topLeft()) moveTo(newPos, propagate); } diff --git a/client/gui/CIntObject.h b/client/gui/CIntObject.h index b6cfd7fd8..da3ebcdc8 100644 --- a/client/gui/CIntObject.h +++ b/client/gui/CIntObject.h @@ -122,6 +122,7 @@ public: const Rect & center(const Point &p, bool propagate = true); //moves object so that point p will be in its center const Rect & center(bool propagate = true); //centers when pos.w and pos.h are set, returns new position void fitToScreen(int borderWidth, bool propagate = true); //moves window to fit into screen + void fitToRect(Rect rect, int borderWidth, bool propagate = true); //moves window to fit into rect void moveBy(const Point &p, bool propagate = true); void moveTo(const Point &p, bool propagate = true);//move this to new position, coordinates are absolute (0,0 is topleft screen corner) diff --git a/client/mainmenu/CHighScoreScreen.h b/client/mainmenu/CHighScoreScreen.h index 9f214ae8c..dbb9aa60c 100644 --- a/client/mainmenu/CHighScoreScreen.h +++ b/client/mainmenu/CHighScoreScreen.h @@ -71,7 +71,7 @@ public: class CHighScoreInputScreen : public CWindowObject { - std::vector> texts; + std::vector> texts; std::shared_ptr input; std::shared_ptr background; std::shared_ptr videoPlayer; diff --git a/client/mainmenu/CStatisticScreen.cpp b/client/mainmenu/CStatisticScreen.cpp index a5a8a7ec1..0cd651404 100644 --- a/client/mainmenu/CStatisticScreen.cpp +++ b/client/mainmenu/CStatisticScreen.cpp @@ -497,6 +497,7 @@ LineChart::LineChart(Rect position, std::string title, TData data, TIcons icons, void LineChart::updateStatusBar(const Point & cursorPosition) { statusBar->moveTo(cursorPosition + Point(-statusBar->pos.w / 2, 20)); + statusBar->fitToRect(pos, 10); Rect r(pos.x + chartArea.x, pos.y + chartArea.y, chartArea.w, chartArea.h); statusBar->setEnabled(r.isInside(cursorPosition)); if(r.isInside(cursorPosition)) @@ -505,7 +506,8 @@ void LineChart::updateStatusBar(const Point & cursorPosition) float y = maxVal - (maxVal / static_cast(chartArea.h)) * (static_cast(cursorPosition.y) - static_cast(r.y)); statusBar->write(CGI->generaltexth->translate("core.genrltxt.64") + ": " + CStatisticScreen::getDay(x) + " " + CGI->generaltexth->translate("vcmi.statisticWindow.value") + ": " + (static_cast(y) > 0 ? std::to_string(static_cast(y)) : std::to_string(y))); } - GH.windows().totalRedraw(); + setRedrawParent(true); + redraw(); } void LineChart::mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance)