Changeset View
Changeset View
Standalone View
Standalone View
pixmapfx/kpPixmapFX_DrawShapes.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | #include "imagelib/kpColor.h" | 44 | #include "imagelib/kpColor.h" | ||
45 | #include "kpDefs.h" | 45 | #include "kpDefs.h" | ||
46 | 46 | | |||
47 | //--------------------------------------------------------------------- | 47 | //--------------------------------------------------------------------- | ||
48 | 48 | | |||
49 | // Returns whether there is only 1 distinct point in <points>. | 49 | // Returns whether there is only 1 distinct point in <points>. | ||
50 | bool kpPixmapFX::Only1PixelInPointArray (const QPolygon &points) | 50 | bool kpPixmapFX::Only1PixelInPointArray (const QPolygon &points) | ||
51 | { | 51 | { | ||
52 | if (points.count () == 0) | 52 | if (points.count () == 0) { | ||
53 | return false; | 53 | return false; | ||
54 | } | ||||
54 | 55 | | |||
55 | for (int i = 1; i < static_cast<int> (points.count ()); i++) | 56 | for (int i = 1; i < static_cast<int> (points.count ()); i++) | ||
56 | { | 57 | { | ||
57 | if (points [i] != points [0]) | 58 | if (points [i] != points [0]) { | ||
58 | return false; | 59 | return false; | ||
59 | } | 60 | } | ||
61 | } | ||||
60 | 62 | | |||
61 | return true; | 63 | return true; | ||
62 | } | 64 | } | ||
63 | 65 | | |||
64 | //--------------------------------------------------------------------- | 66 | //--------------------------------------------------------------------- | ||
65 | 67 | | |||
66 | // Warp the given <width> from 1 to 0. | 68 | // Warp the given <width> from 1 to 0. | ||
67 | // This is not always done (specifically if <drawingEllipse>) because | 69 | // This is not always done (specifically if <drawingEllipse>) because | ||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Line(s) | 180 | void kpPixmapFX::drawPolygon (QImage *image, | |||
183 | const kpColor &fStippleColor) | 185 | const kpColor &fStippleColor) | ||
184 | { | 186 | { | ||
185 | QPainter p(image); | 187 | QPainter p(image); | ||
186 | 188 | | |||
187 | ::QPainterSetPenWithStipple (&p, | 189 | ::QPainterSetPenWithStipple (&p, | ||
188 | fcolor, penWidth, | 190 | fcolor, penWidth, | ||
189 | fStippleColor); | 191 | fStippleColor); | ||
190 | 192 | | |||
191 | if (bcolor.isValid ()) | 193 | if (bcolor.isValid ()) { | ||
192 | p.setBrush (QBrush (bcolor.toQColor())); | 194 | p.setBrush (QBrush (bcolor.toQColor())); | ||
195 | } | ||||
193 | // HACK: seems to be needed if set_Pen_(Qt::color0) else fills with Qt::color0. | 196 | // HACK: seems to be needed if set_Pen_(Qt::color0) else fills with Qt::color0. | ||
194 | else | 197 | else { | ||
195 | p.setBrush (Qt::NoBrush); | 198 | p.setBrush (Qt::NoBrush); | ||
199 | } | ||||
196 | 200 | | |||
197 | // Qt bug: single point doesn't show up depending on penWidth. | 201 | // Qt bug: single point doesn't show up depending on penWidth. | ||
198 | if (Only1PixelInPointArray (points)) | 202 | if (Only1PixelInPointArray (points)) | ||
199 | { | 203 | { | ||
200 | qCDebug(kpLogPixmapfx) << "\tinvoking single point hack"; | 204 | qCDebug(kpLogPixmapfx) << "\tinvoking single point hack"; | ||
201 | p.drawPoint(points [0]); | 205 | p.drawPoint(points [0]); | ||
202 | return; | 206 | return; | ||
203 | } | 207 | } | ||
204 | 208 | | |||
205 | // TODO: why aren't the ends rounded? | 209 | // TODO: why aren't the ends rounded? | ||
206 | p.drawPolygon(points, Qt::OddEvenFill); | 210 | p.drawPolygon(points, Qt::OddEvenFill); | ||
207 | 211 | | |||
208 | if ( isFinal ) | 212 | if ( isFinal ) { | ||
209 | return; | 213 | return; | ||
214 | } | ||||
210 | 215 | | |||
211 | if ( points.count() <= 2 ) | 216 | if ( points.count() <= 2 ) { | ||
212 | return; | 217 | return; | ||
218 | } | ||||
213 | 219 | | |||
214 | p.setCompositionMode(QPainter::RasterOp_SourceXorDestination); | 220 | p.setCompositionMode(QPainter::RasterOp_SourceXorDestination); | ||
215 | p.setPen(QPen(Qt::white)); | 221 | p.setPen(QPen(Qt::white)); | ||
216 | p.drawLine(points[0], points[points.count() - 1]); | 222 | p.drawLine(points[0], points[points.count() - 1]); | ||
217 | } | 223 | } | ||
218 | 224 | | |||
219 | //--------------------------------------------------------------------- | 225 | //--------------------------------------------------------------------- | ||
220 | // public static | 226 | // public static | ||
Show All 17 Lines | 240 | { | |||
238 | 244 | | |||
239 | for (int dy = 0; dy < height; dy += StippleSize) | 245 | for (int dy = 0; dy < height; dy += StippleSize) | ||
240 | { | 246 | { | ||
241 | for (int dx = 0; dx < width; dx += StippleSize) | 247 | for (int dx = 0; dx < width; dx += StippleSize) | ||
242 | { | 248 | { | ||
243 | const bool parity = ((dy + dx) / StippleSize) % 2; | 249 | const bool parity = ((dy + dx) / StippleSize) % 2; | ||
244 | 250 | | |||
245 | kpColor useColor; | 251 | kpColor useColor; | ||
246 | if (!parity) | 252 | if (!parity) { | ||
247 | useColor = color; | 253 | useColor = color; | ||
248 | else | 254 | } | ||
255 | else { | ||||
249 | useColor = stippleColor; | 256 | useColor = stippleColor; | ||
257 | } | ||||
250 | 258 | | |||
251 | painter.fillRect (x + dx, y + dy, StippleSize, StippleSize, useColor.toQColor()); | 259 | painter.fillRect (x + dx, y + dy, StippleSize, StippleSize, useColor.toQColor()); | ||
252 | } | 260 | } | ||
253 | } | 261 | } | ||
254 | 262 | | |||
255 | } | 263 | } | ||
256 | } | 264 | } | ||
257 | 265 | | |||
Show All 16 Lines |