krita

kis_boundary_painter.cc

00001 /*
00002  *  Copyright (c) 2005 Bart Coppens <kde@bartcoppens.be>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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     // Horizontal
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     // Vertical
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 
KDE Home | KDE Accessibility Home | Description of Access Keys