/* -*- 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(); } }