FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour SHAPE & TRANSPARENT Clause using TsButton
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Sat Nov 18, 2006 03:55 PM
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:

            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:


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


Reinaldo.
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Sat Nov 18, 2006 04:56 PM
I get the same ill effect when using TbtnBmp class:



here is the code:
	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.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Sat Nov 18, 2006 08:10 PM
Reinaldo,

Make this change in Class TBtnBmp:
   ...
   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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Sat Nov 18, 2006 08:45 PM
Antonio;

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

      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.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Sat Nov 18, 2006 11:04 PM

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
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Sun Nov 19, 2006 07:14 PM
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.



Reinaldo
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Sun Nov 19, 2006 09:48 PM

Reinaldo,

How are you painting the gradient ?

Is it a brush ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Sun Nov 19, 2006 10:01 PM
Yes, it is a brush.

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


Reinaldo.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Sun Nov 19, 2006 10:17 PM

Reinaldo,

Please email me the brush file, thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Mon Nov 20, 2006 09:29 AM

Reinaldo,

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

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Mon Nov 20, 2006 02:35 PM
Antonio;

After commenting that line, here is what I get:



Reinaldo.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Mon Nov 20, 2006 07:19 PM
Reinaldo,

This should be the right code:
   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
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Mon Nov 20, 2006 07:27 PM

YES!!!!

Thank you.

Reinaldo.

Posts: 158
Joined: Tue Oct 11, 2005 03:10 PM
Pregunta sobre btnbmp
Posted: Thu Nov 30, 2006 06:49 AM

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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
SHAPE & TRANSPARENT Clause using TsButton
Posted: Thu Nov 30, 2006 07:29 AM

Ricardo,

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

regards, saludos

Antonio Linares
www.fivetechsoft.com