summaryrefslogtreecommitdiff
path: root/src/outputwindow.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/outputwindow.cc')
-rw-r--r--src/outputwindow.cc121
1 files changed, 81 insertions, 40 deletions
diff --git a/src/outputwindow.cc b/src/outputwindow.cc
index b7b1a51..8c4cb7b 100644
--- a/src/outputwindow.cc
+++ b/src/outputwindow.cc
@@ -48,16 +48,6 @@ OutputWindow::OutputWindow()
reset();
}
-double OutputWindow::coordX()
-{
- return x;
-}
-
-double OutputWindow::coordY()
-{
- return y;
-}
-
void OutputWindow::stopScript()
{
stop = true;
@@ -103,6 +93,50 @@ void OutputWindow::setColour(int r, int g, int b, int a)
sem.acquire();
}
+double OutputWindow::coordX()
+{
+ return x;
+}
+
+double OutputWindow::coordY()
+{
+ return y;
+}
+
+QImage OutputWindow::acquire(bool includePen)
+{
+ double scale = 2.0;
+
+ // Minimum picture size is 32x32
+ double minx = -16;
+ double miny = -16;
+ double maxx = 16;
+ double maxy = 16;
+ for(const auto& line : lines)
+ {
+ maxx = std::max(line.line.p1().x() * scale, maxx);
+ maxx = std::max(line.line.p2().x() * scale, maxx);
+ maxy = std::max(line.line.p1().y() * scale, maxy);
+ maxy = std::max(line.line.p2().y() * scale, maxy);
+
+ minx = std::min(line.line.p1().x() * scale, minx);
+ minx = std::min(line.line.p2().x() * scale, minx);
+ miny = std::min(line.line.p1().y() * scale, miny);
+ miny = std::min(line.line.p2().y() * scale, miny);
+ }
+
+ int border = 100 * scale;
+ int width = maxx - minx + border*2;
+ int height = maxy - miny + border*2;
+
+ QImage img({width, height}, QImage::Format_ARGB32);
+ img.fill(QColor(0,0,0,0));
+ QPainter painter(&img);
+ paint(painter, {-minx + border, -miny + border}, includePen, scale);
+
+ return img;
+}
+
void OutputWindow::timeout()
{
//x++;
@@ -112,12 +146,28 @@ void OutputWindow::timeout()
timer.start(25);
}
+void OutputWindow::reset()
+{
+ speed = 50;
+ penfile = "gfx/kaiman.png";
+ loadpen = true;
+
+ lines.clear();
+ current_points.clear();
+ x = 0;
+ y = 0;
+ r = 0;
+ colour = QColor(150, 0, 0, 150);
+ stop = false;
+ while(sem.tryAcquire())
+ {
+ }
+}
void OutputWindow::wheelEvent(QWheelEvent* event)
{
double delta = event->delta() / 120.0 * scale;
scale += delta / 10.0;
- printf("%f\n", scale);
if(scale < 0.3)
{
scale = 0.3;
@@ -127,8 +177,14 @@ void OutputWindow::wheelEvent(QWheelEvent* event)
void OutputWindow::paintEvent(QPaintEvent *)
{
//sem.acquire();
- QPainter p(this);
+ QPainter painter(this);
+ paint(painter, {width() / 2.0, height() / 2.0}, true, scale);
+ sem.release();
+}
+void OutputWindow::paint(QPainter& p, const QPointF& offset,
+ bool includePen, double scale)
+{
if(loadpen)
{
QPixmap img(penfile);
@@ -136,16 +192,21 @@ void OutputWindow::paintEvent(QPaintEvent *)
loadpen = false;
}
- QTransform t;
- t.rotate(-r + 90);
- t.scale((100.0 / kaiman.width() * scale),
- (100.0 / kaiman.width() * scale) );
- QImage img = kaiman.transformed(t, Qt::SmoothTransformation);
- p.drawImage((x * scale) - img.width()/2 + width() / 2,
- (y * scale) - img.height()/2 + height() / 2, img);
+ if(includePen)
+ {
+ QTransform t;
+ t.rotate(-r + 90);
+ auto m = std::max(kaiman.width(),kaiman.height());
+ t.scale((100.0 / m * scale),
+ (100.0 / m * scale) );
+ QImage img = kaiman.transformed(t, Qt::SmoothTransformation);
+ p.drawImage((x * scale) - img.width()/2 + offset.x(),
+ (y * scale) - img.height()/2 + offset.y(),
+ img);
+ }
QTransform gt;
- gt.translate(width() / 2, height() / 2);
+ gt.translate(offset.x(), offset.y());
gt.scale(scale, scale);
p.setTransform(gt);
@@ -190,26 +251,6 @@ void OutputWindow::paintEvent(QPaintEvent *)
QPointF p2 = current_points[i + 1];
p.drawLine(QLineF(p1, p2));
}
-
- sem.release();
-}
-
-void OutputWindow::reset()
-{
- speed = 50;
- penfile = "gfx/kaiman.png";
- loadpen = true;
-
- lines.clear();
- current_points.clear();
- x = 0;//(width() / 2) / scale;
- y = 0;//(height() / 2) / scale;
- r = 0;
- colour = QColor(150, 0, 0, 150);
- stop = false;
- while(sem.tryAcquire())
- {
- }
}
static inline int sign(int x)