using XOR for lines

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.
Post Reply
jrincayc
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon Sep 02, 2019 12:20 am

using XOR for lines

Post by jrincayc »

I am trying to figure out how to use wxXOR for lines. I took the test case from the sample at https://wiki.wxwidgets.org/WxDC and added some lines (The spam filter will not let me post the entire code):

Code: Select all

    wxPen myPen = wxPen( wxT("blue"), 5, wxSOLID);
    dc.SetPen(myPen);
    dc.SetBrush(*wxTRANSPARENT_BRUSH);
    dc.SetLogicalFunction(wxXOR);
    dc.DrawLine(10, 20, 30, 40);
    dc.DrawLine(30, 20, 10, 40);
On Fedora linux (with wxWidgets wxGTK3-3.0.4-8.fc30.x86_64) I compile it with:

Code: Select all

g++ draw.cpp -Wall `wx-config-3.0 --cxxflags --libs` -Wall -o draw

If XOR was working as I expected it to, the lines would be drawn in yellow ( 0xffffff ^ 0x0000ff = 0xffff00) and the center of the X would be back to white. Instead I get a black X.

I am trying to understand what I am doing wrong.

Thank you.
jrincayc
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon Sep 02, 2019 12:20 am

Re: using XOR for lines

Post by jrincayc »

The full code I used and a picture of the result is available on Redhat's bugzilla Bug 1606599 comment 9
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: using XOR for lines

Post by doublemax »

Please build and run the "drawing" sample that comes with wxWidgets. Switch to the "raster operations screen." If it looks wrong there, too, please open a bug report at http://trac.wxwidgets.org/
Use the source, Luke!
jrincayc
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon Sep 02, 2019 12:20 am

Re: using XOR for lines

Post by jrincayc »

Ticket #18488 created. Yes, the drawing samples raster operations don't look right.
jrincayc
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon Sep 02, 2019 12:20 am

Re: using XOR for lines

Post by jrincayc »

Hm, from bug #18050:
I'm afraid it might well be fundamentally impossible to implement the logical operations concept with modern graphics systems such as CoreGraphics or recent GTK+ versions, so I don't think this is ever going to be fixed and we'll probably end up deprecating and then removing this API.
Hm, basically I am trying to port ucblogo to wxGTK3. It uses XOR lines to draw the turtle. Then it draws the turtle a second time with the same XOR lines, and the turtle is erased. I am trying to think of an alternative to XOR that doesn't require rewriting the entire logo graphics system.
jrincayc
Earned a small fee
Earned a small fee
Posts: 14
Joined: Mon Sep 02, 2019 12:20 am

Re: using XOR for lines

Post by jrincayc »

FYI: I just modified the code to always just blit the background, and redraw the turtle on top, instead of using XOR to draw then erase the turtle on the background.

If it wasn't for antialiasing, in cairo I could do something similar to the XOR with the Cairo operator DIFFERENCE, but that only works on the pixels that are fully drawn, the anti-aliased ones don't fully undraw.
Post Reply