The HelloWorld code creates a Presentation framework stationery from the TGUIViewStationeryFor<> template, and the VersionDefinitionsMacro takes an instance of THelloWorld and the value kOriginalVersion to indicate that this is the original version of THelloWorld.
Include files
The following include files are used in this chapter for the examples. In the future when Taligent's development environment is available, you will not need to include these files with your code because the development environment will find all of the correct files for you.
#include <Taligent/GUICompoundDocument.h>//TDocumentComponentView declarations
#include <Taligent/TextDisplay.h> //TStandardText and TTextDisplay declarations
#include <Taligent/Graphics.h> //2-D graphics classes declarations
#include <Taligent/Bundles.h> //Attribute bundle declarations
#include <Taligent/RGBColor.h> //TRGBColor declarations
#include <Taligent/Attribute.h> //TColorPaint declarations
#include <Taligent/GrafPens.h> //TSolidPen declarations
#include <Taligent/Transforms.h> //TGrafMatrix declarations
#include <Taligent/AreaGeometry.h> //TGPolygon declarations
PinkMake file
You need to add the LowLevelAlbert and TimeLib libraries to your PinkMake file for the HelloWorld sample application to compile with graphics code added to it. You do this by typing "LowLevelAlbert" and "TimeLib" (without the quotes) on a line where the other libraries are listed in PinkMake. Constructor
To create an instance of THelloWorld you call the constructor with a pointer to an instance of a TGUIBundle. TGUIBundle is a Presentation framework convenience class to keep track of all related information in a document component.
Lines 4 through 6: The constructor passes the pointer to TGUIBundle to the base class, and initializes the base class with the address of a unique number by calling the VViewInitalize function and passing it the global field gMetaInfo. 1 class THelloWorld : public TDocumentComponentView
2 {
3 public:
4 THelloWorld( TGUIBundle* bundle ) :
5 TDocumentComponentView( bundle ),
6 VViewInitialize( &gMetaInfo )
7 {
8 CheckForInitialize( &gMetaInfo );
9 }
Line 8: The constructor implementation must call CheckForInitialize function and pass it the gMetaInfo parameter.
You can find more information on TGUIBundle and VViewInitialize in the View system documentation.
Change drawing area size
By default, the component view drawing area is 250 world-coordinate units wide and 250 world-coordinate units long. Nothing is drawn outside of this area. You can make a function call in the constructor implementation to change this size.
Line 6: SetAllocatedArea( TGRect( 0, 0, 1000, 1000 ) ) changes the size of the drawing area of the view to 1000 world-coordinate units long and 1000 worldcoordinate units wide.1 THelloWorld( TGUIBundle* b) :
2 TDocumentComponentView( b ),
3 VViewInitialize( &gMetaInfo ),
4 {
5 CheckForInitialize( &gMetaInfo );
6 SetAllocatedArea( TGRect( 0, 0, 1000, 1000 ) );
7 }
Destructor
The destructor calls the CheckForFinalize function to run cleanup code for the view. The destructor for all views must do this. See the Taligent Programming Idioms document for more details on the purpose of this function.
~THelloWorld
{
CheckForFinalize( &gMetaInfo );
}
DrawContents function
The graphics are instantiated and their Draw functions called within DrawContents. The DrawContents function is called and gets passed the address of the drawing port (TGrafPort) by the View system when any change to the data is detected. This would happen, for example, when the view is first displayed, when the window containing the view is resized, when a portion of a view is covered and then uncovered, or when the contents of a view are modified.
The View system renders the entire view, regardless of whether only a portion of the view has changed. All necessary clipping takes place at the drawing port. See Chapter 19 for more information on drawing ports.
NOTE To print graphics drawn to a view, pass the view to a printer instance.
void DrawContents( TGrafPort& thePort ) const { //Your code to instantiate and draw 2-D graphics goes here. //The following lines are in the Hello World sample application when you check it out. TStandardText theText( "Hello World" ); TTextDisplay theDisplayedText( theText ); theDisplayedText.SetOrigin( TGPoint( 30, 30 ) ); theDisplayedText.Draw( thePort ); }