Page 1 of 2

New bugs in TBtnBmp

PostPosted: Wed Oct 22, 2014 6:03 pm
by Enrico Maria Giordano
1. The RIGHT clause don't work anymore without a bitmap (texts are always centered).

2. Texts are slightly shifted down.

:-(

EMG

Re: New bugs in TBtnBmp

PostPosted: Thu Oct 23, 2014 6:37 am
by Antonio Linares
Enrico,

Sorry about this. We have been introducing some changes and it seems as still it requires some fine tunning.

Should the text go to the left or to the right if you use RIGHT without a bitmap ?

Re: New bugs in TBtnBmp

PostPosted: Thu Oct 23, 2014 8:31 am
by Enrico Maria Giordano
Antonio Linares wrote:Enrico,

Sorry about this. We have been introducing some changes and it seems as still it requires some fine tunning.


Yes, but no problem my friend.

Antonio Linares wrote:Should the text go to the left or to the right if you use RIGHT without a bitmap ?


Why not? :-)

At least, that's how it used to work with the older TBtnBmp (before the remake).

EMG

Re: New bugs in TBtnBmp

PostPosted: Sat Nov 01, 2014 9:25 am
by Enrico Maria Giordano
This is a dirty and fast fix:

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

   local oRect
   local nTextTop, nTextHeight
   local nStyle   := DT_CENTER + DT_WORDBREAK + DT_TOP  // VCenter we do in the code
   local nBmpWidth
   local nBorderMargin  := If( ::lBarBtn, 2, 4 )
   local nBmpMargin     := 5
   local nClr, hOldFont    // for painting
   local lBmp           :=  !( ::lAdjust .or. Empty( ::hBmp ) ) // Leave space for bmp or not

   if ! Empty( ::cCaption )

      oRect          =  ::GetCliRect()
      nBmpWidth      =  If( lBmp, nBmpWidth( ::hBmp ) + nBmpMargin, 0 )
      nBmpWidth      =  Min( oRect:nWidth / 2 - nBorderMargin, nBmpWidth )

      WITH OBJECT oRect
         // Leave space for nBorderMargin, Space for Bmp and Popup

         :nTop       += nBorderMargin
         :nLeft      += ( nBorderMargin + If( ::nLayOut == LAYOUT_LEFT, nBmpWidth, 0 ) ) // BMP LEEFT
         :nBottom    -= nBorderMargin
         :nRight     -= ( nBorderMargin + If( ::oPopup == nil, 0, 12 ) + ;
                          If( ::nLayOut == LAYOUT_RIGHT, nBmpWidth, 0 ) )
      END

      hOldFont       = SelectObject( ::hDC, ::oFont:hFont )
      nTextHeight    =  DrawText( ::hDC, ::cCaption, oRect:aRect, nOr( DT_TOP + DT_CENTER, DT_WORDBREAK, DT_CALCRECT ) )

      if ( ! lBmp ) .or. ::nLayOut == LAYOUT_LEFT .or. ::nLayOut == LAYOUT_RIGHT .or. ::nLayOut == LAYOUT_CENTER
         // Center vertically if layout is LEFT/RIGHT or NO bitmap
         oRect:nTop  += Int( ( oRect:nHeight - nTextHeight ) / 2 )
      elseif ::nLayOut == LAYOUT_TOP
         // When bitmap is on top, paint text at bottom
         oRect:nTop  =  oRect:nBottom - nTextHeight - 1
      else

      endif

if !lBmp     // EMG
    oRect:nTop -= 1     // EMG
    nStyle = DT_LEFT + DT_WORDBREAK + DT_TOP     // EMG
endif     // EMG

      if ::lPressed

         // Move entire rect by one pixel to right and down
         oRect:MoveBy( 1, 1 )
      endif

      // Start painting now

      nClr        = If( ::IsEnabled(), ::nClrText, If( ::lDisColor, CLR_HGRAY, ::nClrTextDis ) )
      SetTextColor( ::hDC, XEval( nClr, ::lMOver ) )  // XEval Evals if nClr is 'B' else returns nClr
      SetBkMode( ::hDC, 1 )
      DrawText( ::hDC, ::cCaption, oRect:aRect, nStyle  )
      SelectObject( ::hDC, hOldFont )

      // Painting done

   endif

return nil


:-)

EMG

Re: New bugs in TBtnBmp

PostPosted: Sat Nov 01, 2014 11:54 am
by Antonio Linares
Enrico,

Many thanks :-)

is it working fine on other cases too ?

Re: New bugs in TBtnBmp

PostPosted: Sat Nov 01, 2014 11:59 am
by Enrico Maria Giordano
Antonio,

sorry, I don't know. It's only a quick and dirty fix. :-)

EMG

Re: New bugs in TBtnBmp

PostPosted: Sat Nov 01, 2014 12:02 pm
by Antonio Linares
Enrico,

ok, so lets wait for some feedback before including it in FWH :-)

many thanks

Re: New bugs in TBtnBmp

PostPosted: Sat Nov 01, 2014 12:11 pm
by Enrico Maria Giordano
Antonio,

at least we have to cope with right and center alignment. I've only aligned left if there is no bitmap defined.

EMG

Re: New bugs in TBtnBmp

PostPosted: Thu Nov 06, 2014 4:08 pm
by Enrico Maria Giordano
Another bug: bitmaps are slightly shifted up when oPopup is not defined.

Quick and dirty fix:

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

   local oBtnRect, oBmpRect, nTextHeight
   local nBorderMargin  := If( ::lBarBtn, 2, 0 )
   local hBmp, nTop, nLeft, nBmpHeight, nBmpWidth, hOldFont

   if Empty( ::hBmp )
      return nil
   endif

   oBtnRect    := ::GetCliRect()
   WITH OBJECT oBtnRect
      // Leave space for nBorderMargin, Space for Bmp and Popup
      :nTop       += nBorderMargin
      :nLeft      += nBorderMargin
      :nBottom    -= nBorderMargin
      :nRight     -= ( nBorderMargin + If( ::oPopup == nil, 0, 12 ) )
   END

   if ::lAdjust
      hBmp     =  ResizeBitmap( ::hBmp, ::nWidth, ::nHeight )
   elseif nBmpWidth( ::hBmp ) > oBtnRect:nWidth .or. nBmpHeight( ::hBmp ) > oBtnRect:nHeight
      hBmp     =  ResizeBitmap( ::hBmp, oBtnRect:nWidth * 1.1, oBtnRect:nHeight * 1.1, 3 ) // shrink to fit
   else
      hBmp     =  ::hBmp
   endif

   nBmpWidth   =  nBmpWidth(  hBmp )
   nBmpHeight  =  nBmpHeight( hBmp )
   // Center horizontally and vertically to start with
   nTop        =  oBtnRect:nTop  + ( oBtnRect:nHeight - nBmpHeight ) / 2
   nLeft       =  oBtnRect:nLeft + ( oBtnRect:nWidth  - nBmpWidth  ) / 2

   if ! Empty( ::cCaption )  // if there is no caption Bitmap is always centered
      hOldFont       =  SelectObject( ::hDC, ::oFont:hFont )
      nTextHeight    =  DrawText( ::hDC, ::cCaption, oBtnRect:aRect, nOr( DT_CENTER, DT_WORDBREAK, DT_CALCRECT ) )
      SelectObject( ::hDC, hOldFont )

      do case
      case ::nLayOut == LAYOUT_TOP
         nTop     =  oBtnRect:nTop + Max( ( oBtnRect:nHeight - nTextHeight - nBmpHeight ) / 2, 0 )
      case ::nLayOut == LAYOUT_LEFT
         nLeft    = oBtnRect:nLeft + 3 // flush left
      case ::nLayOut == LAYOUT_BOTTOM
         nTop     = oBtnRect:nBottom - ( oBtnRect:nHeight - nTextHeight - nBmpHeight ) / 2
         nTop     = Min( oBtnRect:nBottom - nBmpHeight, nTop )
      case ::nLayOut == LAYOUT_RIGHT
         nLeft    = oBtnRect:nRight - nBmpWidth - 3 // flush right
      endcase
   endif

   if ::oPopup = nil     // EMG
      nTop += 2     // EMG
   endif     // EMG
  ...


EMG

Re: New bugs in TBtnBmp

PostPosted: Sat Nov 15, 2014 4:07 pm
by Enrico Maria Giordano
This is better:

Code: Select all  Expand view
  if ::lBarBtn .and. ::oPopup = nil     // EMG
      nTop += 2     // EMG
   endif     // EMG
 


EMG

Re: New bugs in TBtnBmp

PostPosted: Sat Nov 15, 2014 5:35 pm
by Antonio Linares
Enrico,

Could you email me your modified btnbmp.prg? thanks :-)

Re: New bugs in TBtnBmp

PostPosted: Sat Nov 15, 2014 5:50 pm
by Enrico Maria Giordano
Done, my friend.

Please search for

// EMG

EMG

Re: New bugs in TBtnBmp

PostPosted: Sat Nov 15, 2014 6:05 pm
by Enrico Maria Giordano
But please, keep in mind that mine is not the correct fix, only a quick and dirty one to keep going with my work. :-)

EMG

Re: New bugs in TBtnBmp

PostPosted: Sat Nov 15, 2014 11:09 pm
by Antonio Linares
Enrico,

thanks! :-)

Re: New bugs in TBtnBmp

PostPosted: Tue Dec 09, 2014 10:38 am
by Enrico Maria Giordano
Any news? :-)

EMG