Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Invert Fore/Background Colors

8 views
Skip to first unread message

Peter Pawelko

unread,
May 22, 2009, 12:57:19 PM5/22/09
to
Has anyone been able to successfully invert the foreground and background
colors? Essentially I have a button, and I want the foreground colors and
background colors switched around when a user clicks on the button. The
problem is, this doesn't seem to be working in that the entire thing just
gets painted over with, what I set to be, the foreground color. So the
background color doesn't seem to get painted (yes I called Repaint()).

For example: By default, my Background=Black and my Foreground=White.
When a user clicks the button I'd like Background=white and
Foreground=black, however the entire thing just seems to paint black.

In the meantime I'll keep looking into this or give up and just do a
simple outline

Byron Weber Becker

unread,
May 22, 2009, 1:49:27 PM5/22/09
to Peter Pawelko

I did a quick test in some code I'm preparing for A2. Didn't run into
any problems.

Did you set it back again after you did the drawing in reverse video?
Perhaps your black is being overpainted later on.

Byron

--
---------------------------------------------------------
Byron Weber Becker Voice: 519-888-4567 x34661
School of Computer Science Fax: 519-885-1208
University of Waterloo Office: DC3105
Waterloo, ON N2L 3G1

Peter Pawelko

unread,
May 22, 2009, 2:59:58 PM5/22/09
to
In Component::Paint, before I call PaintComponent, I set the Graphics
object's Background and Foreground Colors to be that of the Background and
Foreground colors of the Component itself. Then I call PaintComponent.
After calling PaintComponent, I set them back to what they were before
(and then I paint children). So it should be setting the background and
foreground specific to each component...or at least that's how I thought
it was working

Byron Weber Becker

unread,
May 22, 2009, 3:26:32 PM5/22/09
to Peter Pawelko
Peter Pawelko wrote:
> In Component::Paint, before I call PaintComponent, I set the Graphics
> object's Background and Foreground Colors to be that of the Background
> and Foreground colors of the Component itself. Then I call
> PaintComponent. After calling PaintComponent, I set them back to what
> they were before (and then I paint children). So it should be setting
> the background and foreground specific to each component...or at least
> that's how I thought it was working

Are you erasing a component before you redraw it? If not, things might
get confusing with what was painted before you inverted the colors.

Peter Pawelko

unread,
May 22, 2009, 3:30:57 PM5/22/09
to
If I'm thinking of it properly, yes I should be erasing it. I do an
XClearArea(...) call in the XWindow::HandlePaintEvent so it should be
clearing the damaged area in the PaintEvent (or in this case, the area of
the component who called Repaint). I checked what the FG and BG colors
were in my Button::PaintComponent and they seem to be properly set to what
I want, so like you said originally I may be overpainting somewhere.
Haven't been successful in finding anywhere obvious yet though :(

Thanks for the suggestions!

On Fri, 22 May 2009, Byron Weber Becker wrote:

christineh...@gmail.com

unread,
Feb 24, 2016, 2:31:36 AM2/24/16
to
How do I invert background colors?
0 new messages