source: trunk/src/ddraw/oslibgpi.cpp@ 8602

Last change on this file since 8602 was 8602, checked in by sandervl, 23 years ago

clipper bugfix

File size: 4.3 KB
Line 
1/* $Id: oslibgpi.cpp,v 1.4 2002-06-08 11:45:20 sandervl Exp $ */
2
3/*
4 * GPI interface code
5 *
6 * Copyright 1999 Christoph Bratschi (cbratschi@datacomm.ch)
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12#define INCL_GPI
13#define INCL_WIN
14#include <os2wrap.h> //Odin32 OS/2 api wrappers
15#include <stdlib.h>
16#include <string.h>
17#include <math.h>
18#include "win32type.h"
19#include <winconst.h>
20#include <winuser32.h>
21#include "oslibgpi.h"
22#include <misc.h>
23
24//******************************************************************************
25//******************************************************************************
26LPRGNDATA OSLibQueryVisibleRegion(HWND hwnd, DWORD screenHeight)
27{
28 HRGN hrgnVis = 0;
29 RECTL rcl = {0,0,1,1};
30 LPRGNDATA lpRgnData = 0;
31 HPS hps = 0;
32 LONG temp, i, lComplexity;
33 ULONG bufSizeNeeded;
34 PRECTL pRectl;
35 HWND hwndClientOS2;
36
37 if(screenHeight == 0) {
38 RECTL desktopRectl;
39 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
40 screenHeight = desktopRectl.xRight;
41 }
42
43// hps = WinGetPS(Win32ToOS2FrameHandle(hwnd));
44 hwndClientOS2 = Win32ToOS2Handle(hwnd);
45 hps = WinGetPS(hwndClientOS2);
46 if(hps == NULL) {
47 dprintf(("OSLibQueryVisibleRegion: WinGetPS %x failed", hwnd));
48 return NULL;
49 }
50 hrgnVis = GreCreateRectRegion(hps, &rcl, 1);
51
52 //If there's an update region, use it. else get visible region
53 lComplexity = WinQueryUpdateRegion(hwndClientOS2, hrgnVis);
54 if(lComplexity == RGN_ERROR || lComplexity == RGN_NULL)
55 {
56 dprintf(("No update region; take visible region"));
57 GreCopyClipRegion(hps, hrgnVis, 0, COPYCRGN_VISRGN);
58 }
59
60 RGNRECT rgnRect;
61 rgnRect.ircStart = 1;
62 rgnRect.crc = 0;
63 rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT;
64 if(!GpiQueryRegionRects(hps, hrgnVis, NULL, &rgnRect, NULL))
65 {
66 dprintf(("WARNING: GpiQueryRegionRects failed! (%x)", WinGetLastError(0)));
67 goto failure;
68 }
69 bufSizeNeeded = rgnRect.crcReturned * sizeof(RECT) + sizeof (RGNDATAHEADER);
70 lpRgnData = (LPRGNDATA)malloc(bufSizeNeeded);
71
72 pRectl = (PRECTL)lpRgnData->Buffer;
73 rgnRect.crc = rgnRect.crcReturned;
74 if(!GpiQueryRegionRects(hps, hrgnVis, NULL, &rgnRect, pRectl))
75 {
76 dprintf(("WARNING: GpiQueryRegionRects failed! (%x)", WinGetLastError(0)));
77 goto failure;
78 }
79 for(i=0;i<rgnRect.crcReturned;i++) {
80 dprintf(("Region rect %d (%d,%d)(%d,%d)", i, pRectl[i].xLeft, pRectl[i].yBottom, pRectl[i].xRight, pRectl[i].yTop));
81 //rectangle is in window coordinate; convert to screen
82 WinMapWindowPoints(hwndClientOS2, HWND_DESKTOP, (PPOINTL)&pRectl[i], 2);
83 dprintf(("Region rect %d (%d,%d)(%d,%d)", i, pRectl[i].xLeft, pRectl[i].yBottom, pRectl[i].xRight, pRectl[i].yTop));
84 temp = pRectl[i].yTop;
85 pRectl[i].yTop = screenHeight - pRectl[i].yBottom;
86 pRectl[i].yBottom = screenHeight - temp;
87 dprintf(("Region rect %d (%d,%d)(%d,%d)", i, pRectl[i].xLeft, pRectl[i].yBottom, pRectl[i].xRight, pRectl[i].yTop));
88 }
89
90 RECTL boundRect;
91 GpiQueryRegionBox(hps, hrgnVis, &boundRect);
92
93 lpRgnData->rdh.dwSize = sizeof(lpRgnData->rdh);
94 lpRgnData->rdh.iType = RDH_RECTANGLES_W; // one and only possible value
95 lpRgnData->rdh.nCount = rgnRect.crcReturned;
96 lpRgnData->rdh.nRgnSize = rgnRect.crcReturned * sizeof(RECT);
97
98 //flip top & bottom for bounding rectangle (not really necessary; but cleaner coding)
99 dprintf(("Boundary (%d,%d)(%d,%d)", boundRect.xLeft, boundRect.yBottom, boundRect.xRight, boundRect.yTop));
100 lpRgnData->rdh.rcBound.left = boundRect.xLeft;
101 lpRgnData->rdh.rcBound.right = boundRect.xRight;
102 lpRgnData->rdh.rcBound.top = screenHeight - boundRect.yBottom;
103 lpRgnData->rdh.rcBound.bottom = screenHeight - boundRect.yTop;
104 dprintf(("Boundary (%d,%d)(%d,%d)", boundRect.xLeft, boundRect.yBottom, boundRect.xRight, boundRect.yTop));
105
106 // Destroy the region now we have finished with it.
107 GreDestroyRegion(hps, hrgnVis);
108 WinReleasePS(hps);
109 return lpRgnData;
110
111failure:
112 if(lpRgnData) free(lpRgnData);
113 if(hrgnVis) GreDestroyRegion(hps, hrgnVis);
114 if(hps) WinReleasePS(hps);
115 return 0;
116}
117//******************************************************************************
118//******************************************************************************
119
Note: See TracBrowser for help on using the repository browser.