How to use wxGraphicContext to draw on a wxBitmap?

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 171
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

How to use wxGraphicContext to draw on a wxBitmap?

Post by Parduz »

I'm building a component which shows a vertical bar chart, using wxGraphicContext to get a nice antialiasing.

The "draft" works, but it needs some optimization. One of them is to draw the fixed part of the chart (axis, labels, grid, etc) on a bitmap each time the component changes size, and then always using that bitmap as a background and redraw only the bars when needed.
chart.jpg
chart.jpg (45.75 KiB) Viewed 276 times
What i don't get is how to use wxGraphicContext to draw on a bitmap.

Could i get a little code showing how to do so?
User avatar
doublemax
Moderator
Moderator
Posts: 18556
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to use wxGraphicContext to draw on a wxBitmap?

Post by doublemax »

https://docs.wxwidgets.org/trunk/classw ... 2dc0686e2e

FWIW: When the background has only little content, i don't think this optimization is worth the effort (yet).
Use the source, Luke!
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 171
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Re: How to use wxGraphicContext to draw on a wxBitmap?

Post by Parduz »

Oh... that's the way. Thanks.
doublemax wrote: Thu Jul 27, 2023 2:08 pm FWIW: When the background has only little content, i don't think this optimization is worth the effort (yet).
Well, the bars needs to be updated the fastest i can, and the program will run on an embedded linux PC, so not a really fast machine: i don't have yet a comparison, but i think that drawing that background (and computing each line and label position) at each refresh takes some relevant time.
Post Reply