purple background when transparency = true

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
marksatterfield
Knows some wx things
Knows some wx things
Posts: 33
Joined: Fri Jun 30, 2017 12:34 pm

purple background when transparency = true

Post by marksatterfield »

I have a Windows application running on WEC7 that uses wxWindows and when I have tranparency set to true on some text and images in the windows they should up with a purple accented output. Any reason for this and how could I remove it? Using wxWidgets 2.8.3
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: purple background when transparency = true

Post by ONEEYEMAN »

Hi,
First of, any reason not to use 3.1.1?
Second - can we see some code and a screenshot of what is displayed? Unfortunately there is no one here on this forum whose name is Johnny-mnemonic. ;-)

Thank you.
marksatterfield
Knows some wx things
Knows some wx things
Posts: 33
Joined: Fri Jun 30, 2017 12:34 pm

Re: purple background when transparency = true

Post by marksatterfield »

I have to use 2.8.3 because the previous version of product uses 2.8.3 and the customer did not want to update for this hardware update.
I cannot show code it is company private but I can tell you that if I have text in a wxWindow and I set the fgcolor to blue, bgcolor to white and I turn on transparency, the text ends up with purple letters. This code has not changed since the last version of the product the only difference is now we are running on WEC7 versus WEC6/
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: purple background when transparency = true

Post by doublemax »

I can tell you that if I have text in a wxWindow and I set the fgcolor to blue, bgcolor to white and I turn on transparency, the text ends up with purple letters.
This sounds like you should be able to build a minimal, compilable sample that shows the problem.

I assume WEC6 is technically XP and WEC7 is WIndows 7?
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: purple background when transparency = true

Post by ONEEYEMAN »

Or even try the drawing sample...

Thank you.
marksatterfield
Knows some wx things
Knows some wx things
Posts: 33
Joined: Fri Jun 30, 2017 12:34 pm

Re: purple background when transparency = true

Post by marksatterfield »

This is running on Windows Embedded Compact 7. In a paint event where paint is a wxDC*, the code does
paint->SetTextBackground((isTransparent()) ? wxColor(255, 0, 255) : mBackColor);
paint->SetFont(mFont);

wxBrush brush((isTransparent()) ? wxColor(255, 0, 255) : mBackColor);
wxPen pen((isTransparent()) ? wxColor(255, 0, 255) : mBackColor);
paint->SetBrush(brush);
paint->SetPen(pen);
paint->DrawRectangle(0, 0, GetSize().GetWidth(), GetSize().GetHeight());

Current mBackColor is dark blue and isTransparent() is returning true if object has
transparency set to true.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: purple background when transparency = true

Post by ONEEYEMAN »

Hi,
Did you create wxPaintDC? If not - you should.

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: purple background when transparency = true

Post by doublemax »

I still think we're missing some context. Please provide compiling sample code.

Are you using native MSW code somewhere that deals with the transparency?
Use the source, Luke!
marksatterfield
Knows some wx things
Knows some wx things
Posts: 33
Joined: Fri Jun 30, 2017 12:34 pm

Re: purple background when transparency = true

Post by marksatterfield »

This code is working on a Box with text that is overlaying a Box with a bitmap image. It is trying to show the text but hide the the background of the text box so the image can show through and only the foreground text is displayed. The wxDC* paint is created in other code. The transparency is set in the setTransparent code inheriting from wxWindow (wx/msw/window.h). Is there something special about setting the background color to RGB(255,0,255) in the way the background is shown such as making it clear so the image in the window containing the bitmap can show thru?

void Text::paintEvent(wxDC* paint)
{
paint->SetTextForeground(mForeColor);
paint->SetTextBackground((isTransparent()) ? wxColor(255, 0, 255) : mBackColor);
paint->SetFont(mFont);

wxBrush brush((isTransparent()) ? wxColor(255, 0, 255) : mBackColor);
wxPen pen((isTransparent()) ? wxColor(255, 0, 255) : mBackColor);

paint->SetBrush(brush);
paint->SetPen(pen);
paint->DrawRectangle(0, 0, GetSize().GetWidth(), GetSize().GetHeight());
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: purple background when transparency = true

Post by doublemax »

setTransparent(wxByte transparency) is only supported for toplevel windows, not for child windows.
There was a wxWindowMSW::SetTransparent(bool) in older wxWidgets versions, but it never did anything.

A method isTransparent() does not exist in wxWidgets.
Also, there is nothing in wxWidgets that lets the color magenta become transparent.

Did you write the whole code for that project yourself? Because it sounds there is some Windows specific code somewhere that you don't know about. (Or that you're not telling about.)
Use the source, Luke!
marksatterfield
Knows some wx things
Knows some wx things
Posts: 33
Joined: Fri Jun 30, 2017 12:34 pm

Re: purple background when transparency = true

Post by marksatterfield »

The isTransparent function is part of the application objects. It just checks a private transparent flag that is set via application function calls.
Thanks for answering my question about magenta! I am using wxWIdgets 2.8.3 and I agree it looks like SetTransparent() is a no-op.

I guess my question is there a better way to do what this code is trying to do?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: purple background when transparency = true

Post by doublemax »

I guess my question is there a better way to do what this code is trying to do?
First i'd be quite curious to know how it ever worked :)

With a screenshot it would be easier to understand what this code actually does. I assume you want to draw something custom on top of a native control? That would be the only situation i can think of, where you would need a hack like this.

Did you try setting the wxTRANSPARENT_WINDOW style flag? Then in the paint event to not draw the background, just draw the text.
Use the source, Luke!
marksatterfield
Knows some wx things
Knows some wx things
Posts: 33
Joined: Fri Jun 30, 2017 12:34 pm

Re: purple background when transparency = true

Post by marksatterfield »

What the code wants to do is have the text foreground to show but the background of the text window to be transparent so the bitmap image in the window under the text window shows through. When the brush and pen are set with a magenta color then the white text shows white with a magenta accent, not really white but sort of a white magenta color. :?

I will look into your suggestion on the transparent flag with no background.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: purple background when transparency = true

Post by doublemax »

What the code wants to do is have the text foreground to show but the background of the text window to be transparent so the bitmap image in the window under the text window shows through.
If you just need to draw text over a bitmap should should combine these two. Have a paint event handler that draws the bitmap and then the text on top.
Use the source, Luke!
marksatterfield
Knows some wx things
Knows some wx things
Posts: 33
Joined: Fri Jun 30, 2017 12:34 pm

Re: purple background when transparency = true

Post by marksatterfield »

This code worked fine in Windows Embedded 6 so it has to be either something defined in the OS or the way I built the wxWidgets library using VS2008.
This code is used all over the application (about 40 windows) for all text windows.
Last edited by marksatterfield on Wed Oct 24, 2018 5:45 pm, edited 1 time in total.
Post Reply