Example

The following code fragments present a group graphic (TMyGroup) and shows what happens when a call to TMyGroup::Draw occurs. The TMyGroup class is created for the purpose of illustration. In most cases, you can just instantiate a TGraphicGroup and call its Draw function to get the functionality shown in this example.

TMyGroup::Draw function implementation

      TMyGroup::Draw( TGrafPort& parentPort )
      {
          TLinkedBundlePort bundlePort( &parentPort, fBundle );
          TLinkedModelMatrixPort matrixPort( &bundlePort, &fModelMatrixState )
          TMyGroupIterator iterator;
          for( MGraphic* child = iterator.First(); child != NIL; child = iterator.Next; )
              child>Draw( matrixPort );
    
    }
    TLinkedModelMatrixPort matrixPort( &bundlePort, &fModelMatrixState )
The constructor to TLinkedModelMatrixPort takes a reference to a port and a model matrix. It establishes a link to the model matrix so that the model matrix supplied in the constructor can be concatenated to the graphic state. The destructor deletes the link.

          for( MGraphic* child = iterator.First(); child != NIL; child = iterator.Next; )
              child>Draw( matrixPort );
The child>Draw call in the for loop iterates the TMyGroup children and calls the Draw function for each child graphic. For example, if the group contains a customized polygon, the TMyPolygon::Draw function is called.

TMyPolygon::Draw function

      TMyPolygon::Draw( TGrafPort& parent )
      {   
          parent.Draw( *this );
      }
The TMyPolygon::Draw function calls TGrafPort::Draw, which gets the device from the drawing port, and calls the TGrafDevice::RenderPolygon function. The RenderPolygon function in the TGrafPort::Draw function has a graphics device.

TSomeGrafDevice::Draw function

      TSomeGrafDevice::Draw(  const TGPolygon& p, 
                              const TGrafState& grafState, 
                              TGrafCache& grafCache )
      {
          grafState.GetAttributeState()>GetAntialiasing();
          grafState.GetModelMatrixState()>GetMatrix();
      }
The grafState.GetModelMatrixState function returns the model matrix stored in the TLinkedViewMatrixPort instance.

The grafState.GetModelMatrixState>GetMatrix function returns the matrix in the matrix state object.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker