File:  [OS/2 SDKs] / os232sdk / toolkt20 / c / samples / image / img_pnt.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:31 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1990, HEAD
Microsoft OS/2 SDK 2.0 05-30-1990

/*==============================================================*\
 *  img_pnt.c - routines for the painting of the main window
 *      Created 1989, 1990 Microsoft Corp.
 *--------------------------------------------------------------
 *
 *  This module contains the code for the main client window
 *  painting.
 *
 *--------------------------------------------------------------*
 *
 *  This source file contains the following functions:
 *
 *      PaintUnSizedImage()
 *      PaintSizedImage()
 *      PaintDrawImage()
 *
\*==============================================================*/
/*--------------------------------------------------------------*\
 *  Include files, macros, defined constants, and externs       *
\*--------------------------------------------------------------*/
#define INCL_DOSMEMMGR
#define INCL_WINMENUS
#define INCL_WINFRAMEMGR
#define INCL_WINPOINTERS
#define INCL_GPIPRIMITIVES
#define INCL_GPIBITMAPS

#include <os2.h>
#include <string.h>
#include "img_main.h"
#include "img_xtrn.h"

/****************************************************************\
 *  Draw Image Routine                                          *
 *--------------------------------------------------------------*
 *                                                              *
 *  Name:    PaintDrawImage()                                   *
 *                                                              *
 *  Purpose: To draw the image data into the bitmap             *
 *                                                              *
 *  Usage:  Routine is called from LoadImage()                  *
 *                                                              *
 *  Method:                                                     *
 *          - creates a memory device context                   *
 *          - defines a memory presentation space               *
 *          - associates the memory DC with the memory PS       *
 *          - creates a bitmap                                  *
 *          - Selects bitmap into memory DC                     *
 *          - draws the image data into the bitmap              *
 *                                                              *
 *  Returns:                                                    *
\****************************************************************/

VOID PaintDrawImage()
{
    POINTL ptl;
    DEVOPENSTRUC dop;
    BITMAPINFOHEADER2 BmapInfo;

    if (vfImgLoaded) {
        /*
         * The memory presentation space is defined to accommodate a
         * particular file of image data. If an image has already been
         * loaded, its resources must be deleted before a new set can be
         * defined.
         */
         GpiDeleteBitmap(vhbm);
         GpiAssociate(vhpsMem, (HDC)NULL);
         GpiDestroyPS(vhpsMem);
         DevCloseDC(vhdcMem);
    }

   /*
    * define the memory device context
    */
    dop.pszLogAddress = (PSZ)NULL;
    dop.pszDriverName = "DISPLAY";
    vhdcMem = DevOpenDC(vhab,
                        OD_MEMORY,
                        "*",
                        2L, /* number of valid elements */
                        (PDEVOPENDATA)&dop,
                        (HDC)NULL);

   /*
    * The memory presentation space is defined and associated with the
    * memory device context. The presentation page is the same size in
    * pels as the image.
    */
    vhpsMem = GpiCreatePS(vhab,
                          vhdcMem,
                          &vsizlImg,
                          (LONG)PU_PELS | GPIT_NORMAL | GPIA_ASSOC);

   /*
    * Create a bit map in a format compatible with the memory device
    * context.
    */

   /*
    * define the bit-map information header
    */
    BmapInfo.cbFix     = 16;                /* bit-map header length   */
    BmapInfo.cx        = vsizlImg.cx;
    BmapInfo.cy        = vsizlImg.cy;
    BmapInfo.cPlanes   = 1L;                /* number of bit planes    */
    BmapInfo.cBitCount = 1L;                /* number of bits per pel  */


   /*
    * The bit map is defined and selected into the memory device
    * context. The output display is cleared.
    */
    vhbm = GpiCreateBitmap(vhpsMem,
                           (PBITMAPINFOHEADER2)&BmapInfo,
                           0L,                     /* no options      */
                           (PBYTE)NULL,            /* no initial data */
                           (PBITMAPINFO2)NULL);


    GpiSetBitmap(vhpsMem, vhbm);
    GpiErase(vhpsMem);
    GpiSetBackMix(vhpsMem, BM_OVERPAINT);

   /*
    * The current position is set to the top-left corner of the memory
    * presentation page before GpiImage is issued to draw the image
    * into it.
    */
    ptl.x = 0;
    ptl.y = vsizlImg.cy;
    GpiSetCurrentPosition(vhpsMem, &ptl);
    GpiImage(vhpsMem,
             0L,
             &vsizlImg,                           /* image size           */
             (LONG)(vsizlImg.cx * vsizlImg.cy/8), /* data length in bytes */
             vpbImgBuf);                          /* image data           */
    GpiSetBitmap(vhpsMem, (HBITMAP)NULL); /* free bit map in memory DC */
    WinInvalidateRect(vhwndClient, (PRECTL)NULL, FALSE);

}   /* PaintDrawImage() */


/****************************************************************\
 *  Paint Unscaled Image Routine                                *
 *--------------------------------------------------------------*
 *                                                              *
 *  Name:    PaintUnSizedImage()                                *
 *                                                              *
 *  Purpose: To paint the image in the client window            *
 *                                                              *
 *  Usage:   Routine is called from MainWndProc()               *
 *                                                              *
 *  Method:                                                     *
 *                                                              *
 *  Returns:                                                    *
\****************************************************************/

VOID PaintUnSizedImage()
{

    WinSetPointer(HWND_DESKTOP, vhptrWait);

    GpiImage(vhps,
             0L,
             &vsizlImg,                           /* size in pels         */
             (LONG)(vsizlImg.cx * vsizlImg.cy/8), /* data length in bytes */
             vpbImgBuf);                          /* image data           */

    WinSetPointer(HWND_DESKTOP, vhptrArrow);

}   /* PaintUnSizedImage() */


/****************************************************************\
 *  Paint Sized Image Routine                                   *
 *--------------------------------------------------------------*
 *                                                              *
 *  Name:    PaintSizedImage()                                  *
 *                                                              *
 *  Purpose: To paint the image in the client window, size      *
 *           it so that the whole of the image is visible       *
 *           (ie scaled as necessary)                           *
 *                                                              *
 *  Usage:   Routine is called from MainWndProc()               *
 *                                                              *
 *  Method:                                                     *
 *                                                              *
 *  Returns:                                                    *
\****************************************************************/

VOID PaintSizedImage()
{
    RECTL  rcl;                   /* client window rectangle    */
    POINTL aptl[5];               /* array of x,y pairs         */

   /*
    * The dimensions of the target rectangle are obtained using the
    * WinQueryWindowRect() call.
    */
    WinQueryWindowRect(vhwndClient, &rcl); /* query client window size */
    aptl[0].x = 0;                         /* bottom left, in          */
    aptl[0].y = 0;                         /*  device coordinates      */
    aptl[1].x = rcl.xRight - rcl.xLeft;    /* top right, in            */
    aptl[1].y = rcl.yTop - rcl.yBottom;    /*  device coordinates      */

   /*
    * The dimensions of the source rectangle are those of the source
    * image.
    */
    aptl[2].x = 0;                         /* bottom left, in          */
    aptl[2].y = 0;                         /*  window coordinates      */
    aptl[3].x = vsizlImg.cx;               /* top right, in            */
    aptl[3].y = vsizlImg.cy;               /*  device coordinates      */

    WinSetPointer(HWND_DESKTOP, vhptrWait);

   /*
    * draw the image
    */
    WinDrawBitmap(vhps,
                  vhbm,
                  (PRECTL)NULL,                /* draw whole bit map   */
                  (PPOINTL)&rcl,               /* bit-map destination  */
                                               /*  is client window    */
                                               /*  rectangle.          */
                  0L,
                  0L,
                  DBM_STRETCH | DBM_IMAGEATTRS);
                                               /* stretch or compress  */
                                               /*  to suit, and use    */
                                               /*  image attributes    */
                                               /*  for color.          */

    WinSetPointer(HWND_DESKTOP, vhptrArrow);

}   /* PaintSizedImage() */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.