chalk

kis_boundary_painter.cpp
1/*
2 * Copyright (c) 2005 Bart Coppens <kde@bartcoppens.be>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18#include <tqpixmap.h>
19#include <tqpainter.h>
20
21#include "kis_boundary.h"
22#include "kis_boundary_painter.h"
23#include "kis_canvas.h"
24#include "kis_canvas_painter.h"
25
26TQPixmap KisBoundaryPainter::createPixmap(const KisBoundary& boundary, int w, int h)
27{
28 TQPixmap target(w, h);
29 KisCanvasPainter painter(&target);
30
31 painter.eraseRect(0, 0, w, h);
32
33 paint(boundary, painter);
34
35 painter.end();
36 return target;
37}
38
39void KisBoundaryPainter::paint(const KisBoundary& boundary, KisCanvasPainter& painter)
40{
41 KisBoundary::PointPairListList::const_iterator it = boundary.m_horSegments.constBegin();
42 KisBoundary::PointPairListList::const_iterator end = boundary.m_horSegments.constEnd();
43
44 // Horizontal
45 while (it != end) {
46 KisBoundary::PointPairList::const_iterator lineIt = (*it).constBegin();
47 KisBoundary::PointPairList::const_iterator lineEnd = (*it).constEnd();
48 while (lineIt != lineEnd) {
49 int x1 = (*lineIt).first.floorX();
50 int y = (*lineIt).first.floorY();
51 int x2 = x1 + (*lineIt).second;
52
53 painter.drawLine(x1, y, x2, y);
54 painter.drawPoint(x2, y);
55
56 ++lineIt;
57 }
58 ++it;
59 }
60
61 // Vertical
62 it = boundary.m_vertSegments.constBegin();
63 end = boundary.m_vertSegments.constEnd();
64
65 while (it != end) {
66 KisBoundary::PointPairList::const_iterator lineIt = (*it).constBegin();
67 KisBoundary::PointPairList::const_iterator lineEnd = (*it).constEnd();
68 while (lineIt != lineEnd) {
69 int x = (*lineIt).first.floorX();
70 int y1 = (*lineIt).first.floorY();
71 int y2 = y1 + (*lineIt).second;
72
73 painter.drawLine(x, y1, x, y2);
74 painter.drawPoint(x, y2);
75
76 ++lineIt;
77 }
78 ++it;
79 }
80}
81
Generates an 'outline' for a paint device.