1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

code review

This commit is contained in:
Laserlicht 2024-08-17 12:25:16 +02:00
parent f7e01eaf67
commit 0c836e0797
4 changed files with 14 additions and 6 deletions

View File

@ -156,12 +156,17 @@ void CIntObject::setRedrawParent(bool on)
} }
void CIntObject::fitToScreen(int borderWidth, bool propagate) 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(); Point newPos = pos.topLeft();
vstd::amax(newPos.x, borderWidth); vstd::amax(newPos.x, rect.x + borderWidth);
vstd::amax(newPos.y, borderWidth); vstd::amax(newPos.y, rect.y + borderWidth);
vstd::amin(newPos.x, GH.screenDimensions().x - borderWidth - pos.w); vstd::amin(newPos.x, rect.x + rect.w - borderWidth - pos.w);
vstd::amin(newPos.y, GH.screenDimensions().y - borderWidth - pos.h); vstd::amin(newPos.y, rect.y + rect.h - borderWidth - pos.h);
if (newPos != pos.topLeft()) if (newPos != pos.topLeft())
moveTo(newPos, propagate); moveTo(newPos, propagate);
} }

View File

@ -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(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 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 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 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) void moveTo(const Point &p, bool propagate = true);//move this to new position, coordinates are absolute (0,0 is topleft screen corner)

View File

@ -71,7 +71,7 @@ public:
class CHighScoreInputScreen : public CWindowObject class CHighScoreInputScreen : public CWindowObject
{ {
std::vector<std::shared_ptr<CIntObject>> texts; std::vector<std::shared_ptr<CLabel>> texts;
std::shared_ptr<CHighScoreInput> input; std::shared_ptr<CHighScoreInput> input;
std::shared_ptr<TransparentFilledRectangle> background; std::shared_ptr<TransparentFilledRectangle> background;
std::shared_ptr<VideoWidgetBase> videoPlayer; std::shared_ptr<VideoWidgetBase> videoPlayer;

View File

@ -497,6 +497,7 @@ LineChart::LineChart(Rect position, std::string title, TData data, TIcons icons,
void LineChart::updateStatusBar(const Point & cursorPosition) void LineChart::updateStatusBar(const Point & cursorPosition)
{ {
statusBar->moveTo(cursorPosition + Point(-statusBar->pos.w / 2, 20)); 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); Rect r(pos.x + chartArea.x, pos.y + chartArea.y, chartArea.w, chartArea.h);
statusBar->setEnabled(r.isInside(cursorPosition)); statusBar->setEnabled(r.isInside(cursorPosition));
if(r.isInside(cursorPosition)) if(r.isInside(cursorPosition))
@ -505,7 +506,8 @@ void LineChart::updateStatusBar(const Point & cursorPosition)
float y = maxVal - (maxVal / static_cast<float>(chartArea.h)) * (static_cast<float>(cursorPosition.y) - static_cast<float>(r.y)); float y = maxVal - (maxVal / static_cast<float>(chartArea.h)) * (static_cast<float>(cursorPosition.y) - static_cast<float>(r.y));
statusBar->write(CGI->generaltexth->translate("core.genrltxt.64") + ": " + CStatisticScreen::getDay(x) + " " + CGI->generaltexth->translate("vcmi.statisticWindow.value") + ": " + (static_cast<int>(y) > 0 ? std::to_string(static_cast<int>(y)) : std::to_string(y))); statusBar->write(CGI->generaltexth->translate("core.genrltxt.64") + ": " + CStatisticScreen::getDay(x) + " " + CGI->generaltexth->translate("vcmi.statisticWindow.value") + ": " + (static_cast<int>(y) > 0 ? std::to_string(static_cast<int>(y)) : std::to_string(y)));
} }
GH.windows().totalRedraw(); setRedrawParent(true);
redraw();
} }
void LineChart::mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) void LineChart::mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance)