18#include <QtCore/qrect.h>
19#include <QtGui/private/qdatabuffer_p.h>
24
25template <
typename InType,
typename OutType,
typename CastType>
class QPolygonClipper
29 buffer1(0), buffer2(0)
31 x1 = y1 = x2 = y2 = 0;
38 void setBoundingRect(
const QRect bounds)
41 x2 = bounds.x() + bounds.width();
43 y2 = bounds.y() + bounds.height();
48 return QRect(QPoint(x1, y1), QPoint(x2, y2));
51 inline OutType intersectLeft(
const OutType &p1,
const OutType &p2)
54 qreal dy = (p1.y - p2.y) / qreal(p1.x - p2.x);
56 t.y =
static_cast<CastType>(p2.y + (x1 - p2.x) * dy);
61 inline OutType intersectRight(
const OutType &p1,
const OutType &p2)
64 qreal dy = (p1.y - p2.y) / qreal(p1.x - p2.x);
66 t.y =
static_cast<CastType>(p2.y + (x2 - p2.x) * dy);
71 inline OutType intersectTop(
const OutType &p1,
const OutType &p2)
74 qreal dx = (p1.x - p2.x) / qreal(p1.y - p2.y);
75 t.x =
static_cast<CastType>(p2.x + (y1 - p2.y) * dx);
81 inline OutType intersectBottom(
const OutType &p1,
const OutType &p2)
84 qreal dx = (p1.x - p2.x) / qreal(p1.y - p2.y);
85 t.x =
static_cast<CastType>(p2.x + (y2 - p2.y) * dx);
91 void clipPolygon(
const InType *inPoints,
int inCount, OutType **outPoints,
int *outCount,
92 bool closePolygon =
true)
105 QDataBuffer<OutType> *source = &buffer1;
106 QDataBuffer<OutType> *clipped = &buffer2;
109 bool doLeft =
false, doRight =
false, doTop =
false, doBottom =
false;
111 for (
int i=0; i<inCount; ++i) {
125 if (doLeft && clipped->size() > 1) {
126 QDataBuffer<OutType> *tmp = source;
132 lastPos = source->size() - 1;
137 if (source->at(0).x >= x1)
138 clipped->add(source->at(0));
140 for (
int i=start; i<inCount; ++i) {
141 const OutType &cpt = source->at(i);
142 const OutType &ppt = source->at(lastPos);
148 clipped->add(intersectLeft(cpt, ppt));
151 }
else if (ppt.x >= x1) {
152 clipped->add(intersectLeft(cpt, ppt));
158 if (doRight && clipped->size() > 1) {
159 QDataBuffer<OutType> *tmp = source;
165 lastPos = source->size() - 1;
170 if (source->at(0).x <= x2)
171 clipped->add(source->at(0));
173 for (
int i=start; i<source->size(); ++i) {
174 const OutType &cpt = source->at(i);
175 const OutType &ppt = source->at(lastPos);
181 clipped->add(intersectRight(cpt, ppt));
184 }
else if (ppt.x <= x2) {
185 clipped->add(intersectRight(cpt, ppt));
193 if (doTop && clipped->size() > 1) {
194 QDataBuffer<OutType> *tmp = source;
200 lastPos = source->size() - 1;
205 if (source->at(0).y >= y1)
206 clipped->add(source->at(0));
208 for (
int i=start; i<source->size(); ++i) {
209 const OutType &cpt = source->at(i);
210 const OutType &ppt = source->at(lastPos);
216 clipped->add(intersectTop(cpt, ppt));
219 }
else if (ppt.y >= y1) {
220 clipped->add(intersectTop(cpt, ppt));
227 if (doBottom && clipped->size() > 1) {
228 QDataBuffer<OutType> *tmp = source;
234 lastPos = source->size() - 1;
239 if (source->at(0).y <= y2)
240 clipped->add(source->at(0));
242 for (
int i=start; i<source->size(); ++i) {
243 const OutType &cpt = source->at(i);
244 const OutType &ppt = source->at(lastPos);
250 clipped->add(intersectBottom(cpt, ppt));
253 }
else if (ppt.y <= y2) {
254 clipped->add(intersectBottom(cpt, ppt));
260 if (closePolygon && clipped->size() > 0) {
262 if (clipped->at(0).x != clipped->at(clipped->size()-1).x ||
263 clipped->at(0).y != clipped->at(clipped->size()-1).y) {
264 OutType ot = clipped->at(0);
268 *outCount = clipped->size();
269 *outPoints = clipped->data();
274 QDataBuffer<OutType> buffer1;
275 QDataBuffer<OutType> buffer2;
void systemStateChanged() override
QPolygonClipper< qt_float_point, qt_float_point, float > polygonClipper
void resetAdaptedOrigin()
void setupAdaptedOrigin(const QPoint &p)
void fillPolygon_translated(const QPointF *points, int pointCount, GCMode gcMode, QPaintEngine::PolygonDrawMode mode)
void clipPolygon_dev(const QPolygonF &poly, QPolygonF *clipped_poly)
bool isCosmeticPen() const
uint adapted_brush_origin
QTransform::TransformationType txop
void strokePolygon_dev(const QPointF *points, int pointCount, bool close)
void decidePathFallback()
const QXcbX11Info * xinfo
void fillPath(const QPainterPath &path, GCMode gcmode, bool transform)
void strokePolygon_translated(const QPointF *points, int pointCount, bool close)
uint has_non_scaling_xform
void fillPolygon_dev(const QPointF *points, int pointCount, GCMode gcMode, QPaintEngine::PolygonDrawMode mode)
friend GC qt_x11_get_pen_gc(QPainter *)
Returns the X11 specific pen GC for the painter p.
void updateState(const QPaintEngineState &state) override
Reimplement this function to update the state of a paint engine.
void drawTextItem(const QPointF &p, const QTextItem &textItem) override
This function draws the text item textItem at position p.
void drawLines(const QLine *lines, int lineCount) override
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool begin(QPaintDevice *pdev) override
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
void updateBrush(const QBrush &brush, const QPointF &pt)
void updateClipRegion_dev(const QRegion ®ion, Qt::ClipOperation op)
void updateFont(const QFont &font)
virtual Drawable handle() const
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.
QX11PaintEngine(QX11PaintEnginePrivate &dptr)
void drawRects(const QRect *rects, int rectCount) override
This is an overloaded member function, provided for convenience. It differs from the above function o...
void updateMatrix(const QTransform &matrix)
Type type() const override
Reimplement this function to return the paint engine \l{Type}.
QPainter::RenderHints supportedRenderHints() const
void updateRenderHints(QPainter::RenderHints hints)
void drawPath(const QPainterPath &path) override
The default implementation ignores the path and does nothing.
void drawPoints(const QPoint *points, int pointCount) override
Draws the first pointCount points in the buffer points.
friend GC qt_x11_get_brush_gc(QPainter *)
Returns the X11 specific brush GC for the painter p.
virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s) override
Reimplement this function to draw the pixmap in the given rect, starting at the given p.
void updatePen(const QPen &pen)
void drawImage(const QRectF &r, const QImage &img, const QRectF &sr, Qt::ImageConversionFlags flags=Qt::AutoColor) override
Reimplement this function to draw the part of the image specified by the sr rectangle in the given re...
bool end() override
Reimplement this function to finish painting on the current paint device.
void drawEllipse(const QRect &r) override
This is an overloaded member function, provided for convenience. It differs from the above function o...
static Display * display()
Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale)
static void setCapStyle(int cap_style, GC gc)
static void x11SetClipRegion(Display *dpy, GC gc, GC gc2, Qt::HANDLE picture, const QRegion &r)
static const qreal aliasedCoordinateDelta
static QPaintEngine::PaintEngineFeatures qt_decide_features()
Q_GUI_EXPORT void qt_x11_drawImage(const QRect &rect, const QPoint &pos, const QImage &image, Drawable hd, GC gc, Display *dpy, Visual *visual, int depth)
static QLine clipStraightLine(const QRect &clip, const QLine &l)
QPixmap qt_toX11Pixmap(const QPixmap &pixmap)
static void x11ClearClipRegion(Display *dpy, GC gc, GC gc2, Qt::HANDLE picture)
static const uchar base_dither_matrix[DITHER_SIZE][DITHER_SIZE]
static const QXcbX11Info * qt_x11Info(const QPaintDevice *pd)
void qt_draw_tile(QPaintEngine *, qreal, qreal, qreal, qreal, const QPixmap &, qreal, qreal)
static QPixmap qt_patternForAlpha(uchar alpha, int screen)
static bool clipLine(QLineF *line, const QRect &rect)
QPixmap qt_pixmapForBrush(int style, bool invert)
int qt_x11SetDefaultScreen(int screen)
QT_BEGIN_NAMESPACE QPainterPath qt_regionToPath(const QRegion ®ion)
void write(QChar *&dest) const
static int size(const HexString< T > &)
static void appendTo(const HexString< T > &str, QChar *&out)