From 50aa9d9c6a83a5ee6550c3d56999ed878828c0af Mon Sep 17 00:00:00 2001 From: jackfiled Date: Mon, 27 Jun 2022 11:00:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E8=8E=B7=E5=BE=97?= =?UTF-8?q?=E5=85=AC=E4=BA=A4=E8=BD=A6=E5=9C=A8=E7=94=BB=E5=B8=83=E4=B8=AD?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/mainScene.h | 23 +++++++++++++++++++++++ src/mainScene.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/include/mainScene.h b/include/mainScene.h index 91dff7f..9c7967a 100644 --- a/include/mainScene.h +++ b/include/mainScene.h @@ -8,10 +8,19 @@ #include "QGraphicsScene" #include "QGraphicsPixmapItem" +/** + * 储存每个站点位置的类 + */ class PosPair{ public: + /* + * 站点位置的x坐标 + */ int pos_x; + /** + * 站点位置的y坐标 + */ int pos_y; PosPair(); @@ -21,17 +30,31 @@ public: * @return 站点之间的距离 */ int GetStopSpaceLength(int stop_number) const; + /** * 加上一定的距离 * @param length 需要加上的距离 */ void AddLength(int length); + /** + * 获得该站点公交车停车的位置x坐标 + * @return + */ + int GetBusPosX() const; + + /** + * 获得该站点公交车停车位置的y坐标 + * @return + */ + int GetBusPosY() const; + private: const int stop_begin_x = 100; const int stop_begin_y = 80; const int stop_rail_width = 300; const int stop_rail_height = 200; + const int stop_bus_distance = 20; int distance = 0; }; diff --git a/src/mainScene.cpp b/src/mainScene.cpp index 1dc2a45..8ae36ef 100644 --- a/src/mainScene.cpp +++ b/src/mainScene.cpp @@ -25,7 +25,7 @@ SceneManager::~SceneManager() void SceneManager::SetStopScene(int node_number) { - // 先清除以下屏幕 + // 先清除屏幕 ClearScene(); stop_node_number = node_number; @@ -117,3 +117,43 @@ void PosPair::AddLength(int length) pos_x = stop_begin_x + distance; } } + +int PosPair::GetBusPosX() const +{ + int result; + + if(pos_x <= stop_begin_x) + { + result = stop_begin_x - stop_bus_distance; + } + else if(pos_x >= stop_begin_x + stop_rail_width) + { + result = pos_x + stop_bus_distance; + } + else + { + result = pos_x; + } + + return result; +} + +int PosPair::GetBusPosY() const +{ + int result; + + if(pos_y <= stop_begin_y) + { + result = stop_begin_y - stop_bus_distance; + } + else if(pos_y >= stop_begin_y + stop_rail_width) + { + result = pos_y + stop_bus_distance; + } + else + { + result = pos_y; + } + + return result; +}