添加了获得公交车在画布中位置的函数

This commit is contained in:
jackfiled 2022-06-27 11:00:00 +08:00
parent 6c9328d783
commit 50aa9d9c6a
2 changed files with 64 additions and 1 deletions

View File

@ -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;
};

View File

@ -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;
}