SHAPE & TRANSPARENT Clause using TsButton

User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

SHAPE & TRANSPARENT Clause using TsButton

Post 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.
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Post 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.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Post 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.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Reinaldo,

How are you painting the gradient ?

Is it a brush ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Post 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.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Reinaldo,

Please email me the brush file, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Reinaldo,

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

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

Antonio Linares
www.fivetechsoft.com
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Post by reinaldocrespo »

Antonio;

After commenting that line, here is what I get:

Image

Reinaldo.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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 )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Post by reinaldocrespo »

YES!!!!

Thank you.


Reinaldo.
ricardog
Posts: 149
Joined: Tue Oct 11, 2005 3:10 pm

Pregunta sobre btnbmp

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Ricardo,

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

Antonio Linares
www.fivetechsoft.com
Post Reply