Custom Drawing

Hi,


I'm wanting to do some custom drawing with TDiagramBlocks. I know that the drawing can be done by accessing TDiagramBlock.Drawer but I want to make sure I achieve this in the best / easiest manner possible. I currently use Diagram Blocks with WMFs for their picture but I want to be able to add a few tags with numbers on them (more or less like notifications on iOS - circle with a number in). 

Now I presume using the Drawer is the way to do this? What is the easiest way to get the custom drawing to be executed each time the diagram changes? Is it in the OnAfterPaint of the diagram and if so, is there a way to detect only components that are showing on the screen at the time to save some processing power? Also, how do I easily take in to account the level of zoom and panning in the diagram? Do I simply need to read these values and then multiply and translate the coordinates appropriately or can this be returned automatically from somewhere? 

Any help would be much appreciated!

Aly

Hello Douglas, 

the best way to learn about block painting is read source code that comes with TMS Diagram Studio. FlowchartBlocks.pas is a good unit to learn how to draw shapes, and ElectricBlocks.pas how to paint shapes. It's a complex mechanism and there are drawers with many properties and methods that help you. Usually you don't have to worry with zooming or what area is being painted - Diagram does that for you. Take a look at those units. Although they create descendants from TCustomDiagramBlock and thus override some methods, it's usually the same approach than using OnDrawShape or OnDrawBlock events. OnAfterPaint event is not used to paint blocks, but instead it's used to paint in the background area of the diagram. It's the lower level of painting available - in that event, yes, you have to calculate everything since you are just painting raw in control area.
If you have any specific question, let me know.

Hi Wagner,


Many thanks for the reply. I will have a look at those units and hopefully that will get me started in the right direction.

Thanks again,

Aly