Page 4 of 6

Re: Bug in TBtnBmp

PostPosted: Sun Jun 29, 2014 9:50 pm
by Antonio Linares
Enrico,

Quite curious, now I tested here again and its fine :-)

Please test this Class TBtnBmp Method Paint() (warning to other users: this is for testing only, don't use this code yet)

Code: Select all  Expand view
METHOD Paint() CLASS TBtnBmp

   local aInfo := ::DispBegin()

   local hBmp := If( ::lPressed, If( Empty( ::hBitmap2 ), If( ::lMOver .and. ;
                     ! Empty( ::hBitmap4 ), ::hBitmap4, ::hBitmap1 ),;
                     ::hBitmap2 ), If( ! IsWindowEnabled( ::hWnd ) .and. ;
                     ! Empty( ::hBitmap3 ), ::hBitmap3, If( ::lMOver .and. ;
                     ! Empty( ::hBitmap4 ), ::hBitmap4, ::hBitmap1 ) ) )

   local nBtn := If( ::lPressed, If( Empty( ::hBitmap2 ), If( ::lMOver .and. ;
                     ! Empty( ::hBitmap4 ), 4, 1 ), 2 ),;
                     If( ! IsWindowEnabled( ::hWnd ) .and. ! Empty( ::hBitmap3 ),;
                     3, If( ::lMOver .and. ! Empty( ::hBitmap4 ), 4, 1 ) ) )

   if ::lTransparent
      SetBrushOrgEx( ::hDC, nBmpWidth( ::oWnd:oBrush:hBitmap ) - ::nLeft,;
                     nBmpHeight( ::oWnd:oBrush:hBitmap ) - ::nTop )
      FillRect( ::hDC, GetClientRect( ::hWnd ), ::oWnd:oBrush:hBrush )
   else
      if Empty( ::bClrGrad )
         FillRect( ::hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )
      else
         if ::aGrad != nil
            GradientFill( ::hDC, 0, 0, ::nHeight, ::nWidth, ::aGrad() )
         endif
      endif  
   endif

   if ! Empty( hBmp )
      if ::lBmpTransparent
         if SetAlpha() .and. ::aAlpha[ nBtn ]
            ABPaint( ::hDC, If( ::lPressed, 1, 0 ), If( ::lPressed, 1, 0 ),;
                     hBmp, ::nAlphaLevel() )
         else
            DrawTransBmp( ::hDC, hBmp, If( ::lPressed, 1, 0 ),;
                          If( ::lPressed, 1, 0 ), ::nWidth, ::nHeight )
         endif
      else
         DrawTransBmp( ::hDC, hBmp, If( ::lPressed, 1, 0 ),;
                       If( ::lPressed, 1, 0 ), ::nWidth, ::nHeight )
      endif
   endif

   ::DispEnd( aInfo )

return nil
 

Re: Bug in TBtnBmp

PostPosted: Sun Jun 29, 2014 9:54 pm
by Antonio Linares
Enrico,

The same one modified as there is no need to call DrawTransBmp() when the bitmap is not going to be used in transparent mode:

Code: Select all  Expand view
METHOD Paint() CLASS TBtnBmp

   local aInfo := ::DispBegin()

   local hBmp := If( ::lPressed, If( Empty( ::hBitmap2 ), If( ::lMOver .and. ;
                     ! Empty( ::hBitmap4 ), ::hBitmap4, ::hBitmap1 ),;
                     ::hBitmap2 ), If( ! IsWindowEnabled( ::hWnd ) .and. ;
                     ! Empty( ::hBitmap3 ), ::hBitmap3, If( ::lMOver .and. ;
                     ! Empty( ::hBitmap4 ), ::hBitmap4, ::hBitmap1 ) ) )

   local nBtn := If( ::lPressed, If( Empty( ::hBitmap2 ), If( ::lMOver .and. ;
                     ! Empty( ::hBitmap4 ), 4, 1 ), 2 ),;
                     If( ! IsWindowEnabled( ::hWnd ) .and. ! Empty( ::hBitmap3 ),;
                     3, If( ::lMOver .and. ! Empty( ::hBitmap4 ), 4, 1 ) ) )

   if ::lTransparent
      SetBrushOrgEx( ::hDC, nBmpWidth( ::oWnd:oBrush:hBitmap ) - ::nLeft,;
                     nBmpHeight( ::oWnd:oBrush:hBitmap ) - ::nTop )
      FillRect( ::hDC, GetClientRect( ::hWnd ), ::oWnd:oBrush:hBrush )
   else
      if Empty( ::bClrGrad )
         FillRect( ::hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )
      else
         if ::aGrad != nil
            GradientFill( ::hDC, 0, 0, ::nHeight, ::nWidth, ::aGrad() )
         endif
      endif  
   endif

   if ! Empty( hBmp )
      if ::lBmpTransparent
         if SetAlpha() .and. ::aAlpha[ nBtn ]
            ABPaint( ::hDC, If( ::lPressed, 1, 0 ), If( ::lPressed, 1, 0 ),;
                     hBmp, ::nAlphaLevel() )
         else
            DrawTransBmp( ::hDC, hBmp, If( ::lPressed, 1, 0 ),;
                          If( ::lPressed, 1, 0 ), ::nWidth, ::nHeight )
         endif
      else
         DrawBitmap( ::hDC, hBmp, If( ::lPressed, 1, 0 ),;
                     If( ::lPressed, 1, 0 ), ::nWidth, ::nHeight )
      endif
   endif

   ::DispEnd( aInfo )

return nil
 

Re: Bug in TBtnBmp

PostPosted: Sun Jun 29, 2014 9:58 pm
by Enrico Maria Giordano
Antonio,

no, it doesn't work fine, sorry:

- the bitmap is expanded to fill all the button
- there is no 3d effect
- the bitmap is not centered

EMG

Re: Bug in TBtnBmp

PostPosted: Sun Jun 29, 2014 9:59 pm
by Antonio Linares
Enrico,

The above method Paint() works fine here on a window:

Image

Re: Bug in TBtnBmp

PostPosted: Sun Jun 29, 2014 10:01 pm
by Antonio Linares
Enrico,

Yes I know it, its only a test. Its not completed yet. Now I am going to use it from a dialog and there the differences start (and that is what I don't want).

thanks for your testings :-)

Re: Bug in TBtnBmp

PostPosted: Sun Jun 29, 2014 10:12 pm
by Antonio Linares
Now, on a dialog the differences begin:

Now searching why that inset border appears

Image

Re: Bug in TBtnBmp

PostPosted: Wed Jul 02, 2014 5:18 am
by Antonio Linares
Enrico,

Could you please test this Class TBtnBmp Method Paint() (warning: it is not finished yet) and let me know if the results are getting better for you ? :-)

thanks

Code: Select all  Expand view
METHOD Paint() CLASS TBtnBmp

   local aInfo := ::DispBegin()
   local nTop, nLeft

   local hBmp := If( ::lPressed, If( Empty( ::hBitmap2 ), If( ::lMOver .and. ;
                     ! Empty( ::hBitmap4 ), ::hBitmap4, ::hBitmap1 ),;
                     ::hBitmap2 ), If( ! IsWindowEnabled( ::hWnd ) .and. ;
                     ! Empty( ::hBitmap3 ), ::hBitmap3, If( ::lMOver .and. ;
                     ! Empty( ::hBitmap4 ), ::hBitmap4, ::hBitmap1 ) ) )

   local nBtn := If( ::lPressed, If( Empty( ::hBitmap2 ), If( ::lMOver .and. ;
                     ! Empty( ::hBitmap4 ), 4, 1 ), 2 ),;
                     If( ! IsWindowEnabled( ::hWnd ) .and. ! Empty( ::hBitmap3 ),;
                     3, If( ::lMOver .and. ! Empty( ::hBitmap4 ), 4, 1 ) ) )

   if ::lTransparent
      SetBrushOrgEx( ::hDC, nBmpWidth( ::oWnd:oBrush:hBitmap ) - ::nLeft,;
                     nBmpHeight( ::oWnd:oBrush:hBitmap ) - ::nTop )
      FillRect( ::hDC, GetClientRect( ::hWnd ), ::oWnd:oBrush:hBrush )
   else
      if Empty( ::bClrGrad )
         FillRect( ::hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )
      else
         if ::aGrad != nil
            GradientFill( ::hDC, 0, 0, ::nHeight, ::nWidth, ::aGrad() )
         endif
      endif  
   endif

   nTop  = ( ::nHeight / 2 ) - ( nBmpHeight( hBmp ) / 2 )
   nLeft = ( ::nWidth / 2 ) - ( nBmpWidth( hBmp ) / 2 )

   if ! Empty( hBmp )
      if ::lBmpTransparent
         if SetAlpha() .and. ::aAlpha[ nBtn ]
            ABPaint( ::hDC, nTop + If( ::lPressed, 1, 0 ),;
                     nLeft + If( ::lPressed, 1, 0 ), hBmp, ::nAlphaLevel() )
         else
            DrawTransBmp( ::hDC, hBmp, nTop + If( ::lPressed, 1, 0 ),;
                          nLeft + If( ::lPressed, 1, 0 ), nBmpWidth( hBmp ),;
                          nBmpHeight( hBmp ) )
         endif
      else
         DrawBitmap( ::hDC, hBmp, nTop + If( ::lPressed, 1, 0 ),;
                     nLeft + If( ::lPressed, 1, 0 ), nBmpWidth( hBmp ),;
                     nBmpHeight( hBmp ) )
      endif
   endif

   ::DispEnd( aInfo )

return nil

Re: Bug in TBtnBmp

PostPosted: Wed Jul 02, 2014 7:48 am
by Enrico Maria Giordano
Antonio,

yes it getting better but:

- bitmaps are not painted transparently
- 3D effect is missing
- bitmaps (on dialogs) are not centered

EMG

Re: Bug in TBtnBmp

PostPosted: Thu Jul 10, 2014 4:22 am
by Antonio Linares
Enrico,

I have finally reorganized Class TBtnBmp Method Paint() and now see how it looks :-)

Code: Select all  Expand view
METHOD Paint() CLASS TBtnBmp

   local aInfo := ::DispBegin()

   ::GetBmp()  

   if ::l2007 .or. ::l2010
      ::PaintBackGroundAs20072010()
   else  
      ::PaintBackGroundStandard()
   endif  

   ::PaintBitmap()

   ::PaintCaption()
   
   ::PaintBorder()
   
   if ::oPopup != nil
      ::PaintPopupSection()
   endif  

   ::DispEnd( aInfo )

return nil


I am sending it to you by email, in case you want to try it. Still it may miss some changes, thus I appreciate your feedback, thanks!

Re: Bug in TBtnBmp

PostPosted: Thu Jul 10, 2014 7:55 am
by Enrico Maria Giordano
Antonio,

it looks better but:

- 3D effect is missing
- bitmaps (on dialogs) are not centered

EMG

Re: Bug in TBtnBmp

PostPosted: Thu Jul 10, 2014 1:45 pm
by Antonio Linares
Enrico,

Do you mean 3D effect for buttons on dialogs ?

Re: Bug in TBtnBmp

PostPosted: Thu Jul 10, 2014 2:19 pm
by Enrico Maria Giordano
Antonio,

yes, Sir, exactly! :-)

EMG

Re: Bug in TBtnBmp

PostPosted: Thu Jul 10, 2014 11:11 pm
by Antonio Linares
Enrico,

They look like "inset", right ?

Like this one, right ?
viewtopic.php?p=161582#p161582

Re: Bug in TBtnBmp

PostPosted: Fri Jul 11, 2014 8:09 am
by Enrico Maria Giordano
Antonio,

no, the other way around. :-)

I can send you an image, if you need it.

EMG

Re: Bug in TBtnBmp

PostPosted: Sat Jul 12, 2014 9:44 am
by Antonio Linares
Enrico,

Yes, please post a screenshot, thanks