Ignore:
Timestamp:
Oct 1, 2001, 12:23:46 AM (24 years ago)
Author:
sandervl
Message:

clipper updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ddraw/OS2CLIPPER.CPP

    r5820 r6901  
    1 /* $Id: OS2CLIPPER.CPP,v 1.12 2001-05-28 17:17:09 phaller Exp $ */
     1/* $Id: OS2CLIPPER.CPP,v 1.13 2001-09-30 22:23:44 sandervl Exp $ */
    22
    33/*
     
    2222#include <winerror.h>
    2323#include <winuser.h>
     24#include <winuser32.h>
     25#include "oslibgpi.h"
    2426
    2527//******************************************************************************
    2628//******************************************************************************
    2729OS2IDirectDrawClipper::OS2IDirectDrawClipper(void) :
    28                  Referenced(0), lastError(DD_OK),
    29                  clipWindow(0)
     30                 Referenced(0), lastError(DD_OK), fDrawingAllowed(TRUE),
     31                 clipWindow(0), lpRgnData(NULL), fClipListChanged(FALSE)
    3032{
    3133  // this constructor creates an unassociated instance of the ddraw clipper,
     
    4648  // lpDraw->Vtbl.AddRef(lpDraw);
    4749  // hDive                   = lpDirectDraw->GetDiveInstance();
    48   windowRect.left = windowRect.right = windowRect.top = windowRect.bottom = 0;
    4950}
    5051
     
    5253//******************************************************************************
    5354OS2IDirectDrawClipper::OS2IDirectDrawClipper(OS2IDirectDraw *lpDirectDraw) :
    54                  Referenced(0), lastError(DD_OK),
    55                  clipWindow(0)
     55                 Referenced(0), lastError(DD_OK), fDrawingAllowed(TRUE),
     56                 clipWindow(0), lpRgnData(NULL), fClipListChanged(FALSE)
    5657{
    5758  lpVtbl                  = &Vtbl;
     
    6970  lpDraw->Vtbl.AddRef(lpDraw);
    7071  hDive                   = lpDirectDraw->GetDiveInstance();
    71   windowRect.left = windowRect.right = windowRect.top = windowRect.bottom = 0;
    7272}
    7373//******************************************************************************
    7474//******************************************************************************
    7575OS2IDirectDrawClipper::~OS2IDirectDrawClipper()
    76 {
     76{
     77  if(lpRgnData) free(lpRgnData);
     78  if(clipWindow) {
     79      WinSetVisibleRgnNotifyProc(clipWindow, NULL, 0);
     80  }
    7781  lpDraw->Vtbl.Release(lpDraw);
    7882}
     
    142146  if(me->clipWindow)
    143147  {
    144       HRGN hRgn, hRgn1;
    145       HDC  hdc;
    146       int  bufneeded;
    147 
    148         hRgn = CreateRectRgn(0, 0, 1, 1);
    149         hdc = GetDC(me->clipWindow);
    150         if(GetClipRgn(hdc, hRgn)) {
    151                 if(lpRect) {
    152                         hRgn1 = CreateRectRgnIndirect(lpRect);
    153                         CombineRgn(hRgn, hRgn, hRgn1, RGN_AND);
    154                         DeleteObject(hRgn1);
    155                 }
    156                 bufneeded = GetRegionData(hRgn, *lpdwSize, lpClipList);
    157                 if(bufneeded > *lpdwSize) {
    158                         rc = DDERR_REGIONTOOSMALL;
    159                 }
    160         }
    161         else    rc = DDERR_NOCLIPLIST;
    162         DeleteObject(hRgn);
    163         ReleaseDC(me->clipWindow, hdc);
     148      RECT *rect = (RECT *)&lpClipList->Buffer;
     149      DWORD regiondatasize;
     150
     151      if(me->lpRgnData == NULL) {
     152          DebugInt3();
     153          return DDERR_NOCLIPLIST;
     154      }
     155      regiondatasize = me->lpRgnData->rdh.dwSize + me->lpRgnData->rdh.nCount*sizeof(RECT);
     156      if(lpClipList == NULL) {
     157          *lpdwSize = regiondatasize;
     158          return DD_OK;
     159      }
     160
     161      if(*lpdwSize < regiondatasize) {
     162          *lpdwSize = regiondatasize;
     163          return DDERR_REGIONTOOSMALL;
     164      }
     165      memcpy(lpClipList, me->lpRgnData, regiondatasize);
     166      dprintf(("Boundary rectangle (%d,%d)(%d,%d)", lpClipList->rdh.rcBound.left, lpClipList->rdh.rcBound.top, lpClipList->rdh.rcBound.right, lpClipList->rdh.rcBound.bottom));
    164167  }
    165168  else { //todo!!
     
    224227HRESULT WIN32API ClipIsClipListChanged(THIS This, BOOL *lpbChanged)
    225228{
     229 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
     230
    226231  dprintf(("DDRAW: ClipIsClipListChanged %x %x", This, lpbChanged));
    227232
    228   return(DD_OK);
    229 }
    230 //******************************************************************************
    231 //******************************************************************************
    232 HRESULT WIN32API ClipSetClipList(THIS This, LPRGNDATA lpClipList, DWORD lpdwSize)
    233 {
    234  OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
    235 
    236   dprintf(("DDRAW: ClipSetClipList %x %x %x", This, lpClipList, lpdwSize));
     233  if(lpbChanged == NULL) {
     234      return DDERR_INVALIDPARAMS;
     235  }
     236  *lpbChanged = me->fClipListChanged;
     237  me->fClipListChanged = FALSE;
     238  return(DD_OK);
     239}
     240//******************************************************************************
     241//******************************************************************************
     242HRESULT WIN32API ClipSetClipList(THIS This, LPRGNDATA lpClipList, DWORD dwFlags)
     243{
     244 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
     245
     246  dprintf(("DDRAW: ClipSetClipList %x %x %x", This, lpClipList, dwFlags));
    237247
    238248  if(me->clipWindow) {
    239         return DDERR_CLIPPERISUSINGHWND;
    240   }
    241   return(DD_OK);
     249      return DDERR_CLIPPERISUSINGHWND;
     250  }
     251  if(lpClipList == NULL) {
     252      //TODO: should protect this with a critical section
     253      if(me->lpRgnData) {
     254          free(me->lpRgnData);
     255          me->lpRgnData = NULL;
     256      }
     257      return DD_OK;
     258  }
     259  //TODO: return error if a clip list is already active??
     260  if(me->lpRgnData) {
     261      free(me->lpRgnData);
     262      me->lpRgnData = NULL;
     263  }
     264  me->lpRgnData = (LPRGNDATA)malloc(lpClipList->rdh.dwSize + lpClipList->rdh.nCount*sizeof(RECT));
     265  memcpy(me->lpRgnData, lpClipList, lpClipList->rdh.dwSize + lpClipList->rdh.nCount*sizeof(RECT));
     266  return DD_OK;
     267}
     268//******************************************************************************
     269//******************************************************************************
     270BOOL WIN32API ClipVisRgnCallback(HWND hwnd, BOOL fDrawingAllowed, DWORD dwUserData)
     271{
     272 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)dwUserData;
     273 LPRGNDATA lpClipList, lpRgnOld;
     274
     275  dprintf(("DDRAW: ClipVisRgnCallback %x %x %x", me, hwnd, fDrawingAllowed));
     276  if(me && me->clipWindow == hwnd) {
     277      me->fClipListChanged = TRUE;
     278      lpRgnOld = me->lpRgnData;
     279      if(fDrawingAllowed == FALSE) {
     280          me->fDrawingAllowed = FALSE;
     281          lpClipList = (LPRGNDATA)malloc(sizeof(RGNDATA));
     282          lpClipList->rdh.dwSize   = sizeof(lpClipList->rdh);
     283          lpClipList->rdh.iType    = RDH_RECTANGLES;    // one and only possible value
     284          lpClipList->rdh.nCount   = 0;
     285          lpClipList->rdh.nRgnSize = 0;
     286          me->lpRgnData = lpClipList;
     287      }
     288      else {
     289          me->fDrawingAllowed = TRUE;
     290          me->lpRgnData = OSLibQueryVisibleRegion(hwnd, me->lpDraw->GetScreenHeight());
     291      }
     292      free(lpRgnOld);
     293  }
     294  return TRUE;
    242295}
    243296//******************************************************************************
     
    250303  dprintf(("DDRAW: ClipSetHWnd %x %x %x", This, reserved, hwnd));
    251304
     305  if(!IsWindow(hwnd)) {
     306      dprintf(("WARNING: ClipSetHWnd invalid window handle"));
     307      return DDERR_INVALIDPARAMS;
     308  }
     309  if(me->clipWindow) {
     310      //TODO: Is this really allowed??
     311      WinSetVisibleRgnNotifyProc(me->clipWindow, NULL, 0);
     312  }
    252313  me->clipWindow = hwnd;
    253   GetClientRect(hwnd, &me->windowRect);
    254 
    255   return(DD_OK);
    256 }
    257 //******************************************************************************
    258 //******************************************************************************
     314  WinSetVisibleRgnNotifyProc(hwnd, ClipVisRgnCallback, (DWORD)me);
     315
     316#if 1
     317  me->lpRgnData = OSLibQueryVisibleRegion(hwnd, me->lpDraw->GetScreenHeight());
     318#else
     319  me->lpRgnData = (LPRGNDATA)malloc(sizeof(RGNDATAHEADER) + sizeof(RECT));
     320  me->lpRgnData->rdh.dwSize = sizeof(RGNDATAHEADER);
     321  me->lpRgnData->rdh.iType  = RDH_RECTANGLES;
     322  me->lpRgnData->rdh.nCount = 1;
     323  me->lpRgnData->rdh.nRgnSize = sizeof(RECT);
     324  //TODO: Do we need to return the window rectangle or the client
     325  //      rectangle converted to screen coordinates??????
     326  GetWindowRect(me->clipWindow, &me->lpRgnData->rdh.rcBound);
     327  RECT *rect = (RECT *)&me->lpRgnData->Buffer;
     328  *rect = me->lpRgnData->rdh.rcBound;
     329#endif
     330
     331  return(DD_OK);
     332}
     333//******************************************************************************
     334//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.