Darkening the crop area impossible?
Bart Coppens
kde at bartcoppens.be
Sun Jan 8 15:50:47 CET 2006
Looking at the GIMP yesterday, I noticed they had a cute little feature: when
you are cropping an image, the part of the image that is not used will be
darkened, so that it is quite clear what part will go away and what not.
I thought the big part of it would have been simple: make a region of the
cropped parts, paint over them with half-transparent black, and done (minus
some other things, updating the part that get un-darkened again and so). But
I got stuck at the first part.
The current code (see bottom) has even different effects with OpenGL verus
regular QPainter! OpenGL draws the entire thing in NotROP even though I
create a _new_ painter, whereas the QPainter just makes it black...
So for archival purposes (and because somebody might now how to fix it for at
least one KisCanvasPainter, that would really be enough to add it), here is
the small patch that doesn't work;
Index: kis_tool_crop.cc
===================================================================
--- kis_tool_crop.cc (revision 495477)
+++ kis_tool_crop.cc (working copy)
@@ -396,6 +396,20 @@
gc.setRasterOp(op);
gc.setPen(old);
+
+ gc.end();
+
+ // Darken the area that will be cropped away
+ KisCanvas* canvas = controller -> kiscanvas();
+ KisCanvasPainter gc2(canvas);
+ QRegion toDraw(0, 0, canvas -> width(), canvas -> height());
+ toDraw = toDraw.subtract(QRegion(startx, starty, endx - startx, endy
- starty));
+
+ rects = toDraw.rects();
+ QColor fillColor(qRgba(0,0,0, 125));
+ for (QMemArray <QRect>::ConstIterator it = rects.begin (); it !=
rects.end (); ++it) {
+ gc2.fillRect (*it, fillColor);
+ }
}
}
Bart Coppens
More information about the kimageshop
mailing list