Sample ==> Vertical-Button-Text ( => Rochinha )

Post Reply
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Sample ==> Vertical-Button-Text ( => Rochinha )

Post by ukoenig »

Hello,

A working-sample, to create Buttons ( BMP ) with vertical-text.

Image

Code: Select all


oProgFont	:= TFont():New("Arial", ,-14,.F.,.F., , , ,.F.)
oBfont1	:= TFont():New("MS Sans Serif", ,-16, .F. ,.T., , , ,.F.)

DEFINE DIALOG oDlg RESOURCE "Tools" OF oWnd ;
TITLE  "BMP-Buttons" FONT oProgFont

// Test.BMP ( Brush not used )

REDEFINE BITMAP oBmp4  ID 210 ADJUST RESOURCE "Blanc"  OF oDlg 
oBmp4:bLClicked := {|| MsgAlert( "Your Function 1" ) }
oBmp4:bMMoved := { || cursorhand() } 

oBMP4:bPainted := { |hDC|OnPaintV( hDC,oBMP4, ;
13003573,15779475,0, ; 
"Vertical  Button", oBfont1, 0 ,"TEST.BMP" ,4 ) } 

REDEFINE BITMAP oBmp5  ID 220 ADJUST RESOURCE "Blanc"  OF oDlg 
oBmp5:bLClicked := {|| MsgAlert( "Your Function 2" ) }
oBmp5:bMMoved := { || cursorhand() } 

oBMP5:bPainted := { |hDC|OnPaintV( hDC,oBMP5, ;
13003573,15779475,0, ; 
"Vertical  Button", oBfont1, 0 ,"TEST.BMP" ,4 ) } 

REDEFINE BITMAP oBmp6  ID 230 ADJUST RESOURCE "Blanc"  OF oDlg 
oBmp6:bLClicked := {|| MsgAlert( "Your Function 3" ) }
oBmp6:bMMoved := { || cursorhand() } 

oBMP6:bPainted := { |hDC|OnPaintV( hDC,oBMP6, ;
13003573,15779475,0, ; 
"Vertical  Button", oBfont1, 0 ,"TEST.BMP" ,4 ) } 

ACTIVATE DIALOG oDlg CENTERED NOWAIT ;
ON INIT ( oDlg:Move( 70 , 50, oDlg:nWidth, oDlg:nHeight, .f.,) ) 

RETURN NIL   

//-------------------  VERTICAL ---------------------------------------------//  
 
FUNCTION ONPAINTV(hDC,oBmp,nVColor, nBColor,nColor,cText, ; 
                     oBfont1,nLEFT, cBRUSH, nPEN) 
LOCAL hOldFont, oNewbrush 
 
xDFONT :=  e_oBfont1 
hOldFont := SelectObject( hDC, oBfont1:hFont ) 
nTOP := 5 
nTXTLG :=  GettextWidth( hDC, cText ) 

nBMPWIDTH  := oBmp:Super:nWidth() 
nBMPLONG   := oBmp:Super:nHeight() 

nFONTHIGHT := oBfont1:nInpHeight * -1 
nFONTWIDTH := INT( e_oBfont1:nSize() ) 

nLEFT := (nBMPWIDTH - nTXTLG) / 2 
aRect := GETCLIENTRECT( oBmp:hWnd ) 
// .T.  Horizontal 
nGRADIENT := Gradient( hDC, aRect, nVColor, nBColor, .T. ) 
oBmp:oBrush := TBrush():New( , nGRADIENT )  
FillRect( hDC, aRect, oBmp:oBrush:hBrush ) 
SetBkMode( hDC, 0 )   // 1 = Transparent 
SetTextColor( hDC,nColor) 
nTOP := nFONTHIGHT / 2 
i := 1 
nBMPWIDTH1 := nBMPWIDTH / 2 
FOR i := 1 to len(cTEXT) 
     cCHAR := SUBSTR(cTEXT,i,1) 
     nCharWidth := GettextWidth( hDC, cCHAR ) 
     TextOut( hDC, nTOP, nBMPWIDTH1 - ( nCharWidth / 2 ),  cCHAR ) 
     IF !empty(cCHAR) 
            nTOP := nTOP + nFONTHIGHT 
     ELSE 
            nTOP := nTOP + ( nFONTHIGHT / 2 ) 
     ENDIF 
NEXT 
SelectObject( hDC, hOldFont ) 

nColor1 := 128  // Border-Color
IF nPEN > 0
   DRAWBOX( aRect, hDC, nColor1, ;
   nBMPLONG, nBMPWIDTH, nPEN )
ENDIF
 
RETURN NIL 

// ----------------------------------------

STATIC FUNCTION DRAWBOX( aRect, hDC, nColor1, ;
nBMPLONG, nBMPWIDHT, nPEN ) 
LOCAL hPen := CREATEPEN( PS_SOLID, nPEN, nColor1 ) 
LOCAL hOldPen := SELECTOBJECT( hDC, hPen ) 

MOVETO( hDC, 0, 0 ) 

LINETO( hDC, nBMPLONG, 0 ) 
LINETO( hDC, nBMPWIDHT, nBMPLONG ) 
LINETO( hDC, 0, nBMPLONG ) 
LINETO( hDC, 0, 0 ) 

DELETEOBJECT( hPen ) 

RETURN NIL

Regards
Uwe :lol:
Last edited by ukoenig on Fri Sep 12, 2008 1:47 pm, edited 3 times in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Uwe,

Well done!

However, I must say it seems much harder to read vertical text than horizontal text. Personally, I would avoid using vertical buttons.

Regards,
James
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Vertical Text

Post by ukoenig »

Hello James,

It was just a special question from Rochinha to do this.
Maybe it helps.

I would be nice, to have a < Button-effect > for Bitmaps.
oBmp:bLClicked := {|| MsgAlert( "Your Function" ) }
maybe it is possible, to add something in method < bLClicked >
changing bitmap-position a few pixel on mouse-click ?

Regards
Uwe :lol:
Last edited by ukoenig on Fri Sep 12, 2008 2:17 pm, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Uwe,

>It was just a special question from Rochinha to do this.

Yes, I saw the other message. It is just that when you actually see an example of the virtical button, it is apparent that it is hard to read.

>I would be nice, to have a < Button-effect > for Bitmaps.
>oBmp:bLClicked := {|| MsgAlert( "Your Function" ) }
>maybe it is possible, to add something in method < bLClicked >

See my answer to your question in another message thread.

Regards,
James
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Hand-cursor

Post by ukoenig »

James,

Thank you very much

< oBmp:bMMoved := { || cursorhand() } >

is included in the sample-source.

Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Post by Rochinha »

ukoenig,

Very nice and thanks!
Post Reply