I’m drawing a custom chart using Direct2D. The chart has x and y-axis labels painted on side of the chart. When I zoom the chart vertically some data will be painted on top of the x-axis labels and I want to keep the axis labels clean at all times. What is the best way of limiting the painting area to a custom rectangle, not the whole control?
I have a couple ideas on my mind but I’m not sure whether there are better ways to do this:
Method 1)
Go GDI style and paint chart area on one panel and axis labels on another panel. This way when I paint to chart panel I couldn’t mess up the axis labels. The problem would be that I would have to make more Direct2D objects (render targets at least for each control (hWnd)) and I’m not sure about the performance implications if I do this.
Method 2)
Copy axis labels to a bitmap every time they are updated and then after chart panel commands draw these bitmaps on top of the control. Is this cheaper than method 1?
Method 3)
Manually check pixel locations on every drawing operation and modify then when necessary. This seems like the worst option.
Edit:
Method 4)
Same as method 1) but paint axis labels using GDI+ and use Direct2D only for the chart.
Method 5)
Using ID2DLayer. I just found this feature from MSDN Documentation. It seems to be what I’m looking for but it came with many warnings about performance implications with frequent use.
Your opinion?
You can use axis aligned clip, which is less hungry.
to push
to pop
Sample from msdn: