summaryrefslogtreecommitdiff
path: root/src/outputwindow.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/outputwindow.cc')
-rw-r--r--src/outputwindow.cc30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/outputwindow.cc b/src/outputwindow.cc
index 0f66a0b..faa4432 100644
--- a/src/outputwindow.cc
+++ b/src/outputwindow.cc
@@ -32,8 +32,12 @@
#include <math.h>
+#define SCALE 2
+
OutputWindow::OutputWindow()
{
+ resize(1000, 1000);
+
QPixmap img("gfx/kaiman.png");
//QPixmap img("gfx/arrow.png");
kaiman = img.toImage();
@@ -49,6 +53,11 @@ OutputWindow::OutputWindow()
reset();
}
+void OutputWindow::stopScript()
+{
+ stop = true;
+}
+
void OutputWindow::timeout()
{
/*
@@ -64,12 +73,15 @@ void OutputWindow::paintEvent(QPaintEvent *)
{
// sem.acquire();
QPainter p(this);
+ // QTransform tp; tp.scale(3, 3); p.setTransform(tp);
QTransform t;
t.rotate(-r + 90);
- t.scale(100.0 / kaiman.width(), 100.0 / kaiman.width());
+ t.scale((100.0 / kaiman.width()) * SCALE,
+ (100.0 / kaiman.width()) * SCALE);
QImage img = kaiman.transformed(t, Qt::SmoothTransformation);
- p.drawImage(x - img.width()/2, y - img.height()/2, img);
+ p.drawImage((x * SCALE) - img.width()/2 ,
+ (y * SCALE)- img.height()/2, img);
QPen pen(QColor(255,0,0,100));
pen.setWidth(4);
@@ -82,9 +94,11 @@ void OutputWindow::paintEvent(QPaintEvent *)
void OutputWindow::reset()
{
points.clear();
- x = width() / 2;
- y = height() / 2;
+ x = (width() / 2) / SCALE;
+ y = (height() / 2) / SCALE;
r = 0;
+ stop = false;
+ while(sem.tryAcquire()) {}
}
static inline int sign(int x)
@@ -103,10 +117,11 @@ void OutputWindow::forward(int x)
float source_y = this->y;
for(int i = 0; i < abs(x); i++) {
+ if(stop) return;
float d = (float)i / (float)x * sign(x);
this->x = source_x + target_x * d;
this->y = source_y + target_y * d;
- points.append(QPointF(this->x, this->y));
+ points.append(QPointF(this->x * SCALE, this->y * SCALE));
sem.acquire();
}
}
@@ -114,8 +129,9 @@ void OutputWindow::forward(int x)
void OutputWindow::turn(int x)
{
sem.acquire();
- for(int i = 0; i < abs(x) * 2; i++) {
- this->r += sign(x) * 0.5;
+ for(int i = 0; i < abs(x)/2; i++) {
+ if(stop) return;
+ this->r += sign(x)*2;
sem.acquire();
}
}