File indexing completed on 2024-02-18 04:04:55

0001 /*
0002     SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "sprite.h"
0008 
0009 #include <QGraphicsEffect>
0010 
0011 #include "kbsrenderer.h"
0012 
0013 Sprite::Sprite(KBSRenderer* renderer, const Coord& scale, const QString& name, bool rotated)
0014 : KGameRenderedItem(renderer, name)
0015 , m_scale(scale)
0016 , m_name(name)
0017 , m_rotated(rotated)
0018 {
0019     refresh(renderer);
0020 }
0021 
0022 Sprite::~Sprite()
0023 {
0024 }
0025 
0026 void Sprite::turnGreen()
0027 {
0028     QGraphicsColorizeEffect * fx = new QGraphicsColorizeEffect();
0029     fx->setColor(QColor(Qt::green));
0030     setGraphicsEffect(fx);
0031 }
0032 
0033 void Sprite::turnRed()
0034 {
0035     QGraphicsColorizeEffect * fx = new QGraphicsColorizeEffect();
0036     fx->setColor(QColor(Qt::red));
0037     setGraphicsEffect(fx);
0038 }
0039 
0040 void Sprite::refresh(KBSRenderer* renderer)
0041 {
0042     if (m_rotated)
0043     {
0044         setTransformOriginPoint(renderer->size().width() / 2,
0045                                 renderer->size().height() / 2);
0046         setRotation(90);
0047        
0048         QSize renderSize(renderer->size().height() * m_scale.y,
0049                          renderer->size().width()  * m_scale.x);
0050         setRenderSize(renderSize);
0051     }
0052     else
0053     {
0054         QSize renderSize(renderer->size().width()  * m_scale.x,
0055                          renderer->size().height() * m_scale.y);
0056         setRenderSize(renderSize);   
0057     }
0058 }