Inverting Colour


#1

There have been a couple of times recently where I've wanted to invert the colour of text or a line based on what it's drawing over the top of.  I can't figure out how to do it though ... any bright ideas? 

 


#2

If you're talking about an old 1990s-style XOR mode, then nope, that's not supported and it's generally considered to be a bad way to do things nowadays, for various reasons.

The best way to draw the bar you've got above would be to use the clip region: i.e. fill the whole thing in back, drawing the text in white. Then clip the graphics context to the area of your green block, then fill the entire area in green, and draw the text again in black.


#3

Nothing elegant, but a couple of suggestions for hacks:

  1. Draw text in white, then draw bar, then draw text in black but clipped to the bar's rect
  2. Convert text to path and combine with rect, but with reverse winding. You could get this to cut the text out of the bar and show the background colour, but I'm not positive it will fill the text which is showing outside the bar

#4

The clip solution sounds good. 

And yes, I was thinking of the cheap, energy efficent 1990s solution (.... dreaming of the days when it was just a case of copying things into the graphics RAM pages....)