FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour FWH 14.07 - TBtnBmp bug
Posts: 40
Joined: Fri Aug 22, 2014 06:21 AM
FWH 14.07 - TBtnBmp bug
Posted: Fri Aug 22, 2014 11:52 AM
Hi,

I upgraded to 14.07 r.2, and I now have a problem with TBtnBmp:
bitmap and text are not painted correctly using RIGHT or LEFT.

Code (fw): Select all Collapse
@ 08, 167 BTNBMP OF oDlg PROMPT "Nuovo Esame" ;
        FONT oFont SIZE 65,15 RIGHT RESOURCE "PASTE" PIXEL NOBORDER 2007


Thanks.
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: FWH 14.07 - TBtnBmp bug
Posted: Fri Aug 22, 2014 04:36 PM
Diego,

Recently we reorganized the Class TBtnBmp Method Paint() and it seems as we still had some painting bugs in it.

I have just fixed it and these are the required changes:

Code (fw): Select all Collapse
METHOD PaintCaption() CLASS TBtnBmp

   local nStyle, nClr
   local hOldFont, aRect, lMultiline, cWord, cWord2
   local nOffset, nMaxWidth, nLine
   local nTxtTop, nTxtLeft, nTxtRight
   local nTxtHeight, nAdjust := 0
   local nLayOut := ::nLayOut

   if ! Empty( ::cCaption )

      if ::oFont == nil
         ::GetFont()
      endif

      lMultiLine = ! Empty( ::cCaption ) .and. CRLF $ ::cCaption

      if lMultiLine
         cWord = cStrWord( ::cCaption, nOffset, CRLF )

         while nOffset < Len( ::cCaption )
            nMaxWidth = Max( nMaxWidth,;
                             Len( cWord2 := cStrWord( ::cCaption, @nOffset, CRLF ) ) )
            if Len( cWord ) < nMaxWidth
              cWord = cWord2
            endif
         end

         nLine = MLCount( ::cCaption )
      else
         cWord      = ::cCaption
         nTxtHeight = GetTextHeight( ::hWnd, ::hDC )
         nTxtTop    = ::nHeight / 2 - nTxtHeight / 2 
         nMaxWidth  = GetTextWidth( 0, cWord, ::oFont:hFont )
         nTxtLeft   = ::nWidth / 2 - nMaxWidth / 2
         nTxtRight  = ::nWidth / 2 + nMaxWidth / 2 
      endif

      if ::nLayout == 2 // LEFT
         nTxtLeft  += nBmpWidth( ::hBmp ) / 2 - 10
         nTxtRight += nBmpWidth( ::hBmp ) / 2 - 10
      endif
      
      if ::nLayout == 4 // RIGHT
         nTxtLeft  -= nBmpWidth( ::hBmp ) / 2 - 5
         nTxtRight -= nBmpWidth( ::hBmp ) / 2 - 5
      endif

      nStyle = nOr( If( ::nLayOut == 0, DT_CENTER, nLayOut ), DT_WORDBREAK ,;
                    If( ::nLayOut % 2 == 0, DT_VCENTER, DT_TOP ) )

      nClr = If( IsWindowEnabled( ::hWnd ), ::nClrText,;
                 If( ::lDisColor, CLR_HGRAY, ::nClrTextDis ) )

      SetTextColor( ::hDC, If( ValType( nClr ) == "B", Eval( nClr, ::lMOver ), nClr ) )
      SetBkMode( ::hDC, 1 )

      if ::oWnd:oFont != nil .or. ::oFont != nil
         hOldFont = SelectObject( ::hDC, ::oFont:hFont )
      endif

      if ::oPopup != nil
         nTxtRight -= 12
      endif

      aRect = { nTxtTop, nTxtLeft - nMaxWidth / 2, ::nHeight - 4, nTxtRight + nMaxWidth / 2 }
      
      lMultiLine = ( nTxtHeight := DrawText( ::hDC, ::cCaption, aRect,;
                     nOr( DT_WORDBREAK, DT_CALCRECT ) ) ) > ;
                     DrawText( ::hDC, ::cCaption, aRect, nOr( DT_SINGLELINE, DT_CALCRECT ) )

      if ::nLayOut == 1 // TOP
         nStyle     = nOr( DT_CENTER, DT_WORDBREAK )
         aRect[ 1 ] = aRect[ 3 ] - nTxtHeight
      endif

      if ::nLayOut == 3
         aRect[ 1 ] = 2
      endif

      if ::lPressed
         aRect[ 1 ]++
         aRect[ 2 ]++
         aRect[ 3 ]++
         aRect[ 4 ]++
      endif   

      DrawText( ::hDC, ::cCaption, aRect, nStyle  )

      SelectObject( ::hDC, hOldFont )
   endif

return nil


and
Code (fw): Select all Collapse
METHOD PaintBitmap() CLASS TBtnBmp

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

   if ! Empty( ::cCaption )
      nTop -= 10
   endif

   if ::oPopup != nil
      nLeft -= 6
   endif

   if ::nLayOut == 2 // LEFT
      nTop  += 10
      nLeft -= 35
   endif
   
   if ::nLayOut == 4 // RIGHT
      nTop  += 10
      nLeft += 35
   endif      

   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

return nil


If you left me know what C compiler you use, I will send you the modified libraries. Now I am going to flight for more than 11 hours (crossing the atlantic ocean), but along this weekend I may be able to send you the libs :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 40
Joined: Fri Aug 22, 2014 06:21 AM
Re: FWH 14.07 - TBtnBmp bug
Posted: Fri Aug 22, 2014 05:03 PM

Hi Antonio,

I compile with xHarbour.com

Thanks.

Continue the discussion