103 lines
2.4 KiB
C++
103 lines
2.4 KiB
C++
#ifndef PAINTER_H
|
|
#define PAINTER_H
|
|
|
|
#include <QPainter>
|
|
|
|
#include <Indoor/geo/Point2.h>
|
|
#include <Indoor/geo/Point3.h>
|
|
|
|
#include "Scaler.h"
|
|
|
|
class Painter {
|
|
|
|
public:
|
|
|
|
Scaler& s;
|
|
QPainter* p;
|
|
int w;
|
|
int h;
|
|
|
|
public:
|
|
|
|
/** ctor */
|
|
Painter(Scaler& s, QPainter* p, int w, int h) : s(s), p(p), w(w), h(h) {
|
|
p->setPen(Qt::black);
|
|
p->setBrush(Qt::NoBrush);
|
|
}
|
|
|
|
int width() {return w;}
|
|
|
|
int height() {return h;}
|
|
|
|
void drawLine(const Point2 p1, const Point2 p2) {
|
|
p->drawLine(s.xms(p1.x), s.yms(p1.y), s.xms(p2.x), s.yms(p2.y));
|
|
}
|
|
void drawLine(const Point3 p1, const Point3 p2) {
|
|
p->drawLine(s.xms(p1.x), s.yms(p1.y), s.xms(p2.x), s.yms(p2.y));
|
|
}
|
|
|
|
void drawCircle(const Point3 center) {
|
|
int r = 5;
|
|
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
|
|
}
|
|
|
|
void drawCircle(const Point2 center) {
|
|
int r = 5;
|
|
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
|
|
}
|
|
|
|
void drawCircle(const Point2 center, const float size_m) {
|
|
int r = s.ms(size_m);
|
|
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
|
|
}
|
|
|
|
void drawLine(const float x1, const float y1, const float x2, const float y2) {
|
|
p->drawLine(s.xms(x1), s.yms(y1), s.xms(x2), s.yms(y2));
|
|
}
|
|
|
|
void drawRect(const float x1, const float y1, const float x2, const float y2) {
|
|
float w = x2-x1;
|
|
float h = y1-y2;
|
|
p->drawRect(s.xms(x1), s.yms(y1), s.ms(w), s.ms(h));
|
|
}
|
|
|
|
void drawText(const Point2 pos, const std::string& text) {
|
|
p->drawText(s.xms(pos.x), s.xms(pos.y), text.c_str());
|
|
}
|
|
|
|
void drawPolygon(const std::vector<Point2>& points) {
|
|
std::vector<QPointF> vec;
|
|
for (const Point2 p : points) {
|
|
vec.push_back(QPointF(s.xms(p.x), s.yms(p.y)));
|
|
}
|
|
p->drawPolygon(vec.data(), vec.size());
|
|
}
|
|
void drawPolygon(const std::vector<Point3>& points) {
|
|
std::vector<QPointF> vec;
|
|
for (const Point3 p : points) {
|
|
vec.push_back(QPointF(s.xms(p.x), s.yms(p.y)));
|
|
}
|
|
p->drawPolygon(vec.data(), vec.size());
|
|
}
|
|
|
|
void setBrush(const QBrush& brush) { p->setBrush(brush); }
|
|
void setBrush(const Qt::BrushStyle& brush) { p->setBrush(brush); }
|
|
|
|
void setPen(const QPen& pen) {p->setPen(pen); }
|
|
void setPen(const QColor& pen) {p->setPen(pen); }
|
|
void setPen(const Qt::PenStyle& pen) {p->setPen(pen); }
|
|
|
|
|
|
|
|
template <typename Pen, typename Brush> void setPenBrush(const Pen& pen, const Brush& brush) {setPen(pen); setBrush(brush);}
|
|
|
|
const Scaler& getScaler() {return s;}
|
|
|
|
private:
|
|
|
|
|
|
|
|
};
|
|
|
|
#endif // PAINTER_H
|