Exemplo n.º 1
0
   /// <summary>Draws the specified dc.</summary>
   /// <param name="dc">dc.</param>
   /// <param name="image">image index.</param>
   /// <param name="rc">target rectangle.</param>
   /// <param name="sz">image size.</param>
   /// <param name="state">optionally ODS_DISABLED or ODS_SELECTED.</param>
   /// <returns></returns>
   BOOL  ImageListEx::Draw(CDC& dc, UINT image, CRect rc, CSize sz, UINT state /*= NULL*/)
   {
      IMAGELISTDRAWPARAMS   oDrawData;

      // Prepare
      ZeroMemory(&oDrawData, sizeof(IMAGELISTDRAWPARAMS));
      oDrawData.cbSize = sizeof(IMAGELISTDRAWPARAMS);

      // Centre icon within drawing rectangle
      CRect draw(rc.CenterPoint(), CSize(0,0));
      draw.InflateRect(sz.cx/2, sz.cy/2);

      // Set properties
      oDrawData.himl   = GetSafeHandle();
      oDrawData.i      = image;
      oDrawData.hdcDst = dc.m_hDC;
      oDrawData.x      = draw.left;
      oDrawData.y      = draw.top;
      oDrawData.fStyle = ILD_TRANSPARENT;

      // Disabled:
      if (state & ODS_DISABLED)
         oDrawData.fState  = ILS_SATURATE;
      
      // Selected:
      else if (state & ODS_SELECTED)
      {
         oDrawData.rgbFg   = CLR_DEFAULT;
         oDrawData.fStyle |= ILD_BLEND;
      }

      /// Draw icon
      return ImageList_DrawIndirect(&oDrawData);
   }
Exemplo n.º 2
0
//----------------------------------------------------------------------------------------------
// DRAW SCROBS
//----------------------------------------------------------------------------------------------
bool cScrobMgrIm :: draw_scrobs ( HDC hdc )
{
	for ( cScrobIm * s = ScrobList.pHead; s; s = s->pNext ) // draw forwards, hit-test backwards
	{
		int iIndex = s->calc_image_index ();
		s->iImageIndex = iIndex;

		if ( s != pHitScrob )
		{
			/* DEFAULT HERE */
			ImageList_SetBkColor ( s->hIL,   CLR_DEFAULT );

			/* TRANSPARENT HERE */
			BOOL iResult = ImageList_Draw ( s->hIL, iIndex, hdc, s->Pos.x, s->Pos.y, ILD_TRANSPARENT );
			UNREFERENCED_PARAMETER(iResult);
			#if 0
			IMAGELISTDRAWPARAMS ilp;
			ZeroMemory ( &ilp, sizeof(ilp) );
			ilp.cbSize = sizeof(ilp);
			ilp.himl = s->hIL;
			ilp.i = iIndex;
			ilp.hdcDst = hdc;
			ilp.x = s->Pos.x;
			ilp.y = s->Pos.y;
			ilp.xBitmap = 0;
			ilp.yBitmap = 0;
			ilp.rgbBk = CLR_NONE;
			ilp.rgbFg = CLR_NONE;
			ilp.fStyle =  ILD_ROP; // ILS_ALPHA;
			ilp.dwRop = SRCCOPY;
			ilp.fState = 0;
			ilp.Frame = 0;
			ilp.crEffect = 0; // 255;
			ImageList_DrawIndirect ( &ilp );
			#endif
		}
	}

	return true;
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: yhcflyy/ui
// TODO alter this so that only the visible columns are redrawn
// TODO this means rename controlSize to clientRect
static void drawItem(struct table *t, HDC dc, intptr_t i, LONG y, LONG height, RECT controlSize)
{
	RECT rsel;
	HBRUSH background;
	int textColor;
	WCHAR msg[100];
	RECT headeritem;
	intptr_t j;
	LRESULT xoff;
	IMAGELISTDRAWPARAMS ip;

	// TODO verify these two
	background = (HBRUSH) (COLOR_WINDOW + 1);
	textColor = COLOR_WINDOWTEXT;
	if (t->selected == i) {
		// these are the colors wine uses (http://source.winehq.org/source/dlls/comctl32/listview.c)
		// the two for unfocused are also suggested by http://stackoverflow.com/questions/10428710/windows-forms-inactive-highlight-color
		background = (HBRUSH) (COLOR_HIGHLIGHT + 1);
		textColor = COLOR_HIGHLIGHTTEXT;
		if (GetFocus() != t->hwnd) {
			background = (HBRUSH) (COLOR_BTNFACE + 1);
			textColor = COLOR_BTNTEXT;
		}
	}

	// first fill the selection rect
	// note that this already only draws the visible area
	rsel.left = controlSize.left;
	rsel.top = y;
	rsel.right = controlSize.right - controlSize.left;
	rsel.bottom = y + height;
	if (FillRect(dc, &rsel, background) == 0)
		abort();

	xoff = SendMessageW(t->header, HDM_GETBITMAPMARGIN, 0, 0);
	// now adjust for horizontal scrolling
	xoff -= t->hpos;

	// now draw the cells
	if (SetTextColor(dc, GetSysColor(textColor)) == CLR_INVALID)
		abort();
	if (SetBkMode(dc, TRANSPARENT) == 0)
		abort();
	for (j = 0; j < t->nColumns; j++) {
		if (SendMessageW(t->header, HDM_GETITEMRECT, (WPARAM) j, (LPARAM) (&headeritem)) == 0)
			abort();
		switch (t->columnTypes[j]) {
		case tableColumnText:
			rsel.left = headeritem.left + xoff;
			rsel.top = y;
			rsel.right = headeritem.right;
			rsel.bottom = y + height;
			// TODO vertical center in case the height is less than the icon height?
			if (DrawTextExW(dc, msg, wsprintf(msg, L"Item %d", i), &rsel, DT_END_ELLIPSIS | DT_LEFT | DT_NOPREFIX | DT_SINGLELINE, NULL) == 0)
				abort();
			break;
		case tableColumnImage:
			// TODO vertically center if image is smaller than text height
			// TODO same for checkboxes
			ZeroMemory(&ip, sizeof (IMAGELISTDRAWPARAMS));
			ip.cbSize = sizeof (IMAGELISTDRAWPARAMS);
			ip.himl = t->checkboxes;//t->imagelist;
			ip.i = (i%8);//0;
			ip.hdcDst = dc;
			ip.x = headeritem.left + xoff;
			ip.y = y;
			ip.cx = 0;		// draw whole image
			ip.cy = 0;
			ip.xBitmap = 0;
			ip.yBitmap = 0;
			ip.rgbBk = CLR_NONE;
			ip.fStyle = ILD_NORMAL | ILD_SCALE;		// TODO alpha-blend; ILD_DPISCALE?
			// TODO ILS_ALPHA?
			if (ImageList_DrawIndirect(&ip) == 0)
				abort();
			break;
		case tableColumnCheckbox:
			// TODO replace all this
			rsel.left = headeritem.left + xoff;
			rsel.top = y;
			rsel.right = rsel.left + t->checkboxWidth;
			rsel.bottom = rsel.top + t->checkboxHeight;
			if (SetDCBrushColor(dc, RGB(255, 0, 0)) == CLR_INVALID)
				abort();
			if (FillRect(dc, &rsel, GetStockObject(DC_BRUSH)) == 0)
				abort();
			break;
		}
		if (t->selected == i && t->focusedColumn == j) {
			rsel.left = headeritem.left;
			rsel.top = y;
			rsel.right = headeritem.right;
			rsel.bottom = y + height;
			if (DrawFocusRect(dc, &rsel) == 0)
				abort();
		}
	}
}
void CXTPSkinObjectToolBar::DrawButtonImage(CDC* pDC, int x, int y, int nIndex)
{
	CToolBarCtrl* pToolBar = (CToolBarCtrl*)this;

	TBBUTTON tbb;
	pToolBar->GetButton(nIndex, &tbb);

	int state = tbb.fsState;
	int nHot = (int)pToolBar->SendMessage(TB_GETHOTITEM);
	BOOL fHotTrack = nHot == nIndex;
	int iIndex = 0;
	int iImage = tbb.iBitmap;

	HIMAGELIST himl = 0;
	BOOL bMonoBitmap = FALSE;

	if (fHotTrack || (state & TBSTATE_CHECKED))
	{
		himl   = GetImageList(HIML_HOT, iIndex);
	}
	else if (!(state & TBSTATE_ENABLED))
	{
		himl = GetImageList(HIML_DISABLED, iIndex);
		bMonoBitmap = himl == NULL;
	}

	if (!himl)
	{
		himl = GetImageList(HIML_NORMAL, iIndex);
	}

	if (himl && (iImage != -1))
	{
		if (bMonoBitmap && IsAlphaImageList(himl))
		{
			XTP_IMAGELISTDRAWPARAMSEX imldp;

			imldp.himl = himl;
			imldp.cbSize = sizeof(imldp);
			imldp.i      = iImage;
			imldp.hdcDst = pDC->GetSafeHdc();
			imldp.x      = x;
			imldp.y      = y;
			imldp.cx     = 0;
			imldp.cy     = 0;
			imldp.xBitmap= 0;
			imldp.yBitmap= 0;
			imldp.rgbBk  = GetColor(COLOR_3DFACE);
			imldp.rgbFg  = CLR_DEFAULT;
			imldp.fStyle = ILD_TRANSPARENT;

			imldp.fState = ILS_SATURATE;
			imldp.Frame = 0;
			imldp.crEffect = 0;

			ImageList_DrawIndirect((IMAGELISTDRAWPARAMS*)&imldp);
		}
		else if (bMonoBitmap)
		{
			int iDxBitmap, iDyBitmap;
			ImageList_GetIconSize(himl, &iDxBitmap, &iDyBitmap);

			CDC dcMono;
			dcMono.CreateCompatibleDC(pDC);

			CBitmap bmp;
			bmp.Attach(CreateBitmap(iDxBitmap + 1, iDyBitmap + 1, 1, 1, 0));

			CBitmap* pOldBitmap = dcMono.SelectObject(&bmp);
			dcMono.SetTextColor(0L);

			XTP_IMAGELISTDRAWPARAMS imldp;

			PatBlt(dcMono, 0, 0, iDxBitmap + 1, iDyBitmap + 1, WHITENESS);

			imldp.cbSize = sizeof(imldp);
			imldp.himl   = himl;
			imldp.i      = iImage;
			imldp.hdcDst = dcMono.GetSafeHdc();
			imldp.x      = 0;
			imldp.y      = 0;
			imldp.cx     = 0;
			imldp.cy     = 0;
			imldp.xBitmap= 0;
			imldp.yBitmap= 0;
			imldp.rgbBk  = GetColor(COLOR_BTNFACE);
			imldp.rgbFg  = CLR_DEFAULT;
			imldp.fStyle = ILD_ROP | ILD_MASK;
			imldp.dwRop  = SRCCOPY;

			ImageList_DrawIndirect((IMAGELISTDRAWPARAMS*)&imldp);

			imldp.fStyle = ILD_ROP | ILD_IMAGE;
			imldp.rgbBk  = GetColor(COLOR_3DHILIGHT);
			imldp.dwRop  = SRCPAINT;


			ImageList_DrawIndirect((IMAGELISTDRAWPARAMS*)&imldp);


			pDC->SetTextColor(0L);
			pDC->SetBkColor(0x00FFFFFF);

			HBRUSH hbrOld = (HBRUSH)SelectObject(pDC->GetSafeHdc(), GetMetrics()->m_brTheme[COLOR_3DHILIGHT]);
			BitBlt(pDC->GetSafeHdc(), x + 1, y + 1, iDxBitmap, iDyBitmap, dcMono, 0, 0, PSDPxax);
			SelectObject(pDC->GetSafeHdc(), hbrOld);

			hbrOld = (HBRUSH)SelectObject(pDC->GetSafeHdc(), GetMetrics()->m_brTheme[COLOR_BTNSHADOW]);
			BitBlt(pDC->GetSafeHdc(), x, y, iDxBitmap, iDyBitmap, dcMono, 0, 0, PSDPxax);
			SelectObject(pDC->GetSafeHdc(), hbrOld);

			dcMono.SelectObject(pOldBitmap);
		}
		else
		{
			XTP_IMAGELISTDRAWPARAMS imldp;

			imldp.himl = himl;
			imldp.cbSize = sizeof(imldp);
			imldp.i      = iImage;
			imldp.hdcDst = pDC->GetSafeHdc();
			imldp.x      = x;
			imldp.y      = y;
			imldp.cx     = 0;
			imldp.cy     = 0;
			imldp.xBitmap= 0;
			imldp.yBitmap= 0;
			imldp.rgbBk  = GetColor(COLOR_3DFACE);
			imldp.rgbFg  = CLR_DEFAULT;
			imldp.fStyle = ILD_TRANSPARENT;

			ImageList_DrawIndirect((IMAGELISTDRAWPARAMS*)&imldp);
		}
	}
}