New bugs in TBtnBmp

New bugs in TBtnBmp

Postby Enrico Maria Giordano » Wed Oct 22, 2014 6:03 pm

1. The RIGHT clause don't work anymore without a bitmap (texts are always centered).

2. Texts are slightly shifted down.

:-(

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: New bugs in TBtnBmp

Postby Antonio Linares » Thu Oct 23, 2014 6:37 am

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

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

Re: New bugs in TBtnBmp

Postby Enrico Maria Giordano » Thu Oct 23, 2014 8:31 am

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
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: New bugs in TBtnBmp

Postby Enrico Maria Giordano » Sat Nov 01, 2014 9:25 am

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
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: New bugs in TBtnBmp

Postby Antonio Linares » Sat Nov 01, 2014 11:54 am

Enrico,

Many thanks :-)

is it working fine on other cases too ?
regards, saludos

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

Re: New bugs in TBtnBmp

Postby Enrico Maria Giordano » Sat Nov 01, 2014 11:59 am

Antonio,

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: New bugs in TBtnBmp

Postby Antonio Linares » Sat Nov 01, 2014 12:02 pm

Enrico,

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

many thanks
regards, saludos

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

Re: New bugs in TBtnBmp

Postby Enrico Maria Giordano » Sat Nov 01, 2014 12:11 pm

Antonio,

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: New bugs in TBtnBmp

Postby Enrico Maria Giordano » Thu Nov 06, 2014 4:08 pm

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
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: New bugs in TBtnBmp

Postby Enrico Maria Giordano » Sat Nov 15, 2014 4:07 pm

This is better:

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


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: New bugs in TBtnBmp

Postby Antonio Linares » Sat Nov 15, 2014 5:35 pm

Enrico,

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

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

Re: New bugs in TBtnBmp

Postby Enrico Maria Giordano » Sat Nov 15, 2014 5:50 pm

Done, my friend.

Please search for

// EMG

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: New bugs in TBtnBmp

Postby Enrico Maria Giordano » Sat Nov 15, 2014 6:05 pm

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
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: New bugs in TBtnBmp

Postby Antonio Linares » Sat Nov 15, 2014 11:09 pm

Enrico,

thanks! :-)
regards, saludos

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


Next

Return to Bugs report & fixes / Informe de errores y arreglos

Who is online

Users browsing this forum: No registered users and 2 guests