// Fixes.cpp
//
// Author : David Shepherd
// Copyright (c) 2002, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Fixes.h"
void DrawDragRect(CDC &dc, LPCRECT lpRect, SIZE size, LPCRECT lpRectLast, SIZE sizeLast, HBRUSH hBrush, HBRUSH hBrushLast)
{
// first, determine the update region and select it
HRGN hRgnNew;
HRGN hRgnOutside, hRgnInside;
hRgnOutside = ::CreateRectRgnIndirect(lpRect);
RECT rect = *lpRect;
::InflateRect(&rect, -size.cx, -size.cy);
::IntersectRect(&rect, &rect, lpRect);
hRgnInside = ::CreateRectRgnIndirect(&rect);
hRgnNew = ::CreateRectRgn(0, 0, 0, 0);
::CombineRgn(hRgnNew, hRgnOutside, hRgnInside, RGN_XOR);
HBRUSH hBrushOld = NULL;
if(hBrush == NULL)
hBrush = CDCHandle::GetHalftoneBrush();
if(hBrushLast == NULL)
hBrushLast = hBrush;
HRGN hRgnLast = NULL, hRgnUpdate = NULL;
if(lpRectLast != NULL)
{
// find difference between new region and old region
hRgnLast = ::CreateRectRgn(0, 0, 0, 0);
::SetRectRgn(hRgnOutside, lpRectLast->left, lpRectLast->top, lpRectLast->right, lpRectLast->bottom);
rect = *lpRectLast;
::InflateRect(&rect, -sizeLast.cx, -sizeLast.cy);
::IntersectRect(&rect, &rect, lpRectLast);
::SetRectRgn(hRgnInside, rect.left, rect.top, rect.right, rect.bottom);
::CombineRgn(hRgnLast, hRgnOutside, hRgnInside, RGN_XOR);
// only diff them if brushes are the same
if(hBrush == hBrushLast)
{
hRgnUpdate = ::CreateRectRgn(0, 0, 0, 0);
::CombineRgn(hRgnUpdate, hRgnLast, hRgnNew, RGN_XOR);
}
}
if(hBrush != hBrushLast && lpRectLast != NULL)
{
// brushes are different -- erase old region first
SelectClipRgn(dc,hRgnLast);
GetClipBox(dc,&rect);
hBrushOld = (HBRUSH)SelectObject(dc,hBrushLast);
PatBlt(dc,rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, PATINVERT);
SelectObject(dc,hBrushOld);
hBrushOld = NULL;
}
// draw into the update/new region
SelectClipRgn(dc,hRgnUpdate != NULL ? hRgnUpdate : hRgnNew);
GetClipBox(dc,&rect);
hBrushOld = (HBRUSH)SelectObject(dc,hBrush);
PatBlt(dc,rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, PATINVERT);
// cleanup DC
if(hBrushOld != NULL)
SelectObject(dc,hBrushOld);
SelectClipRgn(dc,NULL);
DeleteObject(hRgnOutside);
DeleteObject(hRgnInside);
DeleteObject(hRgnNew);
if(hRgnLast!=NULL)
{
DeleteObject(hRgnLast);
}
if(hRgnUpdate!=NULL)
{
DeleteObject(hRgnUpdate);
}
if(hBrush!=NULL)
{
DeleteObject(hBrush);
}
}