Page 1 of 2

SHAPE & TRANSPARENT Clause using TsButton

Posted: Sat Nov 18, 2006 3:55 pm
by reinaldocrespo
Hi,

When using the SHAPE clause with TsButton I get an annoying border when the dialog that contains the button has some kind of background color.

Antonio suggested to fix the tsbutton class using FWTransBmp() function and showed the code below as called from FW Tbitmap Class:

Code: Select all

            hBmpOld = SelectObject( ::hDC, ::hBitmap ) 
            nZeroZeroClr = GetPixel( ::hDC, 0, 0 ) 
            SelectObject( ::hDC, hBmpOld ) 
            nOldClr = SetBkColor( ::hDC, nRGB( 255, 255, 255 ) ) 
            TransBmp( ::hBitmap, ::nWidth(), ::nHeight(), nZeroZeroClr, ::hDC,; 
                      ::nX, ::nY, Super:nWidth(), Super:nHeight() ) 
            SetBkColor( ::hDC, nOldClr )          
Here's an image of the annoying border I'm referring to:
Image

Perhaps someone has already patch Tsbutton to work with transparencies and would like to share the code or show how?


Reinaldo.

Posted: Sat Nov 18, 2006 4:56 pm
by reinaldocrespo
I get the same ill effect when using TbtnBmp class:

Image

here is the code:

Code: Select all

	REDEFINE BTNBMP aoBtns[ 1 ] ID 170 OF oDlg RESOURCE "Save48" TOOLTIP "Save to Disk" NOBORDER ACTION SavePatient( odbf, oFld )
	REDEFINE BTNBMP aoBtns[ 2 ] ID 240 OF oDlg RESOURCE "Exit48" TOOLTIP "Exit" NOBORDER ACTION odlg:end()
	aoBtns[ 1 ]:ltransparent := .t.
	aoBtns[ 2 ]:ltransparent := .t.
Any ideas?

Reinaldo.

Posted: Sat Nov 18, 2006 8:10 pm
by Antonio Linares
Reinaldo,

Make this change in Class TBtnBmp:

Code: Select all

   ...
   local hBmpOld, nZeroZeroClr, nOldClr 
   ...
   if ::lTransparent
      hBmpOld = SelectObject( ::hDC, ::hBitmap1 )
      nZeroZeroClr = GetPixel( ::hDC, 0, 0 )
      SelectObject( ::hDC, hBmpOld )
      nOldClr = SetBkColor( ::hDC, nRGB( 255, 255, 255 ) )
      TransBmp( ::hBitmap1, nBmpWidth( ::hBitmap1 ), nBmpHeight( ::hBitmap1 ), nZeroZeroClr, ::hDC,;
                If( ::lPressed, 2, 1 ), If( ::lPressed, 2, 1 ),;
                nBmpWidth( ::hBitmap1 ), nBmpHeight( ::hBitmap1 ) )
      SetBkColor( ::hDC, nOldClr )          
   else   
      PalBtnPaint( ::hWnd, ::hBitmap1, ::hPalette1, ::hBitmap2, ::hPalette2,;
                   ::hBitmap3, ::hPalette3, ::lPressed, ::lAdjust, ::lBorder,;
                   ::oPopup != nil, ::nClrPane,  ::cCaption, ::nLayout,;
                   If( ::oFont != nil, ::oFont:hFont, 0 ), ::nClrText, ::hDC )
   endif             
Image

Posted: Sat Nov 18, 2006 8:45 pm
by reinaldocrespo
Antonio;

Better. But still. The problem is that I have a grading effect on the background.

Code: Select all

      nZeroZeroClr = GetPixel( ::hDC, 0,0 )
Seems to be taking the color information from the top pixel on the dialog and not from where the actual bmp is to be displayed. I tried using ::ntop, ::nleft; but it made it worse.

Any other idea?

Reinaldo.

Posted: Sat Nov 18, 2006 11:04 pm
by Antonio Linares
Reinaldo,

nZeroZeroClr is the color of the bitmap at 0, 0, used to build a mask to do the transparency.

TransBmp() should paint ok on a gradient. How does it looks ? Please post an image.

Posted: Sun Nov 19, 2006 7:14 pm
by reinaldocrespo
Antonio;

Thank you so much for your interest and for answering every question.

Below is a screen shoot. Notice how the border around the btnbmp is painted with the pixel color of the first leftmost pixel.

Image

Reinaldo

Posted: Sun Nov 19, 2006 9:48 pm
by Antonio Linares
Reinaldo,

How are you painting the gradient ?

Is it a brush ?

Posted: Sun Nov 19, 2006 10:01 pm
by reinaldocrespo
Yes, it is a brush.

Code: Select all

	DEFINE BRUSH oBrush RESOURCE "Bckg"
	DEFINE DIALOG oDlg NAME ... ;
	ICON oIcon OF oOwner TRANSPARENT BRUSH oBrush

Reinaldo.

Posted: Sun Nov 19, 2006 10:17 pm
by Antonio Linares
Reinaldo,

Please email me the brush file, thanks

Posted: Mon Nov 20, 2006 9:29 am
by Antonio Linares
Reinaldo,

Please remove this line from Class TBtnBmp Method Paint():

FillRect( ::hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )

Posted: Mon Nov 20, 2006 2:35 pm
by reinaldocrespo
Antonio;

After commenting that line, here is what I get:

Image

Reinaldo.

Posted: Mon Nov 20, 2006 7:19 pm
by Antonio Linares
Reinaldo,

This should be the right code:

Code: Select all

   if ::lTransparent .and. ! Empty( ::oBrush:hBitmap ) 
      SetBrushOrgEx( ::hDC, nBmpWidth( ::oBrush:hBitmap ) - ::nLeft, nBmpHeight( ::oBrush:hBitmap ) - ::nTop ) 
   endif 
   FillRect( ::hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )

Posted: Mon Nov 20, 2006 7:27 pm
by reinaldocrespo
YES!!!!

Thank you.


Reinaldo.

Pregunta sobre btnbmp

Posted: Thu Nov 30, 2006 6:49 am
by ricardog
Sr. Linares

Al hacer las correcciones a la clase TbtnBmp, (como ud. le sugiere al sr. reinaldo), los bitmaps los coloca en la parte superior izquierda, ademas de borrar el texto del boton.

Me podria ayudar con este detalle. (tambien utilizo degradados)


Por su atencion gracias

Posted: Thu Nov 30, 2006 7:29 am
by Antonio Linares
Ricardo,

Puedes proporcionar un pequeño ejemplo de como lo haces ? gracias