It is currently Wed Jan 27, 2021 1:40 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Tue Jul 18, 2006 9:58 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8149
Location: Fort Nelson, BC, Canada
True, he missed a line:
Code:
    If StartDrawing(WindowOutput(0))
      DrawingFont(GetStockObject_(#DEFAULT_GUI_FONT))
      Length = TextWidth("Hahah")
      StopDrawing()
    EndIf

_________________
BERISHEET


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jul 18, 2006 10:00 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Jul 22, 2003 5:02 pm
Posts: 1542
Location: In a long distant galaxy
it works for me, just use DrawingFont() to calculate sizes from the correct font.

Code:
If OpenWindow(0,0,0,320,240,"test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
 
 
  FontID = GetStockObject_(#DEFAULT_GUI_FONT)
 
  text$ = "haha, hoho"
 
  hDC = GetDC_(WindowID(0))
  SelectObject_(hDC, FontID)
  GetTextExtentPoint32_(hDC, text$, Len(text$), sz.SIZE)
  ReleaseDC_(WindowID(0), hDC)
  Debug sz\cx
  Debug sz\cy
 
  StartDrawing(WindowOutput(0))
  DrawingFont(FontID)
  Debug TextWidth(text$)
  Debug TextHeight(text$)
  StopDrawing()
 
 
EndIf

_________________
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jul 18, 2006 10:01 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Jul 22, 2003 5:02 pm
Posts: 1542
Location: In a long distant galaxy
too fast for me netmaestro :wink:

_________________
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jul 18, 2006 10:04 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8149
Location: Fort Nelson, BC, Canada
I have speed but I don't think I'll ever have the legendary Flype thoroughness!

_________________
BERISHEET


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

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7446
Location: Norway
netmaestro wrote:
True, he missed a line:
Code:
    If StartDrawing(WindowOutput(0))
      DrawingFont(GetStockObject_(#DEFAULT_GUI_FONT))
      Length = TextWidth("Hahah")
      StopDrawing()
    EndIf
Yes, but not he uses API, and an API solution was already posted.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jul 18, 2006 11:11 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Jul 22, 2003 5:02 pm
Posts: 1542
Location: In a long distant galaxy
@trond
So just use FontID = GetGadgetFont(#Gadget) (when it's possible).
maybe a Get/SetWindowFont() would be useful ?

@netmaestro
ah yes, you're right. iwas not sure but now that you said it :
http://www.googlefight.com/index.php?lang=en_GB&word1=flype&word2=netmaestro
:lol:

i have to say that the 'trond' skills easily beats me :
http://www.googlefight.com/index.php?lang=en_GB&word1=flype&word2=trond

but, hey, who's the boss ?
http://www.googlefight.com/index.php?lang=en_GB&word1=fred&word2=trond

:wink:

_________________
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jul 27, 2006 6:21 pm 
Offline
Always Here
Always Here

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7446
Location: Norway
Flype wrote:
@trond
So just use FontID = GetGadgetFont(#Gadget) (when it's possible).

:wink:
Ingenious, thank you.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Dec 03, 2008 1:47 pm 
Offline
New User
New User

Joined: Wed Sep 21, 2005 2:43 pm
Posts: 9
Location: Germany
tried to make a handy procedure out of it, may be you like it.
Code:
Procedure writeTextGadget(GadgetLeft, GadgetTop, Text.s, GadgetNumber = #PB_Any, Flags = 0)
   ; creates a text-gadget sized according to its text
   ; returns gadget-number for #PB_Any or else gadget-id (as usual for gadget-creation)
   Protected ReturnValue
   
   ; to be able to use GetGadgetFont() when getting size gadget is created first and then resized
   ReturnValue = TextGadget(GadgetNumber, GadgetLeft, GadgetTop, 0, 0, Text, Flags)
   If GadgetNumber = #PB_Any
      GadgetNumber = ReturnValue
   EndIf
   
   If ReturnValue
      If StartDrawing(WindowOutput(GetActiveWindow()))
         DrawingFont(GetGadgetFont(GadgetNumber))
         ResizeGadget(GadgetNumber, #PB_Ignore, #PB_Ignore, TextWidth(Text), TextHeight(Text))
         StopDrawing()
         ProcedureReturn ReturnValue
      EndIf
   EndIf
   
   ProcedureReturn #False
EndProcedure


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 44 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