krita
kis_boundary_painter.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <qpixmap.h>
00019 #include <qpainter.h>
00020
00021 #include "kis_boundary.h"
00022 #include "kis_boundary_painter.h"
00023 #include "kis_canvas.h"
00024 #include "kis_canvas_painter.h"
00025
00026 QPixmap KisBoundaryPainter::createPixmap(const KisBoundary& boundary, int w, int h)
00027 {
00028 QPixmap target(w, h);
00029 KisCanvasPainter painter(&target);
00030
00031 painter.eraseRect(0, 0, w, h);
00032
00033 paint(boundary, painter);
00034
00035 painter.end();
00036 return target;
00037 }
00038
00039 void KisBoundaryPainter::paint(const KisBoundary& boundary, KisCanvasPainter& painter)
00040 {
00041 KisBoundary::PointPairListList::const_iterator it = boundary.m_horSegments.constBegin();
00042 KisBoundary::PointPairListList::const_iterator end = boundary.m_horSegments.constEnd();
00043
00044
00045 while (it != end) {
00046 KisBoundary::PointPairList::const_iterator lineIt = (*it).constBegin();
00047 KisBoundary::PointPairList::const_iterator lineEnd = (*it).constEnd();
00048 while (lineIt != lineEnd) {
00049 int x1 = (*lineIt).first.floorX();
00050 int y = (*lineIt).first.floorY();
00051 int x2 = x1 + (*lineIt).second;
00052
00053 painter.drawLine(x1, y, x2, y);
00054 painter.drawPoint(x2, y);
00055
00056 ++lineIt;
00057 }
00058 ++it;
00059 }
00060
00061
00062 it = boundary.m_vertSegments.constBegin();
00063 end = boundary.m_vertSegments.constEnd();
00064
00065 while (it != end) {
00066 KisBoundary::PointPairList::const_iterator lineIt = (*it).constBegin();
00067 KisBoundary::PointPairList::const_iterator lineEnd = (*it).constEnd();
00068 while (lineIt != lineEnd) {
00069 int x = (*lineIt).first.floorX();
00070 int y1 = (*lineIt).first.floorY();
00071 int y2 = y1 + (*lineIt).second;
00072
00073 painter.drawLine(x, y1, x, y2);
00074 painter.drawPoint(x, y2);
00075
00076 ++lineIt;
00077 }
00078 ++it;
00079 }
00080 }
00081
|