Fixed scan-line, changed ui for project

This commit is contained in:
Dawid Pietrykowski 2023-01-15 16:35:45 +01:00
parent 9dc3611bc5
commit 2f5a2a1583
3 changed files with 9 additions and 67 deletions

View File

@ -56,10 +56,6 @@ MyWindow::MyWindow(QWidget *parent) :
poczX = ui->rysujFrame->x(); poczX = ui->rysujFrame->x();
poczY = ui->rysujFrame->y(); poczY = ui->rysujFrame->y();
segment_count = ui->segmentSlider->value();
QString str(("Ilosc segmentow: " + std::to_string(segment_count)).c_str());
ui->segmentLabel->setText(str);
shapes.push_back(Shape()); shapes.push_back(Shape());
// Tworzymy obiekt klasy QImage, o odpowiedniej szerokosci // Tworzymy obiekt klasy QImage, o odpowiedniej szerokosci
@ -89,17 +85,6 @@ void MyWindow::on_exitButton_clicked()
qApp->quit(); qApp->quit();
} }
void MyWindow::on_segmentSlider_valueChanged(int val)
{
segment_count = val;
QString str(("Ilosc segmentow: " + std::to_string(segment_count)).c_str());
ui->segmentLabel->setText(str);
DrawShapes();
update();
}
// Funkcja "odmalowujaca" komponent // Funkcja "odmalowujaca" komponent
void MyWindow::paintEvent(QPaintEvent*) void MyWindow::paintEvent(QPaintEvent*)
{ {
@ -305,9 +290,10 @@ void MyWindow::DrawShapes(){
DrawLine(p1.x, p1.y, p2.x, p2.y, img); DrawLine(p1.x, p1.y, p2.x, p2.y, img);
} }
std::vector<Line> lines; std::vector<Line> lines;
for(int j = 0; j < (int)shapes[i].points.size() - 1; j++){ int points_n = (int)shapes[i].points.size();
for(int j = 0; j < points_n; j++){
Point p1 = shapes[i].points[j]; Point p1 = shapes[i].points[j];
Point p2 = shapes[i].points[j+1]; Point p2 = j == points_n - 1 ? shapes[i].points[0] : shapes[i].points[j+1];
lines.push_back(Line(p1, p2)); lines.push_back(Line(p1, p2));
} }
for(int y = 0; y < wys; y++){ for(int y = 0; y < wys; y++){
@ -325,9 +311,7 @@ std::vector<int> MyWindow::GetIntersectionsWithY(int y, std::vector<Line> lines)
Line l = lines[i]; Line l = lines[i];
if(l.A.x < l.B.x) if(l.A.x < l.B.x)
std::swap(l.A, l.B); std::swap(l.A, l.B);
// if(l.A.x < l.B.x) if((l.A.y <= y && l.B.y > y) || (l.A.y > y && l.B.y <= y)){
// std::swap(l.A, l.B);
if((l.A.y < y && l.B.y > y) || (l.A.y > y && l.B.y < y)){
float d1 = (y - l.A.y); float d1 = (y - l.A.y);
float d2 = (l.B.y - l.A.y); float d2 = (l.B.y - l.A.y);
float dx = (l.B.x - l.A.x); float dx = (l.B.x - l.A.x);
@ -336,7 +320,7 @@ std::vector<int> MyWindow::GetIntersectionsWithY(int y, std::vector<Line> lines)
res.push_back(x); res.push_back(x);
} }
} }
std::sort(res.begin(), res.end(), std::greater<int>()); std::sort(res.begin(), res.end(), std::less<int>());
return res; return res;
} }

View File

@ -155,7 +155,6 @@ private:
private slots: private slots:
void on_cleanButton_clicked(); void on_cleanButton_clicked();
void on_exitButton_clicked(); void on_exitButton_clicked();
void on_segmentSlider_valueChanged(int val);
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
void paintEvent(QPaintEvent*); void paintEvent(QPaintEvent*);

View File

@ -42,7 +42,7 @@
<x>630</x> <x>630</x>
<y>10</y> <y>10</y>
<width>241</width> <width>241</width>
<height>331</height> <height>211</height>
</rect> </rect>
</property> </property>
<property name="title"> <property name="title">
@ -74,60 +74,19 @@
<string>Wyjście</string> <string>Wyjście</string>
</property> </property>
</widget> </widget>
<widget class="QSlider" name="segmentSlider">
<property name="geometry">
<rect>
<x>10</x>
<y>150</y>
<width>221</width>
<height>20</height>
</rect>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>10</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksAbove</enum>
</property>
<property name="tickInterval">
<number>10</number>
</property>
</widget>
<widget class="QLabel" name="segmentLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>131</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>10</x>
<y>186</y> <y>100</y>
<width>221</width> <width>221</width>
<height>131</height> <height>101</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>Naciśnij lewy przycisk myszy by utworzyć punkt. <string>Naciśnij lewy przycisk myszy by utworzyć punkt.
Przytrzymaj lewy przycisk myszy przy punkcie by go przesunąć. Przytrzymaj lewy przycisk myszy przy punkcie by go przesunąć.
Naciśnij prawy przycisk myszy przy punkcie by go usunąć</string> Naciśnij na pierwszy punkt figury aby ją zamknąć</string>
</property> </property>
<property name="textFormat"> <property name="textFormat">
<enum>Qt::PlainText</enum> <enum>Qt::PlainText</enum>