L_VecPaint

#include "lvkrn.h"

L_INT EXT_FUNCTION L_VecPaint(hDC, pVector, bEraseBkgnd)

HDC hDC;

/* device context */

const pVECTORHANDLE pVector;

/* pointer to a vector handle */

L_BOOL bEraseBkgnd;

/* flag that indicates whether to erase the background */

Draws the specified vector into a given device context.

Parameter

Description

hDC

Device context.

pVector

Pointer to a vector handle that references the vector to draw.

bEraseBkgnd

Flag that indicates whether or not to erase the background rectangle when rendering the vector. Possible values are:

 

Value

Meaning

 

TRUE

The background rectangle will be erased when the vector image is rendered to the device context.

 

FALSE

The background rectangle will not be erased.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

If hDC is NULL, this function will assume that pVector is already attached to a window, and will draw the vector image to the window DC.

The background color used to erase the rectangle where the vector image is rendered can be set with L_VecSetBackgroundColor.

If L_VecPaint is called in response to a WM_PAINT message, hDC should be the paint DC obtained from BeginPaint.

This function will use current camera and current viewport of the vector handle to do the necessary projection into the surface of the DC.

Note:

For the OpenGL engine, the background color will always be used to erase all of the image before drawing, regardless of the view port.

Required DLLs and Libraries

LVKRN

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

L_VecRealize, L_VecAttachToWindow, L_VecSetCamera, L_VecSetViewport, L_VecSetBackgroundColor

Example

/* This example will create a HBITMAP for the given vector file. */

HBITMAP LoadAsDDB( L_TCHAR L_FAR *pszFile, L_UINT uWidth, L_UINT uHeight )
{
   /* uWidth and uHeight are the desired bitmap size, the final bitmap size will be less or equal to uWidth and uHeight. */

   VECTORHANDLE   TmpVector;
   VECTORPOINT    min, max;
   L_DOUBLE        Width, Height, Factor;
   RECT           rect;
   HBITMAP        hBitmap;
   HDC            hDC;

   /* First load the vector */
   L_VecLoadFile( pszFile, &TmpVector, NULL, NULL );

   /* Get vector image logical parallelogram */
   L_VecGetObjectParallelogram( &TmpVector, NULL, &min, &max, 0L );

   /* Calculate viewport preserving drawing aspect ratio */
   Width = max.x - min.x;
   Height = max.y - min.y;
   
   if( uWidth < uHeight )
   {
      Factor =  uWidth / Width;

      /* Check if height would fit in size */
      if( ( Factor * Height ) > uHeight )
      {
         /* No can do, calculate based on height */
         Factor = uHeight / Height;
      }
   }
   else
   {
      Factor = uHeight / Height;

      /* Check if width would fit in size */
      if( ( Factor * Width ) > uWidth )
      {
            /* No can do, calculate based on width */
            Factor = uWidth / Width;
      }
   }

   /* Setup viewport rectangle */
   rect.left = 0;
   rect.top = 0;
   rect.right = (L_INT) ( Factor * Width );
   rect.bottom = (L_INT) ( Factor * Height );

   /* Create the DDB */
   hBitmap = CreateCompatibleBitmap( NULL, rect.right, rect.bottom );
   hDC = CreateCompatibleDC( NULL );
   SelectObject( hDC, hBitmap );

   /* Setup viewport */
   L_VecSetViewport( &TmpVector, &rect );

   /* Setup default camera (Top view) */
   L_VecSetCamera( &TmpVector, NULL );
 
   /* Render the vector into the memory DC with black background */
   L_VecSetBackgroundColor( &TmpVector, RGB( 0, 0, 0 ) );
   L_VecPaint( hDC, &TmpVector, TRUE );

   DeleteDC( hDC );

   /* Free the vector cause it's no longer needed */
   L_VecFree( &TmpVector );

   return( hBitmap );
}