dsrc isn't necessary for this repo
[client-tools.git] / src / external / 3rd / application / UiBuilder / UIDirectDrawPrimaryCanvas.cpp
blob3d30b20af6a4d60be94f7375c4311899576b8b1b
1 #include "FirstUiBuilder.h"
2 #include "UIDirectDrawPrimaryCanvas.h"
4 UIDirectDrawPrimaryCanvas::UIDirectDrawPrimaryCanvas( const UISize &Size, HWND NewWindow ) : UIDirectDrawCanvas( Size )
6 mWindow = NewWindow;
9 UIDirectDrawPrimaryCanvas::~UIDirectDrawPrimaryCanvas()
13 bool UIDirectDrawPrimaryCanvas::IsA( const UITypeID Type ) const
15 return (Type == TUIDirectDrawPrimaryCanvas) || UIDirectDrawCanvas::IsA( Type );
18 bool UIDirectDrawPrimaryCanvas::Generate( void ) const
20 if( !mSurface )
22 LPDIRECTDRAWSURFACE7 CreatedSurface;
23 LPDIRECTDRAWCLIPPER SurfaceClipper;
24 DDSURFACEDESC2 ddsd = { sizeof( ddsd ) };
25 HRESULT hr;
27 ddsd.dwFlags = DDSD_CAPS;
28 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
30 hr = gDirectDraw->CreateSurface( &ddsd, &CreatedSurface, 0 );
32 if( FAILED( hr ) )
33 return false;
35 hr = gDirectDraw->CreateClipper( 0, &SurfaceClipper, 0 );
37 if( FAILED( hr ) )
39 assert( false );
41 CreatedSurface->Release();
42 return false;
45 hr = SurfaceClipper->SetHWnd( 0, mWindow );
47 if( FAILED( hr ) )
49 assert( false );
51 SurfaceClipper->Release();
52 CreatedSurface->Release();
53 return false;
56 hr = CreatedSurface->SetClipper( SurfaceClipper );
58 if( FAILED( hr ) )
60 assert( false );
62 SurfaceClipper->Release();
63 CreatedSurface->Release();
64 return false;
67 SurfaceClipper->Release();
69 const_cast<UIDirectDrawPrimaryCanvas *>( this )->SetSurface( CreatedSurface );
71 else if( mSurface->IsLost() )
73 if( FAILED( mSurface->Restore() ) )
74 return false;
76 return true;