feat: add background grid
This commit is contained in:
@@ -9,8 +9,44 @@ NetworkGraphicsScene::NetworkGraphicsScene()
|
||||
{
|
||||
sceneWidth_ = 64000;
|
||||
sceneHeight_ = 64000;
|
||||
gridSize_ = 20;
|
||||
|
||||
setSceneRect(sceneWidth_/-2.0f, sceneHeight_/-2.0f, sceneWidth_, sceneHeight_);
|
||||
|
||||
setBackgroundBrush(QColor("#1b1b1b"));
|
||||
}
|
||||
|
||||
void NetworkGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
QGraphicsScene::drawBackground(painter, rect);
|
||||
|
||||
|
||||
int top = ceil(rect.top());
|
||||
int bottom = floor(rect.bottom());
|
||||
int left = floor(rect.left());
|
||||
int right = ceil(rect.right());
|
||||
|
||||
std::cout << "top: " << top << "\n";
|
||||
std::cout << "bottom: " << bottom << "\n";
|
||||
std::cout << "left: " << left << "\n";
|
||||
std::cout << "right: " << right << "\n";
|
||||
|
||||
QPen gridPen(QColor("#323232"));
|
||||
|
||||
painter->setPen(gridPen);
|
||||
|
||||
QList<QLine> lines;
|
||||
|
||||
for (int y = top - (top % gridSize_); y <= bottom; y += gridSize_) {
|
||||
lines.append(QLine(left, y, right, y));
|
||||
}
|
||||
|
||||
for (int x = left - (left % gridSize_); x <= right; x += gridSize_) {
|
||||
lines.append(QLine(x, bottom, x, top));
|
||||
}
|
||||
|
||||
painter->drawLines(lines);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user