Best methdo to create wxGraphicsContext inside OnPaint(wxPaintEvent&)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Best methdo to create wxGraphicsContext inside OnPaint(wxPaintEvent&)

Frédéric
Hi,

Inside a OnPaint(wxPaintEvent&) event handler, what is the best way to
create a wxGraphicsContext?

1.
wxPaintDC dc{this};
auto gc = wxGraphicsContext::Create(dc);

2.
auto gc = wxGraphicsContext::Create(this);

Is it doing exaclty the same thing in terms of output?
I understood that wxPaintDC was kind of 'mandatory' in the EVT_PAINT
event because it clips the drawing inside the wanted rectangle but is
it going to make the wxGraphicsContext less powerful if it is based on
a wxDC?

Best regards,

F

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: Best methdo to create wxGraphicsContext inside OnPaint(wxPaintEvent&)

Vadim Zeitlin-4
On Wed, 17 Oct 2018 18:00:06 +0200 Frédéric wrote:

F> Inside a OnPaint(wxPaintEvent&) event handler, what is the best way to
F> create a wxGraphicsContext?
F>
F> 1.
F> wxPaintDC dc{this};
F> auto gc = wxGraphicsContext::Create(dc);

 You need to do this because the contract is that you promise the system
to create a wxPaintDC in your wxEVT_PAINT handler.

F> 2.
F> auto gc = wxGraphicsContext::Create(this);

 This probably (didn't test it, to be honest) happens to work nowadays too
because we surreptitiously do the same thing as creating wxPaintDC does for
you behind the scenes if you hadn't done it, but it's still better to do it
explicitly.

F> Is it doing exaclty the same thing in terms of output?
F> I understood that wxPaintDC was kind of 'mandatory' in the EVT_PAINT
F> event because it clips the drawing inside the wanted rectangle

 Not only this, but it also validates the area which had to be drawn, at
least under MSW.

F> but is it going to make the wxGraphicsContext less powerful if it is
F> based on a wxDC?

 Not to the best of my knowledge, no.

 Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/

attachment0 (203 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Best methdo to create wxGraphicsContext inside OnPaint(wxPaintEvent&)

Frédéric
> F> wxPaintDC dc{this};
> F> auto gc = wxGraphicsContext::Create(dc);
>
>  You need to do this because the contract is that you promise the system
> to create a wxPaintDC in your wxEVT_PAINT handler.

OK

> F> 2.
> F> auto gc = wxGraphicsContext::Create(this);
>
>  This probably (didn't test it, to be honest) happens to work nowadays too
> because we surreptitiously do the same thing as creating wxPaintDC does for
> you behind the scenes if you hadn't done it, but it's still better to do it
> explicitly.

Yes, apparently it works but I won't do it!

> F> but is it going to make the wxGraphicsContext less powerful if it is
> F> based on a wxDC?
>
>  Not to the best of my knowledge, no.

OK, thanks. The wxGraphicsContext seems so much superior that I
thought if if was used through a wxDC it would suffer the same
limitations like integer rounding but apprently not.

Thanks,

F

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users