Change wxPaintDC to wxBufferedPaintDC Topic is solved

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.
palikem
Experienced Solver
Experienced Solver
Posts: 69
Joined: Sat Oct 28, 2017 9:33 am
Location: Slovensko

Change wxPaintDC to wxBufferedPaintDC

Post by palikem »

Hi everybody.

I encountered the problem.
I need the y axis to start from the bottom up, using wxBufferedPaintDC.

Using wxPaintDC is ok.

Code: Select all

void testbuffFrm::testbuffFrmPaint(wxPaintEvent& event)
{
    
	wxPaintDC dc(this);
	wxPaintDC dd(okno1);
	wxPaintDC de(okno2);
	
	dc.SetDeviceOrigin(0, dc.GetSize().GetHeight()-1);
    	dc.SetAxisOrientation(true, true);
	
	dc.DrawLine(0, 0, 100, 100);
	dc.DrawText("Test Frame", 100, 100);
	
	de.DrawText("Test okno1", 10, 2);
	dd.DrawText("Test okno2", 10, 2);
}
frame.jpg
using wxBufferedPaintDC is bad

Code: Select all

void testbuffFrm::testbuffFrmPaint(wxPaintEvent& event)
{
    
	wxBufferedPaintDC dc(this);
	wxPaintDC dd(okno1);
	wxPaintDC de(okno2);
	
	dc.SetDeviceOrigin(0, dc.GetSize().GetHeight()-1);
    	dc.SetAxisOrientation(true, true);
    
	dc.SetBackground(*wxWHITE_BRUSH);
	dc.Clear();
	
	dc.DrawLine(0, 0, 100, 100);
	dc.DrawText("Test Frame", 100, 100);
	
	de.DrawText("Test okno1", 10, 2);
	dd.DrawText("Test okno2", 10, 2);
}
frame1.jpg
Thank you for the reactions.
Win8.
wxDev-C++ 7.4.2.569
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Change wxPaintDC to wxBufferedPaintDC

Post by ONEEYEMAN »

Hi,
What's your wx version?
Can you reproduce it in one of the samples provided with the library?

Thank you.
palikem
Experienced Solver
Experienced Solver
Posts: 69
Joined: Sat Oct 28, 2017 9:33 am
Location: Slovensko

Re: Change wxPaintDC to wxBufferedPaintDC

Post by palikem »

wxDev-C++ 7.4.2.569

I do not understand the second question.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Change wxPaintDC to wxBufferedPaintDC

Post by PB »

ONEEYEMAN asked about wxWidgets version. Your IDE version, aside from being listed in the OP, does not tell that. Even if wxWidgets version is somehow unfortunately tied to wxDevC++ version, people who are not unfamiliar with that still cannot tell. BTW, you can display the version info in any wxWidgets application e.g. using <Ctrl>+<Alt>+<Mouse Middle Click> on an empty space (not a control) in a wxFrame.

I tried with wxWidgets 3.1.1 and it seems that SetAxisOrientation() with wxBufferedPaintDC somehow messes things up. For example, the frame background should be white, because you clear the DC with the white brush. Interstingly, it seems to be broken in BOTH your screenshots, even the one using plain wxPaintDC ....

Edit: I noticed that the code which produced the first screenshot differs in more than just the DC class and does not include the Clear(). I admit I didn not expect that when screenshots are to be compared...
palikem
Experienced Solver
Experienced Solver
Posts: 69
Joined: Sat Oct 28, 2017 9:33 am
Location: Slovensko

Re: Change wxPaintDC to wxBufferedPaintDC

Post by palikem »

wxWidgets 2.9.3
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Change wxPaintDC to wxBufferedPaintDC

Post by ONEEYEMAN »

Hi,
There is a folder called samples inside wxWidgets one.
Try to see if there is a call to the function in question in any of the samples in there. Most likely it will be drawing or image sample.
Build and then run it.

If you see same effect - try the Git HEAD version.

If the problem exist even there - open a ticket on trac.wxwidgets.org with explanation on how to reproduce the problem in that sample. Also mention you exact platform and compiler.

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

Re: Change wxPaintDC to wxBufferedPaintDC

Post by doublemax »

Code: Select all

wxPaintDC dc(this);
wxPaintDC dd(okno1);
wxPaintDC de(okno2);
This is a big no-no. In a paint event handler you can only draw onto the window that initiated the paint event. And it doesn't make sense anyway. What are you trying to do here?
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Change wxPaintDC to wxBufferedPaintDC

Post by PB »

I tested with the bundled drawing sample. In the sample, you can mirror the axis (<Ctrl+N> for vertical mirroring) and move the origin (<Ctrl+D> for moving it down).

How to reproduce the issue in the drawing sample
0. Run the drawing sample
1. Press <Ctrl+N> and observe that that the drawings mostly disappears.
2. Keep hitting <Ctrl+D> and watch the drawings start appearing again, scrolling from the top of the frame to its bottom.

Now repeat the steps from above, except before step 1, check "Use wxBufferedPaintDC" from the Drawing menu. You can see that the drawings now come from the bottom to top, i.e., in the opposite direction as it did with plain wxPaintDC. I think this is unexpected and perhaps deserves a question in the wx-users group. However, I would suggest what doublemax has to say about this, before posting there.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Change wxPaintDC to wxBufferedPaintDC

Post by PB »

doublemax wrote:

Code: Select all

wxPaintDC dc(this);
wxPaintDC dd(okno1);
wxPaintDC de(okno2);
This is a big no-no. In a paint event handler you can only draw onto the window that initiated the paint event. And it doesn't make sense anyway.
I did not point this issue out as removing the invalid code had no effect on the main issue.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Change wxPaintDC to wxBufferedPaintDC

Post by doublemax »

However, I would suggest what doublemax has to say about this, before posting there.
I have a faint memory that wxMemoryDCs (which are used internally by wxBufferedPaintDC) don't inherit all properties of the "master" wxDC. But i can't remember if this was a bug or a limitation. So please go ahead and ask on the mailing list. And of course, remove all junk from your code that is not relevant for the problem.

But then again, if you need a quick solution, it's trivial to perform the calculation yourself.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Change wxPaintDC to wxBufferedPaintDC

Post by ONEEYEMAN »

PB,
Did you try that with 3.1.1?

Thank you.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Change wxPaintDC to wxBufferedPaintDC

Post by PB »

doublemax wrote:I have a faint memory that wxMemoryDCs (which are used internally by wxBufferedPaintDC) don't inherit all properties of the "master" wxDC. But i can't remember if this was a bug or a limitation.
As I cannot find this documented anywhere, I would classify it as a bug, as bugs are just undocumented limitations. :P

There is a list of properties that are copied with CopyAttributes() but I am not sure how much is it relevant here...
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Change wxPaintDC to wxBufferedPaintDC

Post by PB »

ONEEYEMAN wrote:PB, Did you try that with 3.1.1?
I have actually tried it with 3.1.2, about two weeks old GIT-master.
palikem
Experienced Solver
Experienced Solver
Posts: 69
Joined: Sat Oct 28, 2017 9:33 am
Location: Slovensko

Re: Change wxPaintDC to wxBufferedPaintDC

Post by palikem »

doublemax wrote:

Code: Select all

wxPaintDC dc(this);
wxPaintDC dd(okno1);
wxPaintDC de(okno2);
This is a big no-no. In a paint event handler you can only draw onto the window that initiated the paint event. And it doesn't make sense anyway. What are you trying to do here?
When you need to draw multiple windows, what is the solution ?
This program is just a sample to sample how to manage it.
I'm solving this problem in another program, which has 5500 rows.
I will not give long codes :D
frame.jpg
frame1.jpg
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Change wxPaintDC to wxBufferedPaintDC

Post by ONEEYEMAN »

Hi,
Every window should have its own EVT_PAINT event in whose handler you should create its own wxPaintDC.

But this is kind of strange. Are those 3 windows are custom drawn?

Thank you.
Post Reply