Page 1 of 1

Special effects with Alpha-Blended Bitmaps

Posted: Mon May 26, 2008 8:39 pm
by ukoenig
Hello,

I want to use the Alpha-BMP's for special effects
I use it on dialog-infos
It is a combination of "normal" and Alpha-Bitmaps

Fire
Image

Glow
Image

Shadow
Image

I have to adjust the Alpha-Bitmap, but in the function
ABPaint is nothing to define bottom and right
only top and left.
How can i adjust a Alpha-Bitmap ( stretch ) ?

ABPaint( hDC, 2, 2, oBmp2:hBitmap, 255 )

Regards

Uwe

Posted: Mon May 26, 2008 11:02 pm
by Antonio Linares
Uwe,

ABPaint() automatically calculates the dimensions of the bitmap.

Why Resizing Alpha-Blended-Bitmaps

Posted: Tue May 27, 2008 8:36 am
by ukoenig
The reason for resizing :
It works with different levels.

1. The resource with the dimension
Image

2. A normal BMP from resource resized and filled
with background and text
Image

3. Result from No. 2
Image

aRect := GETCLIENTRECT( oBmp:hWnd )
nGRADIENT := Gradient( hDC, aRect, nVColor, nBColor, .T. )
oBmp:oBrush := TBrush():New( , nGRADIENT )
SetBkMode( oBmp:hDC, 0 )
FillRect( hDC, aRect, oBmp:oBrush:hBrush )

4. A constructed Alphablended BMP
has to be resized and calculated, to fit as background No. 3
Without resizing, a have to create allways a extra Alpha-BMP
with the dimension for No. 3

Image

5. The End-result
Image

Regards
Uwe

Posted: Tue May 27, 2008 9:15 am
by Antonio Linares
Uwe,

We can add more parameters to ABPaint() if you need them

Alpha-BMP

Posted: Tue May 27, 2008 9:42 am
by ukoenig
Antonio, thank you very much

To have Bottom and Right as well,
like the other BMP's, i could design a frame.
Then there are still other things possible.

Just a underline

Image

Code: Select all

FUNCTION ONPAINT(oDlg1,hDC,oBmp,nVColor, nBColor,nColor,cText, ;
                             oBFont,nPOSLEFT, nEND, nORIENT,cBRUSH, nPEN ) 
LOCAL hOldFont, oNewbrush, hBitmap, aRect, oBmp1, nTOP, nLEFT
LOCAL oBmp2, nCENTER

hOldFont := SelectObject( hDC, oBFont:hFont )

nTXTLG :=  GettextWidth( hDC, cText ) 

nBMPLONG  := oBmp:Super:nWidth() 
nBMPHIGHT := oBmp:Super:nHeight() 
nFONTHIGHT := e_oBfont1:nInpHeight * -1 
IF nPOSLEFT = 0
	nLEFT := (nBMPLONG - nTXTLG) / 2
ELSE
        nLEFT := nPOSLEFT
ENDIF
nNEWHIGHT := nFONTHIGHT

nTOP := (nBMPHIGHT - nNEWHIGHT) / 2

aRect := GETCLIENTRECT( oBmp:hWnd )

nGRADIENT := Gradient( hDC, aRect, nVColor, nBColor, .T. )  // .T.  Horizontal
oBmp:oBrush := TBrush():New( , nGRADIENT )  

SetTextColor( hDC,nColor)
SetBkMode( oBmp:hDC, 0 )

FillRect( hDC, aRect, oBmp:oBrush:hBrush )

TextOut( hDC, nTOP, nLEFT, cText )
SelectObject( hDC, hOldFont ) 

// A simple border
// --------------------
IF nPEN > 0
	DRAWBOX( aRect, hDC, nColor, nBMPLONG, nBMPHIGHT, B_PEN ) 
ENDIF

// Alphablended underline-bmp
// -------------------------------------
DEFINE BITMAP oBmp2 FILENAME "Underline.bmp"

// We have to get the DC from the dialog.
// Then we have to paint the underline-bmp in relation to
// the < dialog-info-BMP-position >
// The position of the BMP-resource comes from
// TControl  oBmp:nTop  and  oBmp:nLeft
// now we can calculate the needed position for the
// underline-BMP

The needed dimensions from TControl :
The Top- and Left-position of a resource inside of a dialog

Image

Code: Select all

nBlendTop := oBmp:nTop + nBMPHIGHT + 10 
nBlendLeft := oBmp:nLeft - 10 
// 10 = Distance between bottom of BMP and Top of Underline-BMP
// and left position of Underline-BMP
// we still have to adjust the length and hight of the underline
// for that we need a Right and Bottom for < ABPaint >

ABPaint( oDlg1:GetDC(), Left, Top, Right, Bottom, oBmp2:hBitmap, 255 )
// 0-255 transparency level

// The new Bottom and Right are needed for adjustment to Dialog-Info
//-------------------------------------------------------------------------------

RETURN NIL


Best Regards

Uwe :lol: