source: trunk/src/ddraw/OS2CLIPPER.CPP@ 6823

Last change on this file since 6823 was 5820, checked in by phaller, 24 years ago

Implemented DirectDrawCreateClipper

File size: 8.1 KB
Line 
1/* $Id: OS2CLIPPER.CPP,v 1.12 2001-05-28 17:17:09 phaller Exp $ */
2
3/*
4 * DX clipper class routines
5 *
6 * Copyright 1998 Sander van Leeuwen
7 * Copyright 1999 Markus Montkowski
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12
13#include <odin.h>
14#include <memory.h>
15
16#define INITGUID
17#include "os2ddraw.h"
18#include "os2clipper.h"
19#define _OS2WIN_H
20#define FAR
21#include <misc.h>
22#include <winerror.h>
23#include <winuser.h>
24
25//******************************************************************************
26//******************************************************************************
27OS2IDirectDrawClipper::OS2IDirectDrawClipper(void) :
28 Referenced(0), lastError(DD_OK),
29 clipWindow(0)
30{
31 // this constructor creates an unassociated instance of the ddraw clipper,
32 // no ddraw object is associated
33
34 lpVtbl = &Vtbl;
35 Vtbl.AddRef = ClipAddRef;
36 Vtbl.Release = ClipRelease;
37 Vtbl.QueryInterface = ClipQueryInterface;
38 Vtbl.GetClipList = ClipGetClipList;
39 Vtbl.GetHWnd = ClipGetHWnd;
40 Vtbl.Initialize = ClipInitialize;
41 Vtbl.IsClipListChanged = ClipIsClipListChanged;
42 Vtbl.SetClipList = ClipSetClipList;
43 Vtbl.SetHWnd = ClipSetHWnd;
44
45 lpDraw = NULL;
46 // lpDraw->Vtbl.AddRef(lpDraw);
47 // hDive = lpDirectDraw->GetDiveInstance();
48 windowRect.left = windowRect.right = windowRect.top = windowRect.bottom = 0;
49}
50
51//******************************************************************************
52//******************************************************************************
53OS2IDirectDrawClipper::OS2IDirectDrawClipper(OS2IDirectDraw *lpDirectDraw) :
54 Referenced(0), lastError(DD_OK),
55 clipWindow(0)
56{
57 lpVtbl = &Vtbl;
58 Vtbl.AddRef = ClipAddRef;
59 Vtbl.Release = ClipRelease;
60 Vtbl.QueryInterface = ClipQueryInterface;
61 Vtbl.GetClipList = ClipGetClipList;
62 Vtbl.GetHWnd = ClipGetHWnd;
63 Vtbl.Initialize = ClipInitialize;
64 Vtbl.IsClipListChanged = ClipIsClipListChanged;
65 Vtbl.SetClipList = ClipSetClipList;
66 Vtbl.SetHWnd = ClipSetHWnd;
67
68 lpDraw = lpDirectDraw;
69 lpDraw->Vtbl.AddRef(lpDraw);
70 hDive = lpDirectDraw->GetDiveInstance();
71 windowRect.left = windowRect.right = windowRect.top = windowRect.bottom = 0;
72}
73//******************************************************************************
74//******************************************************************************
75OS2IDirectDrawClipper::~OS2IDirectDrawClipper()
76{
77 lpDraw->Vtbl.Release(lpDraw);
78}
79//******************************************************************************
80//******************************************************************************
81HRESULT WIN32API ClipQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
82{
83 dprintf(("DDRAW: ClipQueryInterface\n"));
84
85 *ppvObj = NULL;
86
87 if(!IsEqualGUID(riid, IID_IDirectDrawClipper) &&
88 !IsEqualGUID(riid, CLSID_DirectDrawClipper))
89//&& !IsEqualGUID(riid, IID_IUnknown))
90 return E_NOINTERFACE;
91
92 *ppvObj = This;
93
94 ClipAddRef(This);
95 return(DD_OK);
96}
97//******************************************************************************
98//******************************************************************************
99ULONG WIN32API ClipAddRef(THIS This)
100{
101 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
102
103 dprintf(("DDRAW: OS2IDirectDrawClipper::AddRef %d\n", me->Referenced+1));
104
105 return ++me->Referenced;
106}
107//******************************************************************************
108//******************************************************************************
109ULONG WIN32API ClipRelease(THIS This)
110{
111 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
112
113 dprintf(("DDRAW: OS2IDirectDrawClipper::Release %d", me->Referenced-1));
114
115 if(me->Referenced)
116 {
117 me->Referenced--;
118 if(me->Referenced == 0)
119 {
120 delete( me);
121 return(0);
122 }
123 else
124 return me->Referenced;
125 }
126 else
127 return(0);
128}
129//******************************************************************************
130//******************************************************************************
131HRESULT WIN32API ClipGetClipList(THIS This, LPRECT lpRect, LPRGNDATA lpClipList,
132 LPDWORD lpdwSize)
133{
134 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
135 HRESULT rc = DD_OK;
136
137 dprintf(("DDRAW: ClipGetClipList %x %x %x %x", This, lpRect, lpClipList, lpdwSize));
138
139 if(!lpdwSize) {
140 return DDERR_INVALIDPARAMS;
141 }
142 if(me->clipWindow)
143 {
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);
164 }
165 else { //todo!!
166 dprintf(("ClipGetClipList not complete if not associated with window!"));
167 rc = DDERR_NOCLIPLIST;
168 }
169 return rc;
170}
171//******************************************************************************
172//******************************************************************************
173HRESULT WIN32API ClipGetHWnd(THIS This, HWND FAR *pHwnd)
174{
175 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
176
177 dprintf(("DDRAW: ClipGetHWnd %x %x", This, me->clipWindow));
178
179 *pHwnd = me->clipWindow;
180 return(DD_OK);
181}
182//******************************************************************************
183//******************************************************************************
184HRESULT WIN32API ClipInitialize(THIS This, LPDIRECTDRAW lpDD, DWORD dwFlags)
185{
186 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
187
188 dprintf(("DDRAW: ClipInitialize %x %x %x", This, lpDD, dwFlags));
189
190 // check parameters
191 if (dwFlags != 0)
192 return DDERR_INVALIDPARAMS;
193
194 // check if already initialized
195 if (me->hDive != NULL)
196 return(DDERR_ALREADYINITIALIZED); // Init is done during creation see M$ Doc
197
198 // initialize this instance (created with DirectDrawCreateClipper)
199
200 if (lpDD != NULL)
201 {
202 OS2IDirectDraw *os2DD = (OS2IDirectDraw *)lpDD;
203 me->lpDraw = os2DD;
204 me->lpDraw->Vtbl.AddRef(me->lpDraw);
205 me->hDive = me->lpDraw->GetDiveInstance();
206 }
207 else
208 {
209 // we're supposed to create an independent DirectDrawClipper object
210 // now.
211 if (me->lpDraw != NULL)
212 {
213 // we're not handling this any other currently
214 return(DDERR_ALREADYINITIALIZED);
215 }
216 // else
217 // we've been independent and remain so ...
218 }
219
220 return(DD_OK);
221}
222//******************************************************************************
223//******************************************************************************
224HRESULT WIN32API ClipIsClipListChanged(THIS This, BOOL *lpbChanged)
225{
226 dprintf(("DDRAW: ClipIsClipListChanged %x %x", This, lpbChanged));
227
228 return(DD_OK);
229}
230//******************************************************************************
231//******************************************************************************
232HRESULT 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));
237
238 if(me->clipWindow) {
239 return DDERR_CLIPPERISUSINGHWND;
240 }
241 return(DD_OK);
242}
243//******************************************************************************
244//DWORD param not used in DirectX 3
245//******************************************************************************
246HRESULT WIN32API ClipSetHWnd(THIS This, DWORD reserved, HWND hwnd)
247{
248 OS2IDirectDrawClipper *me = (OS2IDirectDrawClipper *)This;
249
250 dprintf(("DDRAW: ClipSetHWnd %x %x %x", This, reserved, hwnd));
251
252 me->clipWindow = hwnd;
253 GetClientRect(hwnd, &me->windowRect);
254
255 return(DD_OK);
256}
257//******************************************************************************
258//******************************************************************************
Note: See TracBrowser for help on using the repository browser.