|
|
1.1 ! root 1: /*==============================================================*\ ! 2: * img_pnt.c - routines for the painting of the main window ! 3: * Created 1989, 1990 Microsoft Corp. ! 4: *-------------------------------------------------------------- ! 5: * ! 6: * This module contains the code for the main client window ! 7: * painting. ! 8: * ! 9: *--------------------------------------------------------------* ! 10: * ! 11: * This source file contains the following functions: ! 12: * ! 13: * PaintUnSizedImage() ! 14: * PaintSizedImage() ! 15: * PaintDrawImage() ! 16: * ! 17: \*==============================================================*/ ! 18: /*--------------------------------------------------------------*\ ! 19: * Include files, macros, defined constants, and externs * ! 20: \*--------------------------------------------------------------*/ ! 21: #define INCL_DOSMEMMGR ! 22: #define INCL_WINMENUS ! 23: #define INCL_WINFRAMEMGR ! 24: #define INCL_WINPOINTERS ! 25: #define INCL_GPIPRIMITIVES ! 26: #define INCL_GPIBITMAPS ! 27: ! 28: #include <os2.h> ! 29: #include <string.h> ! 30: #include "img_main.h" ! 31: #include "img_xtrn.h" ! 32: ! 33: /****************************************************************\ ! 34: * Draw Image Routine * ! 35: *--------------------------------------------------------------* ! 36: * * ! 37: * Name: PaintDrawImage() * ! 38: * * ! 39: * Purpose: To draw the image data into the bitmap * ! 40: * * ! 41: * Usage: Routine is called from LoadImage() * ! 42: * * ! 43: * Method: * ! 44: * - creates a memory device context * ! 45: * - defines a memory presentation space * ! 46: * - associates the memory DC with the memory PS * ! 47: * - creates a bitmap * ! 48: * - Selects bitmap into memory DC * ! 49: * - draws the image data into the bitmap * ! 50: * * ! 51: * Returns: * ! 52: \****************************************************************/ ! 53: ! 54: VOID PaintDrawImage() ! 55: { ! 56: POINTL ptl; ! 57: DEVOPENSTRUC dop; ! 58: BITMAPINFOHEADER2 BmapInfo; ! 59: ! 60: if (vfImgLoaded) { ! 61: /* ! 62: * The memory presentation space is defined to accommodate a ! 63: * particular file of image data. If an image has already been ! 64: * loaded, its resources must be deleted before a new set can be ! 65: * defined. ! 66: */ ! 67: GpiDeleteBitmap(vhbm); ! 68: GpiAssociate(vhpsMem, (HDC)NULL); ! 69: GpiDestroyPS(vhpsMem); ! 70: DevCloseDC(vhdcMem); ! 71: } ! 72: ! 73: /* ! 74: * define the memory device context ! 75: */ ! 76: dop.pszLogAddress = (PSZ)NULL; ! 77: dop.pszDriverName = "DISPLAY"; ! 78: vhdcMem = DevOpenDC(vhab, ! 79: OD_MEMORY, ! 80: "*", ! 81: 2L, /* number of valid elements */ ! 82: (PDEVOPENDATA)&dop, ! 83: (HDC)NULL); ! 84: ! 85: /* ! 86: * The memory presentation space is defined and associated with the ! 87: * memory device context. The presentation page is the same size in ! 88: * pels as the image. ! 89: */ ! 90: vhpsMem = GpiCreatePS(vhab, ! 91: vhdcMem, ! 92: &vsizlImg, ! 93: (LONG)PU_PELS | GPIT_NORMAL | GPIA_ASSOC); ! 94: ! 95: /* ! 96: * Create a bit map in a format compatible with the memory device ! 97: * context. ! 98: */ ! 99: ! 100: /* ! 101: * define the bit-map information header ! 102: */ ! 103: BmapInfo.cbFix = 16; /* bit-map header length */ ! 104: BmapInfo.cx = vsizlImg.cx; ! 105: BmapInfo.cy = vsizlImg.cy; ! 106: BmapInfo.cPlanes = 1L; /* number of bit planes */ ! 107: BmapInfo.cBitCount = 1L; /* number of bits per pel */ ! 108: ! 109: ! 110: /* ! 111: * The bit map is defined and selected into the memory device ! 112: * context. The output display is cleared. ! 113: */ ! 114: vhbm = GpiCreateBitmap(vhpsMem, ! 115: (PBITMAPINFOHEADER2)&BmapInfo, ! 116: 0L, /* no options */ ! 117: (PBYTE)NULL, /* no initial data */ ! 118: (PBITMAPINFO2)NULL); ! 119: ! 120: ! 121: GpiSetBitmap(vhpsMem, vhbm); ! 122: GpiErase(vhpsMem); ! 123: GpiSetBackMix(vhpsMem, BM_OVERPAINT); ! 124: ! 125: /* ! 126: * The current position is set to the top-left corner of the memory ! 127: * presentation page before GpiImage is issued to draw the image ! 128: * into it. ! 129: */ ! 130: ptl.x = 0; ! 131: ptl.y = vsizlImg.cy; ! 132: GpiSetCurrentPosition(vhpsMem, &ptl); ! 133: GpiImage(vhpsMem, ! 134: 0L, ! 135: &vsizlImg, /* image size */ ! 136: (LONG)(vsizlImg.cx * vsizlImg.cy/8), /* data length in bytes */ ! 137: vpbImgBuf); /* image data */ ! 138: GpiSetBitmap(vhpsMem, (HBITMAP)NULL); /* free bit map in memory DC */ ! 139: WinInvalidateRect(vhwndClient, (PRECTL)NULL, FALSE); ! 140: ! 141: } /* PaintDrawImage() */ ! 142: ! 143: ! 144: /****************************************************************\ ! 145: * Paint Unscaled Image Routine * ! 146: *--------------------------------------------------------------* ! 147: * * ! 148: * Name: PaintUnSizedImage() * ! 149: * * ! 150: * Purpose: To paint the image in the client window * ! 151: * * ! 152: * Usage: Routine is called from MainWndProc() * ! 153: * * ! 154: * Method: * ! 155: * * ! 156: * Returns: * ! 157: \****************************************************************/ ! 158: ! 159: VOID PaintUnSizedImage() ! 160: { ! 161: ! 162: WinSetPointer(HWND_DESKTOP, vhptrWait); ! 163: ! 164: GpiImage(vhps, ! 165: 0L, ! 166: &vsizlImg, /* size in pels */ ! 167: (LONG)(vsizlImg.cx * vsizlImg.cy/8), /* data length in bytes */ ! 168: vpbImgBuf); /* image data */ ! 169: ! 170: WinSetPointer(HWND_DESKTOP, vhptrArrow); ! 171: ! 172: } /* PaintUnSizedImage() */ ! 173: ! 174: ! 175: /****************************************************************\ ! 176: * Paint Sized Image Routine * ! 177: *--------------------------------------------------------------* ! 178: * * ! 179: * Name: PaintSizedImage() * ! 180: * * ! 181: * Purpose: To paint the image in the client window, size * ! 182: * it so that the whole of the image is visible * ! 183: * (ie scaled as necessary) * ! 184: * * ! 185: * Usage: Routine is called from MainWndProc() * ! 186: * * ! 187: * Method: * ! 188: * * ! 189: * Returns: * ! 190: \****************************************************************/ ! 191: ! 192: VOID PaintSizedImage() ! 193: { ! 194: RECTL rcl; /* client window rectangle */ ! 195: POINTL aptl[5]; /* array of x,y pairs */ ! 196: ! 197: /* ! 198: * The dimensions of the target rectangle are obtained using the ! 199: * WinQueryWindowRect() call. ! 200: */ ! 201: WinQueryWindowRect(vhwndClient, &rcl); /* query client window size */ ! 202: aptl[0].x = 0; /* bottom left, in */ ! 203: aptl[0].y = 0; /* device coordinates */ ! 204: aptl[1].x = rcl.xRight - rcl.xLeft; /* top right, in */ ! 205: aptl[1].y = rcl.yTop - rcl.yBottom; /* device coordinates */ ! 206: ! 207: /* ! 208: * The dimensions of the source rectangle are those of the source ! 209: * image. ! 210: */ ! 211: aptl[2].x = 0; /* bottom left, in */ ! 212: aptl[2].y = 0; /* window coordinates */ ! 213: aptl[3].x = vsizlImg.cx; /* top right, in */ ! 214: aptl[3].y = vsizlImg.cy; /* device coordinates */ ! 215: ! 216: WinSetPointer(HWND_DESKTOP, vhptrWait); ! 217: ! 218: /* ! 219: * draw the image ! 220: */ ! 221: WinDrawBitmap(vhps, ! 222: vhbm, ! 223: (PRECTL)NULL, /* draw whole bit map */ ! 224: (PPOINTL)&rcl, /* bit-map destination */ ! 225: /* is client window */ ! 226: /* rectangle. */ ! 227: 0L, ! 228: 0L, ! 229: DBM_STRETCH | DBM_IMAGEATTRS); ! 230: /* stretch or compress */ ! 231: /* to suit, and use */ ! 232: /* image attributes */ ! 233: /* for color. */ ! 234: ! 235: WinSetPointer(HWND_DESKTOP, vhptrArrow); ! 236: ! 237: } /* PaintSizedImage() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.