Nateo Concepts -> Custom Object Drawing

# Custom Object Drawing

# Overview

Besides the built in methods of drawing data objects (icons, images, texts, and crossmark curves) you can implement your own methods of drawing data objects. This section describes how this is done.

## Custom Drawing basics

Data is stored in NtDataObjects no matter how the display is done. This means that for any kind of data you can implement your own drawing at any time without changing the data objects' structure. There is no need to specifically prepare the data objects for one kind of drawing or the other. You implement drawing completely separate and can apply another style of drawing any time.
As an example suppose you have data made of floating point values from 0.0 to 1.0 in your data set. The name of these data items shall be 'Circle Data'. Now you decide that you do not want to display this data as plain text that writes the numbers on the screen. Instead you want to show it in filled circles and the radius of the circle shall display the value of the data object: Radius shall range from one pixel (for value 0.0) to 10 pixels (for value 1.0). Then your Time Chart might look likt this:

Of course the NtTimeChartControl has no idea of drawing data like this so it is up to you to program the drawing. The trick is to let the NtTimeChartControl know that this kind of data is subject to custom drawing.
So what is the workflow in custom drawing?
Custom drawing consists of the following steps:

- Your application has to implement the interface NtCustomObjectPaint.
- You must instantiate a NtDisplayDef with displayMethod greater 100 and the correct dataTypeId. This NtDisplayDef must be added to the NtTimeChartControl by calling SetDisplayDef.

While creating the NtDisplayDef is pretty easy (please see the chapter before), implementing the interface NtCustomObjectPaint needs a good understanding of what is going on. To explain this, it is now described how the NtTimeChartControl processes objects for drawing so you understand which part your code needs to take over when drawing objects your way:

1. For each data object the NtTimeChartControl always knows the left and the right edge of the painting rectangle measured in the time unit 'Ticks'. As these edges depend on the size of the visual representation of the object and the object's position in time relative to its time stamp, it is up to your code to calculate these edges for custom drawn objects.
2. For data objects that overlap the current sheet the NtTimeChartControl needs to know the precise position of left and right edge measured in sheet coordinates (which are pixels).
3. For data objects that overlap the current sheet the NtTimeChartControl needs to know the top and bottom in pixels relative to the top of the current row.
4. Finally for custom objects the NtTimeChartControl will call your code to actually do the drawing.

This looks a little complicated at first glance, but in fact it is not too much code to create. Instead of theoretically describing the necessary steps to implement the NtCustomObjectPaint interface, it is better to take a look into the tutorial Custom Object Drawing.

## NtDisplayDefs for custom drawn objects

<< Prev.: Display Definitions Next: Categories >>

Top Concept Overview -> Custom Object Drawing ?2016 Bassaly