New bugs in TBtnBmp
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
New bugs in TBtnBmp
1. The RIGHT clause don't work anymore without a bitmap (texts are always centered).
2. Texts are slightly shifted down.
EMG
2. Texts are slightly shifted down.
EMG
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: New bugs in TBtnBmp
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 ?
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 ?
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: New bugs in TBtnBmp
Yes, but no problem my friend.Antonio Linares wrote:Enrico,
Sorry about this. We have been introducing some changes and it seems as still it requires some fine tunning.
Why not?Antonio Linares wrote:Should the text go to the left or to the right if you use RIGHT without a bitmap ?
At least, that's how it used to work with the older TBtnBmp (before the remake).
EMG
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: New bugs in TBtnBmp
This is a dirty and fast fix:
EMG
Code: Select all
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
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: New bugs in TBtnBmp
Enrico,
Many thanks
is it working fine on other cases too ?
Many thanks
is it working fine on other cases too ?
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: New bugs in TBtnBmp
Antonio,
sorry, I don't know. It's only a quick and dirty fix.
EMG
sorry, I don't know. It's only a quick and dirty fix.
EMG
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: New bugs in TBtnBmp
Enrico,
ok, so lets wait for some feedback before including it in FWH
many thanks
ok, so lets wait for some feedback before including it in FWH
many thanks
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: New bugs in TBtnBmp
Antonio,
at least we have to cope with right and center alignment. I've only aligned left if there is no bitmap defined.
EMG
at least we have to cope with right and center alignment. I've only aligned left if there is no bitmap defined.
EMG
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: New bugs in TBtnBmp
Another bug: bitmaps are slightly shifted up when oPopup is not defined.
Quick and dirty fix:
EMG
Quick and dirty fix:
Code: Select all
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
...
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: New bugs in TBtnBmp
This is better:
EMG
Code: Select all
if ::lBarBtn .and. ::oPopup = nil // EMG
nTop += 2 // EMG
endif // EMG
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: New bugs in TBtnBmp
Enrico,
Could you email me your modified btnbmp.prg? thanks
Could you email me your modified btnbmp.prg? thanks
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: New bugs in TBtnBmp
Done, my friend.
Please search for
// EMG
EMG
Please search for
// EMG
EMG
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: New bugs in TBtnBmp
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
EMG
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact: