Last active
July 17, 2017 17:45
-
-
Save shibbo/15c454724fa443f3fe01d570ef3030f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "objectrenderer.h" | |
#include "objects/object.h" | |
#include "leveleditor/imagecache.h" | |
#include <QPainter> | |
SpriteRenderer::SpriteRenderer(const Sprite *spr) | |
{ | |
this->spr = spr; | |
switch (spr->getID()) { | |
default: | |
ret = new RoundedRectRenderer(spr, QString("%1").arg(spr->getID()), QColor(0,90,150,150)); | |
break; | |
} | |
} | |
void SpriteRenderer::render(QPainter *painter, QRect *drawrect) | |
{ | |
ret->render(painter, drawrect); | |
} | |
NormalImageRenderer::NormalImageRenderer(const Object *obj, QString filename) | |
{ | |
rect = QRect(obj->getx()+obj->getOffsetX(), obj->gety()+obj->getOffsetY(), obj->getWidth(), obj->getHeight()); | |
this->name = filename; | |
} | |
NormalImageRenderer::NormalImageRenderer(QRect rect, QString filename) | |
{ | |
this->rect = rect; | |
this->name = filename; | |
} | |
void NormalImageRenderer::render(QPainter* painter, QRect *) | |
{ | |
painter->drawPixmap(rect, ImageCache::getInstance()->get(SpriteImg, name)); | |
} | |
RoundedRectRenderer::RoundedRectRenderer(const Object *obj, QString text, QColor color, QTextOption align) | |
{ | |
this->obj = obj; | |
this->text = text; | |
this->color = color; | |
this->align = align; | |
} | |
void RoundedRectRenderer::render(QPainter *painter, QRect *) | |
{ | |
QRect rect(obj->getx()+obj->getOffsetX(), obj->gety()+obj->getOffsetY(), obj->getWidth(), obj->getHeight()); | |
painter->setPen(QColor(0,0,0)); | |
QPainterPath path; | |
path.addRoundedRect(rect, 2.0, 2.0); | |
painter->fillPath(path, color); | |
painter->drawPath(path); | |
painter->setFont(QFont("Arial", 7, QFont::Normal)); | |
painter->drawText(rect, text, align); | |
} | |
CircleRenderer::CircleRenderer(int offsetx, int offsety, int width, int height, QString text, QColor color, QTextOption align) | |
{ | |
this->offsetx = offsetx; | |
this->offsety = offsety; | |
this->width = width; | |
this->height = height; | |
this->text = text; | |
this->color = color; | |
this->align = align; | |
} | |
void CircleRenderer::render(QPainter *painter, QRect *) | |
{ | |
QRect ellipse(offsetx, offsety, width, height); | |
painter->setPen(color); | |
painter->drawEllipse(ellipse); | |
painter->setFont(QFont("Arial", 7, QFont::Normal)); | |
painter->drawText(ellipse, text, align); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef OBJECTRENDERER_H | |
#define OBJECTRENDERER_H | |
#include "objects/object.h" | |
#include <QPainter> | |
class ObjectRenderer | |
{ | |
public: | |
ObjectRenderer() {} | |
ObjectRenderer(Object *) {} | |
virtual ~ObjectRenderer() {} | |
virtual void render(QPainter *, QRect *) {} | |
}; | |
class SpriteRenderer: public ObjectRenderer | |
{ | |
public: | |
SpriteRenderer() {} | |
SpriteRenderer(const Sprite *spr); | |
void render(QPainter *painter, QRect *drawrect); | |
protected: | |
const Sprite *spr; | |
ObjectRenderer *ret; | |
}; | |
class LiquidRenderer: public ObjectRenderer | |
{ | |
public: | |
LiquidRenderer() {} | |
LiquidRenderer(const Sprite *liquid, const Zone *zone); | |
void render(QPainter *painter, QRect *drawrect); | |
protected: | |
const Sprite *liquid; | |
const Zone *zone; | |
QString filename; | |
ObjectRenderer *ret; | |
}; | |
class NormalImageRenderer: public ObjectRenderer | |
{ | |
public: | |
NormalImageRenderer(const Object *obj, QString name); | |
NormalImageRenderer(QRect rect, QString name); | |
void render(QPainter *painter, QRect *drawrect); | |
protected: | |
QRect rect; | |
QString name; | |
}; | |
class RoundedRectRenderer: public ObjectRenderer | |
{ | |
public: | |
RoundedRectRenderer(); | |
RoundedRectRenderer(const Object *obj, QString text, QColor color, QTextOption align = Qt::AlignHCenter | Qt::AlignVCenter); | |
void render(QPainter *painter, QRect *drawrect); | |
protected: | |
const Object *obj; | |
QString text; | |
QColor color; | |
QTextOption align; | |
}; | |
class CircleRenderer: public ObjectRenderer | |
{ | |
public: | |
CircleRenderer(); | |
CircleRenderer(int offsetx, int offsety, int width, int height, QString text, QColor color, QTextOption align = Qt::AlignHCenter | Qt::AlignVCenter); | |
void render(QPainter *painter, QRect *drawellipse); | |
protected: | |
QString text; | |
QTextOption align; | |
QColor color; | |
int width; | |
int height; | |
int offsetx; | |
int offsety; | |
}; | |
#endif // OBJECTRENDERER_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment