Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Transparent text with TextOut or ScriptTextOut


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 anders211   Members   -  Reputation: 202

Like
0Likes
Like

Posted 21 December 2012 - 12:57 PM

I have had a problem but I solved it. This is the solution which tell You how to set transparency to the background window.

The solution depends on ivoking twice BitBlt operation. First time when copying current background window into HDC of our bitmap and secondly when You write the text into bitmap and copy them back to HDC of window.

 

 

 

 

HRESULT Buffer::drawText(i32 x, i32 y, RECT* rect)
{
/*HRESULT hr = ScriptTextOut(hdc
_In_ const HDC hdc,
_Inout_ SCRIPT_CACHE *psc,
_In_ int x,
_In_ int y,
_In_ UINT fuOptions,
_In_opt_ const RECT *lprc,
_In_ const SCRIPT_ANALYSIS *psa,
_In_ const WCHAR *pwcReserved,
_In_ int iReserved,
_In_ const WORD *pwGlyphs,
_In_ int cGlyphs,
_In_ const int *piAdvance,
_In_opt_ const int *piJustify,
_In_ const GOFFSET *pGoffset*/

HDC hDC = NULL;
if(mFont.font != NULL)
hDC = mFont.font->GetDC(); //get font DC
else
{
::MessageBox(NULL, "Buffer::drawText - font not initialized", "Warning", MB_ICONWARNING);
return S_FALSE;
}

//Prepare ID3DXFont
HBITMAP hBitmapOld = (HBITMAP) SelectObject(hDC, mBitmap);
COLORREF prevBkColor = SetBkColor(hDC, 0x00FF00);
//HBRUSH hBrush = (HBRUSH)GetStockObject(NULL_BRUSH);
//HBRUSH hBrushOld = (HBRUSH)SelectObject(hDC, hBrush);
//COLORREF dcColorOld = GetDCBrushColor(hDC);
//SetDCBrushColor(hDC, 0xFF0000);
i32 prevBkMode = SetBkMode(hDC, TRANSPARENT);
COLORREF prevTextColor = SetTextColor(hDC, 0x000000);
BitBlt(hDC, rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top, GUI::hDCWin, rect->left, rect->top, SRCCOPY);

SCRIPT_CACHE scriptCache = NULL; //in: font info

//TextOutW(hDC,rect->left, rect->top, mBuffer,getTextSize()); //used for debug purposes
HRESULT hr = ScriptTextOut(hDC, &scriptCache, x, y, ETO_CLIPPED, rect, &mItems[0].a, NULL, 0, &mGlyphs[0], //ETO_OPAQUE set BkColor so don't use it
static_cast<i32>(mGlyphs.size()), &mPiAdvance[0], NULL, &mGoffset[0]); //&mPiJustify[0]
BitBlt(GUI::hDCWin, rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top, hDC, rect->left, rect->top, SRCCOPY);

ScriptFreeCache(&scriptCache);

//Restore hDC of ID3DXFont
SelectObject(hDC, hBitmapOld);
SetBkMode(hDC, prevBkMode);
//SelectObject(hDC, hBrushOld);
SetBkColor(hDC, prevBkColor);
SetTextColor(hDC, prevTextColor);
//SetDCBrushColor(hDC, dcColorOld);

return hr;
}

 



Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS