It is currently Sat Aug 17, 2019 1:59 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: PxLenght of Text in String/TextGadget
PostPosted: Mon May 26, 2003 11:13 am 
Offline
User
User

Joined: Mon May 26, 2003 10:53 am
Posts: 41
Location: Germany
Hi,

is there a way to determine the length (in pixels- not characters) of a text to be displayed in a StringGadget or TextGadget?

I want to display text of varying lengths in deactivated StringGadgets. Long Texts should be displayed in MultiLine Gadgets, short text in single lines to save space. Problem is, i dunno how to find out the number of lines i need for a given text.

thanx,
Searhin


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 26, 2003 12:08 pm 
Offline
TailBite Expert
TailBite Expert

Joined: Fri Apr 25, 2003 6:09 pm
Posts: 1007
Location: Spain
Code:
Procedure TextWidth(text$)
  GetTextExtentPoint32_(GetDC_(0), text$, Len(text$), sz.SIZE)
  ProcedureReturn sz\cx
EndProcedure

_________________
El_Choni


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 26, 2003 2:18 pm 
Offline
User
User

Joined: Mon May 26, 2003 10:53 am
Posts: 41
Location: Germany
WOW!

thanx - that's even easier than i thought :lol:


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 26, 2003 3:35 pm 
Offline
TailBite Expert
TailBite Expert

Joined: Fri Apr 25, 2003 6:09 pm
Posts: 1007
Location: Spain
Have in mind that it gives width for text with the default GUI font. If you change font, you should use this (after UseFont() or SetGadgetFont()):

Code:
Procedure TextWidth(text$, WindowID)
  hDC = GetDC_(WindowID)
  GetTextExtentPoint32_(hDC, text$, Len(text$), sz.SIZE)
  ReleaseDC_(WindowID, hDC)
  ProcedureReturn sz\cx
EndProcedure

_________________
El_Choni


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 26, 2003 4:55 pm 
Offline
User
User

Joined: Mon May 26, 2003 10:53 am
Posts: 41
Location: Germany
ah, okay - now it gives the correct results

thanx again


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 26, 2003 8:41 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13611
Location: France
None API based one:
Code:
If StartDrawing(WindowOutput())
  Length = TextLength("Hahah")
  StopDrawing()
EndIf


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 26, 2003 11:54 pm 
Offline
TailBite Expert
TailBite Expert

Joined: Fri Apr 25, 2003 6:09 pm
Posts: 1007
Location: Spain
:oops:

I had asked for this function several times, and it was already there. Sorry.

_________________
El_Choni


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2003 11:05 am 
Offline
User
User

Joined: Mon May 26, 2003 10:53 am
Posts: 41
Location: Germany
being most embarassed... :oops:


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2003 3:03 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13611
Location: France
No problem guys ;)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 27, 2003 5:06 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1356
A TextHeight(text$) - function would be nice.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed May 28, 2003 5:20 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> A TextHeight(text$) - function would be nice.

Try this:

http://forums.purebasic.com/english/vie ... php?t=3801

Not sure if it does what you want, but the value of "tm\tmHeight" that it
returns might be the height of the text. Give it a try...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed May 28, 2003 12:45 pm 
Offline
TailBite Expert
TailBite Expert

Joined: Fri Apr 25, 2003 6:09 pm
Posts: 1007
Location: Spain
This works with height, too:

Code:
Procedure TextHeight(text$, WindowID)
  hDC = GetDC_(WindowID)
  GetTextExtentPoint32_(hDC, text$, Len(text$), sz.SIZE)
  ReleaseDC_(WindowID, hDC)
  ProcedureReturn sz\cy
EndProcedure


Now, don't tell me there was also a TextHeight() command in PB ;)

_________________
El_Choni


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed May 28, 2003 1:12 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13611
Location: France
I guess it will be soon then ;)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 21, 2004 12:57 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Oct 20, 2004 7:16 pm
Posts: 238
Location: The Village
It would be better if we wouldn't have to do StartDrawing() and StopDrawing() to know the width in pixels of a text. It would be faster. Time is monay :-).

_________________
Be seeing you! :-)

Gansta93
If you speak french, you can visite Le Monde de Gansta93 (Gansta93's World)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jul 18, 2006 9:44 pm 
Offline
Always Here
Always Here

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7439
Location: Norway
Fred wrote:
None API based one:
Code:
If StartDrawing(WindowOutput())
  Length = TextLength("Hahah")
  StopDrawing()
EndIf
That doesn't do what he asked for because the default font inside StartDrawing() and StopDrawing() is different from the default GUI font.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye