Skip to content

Commit

Permalink
training guide: make coordinates relative to img
Browse files Browse the repository at this point in the history
old-commit-hash: 9896438
  • Loading branch information
Comma Device committed Mar 29, 2021
1 parent 99b3111 commit 3766830
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
21 changes: 11 additions & 10 deletions selfdrive/ui/qt/offroad/onboarding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@


void TrainingGuide::mouseReleaseEvent(QMouseEvent *e) {
//qDebug() << e->x() << ", " << e->y();
QPoint touch = QPoint(e->x(), e->y()) - imageCorner;
//qDebug() << touch.x() << ", " << touch.y();

// Check for restart
if (currentIndex == (boundingBox.size() - 1) && 200 <= e->x() && e->x() <= 920 &&
760 <= e->y() && e->y() <= 960) {
if (currentIndex == (boundingBox.size() - 1) && 200 <= touch.x() && touch.x() <= 920 &&
760 <= touch.y() && touch.y() <= 960) {
currentIndex = 0;
} else if (boundingBox[currentIndex][0] <= e->x() && e->x() <= boundingBox[currentIndex][1] &&
boundingBox[currentIndex][2] <= e->y() && e->y() <= boundingBox[currentIndex][3]) {
} else if (boundingBox[currentIndex][0] <= touch.x() && touch.x() <= boundingBox[currentIndex][1] &&
boundingBox[currentIndex][2] <= touch.y() && touch.y() <= boundingBox[currentIndex][3]) {
currentIndex += 1;
}

Expand All @@ -39,17 +40,17 @@ void TrainingGuide::showEvent(QShowEvent *event) {
void TrainingGuide::paintEvent(QPaintEvent *event) {
QPainter painter(this);

QRect devRect(0, 0, painter.device()->width(), painter.device()->height());
QBrush bgBrush("#072339");
painter.fillRect(devRect, bgBrush);
QRect bg(0, 0, painter.device()->width(), painter.device()->height());
QBrush bgBrush("#000000");
painter.fillRect(bg, bgBrush);

QRect rect(image.rect());
rect.moveCenter(devRect.center());
rect.moveCenter(bg.center());
painter.drawImage(rect.topLeft(), image);
imageCorner = rect.topLeft();
}

TermsPage::TermsPage(QWidget *parent) : QFrame(parent){

QVBoxLayout *main_layout = new QVBoxLayout;
main_layout->setMargin(40);
main_layout->setSpacing(40);
Expand Down
1 change: 1 addition & 0 deletions selfdrive/ui/qt/offroad/onboarding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TrainingGuide : public QFrame {

private:
QImage image;
QPoint imageCorner;
int currentIndex = 0;

// Bounding boxes for the a given training guide step
Expand Down

0 comments on commit 3766830

Please sign in to comment.