Example #1
0
bool HandleKeyPress(int (*KeyPressFunction)(int), XEvent Event, KeySym nKeySym) // true if quit pressed
{
    XLookupString (&Event.xkey, 0, 0, &nKeySym, 0);
    switch (KeyPressFunction (nKeySym))
    {
    case KEY_PRESS_NOTHING: break;
    case KEY_PRESS_EXPOSE:
	Event.type = Expose;
	Event.xexpose.count = 0;
	XSendEvent(prDisplay, nWnd, True, 0, &Event);
	break;
    case KEY_PRESS_QUIT:
	XFreePixmap(prDisplay, draw);
	FreeBitmaps(prDisplay, prPixmap);
	XFreeGC(prDisplay, prGC);
	XCloseDisplay (prDisplay);
	return true;
    }
    return false;
}
Example #2
0
BOOL CCustomToolBar::SetButtonBitmaps(LPCTSTR pszResourceName, COLORREF clTransparent, SIZE sizeButton, const UINT* lpIDArray, int nIDCount, HINSTANCE hInstance)
{
	BOOL fResult = FALSE;

	// Free any existing bitmaps.
	FreeBitmaps();

	// Sanity Check.
	ASSERT(lpIDArray != NULL);
	ASSERT(nIDCount > 0);

	TRY
	{
		if ((lpIDArray != NULL)
		 && (nIDCount > 0))
		{
			// Set the button and image sizes for the toolbar.
			// We fake the image size at the minimum value (1,1).
			// For CCustomToolBar, the button and image sizes
			// are always the same.
			ASSERT(sizeButton.cx > 7);
			ASSERT(sizeButton.cy > 6);
			CToolBar::SetSizes(sizeButton, CSize(1, 1));

			// Attempt to load the button bitmaps.
			m_pBitmap = new CBitmap;
         if (Util::LoadResourceBitmap(*m_pBitmap, pszResourceName, m_pPalette, hInstance))
			{
				// Make a copy of the button bitmap ID array.
				m_nBitmapIDCount = nIDCount;
				m_pBitmapIDArray = new UINT[m_nBitmapIDCount];
				memcpy(m_pBitmapIDArray, lpIDArray, m_nBitmapIDCount*sizeof(*lpIDArray));

				// If there's a transparent color, then we need to create a mask bitmap.
				if (clTransparent == (COLORREF)-1)
				{
					// No transparency, so no mask needed.
					m_pBitmapMask = NULL;
					fResult = TRUE;
				}
				else
				{
					// Create a monochrome mask for the button bitmap.

					// Get the bitmap dimensions.
					BITMAP Bitmap;
					if (m_pBitmap->GetBitmap(&Bitmap))
					{
						// Create a DC to hold the bitmap.
						CDC dcBitmap;
						if (dcBitmap.CreateCompatibleDC(NULL))
						{
							// Select our palette into the DC.
							CPalette* pOldPalette;
							SelectPalette(dcBitmap, pOldPalette, TRUE);

							// Select the bitmap into the DC. This will be
							// the "source" DC (color).
							CBitmap* pOldBitmap = dcBitmap.SelectObject(m_pBitmap);
							if (pOldBitmap != NULL)
							{
								// Create the monochrome bitmap for the mask.
								m_pBitmapMask = new CBitmap;
								m_pBitmapMask->CreateBitmap(Bitmap.bmWidth, Bitmap.bmHeight, 1, 1, NULL);

								// Create a DC to hold the mask bitmap.
								CDC dcBitmapMask;
								if (dcBitmapMask.CreateCompatibleDC(&dcBitmap))
								{
									// Select the mask bitmap into the DC. This will be
									// the "destination" DC (monochrome).
									CBitmap* pOldBitmapMask = dcBitmapMask.SelectObject(m_pBitmapMask);
									if (pOldBitmapMask != NULL)
									{
										// Remember the text and background colors set
										// in the source DC. We will be changing them
										// and we'll want to restore them later.
										COLORREF clOldTextColor = dcBitmap.GetTextColor();
										COLORREF clOldBkColor = dcBitmap.GetBkColor();

										// Set the background color of the source DC
										// to the color we want to used for the masked
										// areas. When the color bitmap is copied to
										// the monochrome bitmap, the pixels that match
										// the specified color will be set to 1 in the
										// mask and the other pixels will be set to 0.
										dcBitmap.SetBkColor(PaletteColor(clTransparent));

										// Copy the data. The monochrome mask will be created.
										dcBitmapMask.BitBlt(
											0,
											0,
											Bitmap.bmWidth,
											Bitmap.bmHeight,
											&dcBitmap,
											0,
											0,
											SRCCOPY);

										// Now use the monochrome mask to set all the
										// transparent pixels in the original bitmap
										// to 0's (black). The makes easy to OR the
										// color bitmap onto the destination and
										// achieve a transparent effect.
										dcBitmap.SetTextColor(RGB(255,255,255)); // 0's in mask (opaque) go to 1's
										dcBitmap.SetBkColor(RGB(0,0,0));         // 1's in mask (transparent) go to 0's

										dcBitmap.BitBlt(
											0,
											0,
											Bitmap.bmWidth,
											Bitmap.bmHeight,
											&dcBitmapMask,
											0,
											0,
											SRCAND);

										// Restore the colors we changed.
										dcBitmap.SetBkColor(clOldBkColor);
										dcBitmap.SetTextColor(clOldTextColor);

										// Select the old bitmap back in.
										dcBitmapMask.SelectObject(pOldBitmapMask);
										pOldBitmapMask = NULL;

										// Everything worked!
										fResult = TRUE;
									}

									dcBitmapMask.DeleteDC();
								}

								dcBitmap.SelectObject(pOldBitmap);
								pOldBitmap = NULL;

								// Restore the previous palette.
								DeselectPalette(dcBitmap, pOldPalette, TRUE);
							}

							dcBitmap.DeleteDC();
						}
					}
				}
			}
		}
	}
	END_TRY

	if (!fResult)
	{
		// Something did not work. Make sure any allocated memory is freed.
		FreeBitmaps();
	}

	// Redraw ourselves.
	Invalidate();

	return fResult;
}
Example #3
0
CCustomToolBar::~CCustomToolBar()
{
	// Free any allocated memory.
	FreeBitmaps();
}
IFaceposerModels::CFacePoserModel::~CFacePoserModel()
{
	FreeBitmaps();
}