From dcecacbf52121d6f8adf076d2cebaeec1e141339 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 23 Aug 2012 20:23:19 +0200 Subject: Implement automatic reset/reload when script file changes on disc. --- src/outputwindow.cc | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src/outputwindow.cc') 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 +#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(); } } -- cgit v1.2.3