From b8195d45820378e3d09225d9a291c4951816276d Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 4 Aug 2012 20:41:18 +0200 Subject: Initial import. --- src/outputwindow.cc | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 src/outputwindow.cc (limited to 'src/outputwindow.cc') diff --git a/src/outputwindow.cc b/src/outputwindow.cc new file mode 100644 index 0000000..0f66a0b --- /dev/null +++ b/src/outputwindow.cc @@ -0,0 +1,121 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * outputwindow.cc + * + * Sat Aug 4 13:44:41 CEST 2012 + * Copyright 2012 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Kaiman. + * + * Kaiman is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Kaiman is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Kaiman; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "outputwindow.h" + +#include +#include + +#include + +OutputWindow::OutputWindow() +{ + QPixmap img("gfx/kaiman.png"); + //QPixmap img("gfx/arrow.png"); + kaiman = img.toImage(); + /* + QTransform t; + t.scale(0.2, 0.2); + kaiman = kaiman.transformed(t, Qt::SmoothTransformation); + */ + connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); + timer.setSingleShot(true); + timer.start(25); + + reset(); +} + +void OutputWindow::timeout() +{ + /* + x++; + y++; + r++; + */ + repaint(); + timer.start(25); +} + +void OutputWindow::paintEvent(QPaintEvent *) +{ + // sem.acquire(); + QPainter p(this); + + QTransform t; + t.rotate(-r + 90); + t.scale(100.0 / kaiman.width(), 100.0 / kaiman.width()); + QImage img = kaiman.transformed(t, Qt::SmoothTransformation); + p.drawImage(x - img.width()/2, y - img.height()/2, img); + + QPen pen(QColor(255,0,0,100)); + pen.setWidth(4); + p.setPen(pen); + p.drawLines(points); + + sem.release(); +} + +void OutputWindow::reset() +{ + points.clear(); + x = width() / 2; + y = height() / 2; + r = 0; +} + +static inline int sign(int x) +{ + if(x > 0) return 1; + return -1; +} + +void OutputWindow::forward(int x) +{ + sem.acquire(); + float target_x = sin(r * (M_PI / 180.0)) * x; + float target_y = cos(r * (M_PI / 180.0)) * x; + + float source_x = this->x; + float source_y = this->y; + + for(int i = 0; i < abs(x); i++) { + 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)); + sem.acquire(); + } +} + +void OutputWindow::turn(int x) +{ + sem.acquire(); + for(int i = 0; i < abs(x) * 2; i++) { + this->r += sign(x) * 0.5; + sem.acquire(); + } +} -- cgit v1.2.3