How to calc. the Len of a Textstring with a given Font ?

How to calc. the Len of a Textstring with a given Font ?

Postby ukoenig » Fri Apr 22, 2011 10:32 pm

Hello,

is it possible, to calculate the Len of a Text with a defined Font ?
I don't use a SAY !!!
The Reason for the Question :
1. For my new Image-info ( Right Mouseclick on a Image inside the Browser ),
I don't like to use a normal Alert. I created my own Style.
2. The longest Text will be the Info with Path- and Filename.
I must know the length of this Textline for the needed Width of the Alert.
I don't want to waste Space for the Length. The Height is fixed.

I created a new Function as a Alert-replacement.

Image

Best Regards
Uwe :?:
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
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: How to calc. the Len of a Textstring with a given Font ?

Postby nageswaragunupudi » Fri Apr 22, 2011 11:09 pm

oWnd:GetWidth( cText, oFont )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10489
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to calc. the Len of a Textstring with a given Font ?

Postby ukoenig » Sat Apr 23, 2011 12:24 am

Mr. Rao,

Thank You very much,
It works great.
Now the Alert-width is adjusted to the Textlength, like You can see in the Screenshots ( different Width ).

Image

Image

Code: Select all  Expand view

FUNCTION IMAGE_INFO()
LOCAL oDlg3, cMsgWidth := 300
LOCAL cPath := cFilePath( cImgname )
LOCAL cFile := cFileNoPath( cImgname )

DEFINE DIALOG oDlg3 FROM  90, 60 TO 310, cMsgWidth PIXEL TRANSPARENT ;
STYLE WS_POPUP BRUSH TBrush():New( "NULL" )

nPath := oDlg3:GetWidth( "Path   : " + cPath, oBigfont )
nFile :=  oDlg3:GetWidth( "Name : " + cFile, oBigfont )

// Testing both : Length of Path- and Filename
// ----------------------------------------------------
IF nPath >  nFile
    cMsgWidth := nPath + 60 // + 60 added for the Exit-button-position.
ELSE
    cMsgWidth := nFile + 60
ENDIF

ACTIVATE DIALOG oDlg3 ;
ON INIT ( SETTRANSP( oDlg3 ), ;
          oDlg3:Move( 90, 60, cMsgWidth, 270, .f. ), ;
          PAINT_TITLE(oDlg3,cPath,cFile,cMsgWidth) )

RETURN( NIL )

// ---------------------------
// maybe I will still add the Alpha-channel-info ( .F. or .T. ) !!!

FUNCTION PAINT_TITLE(oDlg3,cPath,cFile,cMsgWidth)
LOCAL oTitle, oImage

DEFINE IMAGE oImage FILENAME cImgname

@  0, 0 TITLE oTitle SIZE cMsgWidth, 190 OF oDlg3 SHADOW ROUND
oTitle:aGrdBack := {}
SET BRUSH OF oTitle TO oBrush3
oTitle:nClrLine1 := 8388608 // darkblue Border

@  30, 30  TITLETEXT OF oTitle TEXT "IMAGE-INFO : " FONT oBigfont  COLOR 8388608

@   70, 30  TITLETEXT OF oTitle TEXT "Path   : "  FONT oTxtfont  COLOR 8388608 // darkblue
@ 100, 30  TITLETEXT OF oTitle TEXT "Name : "  FONT oTxtfont  COLOR 8388608
@ 130, 30  TITLETEXT OF oTitle TEXT "Size   : "  FONT oTxtfont  COLOR 8388608

@    70, 90  TITLETEXT OF oTitle TEXT cPath  FONT oTxtfont  COLOR 128  // red
@  100, 90  TITLETEXT OF oTitle TEXT cFile    FONT oTxtfont  COLOR 128
@  130, 90  TITLETEXT OF oTitle TEXT ALLTRIM(STR(oImage:nWidth())) + " x " + ;
          ALLTRIM(STR(oImage:nHeight()))  FONT oTxtfont  COLOR 128

// calculated Exit-button-position
//-------------------------------------
@  110, cMsgWidth - 80 TITLEIMG OF oTitle BITMAP c_path + "\Bitmaps\Exit.bmp" TRANSPARENT ;  
ACTION oDlg3:End() 

oImage:End()

RETURN( NIL )

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

#define LWA_COLORKEY 1
#define GWL_EXSTYLE -20
#define WS_EX_LAYERED 524288

STATIC FUNCTION SETTRANSP( oDlg )

SETWINDOWLONG( oDlg:hWnd, GWL_EXSTYLE, ;
NOR( GETWINDOWLONG( oDlg:hWnd, GWL_EXSTYLE ), WS_EX_LAYERED ) )
SETLAYEREDWINDOWATTRIBUTES( oDlg:hWnd, , , LWA_COLORKEY )

RETURN NIL
 


Best 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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: How to calc. the Len of a Textstring with a given Font ?

Postby nageswaragunupudi » Sat Apr 23, 2011 2:44 am

Mr. Uwe

You do not have to write your own transparency function any more. FWH does it automatically by setting DATA of the Dialog.

Making a specific color transparent:
In this example below, CLR_RED is made transparent.
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oDlg

   DEFINE DIALOG oDlg SIZE 600,300 PIXEL TITLE "Transparent Dialog"

   oDlg:nSeeThroClr  := CLR_RED

   @ 30,30 SAY '' SIZE oDlg:nWidth/2-60,oDlg:nHeight/2-60 PIXEL OF oDlg ;
      COLOR CLR_BLACK,CLR_RED

   ACTIVATE DIALOG oDlg CENTERED

return nil
 

Screen shot: Background is seen instead of red color.
Image

Following example shows how to make the entire dialog translucent by setting oDlg:nOpacity := <nLevel>. 0 is for full transparency and 255 for full opacity. Any value in between decides the transparency level.
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oDlg

   DEFINE DIALOG oDlg SIZE 600,300 PIXEL TITLE "Transparent Dialog"

   oDlg:nOpacity  := 180

   ACTIVATE DIALOG oDlg CENTERED

return nil
 

Screenshot:
Image

We can vary the level of transparency ( rather opacity ) during runtime too to achieve fading effects.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10489
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to calc. the Len of a Textstring with a given Font ?

Postby ukoenig » Sat Apr 23, 2011 7:34 am

Mr. Rao,

Thank You very much.
It works up from FWH-release December 2010. I'm still working with a older one.
I will include both Solutions.

December 2010
=============

* New: TRNSPARENCY & TRANSLUCENCY OF Windows and Dialogs:

(a) oWnd:nOpacity := <nLevel> ( from 0 to 255 ) makes the Window ( normal or MDI frame ) or dialog transparent / translucent instantly.
nOpacity can be set anytime after creation of the window/dialog and even during runtime.
Level 0 is fully transparent and 255 is fully opaque.
:nOpacity := nil, turns off the transparency feature.
This does not work on child windows.
There is no way to set the nOpacity level to MDICHILD windows separately. nOpacity of MDIFRAME applies to all childwindows too.
(b) oWnd/oDlg:nSeeThroClr := <nColor> instantly makes the area with that color fully transparent (See Through). To turnoff, set :nSeeThroClr := nil.

Added Transparent-info to the Message :
Image

Added this Information to :
FUNCTION IMAGE_INFO()
Code: Select all  Expand view

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

FUNCTION IMAGE_INFO()
LOCAL oDlg3, cMsgWidth := 300
LOCAL cPath := cFilePath( cImgname )
LOCAL cFile := cFileNoPath( cImgname )

DEFINE DIALOG oDlg3 FROM  90, 60 TO 310, cMsgWidth PIXEL TRANSPARENT ;
STYLE WS_POPUP BRUSH TBrush():New( "NULL" )

// You can use for FWH > Release Dezember 20100
//-------------------------------------------------------------------
// DEFINE DIALOG oDlg3 FROM  90, 60 TO 310, cMsgWidth PIXEL
// oDlg3:nOpacity := 0

nPath := oDlg3:GetWidth( "Path   : " + cPath, oBigfont )
nFile :=  oDlg3:GetWidth( "Name : " + cFile, oBigfont )

IF nPath >  nFile
    cMsgWidth := nPath + 60
ELSE
    cMsgWidth := nFile + 60
ENDIF

ACTIVATE DIALOG oDlg3 ;
ON INIT ( SETTRANSP( oDlg3 ), ;
                oDlg3:Move( 90, 60, cMsgWidth, 270, .f. ), ;
                PAINT_TITLE(oDlg3,cPath,cFile,cMsgWidth) )

// You can use for FWH > Release Dezember 20100
//-------------------------------------------------------------------
// ACTIVATE DIALOG oDlg3 ;
// ON INIT ( oDlg3:Move( 90, 60, cMsgWidth, 270, .f. ), ;
//                 PAINT_TITLE(oDlg3,cPath,cFile,cMsgWidth) )

RETURN( NIL )
 


Best 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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: nageswaragunupudi, Otto and 57 guests