Exemple #1
0
LOCAL void Slider_Paint (HWND hWindow, HDC hDC, LPRECT lpRect, BOOL fHighlight)
/***********************************************************************/
{
	BOOL	bHasFocus, bSelected, bDown;
	DWORD	dwStyle;
	RECT	rSrcArea, rDstArea;
	POINT	ptDst;
	UINT	id;
	PDIB	pdibSrc, pdibDst;
	HDC		hWinGDC;

	LPHSLIDERINFO lpInfo;
	if (! (lpInfo = (LPHSLIDERINFO)GetWindowLong (hWindow, GWL_DATAPTR) ) )
		return;

	rSrcArea = *lpRect;
	rDstArea = *lpRect;
	MapWindowPoints (hWindow, GetParent(hWindow), (LPPOINT)& rDstArea, 2 );

	LPSCENE lpScene = CScene::GetScene (GetParent (hWindow) );
	if (! lpScene)
		return;

	if ( !lpScene->GetDIBs( &pdibSrc, &pdibDst, &hWinGDC ) )
		return;
	if ( !pdibSrc || !pdibDst || !hWinGDC )
		return;

	bSelected = GetWindowWord (hWindow, GWW_STATE);
	dwStyle = GetWindowLong (hWindow, GWL_STYLE);
	bHasFocus = (GetFocus () == hWindow);
	bDown = ( bSelected || (lpInfo->bTrack && lpInfo->bInRect && bHasFocus) );

	// Repair the dirty bitmap with the clean bitmap
	if ( pdibSrc->GetCompression() == BI_RLE8 ||
		 pdibDst->GetCompression() == BI_RLE8)
	{ // compressed DIBs must use GDI copying (lose transparency ability)
		pdibSrc->DCBlt( hWinGDC,
						rDstArea.left, rDstArea.top,
						rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
						rDstArea.left, rDstArea.top,
						rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top );
	}
	else
	{
		pdibSrc->DibBlt( pdibDst,
						rDstArea.left, rDstArea.top,
						rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
						rDstArea.left, rDstArea.top,
						rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
						NO /*bTransparent*/ );
	}

	// Draw the slider background
	RECT rSlider = lpInfo->rSlider;
	RECT rInner = lpInfo->rSlider;
	rInner.top = lpInfo->iCenter - (lpInfo->iTrackWidth / 2);
	rInner.bottom = lpInfo->iCenter + (lpInfo->iTrackWidth / 2);
	MapWindowPoints (hWindow, GetParent(hWindow), (LPPOINT)& rSlider, 2);
	MapWindowPoints (hWindow, GetParent(hWindow), (LPPOINT)& rInner, 2);

	// Turn off tick painting because using background bitmap
	#ifdef UNUSED
	HBRUSH hBrush = CreateSolidBrush (lpInfo->rgbBackgnd);
	HBRUSH hBrush2 = (HBRUSH)GetStockObject (BLACK_BRUSH);

	FillRect (hWinGDC, & rSlider, hBrush);
	FillRect (hWinGDC, & rInner, hBrush2);
	DeleteObject (hBrush);
	#endif

	RECT	rClient;
	GetClientRect (hWindow, & rClient);
	MapWindowPoints (hWindow, GetParent(hWindow), (LPPOINT)& rClient, 2 );

	// Turn off tick painting because using background bitmap
	#ifdef UNUSED
	// Draw a chiselled border
	RECT	rBorder = rClient;
	InflateRect (& rBorder, 1, 1);
	int cxButton = rBorder.right - rBorder.left;
	int cyButton = rBorder.bottom - rBorder.top;			   
	HPEN hLitePen = CreatePen (PS_SOLID, 1, RGB (255, 255, 255));
	HPEN hDarkPen = CreatePen (PS_SOLID, 1, RGB (128, 128, 128));
	HPEN hOldPen = (HPEN)SelectObject (hWinGDC, hLitePen);

	MoveToEx (hWinGDC, rBorder.left, rBorder.bottom - 1, NULL);
	LineTo (hWinGDC, rBorder.left, rBorder.top);
	LineTo (hWinGDC, rBorder.right - 1, rBorder.top);
	
	MoveToEx (hWinGDC, rBorder.left + 1, rBorder.bottom - 2, NULL);
	LineTo (hWinGDC, rBorder.left + 1, rBorder.top + 1);
	LineTo (hWinGDC, rBorder.right - 2, rBorder.top + 1);
	
	SelectObject (hWinGDC, hDarkPen);
	MoveToEx (hWinGDC, rBorder.right - 1, rBorder.top, NULL);
	LineTo (hWinGDC, rBorder.right - 1, rBorder.bottom - 1);
	LineTo (hWinGDC, rBorder.left, rBorder.bottom - 1);
	
	MoveToEx (hWinGDC, rBorder.right - 2, rBorder.top + 1, NULL);
	LineTo (hWinGDC, rBorder.right - 2, rBorder.bottom - 2);
	LineTo (hWinGDC, rBorder.left + 1, rBorder.bottom - 2);

	SelectObject (hWinGDC, hOldPen);
	DeleteObject (hLitePen);
	DeleteObject (hDarkPen);

	// If tick-marks are wanted
	if (lpInfo->iTicks)
	{
		int pw = 2; // pen width
		HPEN hTickPen = CreatePen (PS_SOLID, pw, lpInfo->rgbBackgnd);
		hOldPen = (HPEN)SelectObject (hWinGDC, hTickPen);

		int iBmpWidth = lpInfo->rBitmap.right - lpInfo->rBitmap.left;
		int wx = rClient.right - rClient.left - iBmpWidth;
		int dx = wx / lpInfo->iTicks;
		wx = wx - (dx * lpInfo->iTicks) - pw;
		int x = rClient.left + (iBmpWidth + wx + pw) / 2; // wx is now the excess
		int y1 = rClient.top + 2;
		int y2 = y1 + 10;
		for (int idx = 0; idx <= lpInfo->iTicks ; idx++)
		{
			MoveToEx (hWinGDC, x, y1, NULL);
			LineTo (hWinGDC, x, y2);
			x += dx;
		}
		SelectObject (hWinGDC, hOldPen);
		DeleteObject (hTickPen);
	}
	#endif

	rSrcArea = lpInfo->rBitmap;
	rDstArea = lpInfo->rBitmap;
	MapWindowPoints (hWindow, GetParent(hWindow), (LPPOINT)& rDstArea, 2 );

	// Get the control ID to load the bitmap resource
	if (! (id = GetWindowWord (hWindow, GWW_ICONID) ) )
		id = GET_WINDOW_ID (hWindow);

	if (pdibSrc = CDib::LoadDibFromResource (GetWindowInstance (hWindow),
		MAKEINTRESOURCE(id), GetApp()->m_hPal, (dwStyle & BS_MASK) != 0 ))
	{ // Load the resource
		if ( pdibSrc->GetCompression() == BI_RLE8 ||
			 pdibDst->GetCompression() == BI_RLE8 )
		{ // compressed DIBs must use GDI copying (lose transparency ability)
			pdibSrc->DCBlt( hWinGDC,
						rDstArea.left, rDstArea.top,
						rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
						rSrcArea.left, rSrcArea.top,
						rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top );
		}
		else
		{
			RGBTRIPLE rgb;
			LPRGBTRIPLE lpRGB = NULL;
			if (dwStyle & BS_MASK)
			{
				STRING szColor;
				GetWindowText(hWindow, szColor, sizeof(szColor));
				AsciiRGB( szColor, &rgb );
				lpRGB = &rgb;
			}
			if (dwStyle & BS_HIGHLIGHT)
			{
				// Get the transparency color
				BYTE bTrans = *pdibSrc->GetXY(0, 0);

				// Get the color to replace
				LPTR lpColor = pdibSrc->GetXY(1, 0);
				BYTE bColor = *lpColor;
				*lpColor = bTrans;

				// Get the hightlight color
				LPTR lpHighlight = pdibSrc->GetXY(2, 0); 
				BYTE bHighlight = *lpHighlight;
				*lpHighlight = bTrans;

				// Replace the pixels in the DIB
				if (bDown && (bColor != bHighlight))
				{
					HPTR hp = pdibSrc->GetPtr();
					DWORD dwSize = pdibSrc->GetSizeImage();
					while ( dwSize-- )
					{
						if (*hp == bColor)
							*hp = bHighlight;
						++hp;
					}
				}
			}

			// Set slider position if needed
			if (lpInfo->Position)
			{
				int iBmpWidth = lpInfo->rBitmap.right - lpInfo->rBitmap.left;
				int iWidth = rClient.right - rClient.left - iBmpWidth;
				int x = (int)(((long)(lpInfo->Position - lpInfo->Min) * iWidth) / (lpInfo->Max - lpInfo->Min));
				rDstArea.left += x;
				if (rDstArea.left < rClient.left)
					rDstArea.left = rClient.left;
				else
				if (rDstArea.left + iBmpWidth > rClient.right)
					rDstArea.left = rClient.right - iBmpWidth;
				rDstArea.right = rDstArea.left + iBmpWidth;
			}

			pdibSrc->DibBlt( pdibDst,
						rDstArea.left, rDstArea.top,
						rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
						rSrcArea.left, rSrcArea.top,
						rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top,
						(dwStyle & BS_TRANSPARENT) != 0 /*bTransparent*/, lpRGB );
		}
		delete pdibSrc;
	}

	ptDst.x = rSrcArea.left;
	ptDst.y = rSrcArea.top;
	if (lpScene)
		lpScene->Paint( hDC, &rClient, &ptDst );
}
Exemple #2
0
LOCAL void Bmulti_Paint(HWND hWindow, HDC hDC, LPRECT lpRect)
/***********************************************************************/
{
	BOOL bHasFocus, bSelected, bDown;
	DWORD dwStyle;
	RECT rSrcArea, rDstArea;
	POINT ptDst;
	PDIB pdibSrc, pdibDst;
	UINT id;
	HDC hWinGDC;
	HPALETTE hLoadPal;	
	BOOL	fUseScene = TRUE;

	LPBMULTICONTINFO lpInfo;
	if (! (lpInfo = (LPBMULTICONTINFO)GetWindowLong (hWindow, GWL_DATAPTR) ) )
		return;

	rSrcArea = *lpRect;
	rDstArea = *lpRect;

	LPSCENE lpScene = CScene::GetScene(GetParent(hWindow));
	if ( !lpScene )
		return;

	if ( lpScene->GetDIBs( &pdibSrc, &pdibDst, &hWinGDC ) )
	{
		if ( !pdibDst )
			return;
		hLoadPal = GetApp()->m_hPal;
		MapWindowPoints( hWindow, GetParent(hWindow), (LPPOINT)&rDstArea, 2 );
	}
	else
		return;

	bSelected = GetWindowWord (hWindow, GWW_STATE);
	dwStyle = GetWindowLong (hWindow, GWL_STYLE);
	bHasFocus = (GetFocus() == hWindow);
	bDown = ( bSelected || (lpInfo->bTrack && lpInfo->bInRect && bHasFocus) );

	// Draw the Bitmap
	if ( !(id = GetWindowWord( hWindow, GWW_ICONID )) )
		id = GET_WINDOW_ID( hWindow );
	id += lpInfo->State;

	// Repair the dirty bitmap with the clean bitmap
	if ( pdibSrc && pdibDst )
	{
		if ( pdibSrc->GetCompression() == BI_RLE8 || pdibDst->GetCompression() == BI_RLE8)
		{ // compressed DIBs must use GDI copying (lose transparency ability)
			pdibSrc->DCBlt( hWinGDC,
						rDstArea.left, rDstArea.top,
						rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
						rDstArea.left, rDstArea.top,
						rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top );
		}
		else
		{
			pdibSrc->DibBlt( pdibDst,
						rDstArea.left, rDstArea.top,
						rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
						rDstArea.left, rDstArea.top,
						rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
						NO /*bTransparent*/ );
		}
	}

	if (pdibSrc = CDib::LoadDibFromResource( GetWindowInstance(hWindow),
		MAKEINTRESOURCE(id), hLoadPal, (dwStyle & BS_MASK) != 0 ) )
	{ // Load the resource
			// Do highlighting andf transparency
		RGBTRIPLE rgb;
		LPRGBTRIPLE lpRGB = NULL;
		if (dwStyle & BS_MASK)
		{
			STRING szColor;
			GetWindowText(hWindow, szColor, sizeof(szColor));
			AsciiRGB( szColor, &rgb );
			lpRGB = &rgb;
		}
		if (dwStyle & BS_HIGHLIGHT)
		{
			// Get the transparency color
			BYTE bTrans = *pdibSrc->GetXY(0, 0);

			// Get the color to replace
			LPTR lpColor = pdibSrc->GetXY(1, 0);
			BYTE bColor = *lpColor;
			*lpColor = bTrans;

			// Get the hightlight color
			LPTR lpHighlight = pdibSrc->GetXY(2, 0); 
			BYTE bHighlight = *lpHighlight;
			*lpHighlight = bTrans;

			// Replace the pixels in the DIB
			if (bDown && (bColor != bHighlight))
			{
				HPTR hp = pdibSrc->GetPtr();
				DWORD dwSize = pdibSrc->GetSizeImage();
				while ( dwSize-- )
				{
					if (*hp == bColor)
						*hp = bHighlight;
					++hp;
				}
			}
		}
		if ( pdibSrc->GetCompression() == BI_RLE8 || pdibDst->GetCompression() == BI_RLE8 )
		{ // compressed DIBs must use GDI copying (lose transparency ability)
			pdibSrc->DCBlt( hWinGDC,
						rDstArea.left, rDstArea.top,
						rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
						rSrcArea.left, rSrcArea.top,
						rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top );
		}
		else
		{
			pdibSrc->DibBlt( pdibDst,
						rDstArea.left, rDstArea.top,
						rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
						rSrcArea.left, rSrcArea.top,
						rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top,
						(dwStyle & BS_TRANSPARENT) != 0 /*bTransparent*/, lpRGB );
		}
		delete pdibSrc;
	}

	ptDst.x = rSrcArea.left;
	ptDst.y = rSrcArea.top;
	if (fUseScene)
		lpScene->Paint( hDC, &rDstArea, &ptDst );

}
Exemple #3
0
LOCAL void Story_OnDraw(HWND hWindow, HDC hDC, LPRECT lpRect, BOOL fHighlight)
/***********************************************************************/
{
	BOOL bHasFocus, bSelected, bDown;
	DWORD dwStyle;
	RECT rSrcArea, rDstArea;
	PTOON pToon = NULL;
	PDIB pdibSrc, pdibDst;
	LPOFFSCREEN lpOffScreen = NULL;

	if (IsRectEmpty(lpRect))
		return;
	PSTORY pStory = GetStory(hWindow);
	if (!pStory)
		return;
	if (!pStory->m_pDib)
		return;
	// Draw the Bitmap
	rSrcArea = *lpRect;
	rDstArea = *lpRect;

	LPSCENE lpScene = CScene::GetScene(GetParent(hWindow));
	if (lpScene)
		lpOffScreen = lpScene->GetOffScreen();
	if (lpOffScreen)
	{
	 	if ( !(pdibSrc = lpOffScreen->GetReadOnlyDIB()) )
			return;
		MapWindowPoints( hWindow, GetParent(hWindow), (LPPOINT)&rDstArea, 2 );
	}
	else
	{
		// see if there is a toon control
		HWND hToon = FindClassDescendent(GetParent(hWindow), "toon");
		if (!hToon)
			return;
		pToon = GetToon(hToon);
		if (!pToon)
			return;
		pdibSrc = pToon->GetStageDib();
		MapWindowPoints( hWindow, GetParent(hToon), (LPPOINT)&rDstArea, 2 );
 	}

	// create a dib to draw into
	pdibDst = new CDib();
	if (!pdibDst)
		return;
	if (!pdibDst->Create(pdibSrc->GetBitCount(),
						lpRect->right-lpRect->left,
						lpRect->bottom-lpRect->top))
	{
		delete pdibDst;
		return;
	}
	pdibDst->CopyColorTable(pdibSrc);
	
	// copy our color table into the dest dib
	dwStyle = GetWindowLong( hWindow, GWL_STYLE );
	bHasFocus = ( GetFocus() == hWindow );
	bDown = ( bSelected || (bTrack && bInRect && bHasFocus) );

	// draw in background
	pdibSrc->DibBlt( pdibDst,
					0, 0,
				 	rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
				 	rDstArea.left, rDstArea.top,
				 	rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
				 	NO /*bTransparent*/ );

	// now draw in foreground
	RGBTRIPLE rgb;
	LPRGBTRIPLE lpRGB = NULL;
	if (dwStyle & BS_MASK)
	{
		STRING szColor;
		GetWindowText(hWindow, szColor, sizeof(szColor));
		AsciiRGB( szColor, &rgb );
		if (fHighlight)
		{
			// this relies on the fact that AsciiRGB replaces commas
			// with NULL terminators
			LPTSTR lp = szColor + lstrlen(szColor) + 1; // passed red
			lp += lstrlen(lp) + 1; // passed green
			lp += lstrlen(lp) + 1; // passed blue to higlight color
			AsciiRGB(lp, &rgb);
			rgb.rgbtRed = rgb.rgbtGreen = 0; rgb.rgbtBlue = 255;
		}
		else
			rgb.rgbtRed = rgb.rgbtGreen = rgb.rgbtBlue = 0;
		lpRGB = &rgb;
	}
	pStory->m_pDib->DibBlt( pdibDst,
				0, 0,
				rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
				rSrcArea.left, rSrcArea.top,
				rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top,
				YES /*bTransparent*/, lpRGB, App.m_lpLut );

	pdibDst->DCBlt( hDC,
				rSrcArea.left, rSrcArea.top,
				rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top,
			 	0, 0,
				rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top);

	delete pdibDst;
}
Exemple #4
0
LOCAL void Meter_OnDraw(HWND hWindow, HDC hDC, LPRECT lpRect, BOOL fHighlight)
/***********************************************************************/
{
    RECT	rSrcArea, rDstArea, rControlArea;
    POINT	ptDst;
    PDIB	pdibSrc, pdibDst, pdibSrc2, pdibTmp;
    UINT	id;
    LPOFFSCREEN lpOffScreen;
    LPSCENE lpScene;
    HDC		hWinGDC;
    HPALETTE hLoadPal;

    lpScene = CScene::GetScene( GetParent(hWindow) );
    if (!lpScene)
        return;

    LPMETERCONTINFO lpInfo;
    if (!(lpInfo = (LPMETERCONTINFO)GetWindowLong(hWindow, GWL_DATAPTR) ))
        return;

    rSrcArea = * lpRect;
    rDstArea = * lpRect;
    rControlArea = * lpRect;

    lpOffScreen = lpScene->GetOffScreen();
    if (lpOffScreen)
    {
        MapWindowPoints(hWindow, GetParent(hWindow), (LPPOINT)& rDstArea, 2);
        if (!(pdibSrc = lpOffScreen->GetReadOnlyDIB() ) )
            return;
        if (!(pdibDst = lpOffScreen->GetWritableDIB() ) )
            return;
        hWinGDC = lpOffScreen->GetDC();
        hLoadPal = GetApp()->m_hPal;
    }
    else
    {
        return;
    }

    RECT	rClient;
    GetClientRect(hWindow, & rClient);
    MapWindowPoints(hWindow, GetParent(hWindow), (LPPOINT)& rClient, 2 );

    // Get the control style
    DWORD dwStyle = GetWindowStyle(hWindow);
    BOOL bVert = (dwStyle & MC_VERT) ? TRUE : FALSE ;

    // Get the control id
    if (!(id = GetWindowWord(hWindow, GWW_ICONID) ) )
        id = GET_WINDOW_ID(hWindow);

    // Refresh the background,
    // compressed DIBs must use GDI copying (lose transparency ability)
    if (pdibSrc->GetCompression() == BI_RLE8 ||
            pdibDst->GetCompression() == BI_RLE8)
    {
        pdibSrc->DCBlt(hWinGDC,
                       rDstArea.left, rDstArea.top,
                       rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
                       rDstArea.left, rDstArea.top,
                       rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top );
    }
    else
    {
        pdibSrc->DibBlt(pdibDst,
                        rDstArea.left, rDstArea.top,
                        rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
                        rDstArea.left, rDstArea.top,
                        rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
                        NO /*bTransparent*/ );
    }

    // Load the resource
    if (pdibSrc = CDib::LoadDibFromResource(GetWindowInstance(hWindow),
                                            MAKEINTRESOURCE(id), hLoadPal, (dwStyle & BS_MASK) != 0) )
    {
        if (pdibSrc2 = CDib::LoadDibFromResource(GetWindowInstance(hWindow),
                       MAKEINTRESOURCE(id + 1), hLoadPal, (dwStyle & BS_MASK) != 0) )
        {
            int iBitmapWidth = pdibSrc->GetWidth();
            int iBitmapHeight = pdibSrc->GetHeight();

            rSrcArea.left = 0;
            rSrcArea.top = 0;
            rSrcArea.right = rSrcArea.left + iBitmapWidth;
            rSrcArea.bottom = rSrcArea.top + iBitmapHeight;
            rDstArea = rClient;
            rDstArea.right = rDstArea.left + iBitmapWidth;
            rDstArea.bottom = rDstArea.top + iBitmapHeight;

            // Get the position width
            int iPosWidth;
            if (bVert)
            {
                iPosWidth = (int)( (float)iBitmapHeight *
                                   ((float)lpInfo->lPosition / ((float)lpInfo->Max - (float)lpInfo->Min)));
                iPosWidth = iBitmapHeight - iPosWidth;
            }
            else
            {
                iPosWidth = (int)( (float)iBitmapWidth *
                                   ((float)lpInfo->lPosition / ((float)lpInfo->Max - (float)lpInfo->Min)));
            }
            // compressed DIBs must use GDI copying (lose transparency ability)
            if (pdibSrc->GetCompression() == BI_RLE8 ||
                    pdibDst->GetCompression() == BI_RLE8 )
            {
                pdibSrc->DCBlt(hWinGDC,
                               rDstArea.left, rDstArea.top,
                               rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
                               rSrcArea.left, rSrcArea.top,
                               rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top);
            }
            else
            {
                RGBTRIPLE rgb;
                LPRGBTRIPLE lpRGB = NULL;
                if (dwStyle & BS_MASK)
                {
                    STRING szColor;
                    GetWindowText(hWindow, szColor, sizeof(szColor));
                    AsciiRGB(szColor, & rgb);
                    if (fHighlight)
                    {
                        // this relies on the fact that AsciiRGB replaces commas
                        // with NULL terminators
                        LPTSTR lp = szColor + lstrlen(szColor) + 1; // passed red
                        lp += lstrlen(lp) + 1; // passed green
                        lp += lstrlen(lp) + 1; // passed blue to higlight color
                        AsciiRGB(lp, & rgb);
                    }
                    lpRGB = & rgb;
                }
                // Render the first bitmap
                pdibTmp = pdibSrc;
                pdibTmp->DibBlt(pdibDst,
                                rDstArea.left, rDstArea.top,
                                rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
                                rSrcArea.left, rSrcArea.top,
                                rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top,
                                FALSE /*bTransparent*/, lpRGB);
            }

            // Adjust the source and dest rect's and render the 2nd bitmap

            if (bVert)
            {
                //rDstArea.top = rDstArea.top;// iPosWidth;
                rDstArea.bottom = rDstArea.top + iPosWidth;
                //rSrcArea.top = rSrcArea.bottom - iPosWidth;
                rSrcArea.bottom = iPosWidth;
            }
            else
            {
                rDstArea.right = rDstArea.left + iPosWidth;
                rSrcArea.right = rSrcArea.left + iPosWidth;
            }
            // compressed DIBs must use GDI copying (lose transparency ability)
            if (pdibSrc->GetCompression() == BI_RLE8 ||
                    pdibDst->GetCompression() == BI_RLE8 )
            {
                pdibSrc->DCBlt(hWinGDC,
                               rDstArea.left, rDstArea.top,
                               rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
                               rSrcArea.left, rSrcArea.top,
                               rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top);
            }
            else
            {
                RGBTRIPLE rgb;
                LPRGBTRIPLE lpRGB = NULL;
                if (dwStyle & BS_MASK)
                {
                    STRING szColor;
                    GetWindowText(hWindow, szColor, sizeof(szColor));
                    AsciiRGB(szColor, & rgb);
                    if (fHighlight)
                    {
                        // this relies on the fact that AsciiRGB replaces commas
                        // with NULL terminators
                        LPTSTR lp = szColor + lstrlen(szColor) + 1; // passed red
                        lp += lstrlen(lp) + 1; // passed green
                        lp += lstrlen(lp) + 1; // passed blue to higlight color
                        AsciiRGB(lp, & rgb);
                    }
                    lpRGB = & rgb;
                }
                // Render the first bitmap
                pdibTmp = pdibSrc2;
                pdibTmp->DibBlt(pdibDst,
                                rDstArea.left, rDstArea.top,
                                rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
                                rSrcArea.left, rSrcArea.top,
                                rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top,
                                FALSE /*bTransparent*/, lpRGB);

            }
        }
        delete pdibSrc;
        delete pdibSrc2;
    }

    ptDst.x = rControlArea.left;
    ptDst.y = rControlArea.top;
    if (lpOffScreen)
    {
        lpOffScreen->DrawRect(hDC, & rClient, & ptDst);
    }
}
Exemple #5
0
LOCAL void Story_OnDraw(HWND hWindow, HDC hDC, LPRECT lpRect, BOOL fHighlight)
/***********************************************************************/
{
	BOOL bHasFocus, bSelected, bDown;
	DWORD dwStyle;
	RECT rSrcArea, rDstArea;
	POINT ptDst;
	PDIB pdibSrc, pdibDst, pDib;
	LPOFFSCREEN lpOffScreen;
	PTOON pToon;
	LPSCENE lpScene;
	PSTORY pStory;
	RGBQUAD rgbQuad[256];
	BITMAPINFOHEADER bmi;
	LPTR lp;
	HDC hWinGDC;
	HPALETTE hWinGPal = NULL, hDisplayPal = NULL, hOldPal;

	if (IsRectEmpty(lpRect))
		return;
	pStory = GetStory(hWindow);
	if (!pStory)
		return;
	if (!pStory->m_pDib)
		return;
	lpScene = CScene::GetScene(GetParent(hWindow));
	if (!lpScene)
		return;

	rSrcArea = *lpRect;
	rDstArea = *lpRect;
	bSelected = GetWindowWord(hWindow, GWW_STATE );
	dwStyle = GetWindowLong( hWindow, GWL_STYLE );
	bHasFocus = ( GetFocus() == hWindow );
	bDown = ( bSelected || (bTrack && bInRect && bHasFocus) );

	lpOffScreen = lpScene->GetOffScreen();
	if (lpOffScreen)
	{
		MapWindowPoints( hWindow, GetParent(hWindow), (LPPOINT)&rDstArea, 2 );
 		if ( !(pdibSrc = lpOffScreen->GetReadOnlyDIB()) )
			return;
		if ( !(pdibDst = lpOffScreen->GetWritableDIB()) )
			return;
		hWinGDC = lpOffScreen->GetDC();
		hWinGPal = hDisplayPal = GetApp()->m_hPal;
	}
	else
	{
		// fix
		HWND hToon = FindClassDescendent(GetParent(hWindow), "toon");
		if (!hToon)
			return;
		pToon = GetToon(hToon);
		if (!pToon)
			return;
		MapWindowPoints( hWindow, pToon->GetWindow(), (LPPOINT)&rDstArea, 2 );
		pdibSrc = pToon->GetStageDib();
		lp = ToonGetDIBPointer(pToon->GetToonHandle(), &bmi);
		ToonGetColors(pToon->GetToonHandle(), 0, 256, rgbQuad);
		bmi.biClrUsed = 256;
		pdibDst = new CDib(&bmi, rgbQuad, lp);
		if (!pdibDst)
			return;
		hWinGDC = ToonDC(pToon->GetToonHandle());
		// to make sure we don't change the system palette
		hDisplayPal = CopySystemPalette();
		// to match WinG dib
		hWinGPal = CreateCustomPalette(rgbQuad, 256);
	}

	if (!pStory->m_fMappedToPalette && ((dwStyle & BS_MASK) == 0))
	{
		pStory->m_pDib->MapToPalette(hWinGPal);
		pStory->m_fMappedToPalette = TRUE;
	}


	// Copy source dib so we can twiddle its bits
	pDib = new CDib();
	if (!pDib)
	{
		if (!lpOffScreen && hDisplayPal)
			DeleteObject(hDisplayPal);
		if (!lpOffScreen && hWinGPal)
			DeleteObject(hWinGPal);
		return;
	}
	if (!pDib->Create(pStory->m_pDib->GetBitCount(),
						lpRect->right-lpRect->left,
						lpRect->bottom-lpRect->top))
	{
		delete pDib;
		if (!lpOffScreen && hDisplayPal)
			DeleteObject(hDisplayPal);
		if (!lpOffScreen && hWinGPal)
			DeleteObject(hWinGPal);
		return;
	}
	pDib->CopyColorTable(pStory->m_pDib);
	// draw in source bitmap
	pStory->m_pDib->DibBlt( pDib,
					0, 0,
				 	rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top,
				 	rSrcArea.left, rSrcArea.top,
				 	rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top,
				 	NO /*bTransparent*/ );
	
	if ( pdibSrc->GetCompression() == BI_RLE8 ||
		 pdibDst->GetCompression() == BI_RLE8)
	{ // compressed DIBs must use GDI copying (lose transparency ability)
		pdibSrc->DCBlt( hWinGDC,
						rDstArea.left, rDstArea.top,
					 	rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
						rDstArea.left, rDstArea.top,
					 	rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top );
	}
	else
	{
		pdibSrc->DibBlt( pdibDst,
						rDstArea.left, rDstArea.top,
					 	rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
					 	rDstArea.left, rDstArea.top,
					 	rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
					 	NO /*bTransparent*/ );
	}

	if ( pDib->GetCompression() == BI_RLE8 ||
		 pdibDst->GetCompression() == BI_RLE8 )
	{ // compressed DIBs must use GDI copying (lose transparency ability)
		pDib->DCBlt( hWinGDC,
					rDstArea.left, rDstArea.top,
					rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
					rSrcArea.left, rSrcArea.top,
					rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top );
	}
	else
	{
		RGBTRIPLE rgb;
		LPRGBTRIPLE lpRGB = NULL;
		if (dwStyle & BS_MASK)
		{
			STRING szColor;
			GetWindowText(hWindow, szColor, sizeof(szColor));
			AsciiRGB( szColor, &rgb );
			if (fHighlight)
			{
				// this relies on the fact that AsciiRGB replaces commas
				// with NULL terminators
				LPTSTR lp = szColor + lstrlen(szColor) + 1; // passed red
				lp += lstrlen(lp) + 1; // passed green
				lp += lstrlen(lp) + 1; // passed blue to higlight color
				AsciiRGB(lp, &rgb);
				rgb.rgbtRed = rgb.rgbtGreen = 0; rgb.rgbtBlue = 255;
			}
			else
				rgb.rgbtRed = rgb.rgbtGreen = rgb.rgbtBlue = 0;
			lpRGB = &rgb;
		}
		else
		{
			BYTE bTrans = *pStory->m_pDib->GetXY(0, 0);
			LPTR lpColor = pStory->m_pDib->GetXY(1, 0);
			LPTR lpHighlight = pStory->m_pDib->GetXY(2, 0); 
			BYTE bColor = *lpColor;
			BYTE bHighlight = *lpHighlight;
			// if highlight color is the transparent color then
			// we are hiding and showing highlighted area
			// if not, then we are changing the color of highlighted area
			if (bHighlight == bTrans)
			{
				// we need to strip off highlight info if we are not
				// highlighted
				if (!fHighlight && (bColor != bTrans))
				{
					HPTR hp = pDib->GetPtr();
					DWORD dwSize = pDib->GetSizeImage();
					while (dwSize)
					{
						if (*hp != bColor)
							*hp = bTrans;
						++hp;
						--dwSize;
					}
				}
			}
			else
			{
				// we need to change the color if we are highlighted
				if (fHighlight && (bColor != bHighlight) && (bColor != bTrans))
				{
					HPTR hp = pDib->GetPtr();
					DWORD dwSize = pDib->GetSizeImage();
					while (dwSize)
					{
						if (*hp == bColor)
							*hp = bHighlight;
						++hp;
						--dwSize;
					}
				}
			}
		}
		pDib->DibBlt( pdibDst,
					rDstArea.left, rDstArea.top,
					rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
					0, 0,
					rSrcArea.right - rSrcArea.left, rSrcArea.bottom - rSrcArea.top,
					YES/*bTransparent*/, lpRGB, NULL, hWinGPal );
	}
	delete pDib;

	ptDst.x = rSrcArea.left;
	ptDst.y = rSrcArea.top;
	if (lpOffScreen)
	{
		lpOffScreen->DrawRect( hDC, &rDstArea, &ptDst );
	}
	else
	{
		//if (hDisplayPal)
		//{
		//	hOldPal = SelectPalette(hDC, hDisplayPal, FALSE);
		//	RealizePalette(hDC);
		//}
		//pdibDst->DCBlt( hDC,
		//	ptDst.x, ptDst.y,
		//	rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
		//	rDstArea.left, rDstArea.top,
		//	rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top );
		WinGStretchBlt( hDC,
			ptDst.x, ptDst.y,
			rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top,
			hWinGDC,
			rDstArea.left, rDstArea.top,
			rDstArea.right - rDstArea.left, rDstArea.bottom - rDstArea.top );
		//if (hDisplayPal)
	    //{
		//	SelectPalette(hDC, hOldPal, TRUE);
	   	//	DeleteObject(hDisplayPal);
		//}
		if (hWinGPal)
			DeleteObject(hWinGPal);
	}
}