Page 1 of 1

using XOR for lines

Posted: Mon Sep 02, 2019 3:12 am
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.

Re: using XOR for lines

Posted: Mon Sep 02, 2019 2:26 pm
by jrincayc
The full code I used and a picture of the result is available on Redhat's bugzilla Bug 1606599 comment 9

Re: using XOR for lines

Posted: Mon Sep 02, 2019 3:49 pm
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/

Re: using XOR for lines

Posted: Tue Sep 03, 2019 2:42 am
by jrincayc
Ticket #18488 created. Yes, the drawing samples raster operations don't look right.

Re: using XOR for lines

Posted: Tue Sep 03, 2019 12:21 pm
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.

Re: using XOR for lines

Posted: Fri Sep 13, 2019 3:43 pm
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.